=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -p -r1.7 -r1.8 --- texi2mdoc/util.c 2015/02/23 11:44:30 1.7 +++ texi2mdoc/util.c 2015/02/23 11:56:39 1.8 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.7 2015/02/23 11:44:30 kristaps Exp $ */ +/* $Id: util.c,v 1.8 2015/02/23 11:56:39 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -409,13 +409,13 @@ texiexecmacro(struct texi *p, struct teximacro *m, char *val; char **args; - args = argparse(p, buf, sz, pos, &asz); + args = argparse(p, buf, sz, pos, &asz, m->argsz); if (asz != m->argsz) texiwarn(p, "invalid macro argument length"); aasz = asz < m->argsz ? asz : m->argsz; if (0 == aasz) { - parseeof(p, m->value, strlen(m->value)); + parsemembuf(p, m->value, strlen(m->value)); return; } @@ -481,7 +481,7 @@ texiexecmacro(struct texi *p, struct teximacro *m, i = end; } - parseeof(p, val, strlen(val)); + parsemembuf(p, val, strlen(val)); for (i = 0; i < asz; i++) free(args[i]); @@ -839,6 +839,34 @@ parseeof(struct texi *p, const char *buf, size_t sz) } /* + * This is like parseeof() except that it's to be invoked on memory + * buffers while parsing a larger scope. + * This is useful for parsing macro sequences. + * The line, column, and name of the calling file context are saved, the + * column and line reset, then all of these restored after parse. + */ +void +parsemembuf(struct texi *p, const char *buf, size_t sz) +{ + size_t svln, svcol; + const char *svname; + + svln = p->files[p->filepos - 1].line; + svcol = p->files[p->filepos - 1].col; + svname = p->files[p->filepos - 1].name; + + p->files[p->filepos - 1].line = 0; + p->files[p->filepos - 1].col = 0; + p->files[p->filepos - 1].name = ""; + + parseeof(p, buf, sz); + + p->files[p->filepos - 1].line = svln; + p->files[p->filepos - 1].col = svcol; + p->files[p->filepos - 1].name = svname; +} + +/* * Parse a block sequence until we have the "@end endtoken" command * invocation. * This will return immediately at EOF. @@ -1104,7 +1132,7 @@ valueadd(struct texi *p, char *key, char *val) */ char ** argparse(struct texi *p, const char *buf, - size_t sz, size_t *pos, size_t *argsz) + size_t sz, size_t *pos, size_t *argsz, size_t hint) { char **args; size_t start, end, stack; @@ -1133,7 +1161,7 @@ argparse(struct texi *p, const char *buf, * We keep track of embedded-ness in the "stack" * state anyway, so this is free. */ - if (0 == stack && ',' == buf[*pos]) + if (',' == buf[*pos] && 0 == stack && 1 != hint) break; else if (0 == stack && '}' == buf[*pos]) break;