summaryrefslogtreecommitdiffstatshomepage
path: root/makewhatis.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-01 10:46:32 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-01 10:46:32 +0000
commitf3d43c21c08b7c31c8cdfed1d0233f8fe7fd0839 (patch)
treecbd329676d4e865c22ef9fe41d3e06a3892afc67 /makewhatis.c
parent15d8780dcfa10a1b63398b0930d0aa066863229a (diff)
downloadmandoc-f3d43c21c08b7c31c8cdfed1d0233f8fe7fd0839.tar.gz
mandoc-f3d43c21c08b7c31c8cdfed1d0233f8fe7fd0839.tar.zst
mandoc-f3d43c21c08b7c31c8cdfed1d0233f8fe7fd0839.zip
Allow `Nd' scarfed data to allow for non-text nodes as the first node, as well.
Diffstat (limited to 'makewhatis.c')
-rw-r--r--makewhatis.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/makewhatis.c b/makewhatis.c
index d77a206b..7ceeaa9a 100644
--- a/makewhatis.c
+++ b/makewhatis.c
@@ -1,4 +1,4 @@
-/* $Id: makewhatis.c,v 1.13 2011/07/01 10:17:24 kristaps Exp $ */
+/* $Id: makewhatis.c,v 1.14 2011/07/01 10:46:32 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -76,7 +76,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);
@@ -531,16 +531,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 +561,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 +619,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,22 +752,12 @@ 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);
- sz = strlen(n->string) + 1;
- buf_appendb(dbuf, n->string, sz);
- buf_appendb(buf, n->string, sz);
-
- buf_appendmdoc(dbuf, n->next);
- buf_appendmdoc(buf, n->next);
+ buf_appendmdoc(dbuf, n->child, 1);
+ buf_appendmdoc(buf, n->child, 0);
hash_put(hash, buf, TYPE_DESC);
}
@@ -771,7 +770,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 +780,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 +789,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);
}