summaryrefslogtreecommitdiffstats
path: root/mansearch.c
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 /mansearch.c
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.
Diffstat (limited to 'mansearch.c')
-rw-r--r--mansearch.c55
1 files changed, 28 insertions, 27 deletions
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));