=================================================================== RCS file: /cvs/mandoc/Attic/makewhatis.c,v retrieving revision 1.13 retrieving revision 1.17 diff -u -p -r1.13 -r1.17 --- mandoc/Attic/makewhatis.c 2011/07/01 10:17:24 1.13 +++ mandoc/Attic/makewhatis.c 2011/07/10 13:03:31 1.17 @@ -1,4 +1,4 @@ -/* $Id: makewhatis.c,v 1.13 2011/07/01 10:17:24 kristaps Exp $ */ +/* $Id: makewhatis.c,v 1.17 2011/07/10 13:03:31 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -56,6 +56,8 @@ #define TYPE_DESC 0x100 #define TYPE_XREF 0x200 #define TYPE_PATH 0x400 +#define TYPE_ENV 0x800 +#define TYPE_ERR 0x1000 /* Buffer for storing growable data. */ @@ -76,7 +78,7 @@ struct buf { const struct mdoc_meta *m static void buf_appendmdoc(struct buf *, - const struct mdoc_node *); + const struct mdoc_node *, int); static void buf_append(struct buf *, const char *); static void buf_appendb(struct buf *, const void *, size_t); @@ -86,6 +88,8 @@ static int pman_node(MAN_ARGS); static void pmdoc_node(MDOC_ARGS); static void pmdoc_An(MDOC_ARGS); static void pmdoc_Cd(MDOC_ARGS); +static void pmdoc_Er(MDOC_ARGS); +static void pmdoc_Ev(MDOC_ARGS); static void pmdoc_Fd(MDOC_ARGS); static void pmdoc_In(MDOC_ARGS); static void pmdoc_Fn(MDOC_ARGS); @@ -121,8 +125,8 @@ static const pmdoc_nf mdocs[MDOC_MAX] = { pmdoc_Cd, /* Cd */ NULL, /* Cm */ NULL, /* Dv */ - NULL, /* Er */ - NULL, /* Ev */ + pmdoc_Er, /* Er */ + pmdoc_Ev, /* Ev */ NULL, /* Ex */ NULL, /* Fa */ pmdoc_Fd, /* Fd */ @@ -531,16 +535,25 @@ buf_append(struct buf *buf, const char *cp) * This is optimised for general mdoc nodes in this context, which do * not consist of subexpressions and having a recursive call for n->next * would be wasteful. + * The "f" variable should be 0 unless called from pmdoc_Nd for the + * description buffer, which does not start at the beginning of the + * buffer. */ static void -buf_appendmdoc(struct buf *buf, const struct mdoc_node *n) +buf_appendmdoc(struct buf *buf, const struct mdoc_node *n, int f) { for ( ; n; n = n->next) { if (n->child) - buf_appendmdoc(buf, n->child); - if (MDOC_TEXT == n->type) + buf_appendmdoc(buf, n->child, f); + + if (MDOC_TEXT == n->type && f) { + f = 0; + buf_appendb(buf, n->string, + strlen(n->string) + 1); + } else if (MDOC_TEXT == n->type) buf_append(buf, n->string); + } } @@ -552,7 +565,7 @@ pmdoc_An(MDOC_ARGS) if (SEC_AUTHORS != n->sec) return; - buf_appendmdoc(buf, n->child); + buf_appendmdoc(buf, n->child, 0); hash_put(hash, buf, TYPE_AUTHOR); } @@ -610,7 +623,7 @@ pmdoc_Cd(MDOC_ARGS) if (SEC_SYNOPSIS != n->sec) return; - buf_appendmdoc(buf, n->child); + buf_appendmdoc(buf, n->child, 0); hash_put(hash, buf, TYPE_CONFIG); } @@ -743,24 +756,38 @@ pmdoc_Fo(MDOC_ARGS) static void pmdoc_Nd(MDOC_ARGS) { - size_t sz; if (MDOC_BODY != n->type) return; - else if (NULL == (n = n->child)) - return; - /* FIXME: don't assume this. */ - assert(MDOC_TEXT == n->type); + buf_appendmdoc(dbuf, n->child, 1); + buf_appendmdoc(buf, n->child, 0); - sz = strlen(n->string) + 1; - buf_appendb(dbuf, n->string, sz); - buf_appendb(buf, n->string, sz); + hash_put(hash, buf, TYPE_DESC); +} + +/* ARGSUSED */ +static void +pmdoc_Er(MDOC_ARGS) +{ + + if (SEC_ERRORS != n->sec) + return; - buf_appendmdoc(dbuf, n->next); - buf_appendmdoc(buf, n->next); + buf_appendmdoc(buf, n->child, 0); + hash_put(hash, buf, TYPE_ERR); +} - hash_put(hash, buf, TYPE_DESC); +/* ARGSUSED */ +static void +pmdoc_Ev(MDOC_ARGS) +{ + + if (SEC_ENVIRONMENT != n->sec) + return; + + buf_appendmdoc(buf, n->child, 0); + hash_put(hash, buf, TYPE_ENV); } /* ARGSUSED */ @@ -771,7 +798,7 @@ pmdoc_Pa(MDOC_ARGS) if (SEC_FILES != n->sec) return; - buf_appendmdoc(buf, n->child); + buf_appendmdoc(buf, n->child, 0); hash_put(hash, buf, TYPE_PATH); } @@ -781,7 +808,7 @@ pmdoc_Nm(MDOC_ARGS) { if (SEC_NAME == n->sec) { - buf_appendmdoc(buf, n->child); + buf_appendmdoc(buf, n->child, 0); hash_put(hash, buf, TYPE_NAME); return; } else if (SEC_SYNOPSIS != n->sec || MDOC_HEAD != n->type) @@ -790,7 +817,7 @@ pmdoc_Nm(MDOC_ARGS) if (NULL == n->child) buf_append(buf, m->name); - buf_appendmdoc(buf, n->child); + buf_appendmdoc(buf, n->child, 0); hash_put(hash, buf, TYPE_UTILITY); } @@ -934,8 +961,9 @@ pman_node(MAN_ARGS) start++; } + buf->len = 0; + if (sv == start) { - buf->len = 0; buf_append(buf, start); return(1); } @@ -958,6 +986,8 @@ pman_node(MAN_ARGS) sz = strlen(start) + 1; buf_appendb(dbuf, start, sz); buf_appendb(buf, start, sz); + + hash_put(hash, buf, TYPE_DESC); } }