=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -p -r1.8 -r1.9 --- texi2mdoc/main.c 2015/02/18 12:03:21 1.8 +++ texi2mdoc/main.c 2015/02/18 14:52:45 1.9 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.8 2015/02/18 12:03:21 kristaps Exp $ */ +/* $Id: main.c,v 1.9 2015/02/18 14:52:45 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -135,6 +135,7 @@ enum texicmd { TEXICMD_UREF, TEXICMD_URL, TEXICMD_VAR, + TEXICMD_VSKIP, TEXICMD_W, TEXICMD_XREF, TEXICMD__MAX @@ -200,6 +201,8 @@ struct texi { /* Texi disregards spaces and tabs. */ #define isws(_x) \ (' ' == (_x) || '\t' == (_x)) +#define ismspace(_x) \ + (isws((_x) || '\n' == (_x))) static void doblock(struct texi *, enum texicmd, const char *, size_t, size_t *); static void dobracket(struct texi *, enum texicmd, const char *, size_t, size_t *); @@ -334,6 +337,7 @@ static const struct texitok texitoks[TEXICMD__MAX] = { { dolink, "uref", 4 }, /* TEXICMD_UREF */ { dolink, "url", 3 }, /* TEXICMD_URL */ { doliteral, "var", 3 }, /* TEXICMD_VAR */ + { dosp, "vskip", 5 }, /* TEXICMD_VSKIP */ { dobracket, "w", 1 }, /* TEXICMD_W */ { dolink, "xref", 4 }, /* TEXICMD_XREF */ }; @@ -534,7 +538,7 @@ advancenext(struct texi *p, const char *buf, size_t sz { if (p->literal) { - while (*pos < sz && isspace(buf[*pos])) { + while (*pos < sz && ismspace(buf[*pos])) { if (*pos && '\n' == buf[*pos] && '\\' == buf[*pos - 1]) texiputchar(p, 'e'); @@ -544,7 +548,7 @@ advancenext(struct texi *p, const char *buf, size_t sz return(*pos); } - while (*pos < sz && isspace(buf[*pos])) { + while (*pos < sz && ismspace(buf[*pos])) { p->seenws = 1; /* * If it looks like we've printed a double-line, then @@ -606,7 +610,7 @@ texiword(struct texi *p, const char *buf, p->seenws = 0; - while (*pos < sz && ! isspace(buf[*pos])) { + while (*pos < sz && ! ismspace(buf[*pos])) { switch (buf[*pos]) { case ('@'): case ('}'): @@ -644,12 +648,15 @@ texicmd(struct texi *p, const char *buf, assert('@' == buf[pos]); - if (++pos >= sz) + if ((*end = pos) == sz) return(TEXICMD__MAX); + else if ((*end = ++pos) == sz) + return(TEXICMD__MAX); /* Alphabetic commands are special. */ if ( ! isalpha(buf[pos])) { - *end = pos + 1; + if ((*end = pos + 1) == sz) + return(TEXICMD__MAX); for (i = 0; i < TEXICMD__MAX; i++) { if (1 != texitoks[i].len) continue; @@ -660,7 +667,7 @@ texicmd(struct texi *p, const char *buf, return(TEXICMD__MAX); } - for (*end = pos; *end < sz && ! isspace(buf[*end]); (*end)++) + for (*end = pos; *end < sz && ! ismspace(buf[*end]); (*end)++) if ((*end > pos && ('@' == buf[*end] || '{' == buf[*end] || '}' == buf[*end]))) break; @@ -692,7 +699,7 @@ parsearg(struct texi *p, const char *buf, size_t end; enum texicmd cmd; - while (*pos < sz && isspace(buf[*pos])) + while (*pos < sz && ismspace(buf[*pos])) advance(p, buf, pos); if (*pos == sz || (0 == num && '{' != buf[*pos])) return(0); @@ -739,7 +746,7 @@ parsebracket(struct texi *p, const char *buf, size_t s size_t end; enum texicmd cmd; - while (*pos < sz && isspace(buf[*pos])) + while (*pos < sz && ismspace(buf[*pos])) advance(p, buf, pos); if (*pos == sz || '{' != buf[*pos]) @@ -1066,7 +1073,7 @@ doinline(struct texi *p, const char *buf, parsebracket(p, buf, sz, pos); if (*pos < sz - 1 && ismpunct(buf[*pos]) && - isspace(buf[*pos + 1])) { + ismspace(buf[*pos + 1])) { texiputchar(p, ' '); texiputchar(p, buf[*pos]); advance(p, buf, pos); @@ -1365,7 +1372,7 @@ dolink(struct texi *p, enum texicmd cmd, if (*pos < sz - 1 && ismpunct(buf[*pos]) && - isspace(buf[*pos + 1])) { + ismspace(buf[*pos + 1])) { texiputchar(p, ' '); texiputchar(p, buf[*pos]); advance(p, buf, pos); @@ -1479,7 +1486,7 @@ doitem(struct texi *p, enum texicmd cmd, if (TEXILIST_ITEM == p->list) teximacroclose(p); - else + else if (p->outcol > 0) texiputchar(p, '\n'); }