From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (schwarze@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id s9MNA6Xb011090 for ; Wed, 22 Oct 2014 19:10:06 -0400 (EDT) Received: (from schwarze@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id s9MNA5Of000365; Wed, 22 Oct 2014 19:10:05 -0400 (EDT) Date: Wed, 22 Oct 2014 19:10:05 -0400 (EDT) Message-Id: <201410222310.s9MNA5Of000365@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: pod2mdoc: Simple Ft/Fo/Fa/Fc parser and formatter for the SYNOPSIS. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Simple Ft/Fo/Fa/Fc parser and formatter for the SYNOPSIS. Dedicated to bentley@. Modified Files: -------------- pod2mdoc: pod2mdoc.c Revision Data ------------- Index: pod2mdoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.34 retrieving revision 1.35 diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.34 -r1.35 --- pod2mdoc.c +++ pod2mdoc.c @@ -1008,11 +1008,12 @@ command(struct state *st, const char *bu * always stays in OUST_NL/wantws mode. */ static void -verbatim(struct state *st, const char *buf, size_t start, size_t end) +verbatim(struct state *st, char *buf, size_t start, size_t end) { - size_t i; + size_t i, ift, ifo, ifa, ifc; + char *cp; - if ( ! st->parsing || st->paused) + if ( ! st->parsing || st->paused || start == end) return; again: /* @@ -1023,10 +1024,11 @@ again: */ if (SECT_SYNOPSIS == st->sect) { i = start; - for (i = start; i < end && ' ' == buf[i]; i++) - /* Spin. */ ; + while (i < end && buf[i] == ' ') + i++; if (i == end) return; + /* We're an include block! */ if (end - i > 10 && 0 == memcmp(&buf[i], "#include <", 10)) { @@ -1047,10 +1049,54 @@ again: goto again; return; } + + /* Parse function declaration. */ + ifo = ifa = ifc = 0; + for (ift = i; i < end && buf[i] != '\n'; i++) { + if (ifa) { + if (buf[i] == ')') + ifc = i; + } else if (ifo && buf[i] == '(') + ifa = i; + else if (buf[i] == ' ') + ifo = i; + } + + /* Encode function declaration. */ + if (ifc) { + buf[ifo++] = '\0'; + printf(".Ft %s", buf + ift); + if (buf[ifo] == '*') { + fputs(" *", stdout); + ifo++; + } + putchar('\n'); + buf[ifa++] = '\0'; + printf(".Fo %s\n", buf + ifo); + buf[ifc++] = '\0'; + for (;;) { + cp = strchr(buf + ifa, ','); + if (cp != NULL) + *cp = '\0'; + printf(".Fa \"%s\"\n", buf + ifa); + if (cp == NULL) + break; + ifa = cp - buf + 1; + } + puts(".Fc"); + if (buf[ifc] == ';') + ifc++; + if (ifc < i) { + buf[i] = '\0'; + puts(buf + ifc); + } + start = i + 1; + if (start < end) + goto again; + return; + } } - if (start == end) - return; puts(".Bd -literal"); for (last = ' '; start < end; start++) { /* @@ -1335,7 +1381,7 @@ ordinary(struct state *st, const char *b * (default: starts with "="). */ static void -dopar(struct state *st, const char *buf, size_t start, size_t end) +dopar(struct state *st, char *buf, size_t start, size_t end) { assert(OUST_NL == st->oust); @@ -1357,7 +1403,7 @@ dopar(struct state *st, const char *buf, */ static void dofile(const struct args *args, const char *fname, - const struct tm *tm, const char *buf, size_t sz) + const struct tm *tm, char *buf, size_t sz) { char datebuf[64]; struct state st; -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv