From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout.scc.kit.edu (scc-mailout.scc.kit.edu [129.13.185.202]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id pAKHAcaD032111 for ; Sun, 20 Nov 2011 12:10:38 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-02.scc.kit.edu with esmtp (Exim 4.72 #1) id 1RSAua-0005tL-Ih; Sun, 20 Nov 2011 18:10:36 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1RSAua-0003xf-Lo for tech@mdocml.bsd.lv; Sun, 20 Nov 2011 18:10:36 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1RSAua-0007am-Ki for tech@mdocml.bsd.lv; Sun, 20 Nov 2011 18:10:36 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1RSAua-00015v-D5 for tech@mdocml.bsd.lv; Sun, 20 Nov 2011 18:10:36 +0100 Date: Sun, 20 Nov 2011 18:10:36 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: Re: mandocdb: use more macros Message-ID: <20111120171036.GJ31954@iris.usta.de> References: <20111120155209.GH31954@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20111120155209.GH31954@iris.usta.de> User-Agent: Mutt/1.5.21 (2010-09-15) 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