=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -p -r1.25 -r1.26 --- texi2mdoc/main.c 2015/02/20 12:25:25 1.25 +++ texi2mdoc/main.c 2015/02/20 15:37:33 1.26 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.25 2015/02/20 12:25:25 kristaps Exp $ */ +/* $Id: main.c,v 1.26 2015/02/20 15:37:33 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -158,7 +158,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dovalue, "ifclear", 7 }, /* TEXICMD_IFCLEAR */ { doignblock, "ifdocbook", 9 }, /* TEXICMD_IFDOCBOOK */ { doignblock, "ifhtml", 6 }, /* TEXICMD_IFHTML */ - { doignblock, "ifinfo", 6 }, /* TEXICMD_IFINFO */ + { doblock, "ifinfo", 6 }, /* TEXICMD_IFINFO */ { doblock, "ifnotdocbook", 12 }, /* TEXICMD_IFNOTDOCBOOK */ { doblock, "ifnothtml", 9 }, /* TEXICMD_IFNOTHTML */ { doblock, "ifnotinfo", 9 }, /* TEXICMD_IFNOTINFO */ @@ -388,10 +388,34 @@ static void doignblock(struct texi *p, enum texicmd cmd, const char *buf, size_t sz, size_t *pos) { - - p->ign++; - parseto(p, buf, sz, pos, texitoks[cmd].tok); - p->ign--; + char end[32]; + const char *term; + size_t endsz, endpos; + + /* + * We want to completely ignore everything in these blocks, so + * simply jump to the @end block. + */ + endsz = snprintf(end, sizeof(end), + "\n@end %s\n", texitoks[cmd].tok); + assert(endsz < sizeof(end)); + + /* + * Look up where our end token occurs. + * Set our end position based on the relative offset of that + * from our current position, or the EOF if we don't have a + * proper ending point. + */ + term = memmem(&buf[*pos], sz, end, endsz); + endpos = NULL == term ? sz : + *pos + term - &buf[*pos]; + assert(endpos <= sz); + while (*pos < endpos) + advance(p, buf, pos); + + /* Only do this if we're not already at the end. */ + if (endpos < sz) + advanceto(p, buf, pos, endpos + endsz); } static void @@ -464,6 +488,8 @@ doverb(struct texi *p, enum texicmd cmd, const char *end, *term; size_t endsz, endpos; + advanceeoln(p, buf, sz, pos, 1); + /* We end at exactly this token. */ end = "\n@end verbatim\n"; endsz = strlen(end); @@ -479,8 +505,11 @@ doverb(struct texi *p, enum texicmd cmd, teximacro(p, "Bd -literal -offset indent"); assert(endpos <= sz); - /* Run to the point inclusive the endpoint newline. */ - while (*pos < endpos + 1) { + while (*pos < endpos) { + if (buf[*pos] == '\n') + p->outcol = 0; + else + p->outcol++; if (*pos > 0 && '.' == buf[*pos]) if ('\n' == buf[*pos - 1]) fputs("\\&", stdout); @@ -490,7 +519,7 @@ doverb(struct texi *p, enum texicmd cmd, advance(p, buf, pos); } teximacro(p, "Ed"); - advanceto(p, buf, pos, *pos + endpos + endsz); + advanceto(p, buf, pos, endpos + endsz); } static void @@ -681,6 +710,7 @@ dotitle(struct texi *p, enum texicmd cmd, start = end = *pos; while (end < sz && '\n' != buf[end]) end++; + advanceeoln(p, buf, sz, pos, 1); free(p->subtitle); p->subtitle = malloc(end - start + 1); memcpy(p->subtitle, &buf[start], end - start); @@ -894,7 +924,6 @@ dovalue(struct texi *p, enum texicmd cmd, const char *buf, size_t sz, size_t *pos) { size_t start, end; - int clr; char *key, *val; const char *cp; @@ -942,12 +971,10 @@ dovalue(struct texi *p, enum texicmd cmd, else texiputchars(p, cp); } else if (TEXICMD_IFCLEAR == cmd) { - clr = NULL != valuellookup(p, buf, sz, pos); - if (clr) - p->ign++; - parseto(p, buf, sz, pos, texitoks[cmd].tok); - if (clr) - p->ign--; + if (NULL != valuellookup(p, buf, sz, pos)) + doignblock(p, cmd, buf, sz, pos); + else + parseto(p, buf, sz, pos, texitoks[cmd].tok); } else if (TEXICMD_CLEAR == cmd) valuelclear(p, buf, sz, pos); } @@ -1121,6 +1148,9 @@ dotop(struct texi *p, enum texicmd cmd, time_t t; char date[32]; + if (--p->ign) + texierr(p, "@top command while ignoring (%d)", p->ign); + /* * Here we print our standard mdoc(7) prologue. * We use the title set with @settitle for the `Nd' description @@ -1131,7 +1161,6 @@ dotop(struct texi *p, enum texicmd cmd, t = time(NULL); strftime(date, sizeof(date), "%F", localtime(&t)); - p->ign--; teximacroopen(p, "Dd"); texiputchars(p, date); teximacroclose(p);