=================================================================== RCS file: /cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -p -r1.7 -r1.8 --- pod2mdoc/pod2mdoc.c 2014/03/23 23:35:59 1.7 +++ pod2mdoc/pod2mdoc.c 2014/03/23 23:57:38 1.8 @@ -1,4 +1,4 @@ -/* $Id: pod2mdoc.c,v 1.7 2014/03/23 23:35:59 kristaps Exp $ */ +/* $Id: pod2mdoc.c,v 1.8 2014/03/23 23:57:38 kristaps Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * @@ -158,20 +158,6 @@ formatescape(const char *buf, size_t *start, size_t en } /* - * Skip space characters. - */ -static int -skipspace(const char *buf, size_t *start, size_t end) -{ - size_t sv = *start; - - while (*start < end && ' ' == buf[*start]) - (*start)++; - - return(*start > sv); -} - -/* * We're at the character in front of a format code, which is structured * like X<...> and can contain nested format codes. * This consumes the whole format code, and any nested format codes, til @@ -204,6 +190,8 @@ formatcode(const char *buf, size_t *start, if (FMT__MAX == fmt) { putchar(last = buf[(*start)++]); + if ('\\' == last) + putchar('e'); return(0); } @@ -363,6 +351,10 @@ formatcode(const char *buf, size_t *start, else putchar(last = buf[*start]); + /* Protect against character escapes. */ + if ('\\' == last) + putchar('e'); + (*start)++; if (' ' == last) @@ -412,10 +404,15 @@ formatcodeln(const char *buf, size_t *start, size_t en ' ' == buf[*start + 2])) printf("\\&"); - if ('\n' != buf[*start]) - putchar(last = buf[*start]); - else + if ('\n' == buf[*start]) putchar(last = ' '); + else + putchar(last = buf[*start]); + + /* Protect against character escapes. */ + if ('\\' == last) + putchar('e'); + (*start)++; } } @@ -471,7 +468,9 @@ command(struct state *st, const char *buf, size_t star return; start += csz; - skipspace(buf, &start, end); + while (start < end && ' ' == buf[start]) + start++; + len = end - start; if (st->paused) { @@ -624,17 +623,23 @@ command(struct state *st, const char *buf, size_t star static void verbatim(struct state *st, const char *buf, size_t start, size_t end) { - size_t sv = start; + int last; if ( ! st->parsing || st->paused) return; puts(".Bd -literal"); - while (start < end) { - if (start > sv && '\n' == buf[start - 1]) + for (last = ' '; start < end; start++) { + /* + * Handle accidental macros (newline starting with + * control character) and escapes. + */ + if ('\n' == last) if ('.' == buf[start] || '\'' == buf[start]) printf("\\&"); - putchar(buf[start++]); + putchar(last = buf[start]); + if ('\\' == buf[start]) + printf("e"); } putchar('\n'); puts(".Ed"); @@ -704,6 +709,8 @@ ordinary(struct state *st, const char *buf, size_t sta else if ('\n' == last && '\'' == buf[start]) printf("\\&"); putchar(last = buf[start++]); + if ('\\' == last) + putchar('e'); } if (start < end - 1 && '<' == buf[start + 1]) { @@ -713,6 +720,8 @@ ordinary(struct state *st, const char *buf, size_t sta * what, so print a newline now. * Then print the (possibly nested) macros and * following that, a newline. + * Consume all whitespace so we don't + * accidentally start an implicit literal line. */ if (formatcode(buf, &start, end, 0, 0)) { putchar(last = '\n'); @@ -753,6 +762,8 @@ ordinary(struct state *st, const char *buf, size_t sta else if ('\n' == last && '\'' == buf[start]) printf("\\&"); putchar(last = buf[start++]); + if ('\\' == last) + putchar('e'); } }