=================================================================== RCS file: /cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.33 retrieving revision 1.35 diff -u -p -r1.33 -r1.35 --- pod2mdoc/pod2mdoc.c 2014/07/18 23:56:57 1.33 +++ pod2mdoc/pod2mdoc.c 2014/10/22 23:10:05 1.35 @@ -1,4 +1,4 @@ -/* $Id: pod2mdoc.c,v 1.33 2014/07/18 23:56:57 schwarze Exp $ */ +/* $Id: pod2mdoc.c,v 1.35 2014/10/22 23:10:05 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * @@ -666,7 +666,8 @@ formatcode(struct state *st, const char *buf, size_t * break; } } - if (*start + 1 < end && '<' == buf[*start + 1]) { + if (*start + 1 < end && '<' == buf[*start + 1] && + 'A' <= buf[*start] && 'Z' >= buf[*start]) { formatcode(st, buf, start, end, nomacro, 1); continue; } @@ -746,7 +747,8 @@ formatcodeln(struct state *st, const char *linemac, } while (*start < end && ' ' == buf[*start]); } - if (*start + 1 < end && '<' == buf[*start + 1]) { + if (*start + 1 < end && '<' == buf[*start + 1] && + 'A' <= buf[*start] && 'Z' >= buf[*start]) { st->wantws |= wantws; gotmacro = formatcode(st, buf, start, end, nomacro, 1); @@ -1006,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: /* @@ -1021,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)) { @@ -1045,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++) { /* @@ -1220,7 +1268,8 @@ ordinary(struct state *st, const char *buf, size_t sta * Escape initial control characters. */ while (start < end) { - if (start < end - 1 && '<' == buf[start + 1]) + if (start < end - 1 && '<' == buf[start + 1] && + 'A' <= buf[start] && 'Z' >= buf[start]) break; else if ('\n' == buf[start]) break; @@ -1256,7 +1305,8 @@ ordinary(struct state *st, const char *buf, size_t sta outbuf_addchar(st); } - if (start < end - 1 && '<' == buf[start + 1]) { + if (start < end - 1 && '<' == buf[start + 1] && + 'A' <= buf[start] && 'Z' >= buf[start]) { formatcode(st, buf, &start, end, 0, seq); if (OUST_MAC == st->oust) { /* @@ -1294,7 +1344,9 @@ ordinary(struct state *st, const char *buf, size_t sta */ if ( ! st->wantws && start < end && - '<' != buf[start + 1]) { + ('<' != buf[start + 1] || + 'A' > buf[start] || + 'Z' < buf[start])) { printf(" Ns "); st->wantws = 1; } @@ -1329,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); @@ -1351,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;