summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-04-11 21:36:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-04-11 21:36:44 +0000
commit2a9b664f3c097e4aafe7c0b3bad0a4ec3245fccf (patch)
treeae51e854f5443c315917769c68a0d5e34a14fbf3
parentc48f312b0d4b59d3419a2eff6ae2bcfc337dae0f (diff)
downloadmandoc-2a9b664f3c097e4aafe7c0b3bad0a4ec3245fccf.tar.gz
Use dbt_xxxx functions to stash both filename and manual section in the
value part of the index. This is the actual manual section---before, mandoc.cgi was relying on the file suffix, but this can be (e.g.) .man or whatnot. This is The Correct Way (tm).
-rw-r--r--mandoc-db.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/mandoc-db.c b/mandoc-db.c
index 3b8ce1a6..b6f0bddf 100644
--- a/mandoc-db.c
+++ b/mandoc-db.c
@@ -217,7 +217,8 @@ main(int argc, char *argv[])
struct mdoc *mdoc; /* resulting mdoc */
struct man *man; /* resulting man */
char *fn;
- const char *dir; /* result dir (default: cwd) */
+ const char *msec,
+ *dir; /* result dir (default: cwd) */
char ibuf[MAXPATHLEN], /* index fname */
ibbuf[MAXPATHLEN], /* index backup fname */
fbuf[MAXPATHLEN], /* btree fname */
@@ -227,7 +228,7 @@ main(int argc, char *argv[])
*db; /* keyword database */
DBT rkey, rval, /* recno entries */
key, val; /* persistent keyword entries */
- size_t ksz; /* entry buffer size */
+ size_t ksz, rsz; /* entry buffer size */
char vbuf[8];
BTREEINFO info; /* btree configuration */
recno_t rec;
@@ -329,7 +330,7 @@ main(int argc, char *argv[])
rkey.size = sizeof(recno_t);
rec = 1;
- ksz = 0;
+ ksz = rsz = 0;
while (NULL != (fn = *argv++)) {
mparse_reset(mp);
@@ -343,14 +344,17 @@ main(int argc, char *argv[])
if (NULL == mdoc && NULL == man)
continue;
+ msec = NULL != mdoc ?
+ mdoc_meta(mdoc)->msec :
+ man_meta(man)->msec;
+
rkey.data = &rec;
- rval.data = fn;
- rval.size = strlen(fn) + 1;
- if (-1 == (*idx->put)(idx, &rkey, &rval, 0)) {
- perror(ibbuf);
- break;
- }
+ dbt_init(&rval, &rsz);
+ dbt_appendb(&rval, &rsz, fn, strlen(fn) + 1);
+ dbt_appendb(&rval, &rsz, msec, strlen(msec) + 1);
+
+ dbt_put(idx, ibbuf, &rkey, &rval);
memset(val.data, 0, sizeof(uint32_t));
memcpy(val.data + 4, &rec, sizeof(uint32_t));
@@ -368,6 +372,7 @@ main(int argc, char *argv[])
mparse_free(mp);
free(key.data);
+ free(rval.data);
/* Atomically replace the file with our temporary one. */
@@ -447,7 +452,7 @@ pmdoc_Fd(MDOC_ARGS)
uint32_t fl;
const char *start, *end;
size_t sz;
- char nil;
+ const char nil = '\0';
if (SEC_SYNOPSIS != n->sec)
return;
@@ -480,7 +485,6 @@ pmdoc_Fd(MDOC_ARGS)
if ('>' == *end || '"' == *end)
end--;
- nil = '\0';
dbt_appendb(key, ksz, start, end - start + 1);
dbt_appendb(key, ksz, &nil, 1);
@@ -539,7 +543,7 @@ pmdoc_Vt(MDOC_ARGS)
uint32_t fl;
const char *start, *end;
size_t sz;
- char nil;
+ const char nil = '\0';
if (SEC_SYNOPSIS != n->sec)
return;
@@ -567,7 +571,6 @@ pmdoc_Vt(MDOC_ARGS)
if (end == start)
return;
- nil = '\0';
dbt_appendb(key, ksz, start, end - start + 1);
dbt_appendb(key, ksz, &nil, 1);
fl = MANDOC_VARIABLE;
@@ -626,7 +629,7 @@ dbt_put(DB *db, const char *dbn, DBT *key, DBT *val)
return;
assert(key->data);
- assert(8 == val->size);
+ assert(val->size);
assert(val->data);
if (0 == (*db->put)(db, key, val, 0))
@@ -679,7 +682,7 @@ pman_node(MAN_ARGS)
{
const struct man_node *head, *body;
const char *start;
- char nil;
+ const char nil = '\0';
size_t sz;
uint32_t fl;
@@ -703,7 +706,6 @@ pman_node(MAN_ARGS)
0 == strcmp(head->string, "NAME") &&
NULL != (body = body->child) &&
MAN_TEXT == body->type) {
- nil = '\0';
fl = MANDOC_NAME;
memcpy(val->data, &fl, 4);