Skip to content

Commit

Permalink
Sync the code with version 1.1 when it was imported into the NetBSD C…
Browse files Browse the repository at this point in the history
…VS tree.
  • Loading branch information
abhinav-upadhyay committed Feb 18, 2012
1 parent 67e6778 commit cf5f15c
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 48 deletions.
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# $NetBSD: Makefile,v 1.1 2012/02/07 19:13:32 joerg Exp $

.include <bsd.own.mk>

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}; \
Expand Down
2 changes: 1 addition & 1 deletion apropos-utils.3
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion apropos-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD$");
__RCSID("$NetBSD: apropos-utils.c,v 1.1 2012/02/07 19:13:32 joerg Exp $");

#include <sys/stat.h>

Expand Down
19 changes: 10 additions & 9 deletions apropos.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $NetBSD$
.\" $NetBSD: apropos.1,v 1.1 2012/02/07 19:13:32 joerg Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <[email protected]>
.\" All rights reserved.
Expand Down Expand Up @@ -29,15 +29,15 @@
.\" 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
.Nm apropos
.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
Expand Down Expand Up @@ -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.
Expand All @@ -103,4 +105,3 @@ The Sqlite FTS database which contains an index of the manual pages.
.Xr man 1
.Sh AUTHORS
.An Abhinav Upadhyay

44 changes: 31 additions & 13 deletions apropos.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD$");
__RCSID("$NetBSD: apropos.c,v 1.1 2012/02/07 19:13:32 joerg Exp $");

#include <err.h>
#include <search.h>
Expand All @@ -48,32 +48,40 @@ 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 *);
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)
Expand All @@ -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':
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion close_db.3
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion init_db.3
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion makemandb.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $NetBSD$
.\" $NetBSD: makemandb.8,v 1.1 2012/02/07 19:13:32 joerg Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <[email protected]>
.\" All rights reserved.
Expand Down
14 changes: 10 additions & 4 deletions makemandb.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD$");
__RCSID("$NetBSD: makemandb.c,v 1.1 2012/02/07 19:13:32 joerg Exp $");

#include <sys/stat.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion run_query.3
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion run_query_html.3
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion run_query_pager.3
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion whatis.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $NetBSD$
.\" $NetBSD: whatis.1,v 1.1 2012/02/07 19:13:32 joerg Exp $
.\"
.\" Copyright (c) 2012 Joerg Sonnenberger <[email protected]>
.\" All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion whatis.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD$");
__RCSID("$NetBSD: whatis.c,v 1.1 2012/02/07 19:13:32 joerg Exp $");

#include <err.h>
#include <stdio.h>
Expand Down

0 comments on commit cf5f15c

Please sign in to comment.