NAME

run_query_pager - run a query against /var/db/man.db and returns the results in a format which can be piped to a pager

SYNOPSIS



int run_query_pager(sqlite3 *db, query_args *args)

DESCRIPTION

The run_query_pager() is very similar to run_query_html(3) but with following two differences.

  1. run_query_pager will return a 5 column result set, much like run_query(3)

  2. The snippet returned by run_query_pager in the callback function is in a format so that the matching text appears highlighted when piped to a pager.
For more details, refer to the manual page of run_query(3).

RETURN VALUES

On successful execution the run_query_pager() function will return 0 and in case of an error -1 will be returned.

FILES

/var/db/man.db
The Sqlite FTS database which contains an index of the manual pages.

EXAMPLES

Following is a code excerpt of how run_query_pager can be used.
#include 
query_args args;
FILE *pager = popen("more", "w");
char *errmsg = NULL;
const char **sec_nums = {NULL, "2", "3", NULL, NULL, NULL, NULL, NULL, NULL};
args.search_str = argv[1];
args.sec_nums = sec_nums;
args.nrec = "10";
args.callback = &query_callback;
args.callback_data = (void *)pager;
args.errmsg = &errmsg;
if (run_query(db, &args) < 0)
                errx(EXIT_FAILURE, "%s", errmsg);
}
        

free(query); free(errmsg); pclose(pager);

static int query_callback(void *data, int ncol, char **col_values, char **col_names) { FILE *out = (FILE *) data; char *html_result = col_values[0]; fprintf(out, "%s\n", html_result); return 0; }

SEE ALSO

apropos-utils(3), close_db(3), init_db(3), run_query(3), run_query_html(3)

AUTHORS

Abhinav Upadhyay

Get NetBSD Summer of Code projects at SourceForge.net. Fast, secure and Free Open Source software downloads
Abhinav Upadhyay <er.abhinav.upadhyay at gmail dot com>
$Id: run_query_pager.html3,v 1.2 2011/08/25 06:52:59 abhinavupadhyay Exp $