From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Make the stored "cat"/"mdoc"/"man" strings just be c/d/a
Date: Fri, 16 Dec 2011 07:06:35 -0500 (EST) [thread overview]
Message-ID: <201112161206.pBGC6ZII023088@krisdoz.my.domain> (raw)
Log Message:
-----------
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.
Modified Files:
--------------
mdocml:
apropos_db.c
apropos_db.h
catman.c
cgi.c
mandocdb.8
mandocdb.c
Revision Data
-------------
Index: mandocdb.8
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.8,v
retrieving revision 1.13
retrieving revision 1.14
diff -Lmandocdb.8 -Lmandocdb.8 -u -p -r1.13 -r1.14
--- mandocdb.8
+++ mandocdb.8
@@ -110,14 +110,13 @@ database with record values consisting o
.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 ,
Index: catman.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/catman.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lcatman.c -Lcatman.c -u -p -r1.6 -r1.7
--- catman.c
+++ catman.c
@@ -204,7 +204,7 @@ indexhtml(char *src, size_t ssz, char *d
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 *d
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';
Index: apropos_db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -Lapropos_db.c -Lapropos_db.c -u -p -r1.23 -r1.24
--- apropos_db.c
+++ apropos_db.c
@@ -365,6 +365,7 @@ index_read(const DBT *key, const DBT *va
{
size_t left;
char *np, *cp;
+ char type;
#define INDEX_BREAD(_dst) \
do { \
@@ -375,13 +376,23 @@ index_read(const DBT *key, const DBT *va
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);
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.35 -r1.36
--- mandocdb.c
+++ mandocdb.c
@@ -528,6 +528,7 @@ index_merge(const struct of *of, struct
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
*/
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 *
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 *
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 *
* 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;
/*
Index: apropos_db.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lapropos_db.h -Lapropos_db.h -u -p -r1.10 -r1.11
--- apropos_db.h
+++ apropos_db.h
@@ -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.) */
Index: cgi.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/cgi.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -Lcgi.c -Lcgi.c -u -p -r1.34 -r1.35
--- cgi.c
+++ cgi.c
@@ -752,8 +752,8 @@ pg_show(const struct req *req, char *pat
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 *pat
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);
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2011-12-16 12:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201112161206.pBGC6ZII023088@krisdoz.my.domain \
--to=kristaps@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).