=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -p -r1.12 -r1.13 --- texi2mdoc/util.c 2015/02/23 22:50:11 1.12 +++ texi2mdoc/util.c 2015/02/24 14:35:40 1.13 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.12 2015/02/23 22:50:11 kristaps Exp $ */ +/* $Id: util.c,v 1.13 2015/02/24 14:35:40 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -160,9 +160,7 @@ texierr(struct texi *p, const char *fmt, ...) /* * Put a single data character to the output if we're not ignoring. - * Makes sure we don't spurriously start a macro. - * Adjusts our output status. - * This shouldn't be called for macros: just for ordinary text. + * Escape starting a line with a control character and slashes. */ void texiputchar(struct texi *p, char c) @@ -170,13 +168,14 @@ texiputchar(struct texi *p, char c) if (p->ign) return; - if ('.' == c && 0 == p->outcol) fputs("\\&", stdout); if ('\'' == c && 0 == p->outcol) fputs("\\&", stdout); putchar(c); + if ('\\' == c) + putchar('e'); p->seenvs = 0; if ('\n' == c) { p->outcol = 0; @@ -186,15 +185,22 @@ texiputchar(struct texi *p, char c) } /* - * Put multiple characters (see texiputchar()). - * This shouldn't be called for macros: just for ordinary text. + * Put an opaque series of characters. + * Characters starting a line with a control character are escaped, but + * that's it, so don't use this for non-controlled sequences of text. */ void texiputchars(struct texi *p, const char *s) { - while ('\0' != *s) - texiputchar(p, *s++); + if (p->ign) + return; + if ('.' == *s && 0 == p->outcol) + fputs("\\&", stdout); + if ('\'' == *s && 0 == p->outcol) + fputs("\\&", stdout); + p->outcol += fputs(s, stdout); + p->seenvs = 0; } /* @@ -367,9 +373,6 @@ advancenext(struct texi *p, const char *buf, size_t sz if (p->literal) { while (*pos < sz && ismspace(buf[*pos])) { - if (*pos && '\n' == buf[*pos] && - '\\' == buf[*pos - 1]) - texiputchar(p, 'e'); texiputchar(p, buf[*pos]); advance(p, buf, pos); } @@ -551,9 +554,6 @@ texiword(struct texi *p, const char *buf, '\'' == buf[*pos + 1]) { texiputchars(p, "\\(rq"); advance(p, buf, pos); - } else if ('\\' == buf[*pos]) { - texiputchar(p, buf[*pos]); - texiputchar(p, 'e'); } else texiputchar(p, buf[*pos]); advance(p, buf, pos); @@ -1036,20 +1036,10 @@ parsefile(struct texi *p, const char *fname, int parse p->filepos++; if ( ! parse) { - /* - * We're printing verbatim output. - * Make sure it doesn't get interpreted as mdoc by - * escaping escapes and making sure leading dots don't - * trigger mdoc(7) expansion. - */ - for (i = 0; i < f->mapsz; i++) { - if (i > 0 && '.' == f->map[i]) - if ('\n' == f->map[i - 1]) - fputs("\\&", stdout); - putchar(f->map[i]); - if ('\\' == f->map[i]) - putchar('e'); - } + for (i = 0; i < f->mapsz; i++) + texiputchar(p, f->map[i]); + if (p->outcol) + texiputchar(p, '\n'); } else parseeof(p, f->map, f->mapsz); texifilepop(p);