summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-08-17 03:24:47 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-08-17 03:24:47 +0000
commite88e13e117e3b7d9de27952e40bb54cc9f589074 (patch)
treea2409683c88f57d8151056a5e42519a2886d87f4
parente787f86b365b1779d9ea4b2c1b4b35617a18d0ba (diff)
downloadmandoc-e88e13e117e3b7d9de27952e40bb54cc9f589074.tar.gz
Fully integrate apropos(1) into mandoc(1).
Switch the argmode on the progname, including man(1). Provide -f and -k options to switch the argmode. Store the argmode inside struct search, generalizing the flags. Derive the deftype from the argmode when needed instead of storing it. Store the outkey inside struct search instead of passing it alone. While here, get rid of the trailing blanks in Makefile.depend.
-rw-r--r--Makefile8
-rw-r--r--Makefile.depend37
-rw-r--r--apropos.c123
-rw-r--r--cgi.c6
-rw-r--r--main.c155
-rw-r--r--manpage.c5
-rw-r--r--mansearch.c55
-rw-r--r--mansearch.h19
8 files changed, 189 insertions, 219 deletions
diff --git a/Makefile b/Makefile
index 0a699c62..cf68fa72 100644
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,7 @@ TESTSRCS = test-dirent-namlen.c \
test-strsep.c \
test-wchar.c
-SRCS = apropos.c \
- arch.c \
+SRCS = arch.c \
att.c \
cgi.c \
chars.c \
@@ -228,7 +227,7 @@ MAKEWHATIS_OBJS = mandocdb.o mansearch_const.o manpath.o
PRECONV_OBJS = preconv.o
-APROPOS_OBJS = apropos.o mansearch.o mansearch_const.o manpath.o
+APROPOS_OBJS = mansearch.o mansearch_const.o manpath.o
CGI_OBJS = $(MANDOC_HTML_OBJS) \
cgi.o \
@@ -369,7 +368,8 @@ Makefile.local config.h: configure ${TESTSRCS}
depend: config.h
mkdep -f Makefile.depend $(CFLAGS) $(SRCS)
perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \
- s|\\\n||g; s| +| |g; print;' Makefile.depend > Makefile.tmp
+ s|\\\n||g; s| +| |g; s| $$||mg; print;' \
+ Makefile.depend > Makefile.tmp
mv Makefile.tmp Makefile.depend
libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
diff --git a/Makefile.depend b/Makefile.depend
index 5f2e40fa..9ac53738 100644
--- a/Makefile.depend
+++ b/Makefile.depend
@@ -1,4 +1,3 @@
-apropos.o: apropos.c config.h manpath.h mansearch.h
arch.o: arch.c config.h mdoc.h libmdoc.h arch.in
att.o: att.c config.h mdoc.h libmdoc.h att.in
cgi.o: cgi.c config.h mandoc.h mandoc_aux.h main.h manpath.h mansearch.h cgi.h
@@ -6,7 +5,7 @@ chars.o: chars.c config.h mandoc.h mandoc_aux.h libmandoc.h chars.in
compat_fgetln.o: compat_fgetln.c config.h
compat_fts.o: compat_fts.c config.h compat_fts.h
compat_getsubopt.o: compat_getsubopt.c config.h
-compat_ohash.o: compat_ohash.c config.h
+compat_ohash.o: compat_ohash.c config.h compat_ohash.h
compat_reallocarray.o: compat_reallocarray.c config.h
compat_sqlite3_errstr.o: compat_sqlite3_errstr.c config.h
compat_strcasestr.o: compat_strcasestr.c config.h
@@ -19,7 +18,7 @@ eqn_html.o: eqn_html.c config.h mandoc.h out.h html.h
eqn_term.o: eqn_term.c config.h mandoc.h out.h term.h
html.o: html.c config.h mandoc.h mandoc_aux.h libmandoc.h out.h html.h main.h
lib.o: lib.c config.h mdoc.h libmdoc.h lib.in
-main.o: main.c config.h mandoc.h mandoc_aux.h main.h mdoc.h man.h
+main.o: main.c config.h mandoc.h mandoc_aux.h main.h mdoc.h man.h manpath.h mansearch.h
man.o: man.c config.h man.h mandoc.h mandoc_aux.h libman.h libmandoc.h
man_hash.o: man_hash.c config.h man.h mandoc.h libman.h
man_html.o: man_html.c config.h mandoc.h mandoc_aux.h out.h html.h man.h main.h
@@ -28,10 +27,10 @@ man_term.o: man_term.c config.h mandoc.h mandoc_aux.h out.h man.h term.h main.h
man_validate.o: man_validate.c config.h man.h mandoc.h mandoc_aux.h libman.h libmandoc.h
mandoc.o: mandoc.c config.h mandoc.h mandoc_aux.h libmandoc.h
mandoc_aux.o: mandoc_aux.c config.h mandoc.h mandoc_aux.h
-mandocdb.o: mandocdb.c config.h compat_fts.h mdoc.h man.h mandoc.h mandoc_aux.h manpath.h mansearch.h
+mandocdb.o: mandocdb.c config.h compat_fts.h compat_ohash.h mdoc.h man.h mandoc.h mandoc_aux.h manpath.h mansearch.h
manpage.o: manpage.c config.h manpath.h mansearch.h
manpath.o: manpath.c config.h mandoc_aux.h manpath.h
-mansearch.o: mansearch.c config.h mandoc.h mandoc_aux.h manpath.h mansearch.h
+mansearch.o: mansearch.c config.h compat_ohash.h mandoc.h mandoc_aux.h manpath.h mansearch.h
mansearch_const.o: mansearch_const.c config.h manpath.h mansearch.h
mdoc.o: mdoc.c config.h mdoc.h mandoc.h mandoc_aux.h libmdoc.h libmandoc.h
mdoc_argv.o: mdoc_argv.c config.h mdoc.h mandoc.h mandoc_aux.h libmdoc.h libmandoc.h
@@ -43,7 +42,7 @@ mdoc_term.o: mdoc_term.c config.h mandoc.h mandoc_aux.h out.h term.h mdoc.h main
mdoc_validate.o: mdoc_validate.c config.h mdoc.h mandoc.h mandoc_aux.h libmdoc.h libmandoc.h
msec.o: msec.c config.h mandoc.h libmandoc.h msec.in
out.o: out.c config.h mandoc_aux.h mandoc.h out.h
-preconv.o: preconv.c config.h
+preconv.o: preconv.c config.h
read.o: read.c config.h mandoc.h mandoc_aux.h libmandoc.h mdoc.h man.h main.h
roff.o: roff.c config.h mandoc.h mandoc_aux.h libroff.h libmandoc.h predefs.in
st.o: st.c config.h mdoc.h libmdoc.h st.in
@@ -58,14 +57,18 @@ term_ascii.o: term_ascii.c config.h mandoc.h mandoc_aux.h out.h term.h main.h
term_ps.o: term_ps.c config.h mandoc.h mandoc_aux.h out.h main.h term.h
tree.o: tree.c config.h mandoc.h mdoc.h man.h main.h
vol.o: vol.c config.h mdoc.h libmdoc.h vol.in
-test-fgetln.o: test-fgetln.c
-test-getsubopt.o: test-getsubopt.c
-test-mmap.o: test-mmap.c
-test-ohash.o: test-ohash.c
-test-reallocarray.o: test-reallocarray.c
-test-sqlite3_errstr.o: test-sqlite3_errstr.c
-test-strcasestr.o: test-strcasestr.c
-test-strlcat.o: test-strlcat.c
-test-strlcpy.o: test-strlcpy.c
-test-strptime.o: test-strptime.c
-test-strsep.o: test-strsep.c
+test-dirent-namlen.o: test-dirent-namlen.c
+test-fgetln.o: test-fgetln.c
+test-fts.o: test-fts.c
+test-getsubopt.o: test-getsubopt.c
+test-mmap.o: test-mmap.c
+test-ohash.o: test-ohash.c
+test-reallocarray.o: test-reallocarray.c
+test-sqlite3.o: test-sqlite3.c
+test-sqlite3_errstr.o: test-sqlite3_errstr.c
+test-strcasestr.o: test-strcasestr.c
+test-strlcat.o: test-strlcat.c
+test-strlcpy.o: test-strlcpy.c
+test-strptime.o: test-strptime.c
+test-strsep.o: test-strsep.c
+test-wchar.o: test-wchar.c
diff --git a/apropos.c b/apropos.c
deleted file mode 100644
index 66a83733..00000000
--- a/apropos.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/* $Id$ */
-/*
- * Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-#include "config.h"
-
-#include <sys/param.h>
-#include <sys/types.h>
-
-#include <assert.h>
-#include <getopt.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "manpath.h"
-#include "mansearch.h"
-
-
-int
-apropos(int argc, char *argv[])
-{
- int ch, whatis;
- struct mansearch search;
- size_t i, sz;
- struct manpage *res;
- struct manpaths paths;
- char *defpaths, *auxpaths;
- char *conf_file;
- char *progname;
- const char *outkey;
- extern char *optarg;
- extern int optind;
-
- progname = strrchr(argv[0], '/');
- if (progname == NULL)
- progname = argv[0];
- else
- ++progname;
-
- whatis = (0 == strncmp(progname, "whatis", 6));
-
- memset(&paths, 0, sizeof(struct manpaths));
- memset(&search, 0, sizeof(struct mansearch));
-
- auxpaths = defpaths = NULL;
- conf_file = NULL;
- outkey = "Nd";
-
- while (-1 != (ch = getopt(argc, argv, "C:M:m:O:S:s:")))
- switch (ch) {
- case 'C':
- conf_file = optarg;
- break;
- case 'M':
- defpaths = optarg;
- break;
- case 'm':
- auxpaths = optarg;
- break;
- case 'O':
- outkey = optarg;
- break;
- case 'S':
- search.arch = optarg;
- break;
- case 's':
- search.sec = optarg;
- break;
- default:
- goto usage;
- }
-
- argc -= optind;
- argv += optind;
-
- if (0 == argc)
- goto usage;
-
- search.deftype = whatis ? TYPE_Nm : TYPE_Nm | TYPE_Nd;
- search.flags = whatis ? MANSEARCH_WHATIS : 0;
-
- manpath_parse(&paths, conf_file, defpaths, auxpaths);
- mansearch_setup(1);
- ch = mansearch(&search, &paths, argc, argv, outkey, &res, &sz);
- manpath_free(&paths);
-
- if (0 == ch)
- goto usage;
-
- for (i = 0; i < sz; i++) {
- printf("%s - %s\n", res[i].names,
- NULL == res[i].output ? "" : res[i].output);
- free(res[i].file);
- free(res[i].names);
- free(res[i].output);
- }
-
- free(res);
- mansearch_setup(0);
- return(sz ? EXIT_SUCCESS : EXIT_FAILURE);
-usage:
- fprintf(stderr, "usage: %s [-C file] [-M path] [-m path] "
- "[-O outkey] "
- "[-S arch] [-s section]%s ...\n", progname,
- whatis ? " name" : "\n expression");
- return(EXIT_FAILURE);
-}
diff --git a/cgi.c b/cgi.c
index 4f8339e2..42457840 100644
--- a/cgi.c
+++ b/cgi.c
@@ -973,8 +973,8 @@ pg_search(const struct req *req)
search.arch = req->q.arch;
search.sec = req->q.sec;
- search.deftype = req->q.equal ? TYPE_Nm : (TYPE_Nm | TYPE_Nd);
- search.flags = req->q.equal ? MANSEARCH_MAN : 0;
+ search.outkey = "Nd";
+ search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR;
paths.sz = 1;
paths.paths = mandoc_malloc(sizeof(char *));
@@ -1003,7 +1003,7 @@ pg_search(const struct req *req)
ep++;
}
- if (0 == mansearch(&search, &paths, sz, cp, "Nd", &res, &ressz))
+ if (0 == mansearch(&search, &paths, sz, cp, &res, &ressz))
pg_noresult(req, "You entered an invalid query.");
else if (0 == ressz)
pg_noresult(req, "No results found.");
diff --git a/main.c b/main.c
index de1f33f4..88947d97 100644
--- a/main.c
+++ b/main.c
@@ -32,6 +32,8 @@
#include "main.h"
#include "mdoc.h"
#include "man.h"
+#include "manpath.h"
+#include "mansearch.h"
#if !defined(__GNUC__) || (__GNUC__ < 2)
# if !defined(lint)
@@ -68,17 +70,13 @@ struct curparse {
char outopts[BUFSIZ]; /* buf of output opts */
};
-#if HAVE_SQLITE3
-int apropos(int, char**);
-#endif
-
static int moptions(int *, char *);
static void mmsg(enum mandocerr, enum mandoclevel,
const char *, int, int, const char *);
static void parse(struct curparse *, int,
const char *, enum mandoclevel *);
static int toptions(struct curparse *, char *);
-static void usage(void) __attribute__((noreturn));
+static void usage(enum argmode) __attribute__((noreturn));
static void version(void) __attribute__((noreturn));
static int woptions(struct curparse *, char *);
@@ -88,11 +86,19 @@ static const char *progname;
int
main(int argc, char *argv[])
{
- int c;
struct curparse curp;
- int options;
- enum mandoclevel rc;
+ struct mansearch search;
+ struct manpaths paths;
+ char *conf_file, *defpaths, *auxpaths;
char *defos;
+#if HAVE_SQLITE3
+ struct manpage *res;
+ size_t i, sz;
+#endif
+ enum mandoclevel rc;
+ int show_usage;
+ int options;
+ int c;
progname = strrchr(argv[0], '/');
if (progname == NULL)
@@ -100,21 +106,40 @@ main(int argc, char *argv[])
else
++progname;
-#if HAVE_SQLITE3
- if (0 == strncmp(progname, "apropos", 7) ||
- 0 == strncmp(progname, "whatis", 6))
- return(apropos(argc, argv));
-#endif
+ /* Search options. */
- memset(&curp, 0, sizeof(struct curparse));
+ memset(&paths, 0, sizeof(struct manpaths));
+ conf_file = defpaths = auxpaths = NULL;
- options = MPARSE_SO;
+ memset(&search, 0, sizeof(struct mansearch));
+ search.outkey = "Nd";
+
+ if (strcmp(progname, "man") == 0)
+ search.argmode = ARG_NAME;
+ else if (strncmp(progname, "apropos", 7) == 0)
+ search.argmode = ARG_EXPR;
+ else if (strncmp(progname, "whatis", 6) == 0)
+ search.argmode = ARG_WORD;
+ else
+ search.argmode = ARG_FILE;
+
+ /* Parser and formatter options. */
+
+ memset(&curp, 0, sizeof(struct curparse));
curp.outtype = OUTT_ASCII;
curp.wlevel = MANDOCLEVEL_FATAL;
+ options = MPARSE_SO;
defos = NULL;
- while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:")))
+ show_usage = 0;
+ while (-1 != (c = getopt(argc, argv, "C:fI:kM:m:O:S:s:T:VW:"))) {
switch (c) {
+ case 'C':
+ conf_file = optarg;
+ break;
+ case 'f':
+ search.argmode = ARG_WORD;
+ break;
case 'I':
if (strncmp(optarg, "os=", 3)) {
fprintf(stderr,
@@ -130,14 +155,26 @@ main(int argc, char *argv[])
}
defos = mandoc_strdup(optarg + 3);
break;
+ case 'k':
+ search.argmode = ARG_EXPR;
+ break;
+ case 'M':
+ defpaths = optarg;
+ break;
case 'm':
- if ( ! moptions(&options, optarg))
- return((int)MANDOCLEVEL_BADARG);
+ auxpaths = optarg;
break;
case 'O':
+ search.outkey = optarg;
(void)strlcat(curp.outopts, optarg, BUFSIZ);
(void)strlcat(curp.outopts, ",", BUFSIZ);
break;
+ case 'S':
+ search.arch = optarg;
+ break;
+ case 's':
+ search.sec = optarg;
+ break;
case 'T':
if ( ! toptions(&curp, optarg))
return((int)MANDOCLEVEL_BADARG);
@@ -150,9 +187,45 @@ main(int argc, char *argv[])
version();
/* NOTREACHED */
default:
- usage();
- /* NOTREACHED */
+ show_usage = 1;
+ break;
}
+ }
+
+ if (show_usage)
+ usage(search.argmode);
+
+ argc -= optind;
+ argv += optind;
+
+ /* man(1), whatis(1), apropos(1) */
+
+ if (search.argmode != ARG_FILE) {
+#if HAVE_SQLITE3
+ if (argc == 0)
+ usage(search.argmode);
+ manpath_parse(&paths, conf_file, defpaths, auxpaths);
+ mansearch_setup(1);
+ if( ! mansearch(&search, &paths, argc, argv, &res, &sz))
+ usage(search.argmode);
+ manpath_free(&paths);
+ for (i = 0; i < sz; i++)
+ printf("%s - %s\n", res[i].names,
+ res[i].output == NULL ? "" : res[i].output);
+ mansearch_free(res, sz);
+ mansearch_setup(0);
+ return((int)MANDOCLEVEL_OK);
+#else
+ fputs("mandoc: database support not compiled in\n",
+ stderr);
+ return((int)MANDOCLEVEL_BADARG);
+#endif
+ }
+
+ /* mandoc(1) */
+
+ if ( ! moptions(&options, auxpaths))
+ return((int)MANDOCLEVEL_BADARG);
curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
@@ -162,9 +235,6 @@ main(int argc, char *argv[])
if (OUTT_MAN == curp.outtype)
mparse_keep(curp.mp);
- argc -= optind;
- argv += optind;
-
rc = MANDOCLEVEL_OK;
if (NULL == *argv)
@@ -190,24 +260,35 @@ static void
version(void)
{
- printf("%s %s\n", progname, VERSION);
+ printf("mandoc %s\n", VERSION);
exit((int)MANDOCLEVEL_OK);
}
static void
-usage(void)
+usage(enum argmode argmode)
{
- fprintf(stderr, "usage: %s "
- "[-V] "
- "[-Ios=name] "
- "[-mformat] "
- "[-Ooption] "
- "[-Toutput] "
- "[-Wlevel]\n"
- "\t [file ...]\n",
- progname);
-
+ switch (argmode) {
+ case ARG_FILE:
+ fputs("usage: mandoc [-V] [-Ios=name] [-mformat]"
+ " [-Ooption] [-Toutput] [-Wlevel]\n"
+ "\t [file ...]\n", stderr);
+ break;
+ case ARG_NAME:
+ fputs("usage: man [-acfhkVw] [-C file] "
+ "[-M path] [-m path] [-S arch] [-s section]\n"
+ "\t [section] name ...\n", stderr);
+ break;
+ case ARG_WORD:
+ fputs("usage: whatis [-V] [-C file] [-M path] [-m path] "
+ "[-S arch] [-s section] name ...\n", stderr);
+ break;
+ case ARG_EXPR:
+ fputs("usage: apropos [-V] [-C file] [-M path] [-m path] "
+ "[-O outkey] [-S arch]\n"
+ "\t [-s section] expression ...\n", stderr);
+ break;
+ }
exit((int)MANDOCLEVEL_BADARG);
}
@@ -328,7 +409,9 @@ static int
moptions(int *options, char *arg)
{
- if (0 == strcmp(arg, "doc"))
+ if (arg == NULL)
+ /* nothing to do */;
+ else if (0 == strcmp(arg, "doc"))
*options |= MPARSE_MDOC;
else if (0 == strcmp(arg, "andoc"))
/* nothing to do */;
diff --git a/manpage.c b/manpage.c
index 28d1c3d8..27ffd392 100644
--- a/manpage.c
+++ b/manpage.c
@@ -87,10 +87,11 @@ main(int argc, char *argv[])
if (0 == argc)
goto usage;
- search.deftype = TYPE_Nm | TYPE_Nd;
+ search.outkey = "Nd";
+ search.argmode = ARG_EXPR;
manpath_parse(&paths, conf_file, defpaths, auxpaths);
- ch = mansearch(&search, &paths, argc, argv, "Nd", &res, &sz);
+ ch = mansearch(&search, &paths, argc, argv, &res, &sz);
manpath_free(&paths);
if (0 == ch)
diff --git a/mansearch.c b/mansearch.c
index 4a74d0db..a4d03d08 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -159,7 +159,6 @@ int
mansearch(const struct mansearch *search,
const struct manpaths *paths,
int argc, char *argv[],
- const char *outkey,
struct manpage **res, size_t *sz)
{
int fd, rc, c, indexbit;
@@ -195,11 +194,11 @@ mansearch(const struct mansearch *search,
goto out;
outbit = 0;
- if (NULL != outkey) {
+ if (NULL != search->outkey) {
for (indexbit = 0, iterbit = 1;
indexbit < mansearch_keymax;
indexbit++, iterbit <<= 1) {
- if (0 == strcasecmp(outkey,
+ if (0 == strcasecmp(search->outkey,
mansearch_keynames[indexbit])) {
outbit = iterbit;
break;
@@ -367,6 +366,19 @@ out:
return(rc);
}
+void
+mansearch_free(struct manpage *res, size_t sz)
+{
+ size_t i;
+
+ for (i = 0; i < sz; i++) {
+ free(res[i].file);
+ free(res[i].names);
+ free(res[i].output);
+ }
+ free(res);
+}
+
static int
manpage_compare(const void *vp1, const void *vp2)
{
@@ -739,35 +751,29 @@ exprterm(const struct mansearch *search, char *buf, int cs)
e = mandoc_calloc(1, sizeof(struct expr));
- if (MANSEARCH_MAN & search->flags) {
- e->bits = search->deftype;
+ if (search->argmode == ARG_NAME) {
+ e->bits = TYPE_Nm;
e->substr = buf;
e->equal = 1;
return(e);
}
/*
- * Look for an '=' or '~' operator,
- * unless forced to some fixed macro keys.
+ * Separate macro keys from search string.
+ * If needed, request regular expression handling
+ * by setting e->substr to NULL.
*/
- if (MANSEARCH_WHATIS & search->flags)
- val = NULL;
- else
- val = strpbrk(buf, "=~");
-
- if (NULL == val) {
- e->bits = search->deftype;
+ if (search->argmode == ARG_WORD) {
+ e->bits = TYPE_Nm;
+ e->substr = NULL;
+ mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", buf);
+ } else if ((val = strpbrk(buf, "=~")) == NULL) {
+ e->bits = TYPE_Nm | TYPE_Nd;
e->substr = buf;
-
- /*
- * Found an operator.
- * Regexp search is requested by !e->substr.
- */
-
} else {
if (val == buf)
- e->bits = search->deftype;
+ e->bits = TYPE_Nm | TYPE_Nd;
if ('=' == *val)
e->substr = val + 1;
*val++ = '\0';
@@ -777,15 +783,10 @@ exprterm(const struct mansearch *search, char *buf, int cs)
/* Compile regular expressions. */
- if (MANSEARCH_WHATIS & search->flags) {
- e->substr = NULL;
- mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", buf);
- }
-
if (NULL == e->substr) {
irc = regcomp(&e->regexp, val,
REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE));
- if (MANSEARCH_WHATIS & search->flags)
+ if (search->argmode == ARG_WORD)
free(val);
if (irc) {
regerror(irc, &e->regexp, errbuf, sizeof(errbuf));
diff --git a/mansearch.h b/mansearch.h
index 7c5a7c00..d36173fd 100644
--- a/mansearch.h
+++ b/mansearch.h
@@ -68,7 +68,12 @@
#define NAME_HEAD 0x0000004000000010ULL
#define NAME_MASK 0x000000000000001fULL
-__BEGIN_DECLS
+enum argmode {
+ ARG_FILE = 0,
+ ARG_NAME,
+ ARG_WORD,
+ ARG_EXPR
+};
struct manpage {
char *file; /* to be prefixed by manpath */
@@ -81,21 +86,21 @@ struct manpage {
struct mansearch {
const char *arch; /* architecture/NULL */
const char *sec; /* mansection/NULL */
- uint64_t deftype; /* type if no key */
- int flags;
-#define MANSEARCH_WHATIS 0x01 /* whatis(1) mode: whole words, no keys */
-#define MANSEARCH_MAN 0x02 /* man(1) mode: string equality, no keys */
+ const char *outkey; /* show content of this macro */
+ enum argmode argmode; /* interpretation of arguments */
};
+__BEGIN_DECLS
+
int mansearch_setup(int);
int mansearch(const struct mansearch *cfg, /* options */
const struct manpaths *paths, /* manpaths */
int argc, /* size of argv */
char *argv[], /* search terms */
- const char *outkey, /* name of additional output key */
struct manpage **res, /* results */
size_t *ressz); /* results returned */
+void mansearch_free(struct manpage *, size_t);
__END_DECLS
-#endif /*!MANSEARCH_H*/
+#endif /* MANSEARCH_H */