=================================================================== RCS file: /cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -p -r1.32 -r1.33 --- pod2mdoc/pod2mdoc.c 2014/07/18 05:09:32 1.32 +++ pod2mdoc/pod2mdoc.c 2014/07/18 23:56:57 1.33 @@ -1,4 +1,4 @@ -/* $Id: pod2mdoc.c,v 1.32 2014/07/18 05:09:32 schwarze Exp $ */ +/* $Id: pod2mdoc.c,v 1.33 2014/07/18 23:56:57 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * @@ -169,6 +169,7 @@ outbuf_addstr(struct state *st, const char *str) if (st->outbuflen + slen >= st->outbufsz) outbuf_grow(st, slen); memcpy(st->outbuf + st->outbuflen, str, slen+1); + st->outbuflen += slen; last = str[slen - 1]; st->wantws = 0; } @@ -242,7 +243,7 @@ formatescape(struct state *st, const char *buf, size_t outbuf_addstr(st, "\\(la"); else if (0 == strcmp(esc, "gt")) outbuf_addstr(st, "\\(ra"); - else if (0 == strcmp(esc, "vb")) + else if (0 == strcmp(esc, "verbar")) outbuf_addstr(st, "\\(ba"); else if (0 == strcmp(esc, "sol")) outbuf_addstr(st, "\\(sl"); @@ -469,7 +470,7 @@ again: * We usually exit in OUST_MAC mode, except when * entering without OUST_MAC and the code is invalid. */ -static void +static int formatcode(struct state *st, const char *buf, size_t *start, size_t end, int nomacro, int pos) { @@ -512,7 +513,7 @@ formatcode(struct state *st, const char *buf, size_t * */ if (FMT_ESCAPE == fmt) { formatescape(st, buf, start, end); - return; + return(0); } else if (FMT_NULL == fmt || FMT_INDEX == fmt) { /* * Just consume til the end delimiter, accounting for @@ -542,7 +543,7 @@ formatcode(struct state *st, const char *buf, size_t * if (isspace(last)) while (*start < end && isspace((int)buf[*start])) (*start)++; - return; + return(0); } /* @@ -680,7 +681,7 @@ formatcode(struct state *st, const char *buf, size_t * continue; } - if (OUST_MAC == st->oust) { + if (OUST_MAC == st->oust && FMT__MAX != fmt) { if ( ! st->wantws) { printf(" Ns "); st->wantws = 1; @@ -708,11 +709,14 @@ formatcode(struct state *st, const char *buf, size_t * putchar('e'); } + if (FMT__MAX == fmt) + return(0); + if ( ! nomacro && FMT_CODE == fmt) printf(" Qc "); - if (FMT__MAX != fmt) - st->wantws = ' ' == last; + st->wantws = ' ' == last; + return(1); } /* @@ -725,27 +729,51 @@ static void formatcodeln(struct state *st, const char *linemac, const char *buf, size_t *start, size_t end, int nomacro) { + int gotmacro, wantws; assert(OUST_NL == st->oust); assert(st->wantws); printf(".%s ", linemac); st->oust = OUST_MAC; - last = ' '; + gotmacro = 0; while (*start < end) { + wantws = ' ' == buf[*start] || '\n' == buf[*start]; + if (wantws) { + last = ' '; + do { + (*start)++; + } while (*start < end && ' ' == buf[*start]); + } + if (*start + 1 < end && '<' == buf[*start + 1]) { - formatcode(st, buf, start, end, nomacro, 1); + st->wantws |= wantws; + gotmacro = formatcode(st, buf, + start, end, nomacro, 1); continue; } - if (OUST_MAC == st->oust) { - if ( ! st->wantws && - ' ' != buf[*start] && - '\n' != buf[*start]) - printf(" Ns "); - st->wantws = 1; + if (gotmacro) { + if (*start < end || st->outbuflen) { + if (st->wantws || + (wantws && !st->outbuflen)) + printf(" No "); + else + printf(" Ns "); + } + gotmacro = 0; } + outbuf_flush(st); + st->wantws = wantws; + if (*start >= end) + break; + + if (st->wantws) { + putchar(' '); + st->wantws = 0; + } + /* * Since we're already on a macro line, we want to make * sure that we don't inadvertently invoke a macro. @@ -754,18 +782,15 @@ formatcodeln(struct state *st, const char *linemac, * something that needn't be escaped. */ if (' ' == last && end - *start > 1 && - isupper((int)buf[*start]) && - islower((int)buf[*start + 1]) && - (end - *start == 2 || - ' ' == buf[*start + 2])) + isupper((unsigned char)buf[*start]) && + islower((unsigned char)buf[*start + 1]) && + (end - *start == 2 || ' ' == buf[*start + 2])) printf("\\&"); - if ('\n' == buf[*start]) - putchar(last = ' '); - else - putchar(last = buf[*start]); + putchar(last = buf[*start]); /* Protect against character escapes. */ + if ('\\' == last) putchar('e');