=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.17 retrieving revision 1.19 diff -u -p -r1.17 -r1.19 --- texi2mdoc/util.c 2015/02/28 00:03:20 1.17 +++ texi2mdoc/util.c 2015/02/28 13:16:44 1.19 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.17 2015/02/28 00:03:20 kristaps Exp $ */ +/* $Id: util.c,v 1.19 2015/02/28 13:16:44 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -591,7 +591,7 @@ parseword(struct texi *p, size_t *pos, char extra) * index after the command name. */ enum texicmd -texicmd(struct texi *p, size_t pos, size_t *end, struct teximacro **macro) +texicmd(const struct texi *p, size_t pos, size_t *end, struct teximacro **macro) { size_t i, len, toksz; @@ -719,9 +719,9 @@ parsearg(struct texi *p, size_t *pos, size_t num) * This will stop in the event of EOF or if we're not at a bracket. */ void -parsebracket(struct texi *p, size_t *pos) +parsebracket(struct texi *p, size_t *pos, int dostack) { - size_t end, sv; + size_t end, sv, stack; enum texicmd cmd; struct teximacro *macro; @@ -732,12 +732,25 @@ parsebracket(struct texi *p, size_t *pos) return; advance(p, pos); + stack = 0; while ((*pos = advancenext(p, pos)) < BUFSZ(p)) { switch (BUF(p)[*pos]) { case ('}'): + if (stack > 0) { + stack--; + advance(p, pos); + texiputchar(p, '}'); + continue; + } advance(p, pos); return; case ('{'): + if (dostack) { + stack++; + advance(p, pos); + texiputchar(p, '{'); + continue; + } if (0 == p->ign) texiwarn(p, "unexpected \"{\""); advance(p, pos); @@ -814,6 +827,23 @@ parseeoln(struct texi *p, size_t *pos) } /* + * Peek to see if there's a command after subsequent whitespace. + * If so, return the macro identifier. + * This DOES NOT work with user-defined macros. + */ +enum texicmd +peekcmd(const struct texi *p, size_t pos) +{ + size_t end; + + while (pos < BUFSZ(p) && ismspace(BUF(p)[pos])) + pos++; + if (pos == BUFSZ(p) || '@' != BUF(p)[pos]) + return(TEXICMD__MAX); + return(texicmd(p, pos, &end, NULL)); +} + +/* * Parse a single word or command. * This will return immediately at the EOF. */ @@ -874,7 +904,7 @@ parselinearg(struct texi *p, size_t *pos) } if (*pos < BUFSZ(p) && '{' == BUF(p)[*pos]) - parsebracket(p, pos); + parsebracket(p, pos, 0); else if (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) parsesingle(p, pos); else