aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-12-16 12:06:35 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-12-16 12:06:35 +0000
commit1cf41474327ca813976f622e8e0b73bb3841a44c (patch)
treefc81fa3b092a418c199ec9ce185c91c9be1a38bd
parent385adb0d5fa1bc2a7c177241fa3d9671d7af1582 (diff)
downloadmandoc-1cf41474327ca813976f622e8e0b73bb3841a44c.tar.gz
mandoc-1cf41474327ca813976f622e8e0b73bb3841a44c.tar.zst
mandoc-1cf41474327ca813976f622e8e0b73bb3841a44c.zip
Make the stored "cat"/"mdoc"/"man" strings just be c/d/a single-character
bytes. This cuts down a little in index size and allows for cleaner extraction of information.
-rw-r--r--apropos_db.c20
-rw-r--r--apropos_db.h10
-rw-r--r--catman.c17
-rw-r--r--cgi.c22
-rw-r--r--mandocdb.815
-rw-r--r--mandocdb.c16
6 files changed, 56 insertions, 44 deletions
diff --git a/apropos_db.c b/apropos_db.c
index fd657558..0d2b0728 100644
--- a/apropos_db.c
+++ b/apropos_db.c
@@ -1,4 +1,4 @@
-/* $Id: apropos_db.c,v 1.23 2011/12/10 21:46:59 kristaps Exp $ */
+/* $Id: apropos_db.c,v 1.24 2011/12/16 12:06:35 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -365,6 +365,7 @@ index_read(const DBT *key, const DBT *val, int index,
{
size_t left;
char *np, *cp;
+ char type;
#define INDEX_BREAD(_dst) \
do { \
@@ -375,13 +376,23 @@ index_read(const DBT *key, const DBT *val, int index,
cp = np + 1; \
} while (/* CONSTCOND */ 0)
- left = val->size;
- cp = (char *)val->data;
+ if (0 == (left = val->size))
+ return(0);
+ cp = val->data;
rec->res.rec = *(recno_t *)key->data;
rec->res.volume = index;
- INDEX_BREAD(rec->res.type);
+ if ('d' == (type = *cp++))
+ rec->res.type = RESTYPE_MDOC;
+ else if ('a' == type)
+ rec->res.type = RESTYPE_MAN;
+ else if ('c' == type)
+ rec->res.type = RESTYPE_CAT;
+ else
+ return(0);
+
+ left--;
INDEX_BREAD(rec->res.file);
INDEX_BREAD(rec->res.cat);
INDEX_BREAD(rec->res.title);
@@ -581,7 +592,6 @@ static void
recfree(struct rec *rec)
{
- free(rec->res.type);
free(rec->res.file);
free(rec->res.cat);
free(rec->res.title);
diff --git a/apropos_db.h b/apropos_db.h
index be48b063..2af91206 100644
--- a/apropos_db.h
+++ b/apropos_db.h
@@ -1,4 +1,4 @@
-/* $Id: apropos_db.h,v 1.10 2011/11/27 23:11:37 schwarze Exp $ */
+/* $Id: apropos_db.h,v 1.11 2011/12/16 12:06:35 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -17,8 +17,14 @@
#ifndef APROPOS_H
#define APROPOS_H
+enum restype {
+ RESTYPE_MAN, /* man(7) file */
+ RESTYPE_MDOC, /* mdoc(7) file */
+ RESTYPE_CAT /* pre-formatted file */
+};
+
struct res {
- char *type; /* file type: mdoc, man or cat */
+ enum restype type; /* input file type */
char *file; /* file in file-system */
char *cat; /* category (3p, 3, etc.) */
char *title; /* title (FOO, etc.) */
diff --git a/catman.c b/catman.c
index 54971293..2ac27e5a 100644
--- a/catman.c
+++ b/catman.c
@@ -1,4 +1,4 @@
-/* $Id: catman.c,v 1.6 2011/12/16 08:04:34 kristaps Exp $ */
+/* $Id: catman.c,v 1.7 2011/12/16 12:06:35 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -204,7 +204,7 @@ indexhtml(char *src, size_t ssz, char *dst, size_t dsz)
DBT key, val;
int c, rc;
unsigned int fl;
- const char *f, *cp;
+ const char *f;
char *d;
char fname[MAXPATHLEN];
pid_t pid;
@@ -223,14 +223,15 @@ indexhtml(char *src, size_t ssz, char *dst, size_t dsz)
fl = R_FIRST;
while (0 == (c = (*idx->seq)(idx, &key, &val, fl))) {
fl = R_NEXT;
- cp = (const char *)val.data;
+ /*
+ * If the record is zero-length, then it's unassigned.
+ * Skip past these.
+ */
if (0 == val.size)
continue;
- if (NULL == (f = memchr(cp, '\0', val.size)))
- break;
- if (++f - cp >= (int)val.size)
- break;
- if (NULL == memchr(f, '\0', val.size - (f - cp)))
+
+ f = (const char *)val.data + 1;
+ if (NULL == memchr(f, '\0', val.size - 1))
break;
src[(int)ssz] = dst[(int)dsz] = '\0';
diff --git a/cgi.c b/cgi.c
index 002855d7..515b1162 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.34 2011/12/16 08:04:34 kristaps Exp $ */
+/* $Id: cgi.c,v 1.35 2011/12/16 12:06:35 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -752,8 +752,8 @@ pg_show(const struct req *req, char *path)
size_t sz;
char *sub;
char file[MAXPATHLEN];
- const char *fn, *cp;
- int rc;
+ const char *cp;
+ int rc, catm;
unsigned int vol, rec, mr;
DB *idx;
DBT key, val;
@@ -824,21 +824,21 @@ pg_show(const struct req *req, char *path)
if (0 != (rc = (*idx->get)(idx, &key, &val, 0))) {
rc < 0 ? resp_baddb() : resp_error400();
goto out;
- }
+ } else if (0 == val.size) {
+ resp_baddb();
+ goto out;
+ }
cp = (char *)val.data;
+ catm = 'c' == *cp++;
- if (NULL == (fn = memchr(cp, '\0', val.size)))
- resp_baddb();
- else if (++fn - cp >= (int)val.size)
- resp_baddb();
- else if (NULL == memchr(fn, '\0', val.size - (fn - cp)))
+ if (NULL == memchr(cp, '\0', val.size - 1))
resp_baddb();
else {
file[(int)sz] = '\0';
strlcat(file, "/", MAXPATHLEN);
- strlcat(file, fn, MAXPATHLEN);
- if (0 == strcmp(cp, "cat"))
+ strlcat(file, cp, MAXPATHLEN);
+ if (catm)
catman(req, file);
else
format(req, file);
diff --git a/mandocdb.8 b/mandocdb.8
index a19b0083..38b928fd 100644
--- a/mandocdb.8
+++ b/mandocdb.8
@@ -1,4 +1,4 @@
-.\" $Id: mandocdb.8,v 1.13 2011/12/16 08:04:34 kristaps Exp $
+.\" $Id: mandocdb.8,v 1.14 2011/12/16 12:06:35 kristaps Exp $
.\"
.\" Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -110,14 +110,13 @@ database with record values consisting of
.Pp
.Bl -enum -compact
.It
-the string
-.Cm mdoc ,
-.Cm man ,
+the character
+.Cm d ,
+.Cm a ,
or
-.Cm cat
+.Cm c
to indicate the file type
.Po
-file in
.Xr mdoc 7 ,
.Xr man 7 ,
and post-formatted, respectively
@@ -137,9 +136,7 @@ and the description.
.Pp
Each of the above is NUL-terminated.
.Pp
-Both the manual section and description may be zero-length if the record
-is unassigned.
-Entries are sequentially-numbered, but the filenames are unordered.
+If the record value is zero-length, it is unassigned.
.Ss Keyword Database
The keyword database,
.Pa mandoc.db ,
diff --git a/mandocdb.c b/mandocdb.c
index d9acf3e8..24758a0e 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.35 2011/12/16 08:04:34 kristaps Exp $ */
+/* $Id: mandocdb.c,v 1.36 2011/12/16 12:06:35 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -528,6 +528,7 @@ index_merge(const struct of *of, struct mparse *mp,
size_t sv;
unsigned seq;
struct db_val vbuf;
+ char type;
for (rec = 0; of; of = of->next) {
fn = of->fname;
@@ -608,7 +609,8 @@ index_merge(const struct of *of, struct mparse *mp,
*/
dbuf->len = 0;
- buf_append(dbuf, mdoc ? "mdoc" : (man ? "man" : "cat"));
+ type = mdoc ? 'd' : (man ? 'a' : 'c');
+ buf_appendb(dbuf, &type, 1);
buf_appendb(dbuf, fn, strlen(fn) + 1);
buf_appendb(dbuf, msec, strlen(msec) + 1);
buf_appendb(dbuf, mtitle, strlen(mtitle) + 1);
@@ -696,7 +698,7 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
recno_t **recs, size_t *recsz, size_t *reccur)
{
const struct of *of;
- const char *fn, *cp;
+ const char *fn;
struct db_val *vbuf;
unsigned seq, sseq;
DBT key, val;
@@ -707,7 +709,6 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) {
seq = R_NEXT;
*maxrec = *(recno_t *)key.data;
- cp = val.data;
/* Deleted records are zero-sized. Skip them. */
@@ -721,11 +722,8 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
* Failing any of these, we go into our error handler.
*/
- if (NULL == (fn = memchr(cp, '\0', val.size)))
- break;
- if (++fn - cp >= (int)val.size)
- break;
- if (NULL == memchr(fn, '\0', val.size - (fn - cp)))
+ fn = (char *)val.data + 1;
+ if (NULL == memchr(fn, '\0', val.size - 1))
break;
/*