version 1.16, 2015/02/25 15:50:56 |
version 1.17, 2015/02/28 00:03:20 |
Line 330 advance(struct texi *p, size_t *pos) |
|
Line 330 advance(struct texi *p, size_t *pos) |
|
f->col = 0; |
f->col = 0; |
} else |
} else |
f->col++; |
f->col++; |
} else |
} else { |
--f->insplice; |
--f->insplice; |
|
if (0 == f->insplice) |
|
f->depth = 0; |
|
} |
|
|
(*pos)++; |
(*pos)++; |
} |
} |
Line 439 advanceto(struct texi *p, size_t *pos, size_t end) |
|
Line 442 advanceto(struct texi *p, size_t *pos, size_t end) |
|
} |
} |
|
|
static void |
static void |
texiexecmacro(struct texi *p, struct teximacro *m, size_t *pos) |
texiexecmacro(struct texi *p, struct teximacro *m, size_t sv, size_t *pos) |
{ |
{ |
size_t valsz, realsz, aasz, asz, |
size_t valsz, realsz, aasz, asz, |
ssz, i, j, k, start, end; |
ssz, i, j, k, start, end; |
Line 447 texiexecmacro(struct texi *p, struct teximacro *m, siz |
|
Line 450 texiexecmacro(struct texi *p, struct teximacro *m, siz |
|
char **args; |
char **args; |
const char *cp; |
const char *cp; |
|
|
|
/* Disregard empty macros. */ |
|
if (0 == (valsz = realsz = strlen(m->value))) |
|
return; |
|
|
|
/* |
|
* This is important: it protect us from macros that invoke more |
|
* macros, possibly going on infinitely. |
|
* We use "sv" instead of the current position because we might |
|
* be invoked at the end of the macro (i.e., insplice == 0). |
|
* The "sv" value was initialised at the start of the macro. |
|
*/ |
|
if (sv > 0) |
|
if (++p->files[p->filepos].depth > 64) |
|
texierr(p, "maximium recursive depth"); |
|
|
args = argparse(p, pos, &asz, m->argsz); |
args = argparse(p, pos, &asz, m->argsz); |
if (asz != m->argsz) |
if (asz != m->argsz) |
texiwarn(p, "invalid macro argument length"); |
texiwarn(p, "invalid macro argument length"); |
aasz = asz < m->argsz ? asz : m->argsz; |
aasz = asz < m->argsz ? asz : m->argsz; |
|
|
if (0 == aasz) { |
if (0 == aasz) { |
texisplice(p, m->value, strlen(m->value), pos); |
texisplice(p, m->value, valsz, pos); |
return; |
return; |
} |
} |
|
|
valsz = realsz = strlen(m->value); |
|
val = strdup(m->value); |
val = strdup(m->value); |
|
|
for (i = j = 0; i < realsz; i++) { |
for (i = j = 0; i < realsz; i++) { |
Line 653 texicmd(struct texi *p, size_t pos, size_t *end, struc |
|
Line 670 texicmd(struct texi *p, size_t pos, size_t *end, struc |
|
int |
int |
parsearg(struct texi *p, size_t *pos, size_t num) |
parsearg(struct texi *p, size_t *pos, size_t num) |
{ |
{ |
size_t end; |
size_t end, sv; |
enum texicmd cmd; |
enum texicmd cmd; |
struct teximacro *macro; |
struct teximacro *macro; |
|
|
Line 684 parsearg(struct texi *p, size_t *pos, size_t num) |
|
Line 701 parsearg(struct texi *p, size_t *pos, size_t num) |
|
continue; |
continue; |
} |
} |
|
|
|
sv = p->files[p->filepos - 1].insplice; |
cmd = texicmd(p, *pos, &end, ¯o); |
cmd = texicmd(p, *pos, &end, ¯o); |
advanceto(p, pos, end); |
advanceto(p, pos, end); |
if (NULL != macro) |
if (NULL != macro) |
texiexecmacro(p, macro, pos); |
texiexecmacro(p, macro, sv, pos); |
if (TEXICMD__MAX == cmd) |
if (TEXICMD__MAX == cmd) |
continue; |
continue; |
if (NULL != texitoks[cmd].fp) |
if (NULL != texitoks[cmd].fp) |
Line 703 parsearg(struct texi *p, size_t *pos, size_t num) |
|
Line 721 parsearg(struct texi *p, size_t *pos, size_t num) |
|
void |
void |
parsebracket(struct texi *p, size_t *pos) |
parsebracket(struct texi *p, size_t *pos) |
{ |
{ |
size_t end; |
size_t end, sv; |
enum texicmd cmd; |
enum texicmd cmd; |
struct teximacro *macro; |
struct teximacro *macro; |
|
|
Line 731 parsebracket(struct texi *p, size_t *pos) |
|
Line 749 parsebracket(struct texi *p, size_t *pos) |
|
continue; |
continue; |
} |
} |
|
|
|
sv = p->files[p->filepos - 1].insplice; |
cmd = texicmd(p, *pos, &end, ¯o); |
cmd = texicmd(p, *pos, &end, ¯o); |
advanceto(p, pos, end); |
advanceto(p, pos, end); |
if (NULL != macro) |
if (NULL != macro) |
texiexecmacro(p, macro, pos); |
texiexecmacro(p, macro, sv, pos); |
if (TEXICMD__MAX == cmd) |
if (TEXICMD__MAX == cmd) |
continue; |
continue; |
if (NULL != texitoks[cmd].fp) |
if (NULL != texitoks[cmd].fp) |
Line 750 parsebracket(struct texi *p, size_t *pos) |
|
Line 769 parsebracket(struct texi *p, size_t *pos) |
|
void |
void |
parseeoln(struct texi *p, size_t *pos) |
parseeoln(struct texi *p, size_t *pos) |
{ |
{ |
size_t end; |
size_t end, sv; |
enum texicmd cmd; |
enum texicmd cmd; |
struct teximacro *macro; |
struct teximacro *macro; |
|
|
Line 779 parseeoln(struct texi *p, size_t *pos) |
|
Line 798 parseeoln(struct texi *p, size_t *pos) |
|
continue; |
continue; |
} |
} |
|
|
|
sv = p->files[p->filepos - 1].insplice; |
cmd = texicmd(p, *pos, &end, ¯o); |
cmd = texicmd(p, *pos, &end, ¯o); |
advanceto(p, pos, end); |
advanceto(p, pos, end); |
if (NULL != macro) |
if (NULL != macro) |
texiexecmacro(p, macro, pos); |
texiexecmacro(p, macro, sv, pos); |
if (TEXICMD__MAX == cmd) |
if (TEXICMD__MAX == cmd) |
continue; |
continue; |
if (NULL != texitoks[cmd].fp) |
if (NULL != texitoks[cmd].fp) |
Line 800 parseeoln(struct texi *p, size_t *pos) |
|
Line 820 parseeoln(struct texi *p, size_t *pos) |
|
static void |
static void |
parsesingle(struct texi *p, size_t *pos) |
parsesingle(struct texi *p, size_t *pos) |
{ |
{ |
size_t end; |
size_t end, sv; |
enum texicmd cmd; |
enum texicmd cmd; |
struct teximacro *macro; |
struct teximacro *macro; |
|
|
Line 825 parsesingle(struct texi *p, size_t *pos) |
|
Line 845 parsesingle(struct texi *p, size_t *pos) |
|
return; |
return; |
} |
} |
|
|
|
sv = p->files[p->filepos - 1].insplice; |
cmd = texicmd(p, *pos, &end, ¯o); |
cmd = texicmd(p, *pos, &end, ¯o); |
advanceto(p, pos, end); |
advanceto(p, pos, end); |
if (NULL != macro) |
if (NULL != macro) |
texiexecmacro(p, macro, pos); |
texiexecmacro(p, macro, sv, pos); |
if (TEXICMD__MAX == cmd) |
if (TEXICMD__MAX == cmd) |
return; |
return; |
if (NULL != texitoks[cmd].fp) |
if (NULL != texitoks[cmd].fp) |
Line 905 texisplice(struct texi *p, const char *buf, size_t sz, |
|
Line 926 texisplice(struct texi *p, const char *buf, size_t sz, |
|
void |
void |
parseto(struct texi *p, size_t *pos, const char *endtoken) |
parseto(struct texi *p, size_t *pos, const char *endtoken) |
{ |
{ |
size_t end; |
size_t end, sv; |
enum texicmd cmd; |
enum texicmd cmd; |
size_t endtoksz; |
size_t endtoksz; |
struct teximacro *macro; |
struct teximacro *macro; |
Line 932 parseto(struct texi *p, size_t *pos, const char *endto |
|
Line 953 parseto(struct texi *p, size_t *pos, const char *endto |
|
continue; |
continue; |
} |
} |
|
|
|
sv = p->files[p->filepos - 1].insplice; |
cmd = texicmd(p, *pos, &end, ¯o); |
cmd = texicmd(p, *pos, &end, ¯o); |
advanceto(p, pos, end); |
advanceto(p, pos, end); |
if (TEXICMD_END == cmd) { |
if (TEXICMD_END == cmd) { |
Line 952 parseto(struct texi *p, size_t *pos, const char *endto |
|
Line 974 parseto(struct texi *p, size_t *pos, const char *endto |
|
continue; |
continue; |
} |
} |
if (NULL != macro) |
if (NULL != macro) |
texiexecmacro(p, macro, pos); |
texiexecmacro(p, macro, sv, pos); |
if (TEXICMD__MAX == cmd) |
if (TEXICMD__MAX == cmd) |
continue; |
continue; |
if (NULL != texitoks[cmd].fp) |
if (NULL != texitoks[cmd].fp) |
Line 1209 argparse(struct texi *p, size_t *pos, size_t *argsz, s |
|
Line 1231 argparse(struct texi *p, size_t *pos, size_t *argsz, s |
|
args = NULL; |
args = NULL; |
*argsz = 0; |
*argsz = 0; |
|
|
|
if (*pos == BUFSZ(p)) |
|
return(args); |
|
|
if ('{' != BUF(p)[*pos] && hint) { |
if ('{' != BUF(p)[*pos] && hint) { |
/* |
/* |
* Special case: if we encounter an unbracketed argument |
* Special case: if we encounter an unbracketed argument |
Line 1234 argparse(struct texi *p, size_t *pos, size_t *argsz, s |
|
Line 1259 argparse(struct texi *p, size_t *pos, size_t *argsz, s |
|
return(args); |
return(args); |
} else if ('{' != BUF(p)[*pos]) |
} else if ('{' != BUF(p)[*pos]) |
return(args); |
return(args); |
|
|
|
assert('{' == BUF(p)[*pos]); |
|
|
/* Parse til the closing '}', putting into the array. */ |
/* Parse til the closing '}', putting into the array. */ |
advance(p, pos); |
advance(p, pos); |