Skip to content

Commit

Permalink
Change the type of the snippet_length argument of the run_query funct…
Browse files Browse the repository at this point in the history
…ions from int to size_t.

Update the man pages as well.
  • Loading branch information
abhinav-upadhyay committed Dec 3, 2011
1 parent 1b7b3d8 commit c4b17c0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
10 changes: 5 additions & 5 deletions apropos-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
typedef struct orig_callback_data {
void *data;
int (*callback) (void *, const char *, const char *, const char *,
const char *, int);
const char *, size_t);
} orig_callback_data;

typedef struct inverse_document_frequency {
Expand Down Expand Up @@ -514,15 +514,15 @@ run_query(sqlite3 *db, const char *snippet_args[3], query_args *args)
*/
static int
callback_html(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, int snippet_length)
const char *name_desc, const char *snippet, size_t snippet_length)
{
char *temp = (char *) snippet;
int i = 0;
int sz = 0;
size_t sz = 0;
int count = 0;
struct orig_callback_data *orig_data = (struct orig_callback_data *) data;
int (*callback) (void *, const char *, const char *, const char *,
const char *, int) = orig_data->callback;
const char *, size_t) = orig_data->callback;

/* First scan the snippet to find out the number of occurrences of {'>', '<'
* '"', '&'}.
Expand Down Expand Up @@ -663,7 +663,7 @@ pager_highlight(char *str)
*/
static int
callback_pager(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, int snippet_length)
const char *name_desc, const char *snippet, size_t snippet_length)
{
struct orig_callback_data *orig_data = (struct orig_callback_data *) data;
(orig_data->callback)(orig_data->data, section, name, name_desc, snippet,
Expand Down
2 changes: 1 addition & 1 deletion apropos-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef struct query_args {
int nrec; // number of records to fetch
int offset; //From which position to start processing the records
int (*callback) (void *, const char *, const char *, const char *,
const char *, int); // The callback function
const char *, size_t); // The callback function
void *callback_data; // data to pass to the callback function
char **errmsg; // buffer for storing the error msg
} query_args;
Expand Down
4 changes: 2 additions & 2 deletions apropos.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef struct callback_data {

static void remove_stopwords(char **);
static int query_callback(void *, const char * , const char *, const char *,
const char *, int);
const char *, size_t);
__dead static void usage(void);

int
Expand Down Expand Up @@ -186,7 +186,7 @@ main(int argc, char *argv[])
*/
static int
query_callback(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, int snippet_length)
const char *name_desc, const char *snippet, size_t snippet_length)
{
callback_data *cbdata = (callback_data *) data;
FILE *out = cbdata->out;
Expand Down
10 changes: 5 additions & 5 deletions run_query.3
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 02, 2011
.Dd December 03, 2011
.Dt RUN_QUERY 3
.Os
.Sh NAME
Expand Down Expand Up @@ -121,7 +121,7 @@ n records from the result-set will be omitted and rest m-n (or less) records wil
be available for processing inside the callback.
Use a negative value if you don't wish to offset any records.
.It Li int (*callback) (void *, const char *, const char *, const char *,\
const char *, int)
const char *, size_t)
This is the callback function which will
be called for each row retrieved from the database.
The function should return a value of 0 on successful execution.
Expand Down Expand Up @@ -151,7 +151,7 @@ then the caller should make sure to free it.
The interface of the callback function is
.Ft int
.Fn (*callback) "void *callback_data" "const char *section" "const char *name"\
"const char *name_desc" "const char *snippet" "int snippet_length"
"const char *name_desc" "const char *snippet" "size_t snippet_length"
.Pp
Its arguments are:
.Bl -column -offset indent "Function" "Argument Description"
Expand All @@ -163,7 +163,7 @@ page belongs.
page obtained from it's NAME section.
.It Li const char *snippet Ta This is a snippet of the matching text from this
man page.
.It Li int snippet_length Ta This is the length of the snippet.
.It Li size_t snippet_length Ta This is the length of the snippet.
.El
.Sh RETURN VALUES
On successful execution the
Expand Down Expand Up @@ -200,7 +200,7 @@ free(errmsg);

static int
query_callback(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, int snippet_length )
const char *name_desc, const char *snippet, size_t snippet_length )
{
/* The user supplied data could be obtained as follows */
// my_data *buf = (my_data *) data;
Expand Down
4 changes: 2 additions & 2 deletions run_query_html.3
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 02, 2011
.Dd December 03, 2011
.Dt RUN_QUERY_HTML 3
.Os
.Sh NAME
Expand Down Expand Up @@ -99,7 +99,7 @@ free(errmsg);

static int
query_callback(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, int snippet_length)
const char *name_desc, const char *snippet, size_t snippet_length)
{
fprintf(stdout, "%s(%s)\t%s\en%s\en\en", name, section, name_desc,
snippet);
Expand Down
24 changes: 8 additions & 16 deletions run_query_pager.3
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd August 19, 2011
.Dd December 03, 2011
.Dt RUN_QUERY_PAGER 3
.Os
.Sh NAME
Expand All @@ -47,18 +47,9 @@ The
.Fn run_query_pager
is very similar to
.Xr run_query_html 3
but with following two differences.
.Bl -enum -offset indent
.It
.Nm
will return a 5 column result set, much like
.Xr run_query 3
.It
The snippet returned by
.Nm
in the callback function is in a format so that the matching text appears
highlighted when piped to a pager.
.El
with the only difference that the snippet returned is formatted in a manner so
that the matching text in it appears highlighted when viewed using a pager.
.Pp
For more details, refer to the manual page of
.Xr run_query 3 .
.Sh RETURN VALUES
Expand Down Expand Up @@ -96,11 +87,12 @@ free(errmsg);
pclose(pager);

static int
query_callback(void *data, int ncol, char **col_values, char **col_names)
query_callback(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, size_t snippet_length)
{
FILE *out = (FILE *) data;
char *html_result = col_values[0];
fprintf(out, "%s\en", html_result);
fprintf(out, "%s(%s)\t%s\en%s\en\en", name, section, name_desc,
snippet);
return 0;
}
.Ed
Expand Down

0 comments on commit c4b17c0

Please sign in to comment.