=================================================================== RCS file: /cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -p -r1.34 -r1.35 --- pod2mdoc/pod2mdoc.c 2014/07/19 00:42:22 1.34 +++ pod2mdoc/pod2mdoc.c 2014/10/22 23:10:05 1.35 @@ -1,4 +1,4 @@ -/* $Id: pod2mdoc.c,v 1.34 2014/07/19 00:42:22 schwarze Exp $ */ +/* $Id: pod2mdoc.c,v 1.35 2014/10/22 23:10:05 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * @@ -1008,11 +1008,12 @@ command(struct state *st, const char *buf, size_t star * 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 *buf, size_t sta * (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, size_t start, */ 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;