+ pmdoc_node(db, dbn, key, ksz, val, rval, rsz, n->child);
+ pmdoc_node(db, dbn, key, ksz, val, rval, rsz, n->next);
+}
+
+static int
+pman_node(MAN_ARGS)
+{
+ const struct man_node *head, *body;
+ const char *start, *sv;
+ size_t sz;
+ uint32_t fl;
+
+ if (NULL == n)
+ return(0);
+
+ /*
+ * We're only searching for one thing: the first text child in
+ * the BODY of a NAME section. Since we don't keep track of
+ * sections in -man, run some hoops to find out whether we're in
+ * the correct section or not.
+ */
+
+ if (MAN_BODY == n->type && MAN_SH == n->tok) {
+ body = n;
+ assert(body->parent);
+ if (NULL != (head = body->parent->head) &&
+ 1 == head->nchild &&
+ NULL != (head = (head->child)) &&
+ MAN_TEXT == head->type &&
+ 0 == strcmp(head->string, "NAME") &&
+ NULL != (body = body->child) &&
+ MAN_TEXT == body->type) {
+
+ fl = MANDOC_NAME;
+ memcpy(val->data, &fl, 4);
+
+ assert(body->string);
+ start = sv = body->string;
+
+ /*
+ * Go through a special heuristic dance here.
+ * This is why -man manuals are great!
+ * Conventionally, one or more manual names are
+ * comma-specified prior to a whitespace, then a
+ * dash, then a description. Try to puzzle out
+ * the name parts here.
+ */
+
+ for ( ;; ) {
+ sz = strcspn(start, " ,");
+ if ('\0' == start[(int)sz])
+ break;
+
+ dbt_init(key, ksz);
+ dbt_appendb(key, ksz, start, sz);
+ dbt_appendb(key, ksz, "", 1);
+
+ dbt_put(db, dbn, key, val);
+
+ if (' ' == start[(int)sz]) {
+ start += (int)sz + 1;
+ break;
+ }
+
+ assert(',' == start[(int)sz]);
+ start += (int)sz + 1;
+ while (' ' == *start)
+ start++;
+ }
+
+ if (sv == start) {
+ dbt_init(key, ksz);
+ dbt_append(key, ksz, start);
+ return(1);
+ }
+
+ while (' ' == *start)
+ start++;
+
+ if ('\\' == *start && '-' == *(start + 1))
+ start += 2;
+ else if ('-' == *start)
+ start++;
+
+ while (' ' == *start)
+ start++;
+
+ dbt_appendb(rval, rsz, start, strlen(start) + 1);
+ }
+ }
+
+ if (pman_node(db, dbn, key, ksz, val, rval, rsz, n->child))
+ return(1);
+ if (pman_node(db, dbn, key, ksz, val, rval, rsz, n->next))
+ return(1);
+
+ return(0);