version 1.84, 2020/01/08 12:16:24 |
version 1.86, 2023/04/28 19:11:03 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
|
* Copyright (c) 2014, 2015, 2017, 2018, 2020, 2022 |
|
* Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2014,2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org> |
|
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 355 eqn_def_find(struct eqn_node *ep) |
|
Line 356 eqn_def_find(struct eqn_node *ep) |
|
/* |
/* |
* Parse a token from the input text. The modes are: |
* Parse a token from the input text. The modes are: |
* MODE_QUOTED: Use *ep->start as the delimiter; the token ends |
* MODE_QUOTED: Use *ep->start as the delimiter; the token ends |
* before its next occurence. Do not interpret the token in any |
* before its next occurrence. Do not interpret the token in any |
* way and return EQN_TOK_QUOTED. All other modes behave like |
* way and return EQN_TOK_QUOTED. All other modes behave like |
* MODE_QUOTED when *ep->start is '"'. |
* MODE_QUOTED when *ep->start is '"'. |
* MODE_NOSUB: If *ep->start is a curly brace, the token ends after it; |
* MODE_NOSUB: If *ep->start is a curly brace, the token ends after it; |
Line 375 eqn_def_find(struct eqn_node *ep) |
|
Line 376 eqn_def_find(struct eqn_node *ep) |
|
static enum eqn_tok |
static enum eqn_tok |
eqn_next(struct eqn_node *ep, enum parse_mode mode) |
eqn_next(struct eqn_node *ep, enum parse_mode mode) |
{ |
{ |
static int last_len, lim; |
|
|
|
struct eqn_def *def; |
struct eqn_def *def; |
size_t start; |
size_t start; |
int diff, i, quoted; |
int diff, i, newlen, quoted; |
enum eqn_tok tok; |
enum eqn_tok tok; |
|
|
/* |
/* |
* Reset the recursion counter after advancing |
* Reset the recursion counter after advancing |
* beyond the end of the previous substitution. |
* beyond the end of the rightmost substitution. |
*/ |
*/ |
if (ep->end - ep->data >= last_len) |
if (ep->end - ep->data >= ep->sublen) |
lim = 0; |
ep->subcnt = 0; |
|
|
ep->start = ep->end; |
ep->start = ep->end; |
quoted = mode == MODE_QUOTED; |
quoted = mode == MODE_QUOTED; |
Line 434 eqn_next(struct eqn_node *ep, enum parse_mode mode) |
|
Line 433 eqn_next(struct eqn_node *ep, enum parse_mode mode) |
|
return EQN_TOK__MAX; |
return EQN_TOK__MAX; |
if ((def = eqn_def_find(ep)) == NULL) |
if ((def = eqn_def_find(ep)) == NULL) |
break; |
break; |
if (++lim > EQN_NEST_MAX) { |
if (++ep->subcnt > EQN_NEST_MAX) { |
mandoc_msg(MANDOCERR_ROFFLOOP, |
mandoc_msg(MANDOCERR_ROFFLOOP, |
ep->node->line, ep->node->pos, NULL); |
ep->node->line, ep->node->pos, NULL); |
return EQN_TOK_EOF; |
break; |
} |
} |
|
|
/* Replace a defined name with its string value. */ |
/* Replace a defined name with its string value. */ |
Line 446 eqn_next(struct eqn_node *ep, enum parse_mode mode) |
|
Line 445 eqn_next(struct eqn_node *ep, enum parse_mode mode) |
|
ep->sz += diff; |
ep->sz += diff; |
ep->data = mandoc_realloc(ep->data, ep->sz + 1); |
ep->data = mandoc_realloc(ep->data, ep->sz + 1); |
ep->start = ep->data + start; |
ep->start = ep->data + start; |
|
ep->sublen += diff; |
} |
} |
if (diff) |
if (diff) |
memmove(ep->start + def->valsz, ep->start + ep->toksz, |
memmove(ep->start + def->valsz, ep->start + ep->toksz, |
strlen(ep->start + ep->toksz) + 1); |
strlen(ep->start + ep->toksz) + 1); |
memcpy(ep->start, def->val, def->valsz); |
memcpy(ep->start, def->val, def->valsz); |
last_len = ep->start - ep->data + def->valsz; |
newlen = ep->start - ep->data + def->valsz; |
|
if (ep->sublen < newlen) |
|
ep->sublen = newlen; |
} |
} |
if (mode != MODE_TOK) |
if (mode != MODE_TOK) |
return quoted ? EQN_TOK_QUOTED : EQN_TOK__MAX; |
return quoted ? EQN_TOK_QUOTED : EQN_TOK__MAX; |
Line 678 eqn_parse(struct eqn_node *ep) |
|
Line 680 eqn_parse(struct eqn_node *ep) |
|
return; |
return; |
|
|
ep->start = ep->end = ep->data; |
ep->start = ep->end = ep->data; |
|
ep->sublen = 0; |
|
ep->subcnt = 0; |
|
|
next_tok: |
next_tok: |
tok = eqn_next(ep, MODE_TOK); |
tok = eqn_next(ep, MODE_TOK); |