aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mansearch.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2012-06-09 14:11:15 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2012-06-09 14:11:15 +0000
commita1018d4b412e9aa03fb18ff79885199f171b2220 (patch)
tree1908fbf70600a99f6a300ad6a213793b69a134bc /mansearch.c
parentf87aa508ace733fdcbd5a14be84a4b4f7d8da43d (diff)
downloadmandoc-a1018d4b412e9aa03fb18ff79885199f171b2220.tar.gz
mandoc-a1018d4b412e9aa03fb18ff79885199f171b2220.tar.zst
mandoc-a1018d4b412e9aa03fb18ff79885199f171b2220.zip
Merge whatis.1 into apropos.1 (and remove), add whatis bits to apropos
(via mansearch), and merge mandocdb.h into mansearch.h (and remove).
Diffstat (limited to 'mansearch.c')
-rw-r--r--mansearch.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/mansearch.c b/mansearch.c
index 70e6ad05..bec483fc 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -1,4 +1,4 @@
-/* $Id: mansearch.c,v 1.4 2012/06/09 11:00:13 kristaps Exp $ */
+/* $Id: mansearch.c,v 1.5 2012/06/09 14:11:16 kristaps Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -39,7 +39,6 @@
#include "mandoc.h"
#include "manpath.h"
-#include "mandocdb.h"
#include "mansearch.h"
#define SQL_BIND_TEXT(_db, _s, _i, _v) \
@@ -117,15 +116,16 @@ static const struct type types[] = {
static void *hash_alloc(size_t, void *);
static void hash_free(void *, size_t, void *);
static void *hash_halloc(size_t, void *);
-static struct expr *exprcomp(int, char *[]);
+static struct expr *exprcomp(const struct mansearch *,
+ int, char *[]);
static void exprfree(struct expr *);
-static struct expr *exprterm(char *);
+static struct expr *exprterm(const struct mansearch *, char *);
static char *sql_statement(const struct expr *,
const char *, const char *);
int
-mansearch(const struct manpaths *paths,
- const char *arch, const char *sec,
+mansearch(const struct mansearch *search,
+ const struct manpaths *paths,
int argc, char *argv[],
struct manpage **res, size_t *sz)
{
@@ -158,7 +158,7 @@ mansearch(const struct manpaths *paths,
if (0 == argc)
goto out;
- if (NULL == (e = exprcomp(argc, argv)))
+ if (NULL == (e = exprcomp(search, argc, argv)))
goto out;
/*
@@ -176,7 +176,7 @@ mansearch(const struct manpaths *paths,
goto out;
}
- sql = sql_statement(e, arch, sec);
+ sql = sql_statement(e, search->arch, search->sec);
/*
* Loop over the directories (containing databases) for us to
@@ -211,10 +211,10 @@ mansearch(const struct manpaths *paths,
if (SQLITE_OK != c)
fprintf(stderr, "%s\n", sqlite3_errmsg(db));
- if (NULL != arch)
- SQL_BIND_TEXT(db, s, j, arch);
- if (NULL != sec)
- SQL_BIND_TEXT(db, s, j, arch);
+ if (NULL != search->arch)
+ SQL_BIND_TEXT(db, s, j, search->arch);
+ if (NULL != search->sec)
+ SQL_BIND_TEXT(db, s, j, search->sec);
for (ep = e; NULL != ep; ep = ep->next) {
SQL_BIND_TEXT(db, s, j, ep->v);
@@ -346,7 +346,7 @@ sql_statement(const struct expr *e, const char *arch, const char *sec)
* "(", "foo=bar", etc.).
*/
static struct expr *
-exprcomp(int argc, char *argv[])
+exprcomp(const struct mansearch *search, int argc, char *argv[])
{
int i;
struct expr *first, *next, *cur;
@@ -354,7 +354,7 @@ exprcomp(int argc, char *argv[])
first = cur = NULL;
for (i = 0; i < argc; i++) {
- next = exprterm(argv[i]);
+ next = exprterm(search, argv[i]);
if (NULL == next) {
exprfree(first);
return(NULL);
@@ -370,7 +370,7 @@ exprcomp(int argc, char *argv[])
}
static struct expr *
-exprterm(char *buf)
+exprterm(const struct mansearch *search, char *buf)
{
struct expr *e;
char *key, *v;
@@ -381,6 +381,14 @@ exprterm(char *buf)
e = mandoc_calloc(1, sizeof(struct expr));
+ /*"whatis" mode uses an opaque string and default fields. */
+
+ if (MANSEARCH_WHATIS & search->flags) {
+ e->v = buf;
+ e->bits = search->deftype;
+ return(e);
+ }
+
/*
* If no =~ is specified, search with equality over names and
* descriptions.
@@ -389,10 +397,10 @@ exprterm(char *buf)
if (NULL == (v = strpbrk(buf, "=~"))) {
e->v = buf;
- e->bits = TYPE_Nm | TYPE_Nd;
+ e->bits = search->deftype;
return(e);
} else if (v == buf)
- e->bits = TYPE_Nm | TYPE_Nd;
+ e->bits = search->deftype;
e->glob = '~' == *v;
*v++ = '\0';