From cf5f15c74a2ba8451126b8ebe089cf2b0df38758 Mon Sep 17 00:00:00 2001 From: Abhinav Upadhyay Date: Sat, 18 Feb 2012 20:32:38 +0530 Subject: [PATCH] Sync the code with version 1.1 when it was imported into the NetBSD CVS tree. --- Makefile | 25 +++++++++++++------------ apropos-utils.3 | 2 +- apropos-utils.c | 2 +- apropos.1 | 19 ++++++++++--------- apropos.c | 44 +++++++++++++++++++++++++++++++------------- close_db.3 | 2 +- init_db.3 | 2 +- makemandb.8 | 2 +- makemandb.c | 14 ++++++++++---- run_query.3 | 2 +- run_query_html.3 | 2 +- run_query_pager.3 | 2 +- whatis.1 | 2 +- whatis.c | 2 +- 14 files changed, 74 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index e51200d..040dbac 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,31 @@ +# $NetBSD: Makefile,v 1.1 2012/02/07 19:13:32 joerg Exp $ + .include MDIST= ${NETBSDSRCDIR}/external/bsd/mdocml/dist MDOCDIR=${NETBSDSRCDIR}/external/bsd/mdocml -PROGS= makemandb apropos -SRCS.makemandb= makemandb.c sqlite3.c apropos-utils.c -SRCS.apropos= apropos.c sqlite3.c apropos-utils.c -SRCS.whatis= whatis.c apropos-utils.c sqlite3.c -MAN= apropos-utils.3 init_db.3 close_db.3 run_query.3 run_query_html.3 run_query_pager.3 +PROGS= makemandb apropos whatis +SRCS.makemandb= makemandb.c apropos-utils.c +SRCS.apropos= apropos.c apropos-utils.c +SRCS.whatis= whatis.c apropos-utils.c MAN.makemandb= makemandb.8 MAN.apropos= apropos.1 MAN.whatis= whatis.1 -.PATH: ${MDIST} -CPPFLAGS+=-I${MDIST} -CPPFLAGS+=-DSQLITE_ENABLE_FTS3 -CPPFLAGS+=-DSQLITE_ENABLE_FTS3_PARENTHESIS +BINDIR.apropos= /usr/bin +BINDIR.makemandb= /usr/sbin +BINDIR.whatis= /usr/bin + +CPPFLAGS+=-I${MDIST} -I${.OBJDIR} MDOCMLOBJDIR!= cd ${MDOCDIR}/lib/libmandoc && ${PRINTOBJDIR} MDOCMLLIB= ${MDOCMLOBJDIR}/libmandoc.a DPADD.makemandb+= ${MDOCMLLIB} LDADD.makemandb+= -L${MDOCMLOBJDIR} -lmandoc -LDADD+= -lm -LDADD+= -lz -LDADD+= -lutil +DPADD+= ${LIBSQLITE3} ${LIBM} ${LIBZ} ${LIBUTIL} +LDADD+= -lsqlite3 -lm -lz -lutil stopwords.c: stopwords.txt ( set -e; ${TOOL_NBPERF} -n stopwords_hash -s -p ${.ALLSRC}; \ diff --git a/apropos-utils.3 b/apropos-utils.3 index 198efc7..7aeeb23 100644 --- a/apropos-utils.3 +++ b/apropos-utils.3 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: apropos-utils.3,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/apropos-utils.c b/apropos-utils.c index 8118ddb..35af789 100644 --- a/apropos-utils.c +++ b/apropos-utils.c @@ -31,7 +31,7 @@ */ #include -__RCSID("$NetBSD$"); +__RCSID("$NetBSD: apropos-utils.c,v 1.1 2012/02/07 19:13:32 joerg Exp $"); #include diff --git a/apropos.1 b/apropos.1 index 7269f67..c6032de 100644 --- a/apropos.1 +++ b/apropos.1 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: apropos.1,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. @@ -29,7 +29,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 22, 2012 +.Dd February 6, 2012 .Dt APROPOS 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd search the complete content of all man pages .Sh SYNOPSIS .Nm -.Op Fl 123456789p +.Op Fl 123456789Ccp .Op Fl n Ar Number of results .Op Fl S Ar machine .Ar query @@ -81,13 +81,15 @@ Search only within section 7 manual pages. Search only within section 8 manual pages. .It Fl 9 Search only within section 9 manual pages. +.It Fl C +Do not show the context of the match. +.It Fl c +Do show the context of the match (default). .It Fl n -Output only the specified number of search results. -This option can be used to override the default limit of maximum 10 results per -query. +Output up to the specified number of search results. +The default limit is 10. .It Fl p -Display all matching results (instead of the default of 10) -and pipe them through a pager (defaulting to +Display all matching results and pipe them through a pager (defaulting to .Xr more 1 ) . .It Fl S Limit the search to the pages for the specified machine architecture. @@ -103,4 +105,3 @@ The Sqlite FTS database which contains an index of the manual pages. .Xr man 1 .Sh AUTHORS .An Abhinav Upadhyay - diff --git a/apropos.c b/apropos.c index d74a9a1..e0a551f 100644 --- a/apropos.c +++ b/apropos.c @@ -31,7 +31,7 @@ */ #include -__RCSID("$NetBSD$"); +__RCSID("$NetBSD: apropos.c,v 1.1 2012/02/07 19:13:32 joerg Exp $"); #include #include @@ -48,12 +48,14 @@ typedef struct apropos_flags { int sec_nums[SECMAX]; int nresults; int pager; + int no_context; const char *machine; } apropos_flags; typedef struct callback_data { int count; FILE *out; + apropos_flags *aflags; } callback_data; static char *remove_stopwords(const char *); @@ -61,19 +63,25 @@ static int query_callback(void *, const char * , const char *, const char *, const char *, size_t); __dead static void usage(void); +#define _PATH_PAGER "/usr/bin/more -s" + int main(int argc, char *argv[]) { +#ifdef NOTYET + static const char *snippet_args[] = {"\033[1m", "\033[0m", "..."}; +#endif + query_args args; char *query = NULL; // the user query char ch; char *errmsg = NULL; char *str; int rc = 0; callback_data cbdata; - const char *snippet_args[] = {"\033[1m", "\033[0m", "..."}; cbdata.out = stdout; // the default output stream cbdata.count = 0; apropos_flags aflags; + cbdata.aflags = &aflags; sqlite3 *db; setprogname(argv[0]); if (argc < 2) @@ -85,7 +93,7 @@ main(int argc, char *argv[]) * index element in sec_nums is set to the string representing that * section number. */ - while ((ch = getopt(argc, argv, "123456789n:pS:")) != -1) { + while ((ch = getopt(argc, argv, "123456789Ccn:pS:")) != -1) { switch (ch) { case '1': case '2': @@ -98,6 +106,12 @@ main(int argc, char *argv[]) case '9': aflags.sec_nums[atoi(&ch) - 1] = 1; break; + case 'C': + aflags.no_context = 1; + break; + case 'c': + aflags.no_context = 0; + break; case 'n': aflags.nresults = atoi(optarg); break; @@ -136,14 +150,16 @@ main(int argc, char *argv[]) /* If user wants to page the output, then set some settings */ if (aflags.pager) { + const char *pager = getenv("PAGER"); + if (pager == NULL) + pager = _PATH_PAGER; /* Open a pipe to the pager */ - if ((cbdata.out = popen("more", "w")) == NULL) { + if ((cbdata.out = popen(pager, "w")) == NULL) { close_db(db); err(EXIT_FAILURE, "pipe failed"); } } - query_args args; args.search_str = query; args.sec_nums = aflags.sec_nums; args.nrec = aflags.nresults ? aflags.nresults : 10; @@ -153,12 +169,11 @@ main(int argc, char *argv[]) args.callback_data = &cbdata; args.errmsg = &errmsg; - if (aflags.pager) { - rc = run_query_pager(db, &args); - pclose(cbdata.out); - } else { - rc = run_query(db, snippet_args, &args); - } +#ifdef NOTYET + rc = run_query(db, snippet_args, &args); +#else + rc = run_query_pager(db, &args); +#endif free(query); close_db(db); @@ -195,8 +210,11 @@ query_callback(void *data, const char *section, const char *name, callback_data *cbdata = (callback_data *) data; FILE *out = cbdata->out; cbdata->count++; - fprintf(out, "%s(%s)\t%s\n%s\n\n", name, section, name_desc, - snippet); + fprintf(out, "%s(%s)\t%s\n", name, section, name_desc); + + if (cbdata->aflags->no_context == 0) + fprintf(out, "%s\n\n", snippet); + return 0; } diff --git a/close_db.3 b/close_db.3 index ac87548..439e947 100644 --- a/close_db.3 +++ b/close_db.3 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: close_db.3,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/init_db.3 b/init_db.3 index 4174d98..bee7241 100644 --- a/init_db.3 +++ b/init_db.3 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: init_db.3,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/makemandb.8 b/makemandb.8 index a3df9d8..c23c6fa 100644 --- a/makemandb.8 +++ b/makemandb.8 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: makemandb.8,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/makemandb.c b/makemandb.c index 3f7b682..b55121b 100644 --- a/makemandb.c +++ b/makemandb.c @@ -17,7 +17,7 @@ */ #include -__RCSID("$NetBSD$"); +__RCSID("$NetBSD: makemandb.c,v 1.1 2012/02/07 19:13:32 joerg Exp $"); #include #include @@ -1071,9 +1071,12 @@ pman_parse_name(const struct man_node *n, mandb_rec *rec) if (n == NULL) return; - if (n->type == MAN_TEXT) - concat(&rec->name_desc, n->string); - + if (n->type == MAN_TEXT) { + char *tmp = parse_escape(n->string); + concat(&rec->name_desc, tmp); + free(tmp); + } + if (n->child) pman_parse_name(n->child, rec); @@ -1875,6 +1878,9 @@ parse_escape(const char *str) } while (backslash != NULL); if (last_backslash != NULL) strcpy(iter, last_backslash); + iter = result; + while ((iter = strchr(iter, ASCII_HYPH)) != NULL) + *iter = '-'; return result; } diff --git a/run_query.3 b/run_query.3 index f38d55c..cf971fa 100644 --- a/run_query.3 +++ b/run_query.3 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: run_query.3,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/run_query_html.3 b/run_query_html.3 index 98f4730..276a491 100644 --- a/run_query_html.3 +++ b/run_query_html.3 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: run_query_html.3,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/run_query_pager.3 b/run_query_pager.3 index d9808e6..17157da 100644 --- a/run_query_pager.3 +++ b/run_query_pager.3 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: run_query_pager.3,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2011 Abhinav Upadhyay .\" All rights reserved. diff --git a/whatis.1 b/whatis.1 index 8dc77cd..4660b5a 100644 --- a/whatis.1 +++ b/whatis.1 @@ -1,4 +1,4 @@ -.\" $NetBSD$ +.\" $NetBSD: whatis.1,v 1.1 2012/02/07 19:13:32 joerg Exp $ .\" .\" Copyright (c) 2012 Joerg Sonnenberger .\" All rights reserved. diff --git a/whatis.c b/whatis.c index d73f470..fd2e62c 100644 --- a/whatis.c +++ b/whatis.c @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD$"); +__RCSID("$NetBSD: whatis.c,v 1.1 2012/02/07 19:13:32 joerg Exp $"); #include #include