From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Use a little more horsepower in parsing out NAME sections from
Date: Tue, 5 Apr 2011 10:10:52 -0400 (EDT) [thread overview]
Message-ID: <201104051410.p35EAqsH017693@krisdoz.my.domain> (raw)
Log Message:
-----------
Use a little more horsepower in parsing out NAME sections from -man
manuals. This covers the majority case.
Modified Files:
--------------
mdocml:
mandoc-db.c
Revision Data
-------------
Index: mandoc-db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc-db.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -Lmandoc-db.c -Lmandoc-db.c -u -p -r1.7 -r1.8
--- mandoc-db.c
+++ mandoc-db.c
@@ -66,6 +66,7 @@ static void dbt_append(DBT *, size_t
static void dbt_appendb(DBT *, size_t *,
const void *, size_t);
static void dbt_init(DBT *, size_t *);
+static void dbt_put(DB *, const char *, DBT *, DBT *);
static void usage(void);
static void pman(DB *, const char *,
DBT *, size_t *, DBT *,
@@ -619,6 +620,25 @@ pmdoc_Nm(MDOC_ARGS)
memcpy(val->data, &fl, 4);
}
+static void
+dbt_put(DB *db, const char *dbn, DBT *key, DBT *val)
+{
+
+ if (0 == key->size)
+ return;
+
+ assert(key->data);
+ assert(8 == val->size);
+ assert(val->data);
+
+ if (0 == (*db->put)(db, key, val, 0))
+ return;
+
+ perror(dbn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ /* NOTREACHED */
+}
+
/*
* Call out to per-macro handlers after clearing the persistent database
* key. If the macro sets the database key, flush it to the database.
@@ -646,14 +666,8 @@ pmdoc_node(MDOC_ARGS)
dbt_init(key, ksz);
(*mdocs[n->tok])(db, dbn, key, ksz, val, n);
- if (0 == key->size)
- break;
- if (0 == (*db->put)(db, key, val, 0))
- break;
-
- perror(dbn);
- exit((int)MANDOCLEVEL_SYSERR);
- /* NOTREACHED */
+ dbt_put(db, dbn, key, val);
+ break;
default:
break;
}
@@ -666,8 +680,9 @@ static int
pman_node(MAN_ARGS)
{
const struct man_node *head, *body;
- const char *end, *start;
+ const char *start;
char nil;
+ size_t sz;
uint32_t fl;
if (NULL == n)
@@ -692,15 +707,40 @@ pman_node(MAN_ARGS)
MAN_TEXT == body->type) {
nil = '\0';
- start = body->string;
- if (NULL == (end = strchr(start, ' ')))
- end = start + strlen(start);
-
- dbt_init(key, ksz);
- dbt_appendb(key, ksz, start, end - start + 1);
- dbt_appendb(key, ksz, &nil, 1);
fl = MANDOC_NAME;
memcpy(val->data, &fl, 4);
+
+ start = 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.
+ */
+
+ while (start) {
+ sz = strcspn(start, " ,");
+ if ('\0' == start[(int)sz])
+ break;
+
+ dbt_init(key, ksz);
+ dbt_appendb(key, ksz, start, sz);
+ dbt_appendb(key, ksz, &nil, 1);
+
+ dbt_put(db, dbn, key, val);
+
+ if (' ' == start[(int)sz])
+ break;
+
+ assert(',' == start[(int)sz]);
+ start += (int)sz + 1;
+ while (' ' == *start)
+ start++;
+ }
+
return(1);
}
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2011-04-05 14:10 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=201104051410.p35EAqsH017693@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).