From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: mandocdb: use more macros
Date: Sun, 20 Nov 2011 18:10:36 +0100 [thread overview]
Message-ID: <20111120171036.GJ31954@iris.usta.de> (raw)
In-Reply-To: <20111120155209.GH31954@iris.usta.de>
And here is another patch, improving function handling,
to be applied on top of the previous one:
--- mandocdb.c.orig
+++ mandocdb.c
@@ -106,14 +106,13 @@ static void pformatted(DB *, struct buf *, struct buf *,
const struct of *);
static int pman_node(MAN_ARGS);
static void pmdoc_node(MDOC_ARGS);
+static int pmdoc_head(MDOC_ARGS);
static int pmdoc_Fd(MDOC_ARGS);
static int pmdoc_In(MDOC_ARGS);
static int pmdoc_Fn(MDOC_ARGS);
-static int pmdoc_Fo(MDOC_ARGS);
static int pmdoc_Nd(MDOC_ARGS);
static int pmdoc_Nm(MDOC_ARGS);
static int pmdoc_Sh(MDOC_ARGS);
-static int pmdoc_Ss(MDOC_ARGS);
static int pmdoc_St(MDOC_ARGS);
static int pmdoc_Vt(MDOC_ARGS);
static int pmdoc_Xr(MDOC_ARGS);
@@ -133,7 +132,7 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = {
{ NULL, 0, 0 }, /* Dt */
{ NULL, 0, 0 }, /* Os */
{ pmdoc_Sh, TYPE_Sh, MDOCF_CHILD }, /* Sh */
- { pmdoc_Ss, TYPE_Ss, MDOCF_CHILD }, /* Ss */
+ { pmdoc_head, TYPE_Ss, MDOCF_CHILD }, /* Ss */
{ NULL, 0, 0 }, /* Pp */
{ NULL, 0, 0 }, /* D1 */
{ NULL, 0, 0 }, /* Dl */
@@ -151,11 +150,11 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = {
{ NULL, TYPE_Er, MDOCF_CHILD }, /* Er */
{ NULL, TYPE_Ev, MDOCF_CHILD }, /* Ev */
{ NULL, 0, 0 }, /* Ex */
- { NULL, 0, 0 }, /* Fa */
+ { NULL, TYPE_Fa, MDOCF_CHILD }, /* Fa */
{ pmdoc_Fd, TYPE_In, 0 }, /* Fd */
{ NULL, TYPE_Fl, MDOCF_CHILD }, /* Fl */
- { pmdoc_Fn, TYPE_Fn, 0 }, /* Fn */
- { NULL, 0, 0 }, /* Ft */
+ { pmdoc_Fn, 0, 0 }, /* Fn */
+ { NULL, TYPE_Ft, MDOCF_CHILD }, /* Ft */
{ NULL, TYPE_Ic, MDOCF_CHILD }, /* Ic */
{ pmdoc_In, TYPE_In, 0 }, /* In */
{ NULL, TYPE_Li, MDOCF_CHILD }, /* Li */
@@ -224,7 +223,7 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = {
{ NULL, 0, 0 }, /* Ux */
{ NULL, 0, 0 }, /* Xc */
{ NULL, 0, 0 }, /* Xo */
- { pmdoc_Fo, TYPE_Fn, 0 }, /* Fo */
+ { pmdoc_head, TYPE_Fn, 0 }, /* Fo */
{ NULL, 0, 0 }, /* Fc */
{ NULL, 0, 0 }, /* Oo */
{ NULL, 0, 0 }, /* Oc */
@@ -808,6 +807,14 @@ hash_reset(DB **db)
/* ARGSUSED */
static int
+pmdoc_head(MDOC_ARGS)
+{
+
+ return(MDOC_HEAD == n->type);
+}
+
+/* ARGSUSED */
+static int
pmdoc_Fd(MDOC_ARGS)
{
const char *start, *end;
@@ -867,26 +874,50 @@ pmdoc_In(MDOC_ARGS)
static int
pmdoc_Fn(MDOC_ARGS)
{
+ struct mdoc_node *nn;
const char *cp;
-
- if (SEC_SYNOPSIS != n->sec)
- return(0);
- if (NULL == n->child || MDOC_TEXT != n->child->type)
+
+ nn = n->child;
+
+ if (NULL == nn || MDOC_TEXT != nn->type)
return(0);
- /* .Fn "struct type *arg" "foo" */
+ /* .Fn "struct type *name" "char *arg" */
- cp = strrchr(n->child->string, ' ');
+ cp = strrchr(nn->string, ' ');
if (NULL == cp)
- cp = n->child->string;
+ cp = nn->string;
/* Strip away pointer symbol. */
while ('*' == *cp)
cp++;
+ /* Store the function name. */
+
buf_append(buf, cp);
- return(1);
+ hash_put(hash, buf, TYPE_Fn);
+
+ /* Store the function type. */
+
+ if (nn->string < cp) {
+ buf->len = 0;
+ buf_appendb(buf, nn->string, cp - nn->string);
+ buf_appendb(buf, "", 1);
+ hash_put(hash, buf, TYPE_Ft);
+ }
+
+ /* Store the arguments. */
+
+ for (nn = nn->next; nn; nn = nn->next) {
+ if (MDOC_TEXT != nn->type)
+ continue;
+ buf->len = 0;
+ buf_append(buf, nn->string);
+ hash_put(hash, buf, TYPE_Fa);
+ }
+
+ return(0);
}
/* ARGSUSED */
@@ -959,21 +990,6 @@ pmdoc_Vt(MDOC_ARGS)
/* ARGSUSED */
static int
-pmdoc_Fo(MDOC_ARGS)
-{
-
- if (SEC_SYNOPSIS != n->sec || MDOC_HEAD != n->type)
- return(0);
- if (NULL == n->child || MDOC_TEXT != n->child->type)
- return(0);
-
- buf_append(buf, n->child->string);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
pmdoc_Nd(MDOC_ARGS)
{
@@ -1008,14 +1024,6 @@ pmdoc_Sh(MDOC_ARGS)
return(SEC_CUSTOM == n->sec && MDOC_HEAD == n->type);
}
-/* ARGSUSED */
-static int
-pmdoc_Ss(MDOC_ARGS)
-{
-
- return(MDOC_HEAD == n->type);
-}
-
static void
hash_put(DB *db, const struct buf *buf, uint64_t mask)
{
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next prev parent reply other threads:[~2011-11-20 17:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-20 15:52 Ingo Schwarze
2011-11-20 17:10 ` Ingo Schwarze [this message]
2011-12-05 23:02 ` Ingo Schwarze
2011-12-07 1:00 ` Kristaps Dzonsons
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=20111120171036.GJ31954@iris.usta.de \
--to=schwarze@usta.de \
--cc=tech@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).