version 1.148, 2014/11/27 22:27:56 |
version 1.149, 2014/11/28 01:05:43 |
Line 62 static int phrase(struct mdoc *, int, int, char *); |
|
Line 62 static int phrase(struct mdoc *, int, int, char *); |
|
static enum mdoct rew_alt(enum mdoct); |
static enum mdoct rew_alt(enum mdoct); |
static enum rew rew_dohalt(enum mdoct, enum mdoc_type, |
static enum rew rew_dohalt(enum mdoct, enum mdoc_type, |
const struct mdoc_node *); |
const struct mdoc_node *); |
static int rew_elem(struct mdoc *, enum mdoct); |
static void rew_elem(struct mdoc *, enum mdoct); |
static int rew_last(struct mdoc *, |
static void rew_last(struct mdoc *, const struct mdoc_node *); |
const struct mdoc_node *); |
|
static int rew_sub(enum mdoc_type, struct mdoc *, |
static int rew_sub(enum mdoc_type, struct mdoc *, |
enum mdoct, int, int); |
enum mdoct, int, int); |
|
|
Line 238 mdoc_macroend(struct mdoc *mdoc) |
|
Line 237 mdoc_macroend(struct mdoc *mdoc) |
|
|
|
/* Rewind to the first. */ |
/* Rewind to the first. */ |
|
|
return(rew_last(mdoc, mdoc->first)); |
rew_last(mdoc, mdoc->first); |
|
return(1); |
} |
} |
|
|
/* |
/* |
Line 268 lookup_raw(const char *p) |
|
Line 268 lookup_raw(const char *p) |
|
return(MDOC_MAX); |
return(MDOC_MAX); |
} |
} |
|
|
static int |
static void |
rew_last(struct mdoc *mdoc, const struct mdoc_node *to) |
rew_last(struct mdoc *mdoc, const struct mdoc_node *to) |
{ |
{ |
struct mdoc_node *n, *np; |
struct mdoc_node *n, *np; |
|
|
assert(to); |
assert(to); |
mdoc->next = MDOC_NEXT_SIBLING; |
mdoc->next = MDOC_NEXT_SIBLING; |
|
|
|
|
while (mdoc->last != to) { |
while (mdoc->last != to) { |
/* |
/* |
* Save the parent here, because we may delete the |
* Save the parent here, because we may delete the |
Line 285 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
Line 283 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
* out to be lost. |
* out to be lost. |
*/ |
*/ |
np = mdoc->last->parent; |
np = mdoc->last->parent; |
if ( ! mdoc_valid_post(mdoc)) |
mdoc_valid_post(mdoc); |
return(0); |
|
n = mdoc->last; |
n = mdoc->last; |
mdoc->last = np; |
mdoc->last = np; |
assert(mdoc->last); |
assert(mdoc->last); |
mdoc->last->last = n; |
mdoc->last->last = n; |
} |
} |
|
mdoc_valid_post(mdoc); |
return(mdoc_valid_post(mdoc)); |
|
} |
} |
|
|
/* |
/* |
Line 455 rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
Line 451 rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
REWIND_FORCE : REWIND_LATER); |
REWIND_FORCE : REWIND_LATER); |
} |
} |
|
|
static int |
static void |
rew_elem(struct mdoc *mdoc, enum mdoct tok) |
rew_elem(struct mdoc *mdoc, enum mdoct tok) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
Line 465 rew_elem(struct mdoc *mdoc, enum mdoct tok) |
|
Line 461 rew_elem(struct mdoc *mdoc, enum mdoct tok) |
|
n = n->parent; |
n = n->parent; |
assert(MDOC_ELEM == n->type); |
assert(MDOC_ELEM == n->type); |
assert(tok == n->tok); |
assert(tok == n->tok); |
|
rew_last(mdoc, n); |
return(rew_last(mdoc, n)); |
|
} |
} |
|
|
/* |
/* |
Line 587 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
Line 582 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
} |
} |
|
|
assert(n); |
assert(n); |
if ( ! rew_last(mdoc, n)) |
rew_last(mdoc, n); |
return(0); |
|
|
|
/* |
/* |
* The current block extends an enclosing block. |
* The current block extends an enclosing block. |
* Now that the current block ends, close the enclosing block, too. |
* Now that the current block ends, close the enclosing block, too. |
*/ |
*/ |
while (NULL != (n = n->pending)) { |
while (NULL != (n = n->pending)) { |
if ( ! rew_last(mdoc, n)) |
rew_last(mdoc, n); |
return(0); |
|
if (MDOC_HEAD == n->type && |
if (MDOC_HEAD == n->type && |
! mdoc_body_alloc(mdoc, n->line, n->pos, n->tok)) |
! mdoc_body_alloc(mdoc, n->line, n->pos, n->tok)) |
return(0); |
return(0); |
Line 801 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 794 blk_exp_close(MACRO_PROT_ARGS) |
|
if ( ! mdoc_elem_alloc(mdoc, line, ppos, |
if ( ! mdoc_elem_alloc(mdoc, line, ppos, |
MDOC_br, NULL)) |
MDOC_br, NULL)) |
return(0); |
return(0); |
if ( ! rew_elem(mdoc, MDOC_br)) |
rew_elem(mdoc, MDOC_br); |
return(0); |
|
} else if ( ! mdoc_tail_alloc(mdoc, line, ppos, atok)) |
} else if ( ! mdoc_tail_alloc(mdoc, line, ppos, atok)) |
return(0); |
return(0); |
} |
} |
Line 812 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 804 blk_exp_close(MACRO_PROT_ARGS) |
|
lastarg = *pos; |
lastarg = *pos; |
|
|
if (j == maxargs && ! flushed) { |
if (j == maxargs && ! flushed) { |
if ( ! (endbody != NULL ? rew_last(mdoc, endbody) : |
if (endbody != NULL) |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))) |
rew_last(mdoc, endbody); |
|
else if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)) |
return(0); |
return(0); |
flushed = 1; |
flushed = 1; |
} |
} |
Line 837 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 830 blk_exp_close(MACRO_PROT_ARGS) |
|
} |
} |
|
|
if ( ! flushed) { |
if ( ! flushed) { |
if ( ! (endbody != NULL ? rew_last(mdoc, endbody) : |
if (endbody != NULL) |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))) |
rew_last(mdoc, endbody); |
|
else if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)) |
return(0); |
return(0); |
flushed = 1; |
flushed = 1; |
} |
} |
Line 850 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 844 blk_exp_close(MACRO_PROT_ARGS) |
|
break; |
break; |
} |
} |
|
|
if ( ! flushed && ! (endbody != NULL ? rew_last(mdoc, endbody) : |
if ( ! flushed) { |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))) |
if (endbody != NULL) |
return(0); |
rew_last(mdoc, endbody); |
|
else if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)) |
|
return(0); |
|
} |
|
|
if ( ! nl) |
if ( ! nl) |
return(1); |
return(1); |
Line 959 in_line(MACRO_PROT_ARGS) |
|
Line 956 in_line(MACRO_PROT_ARGS) |
|
*/ |
*/ |
|
|
if (MDOC_MAX != ntok) { |
if (MDOC_MAX != ntok) { |
if (scope && ! rew_elem(mdoc, tok)) |
if (scope) |
return(0); |
rew_elem(mdoc, tok); |
if (nc && 0 == cnt) { |
if (nc && 0 == cnt) { |
if ( ! mdoc_elem_alloc(mdoc, |
if ( ! mdoc_elem_alloc(mdoc, |
line, ppos, tok, arg)) |
line, ppos, tok, arg)) |
return(0); |
return(0); |
if ( ! rew_last(mdoc, mdoc->last)) |
rew_last(mdoc, mdoc->last); |
return(0); |
|
} else if ( ! nc && 0 == cnt) { |
} else if ( ! nc && 0 == cnt) { |
mdoc_argv_free(arg); |
mdoc_argv_free(arg); |
mandoc_msg(MANDOCERR_MACRO_EMPTY, |
mandoc_msg(MANDOCERR_MACRO_EMPTY, |
Line 1011 in_line(MACRO_PROT_ARGS) |
|
Line 1007 in_line(MACRO_PROT_ARGS) |
|
* Close out our scope, if one is open, before |
* Close out our scope, if one is open, before |
* any punctuation. |
* any punctuation. |
*/ |
*/ |
if (scope && ! rew_elem(mdoc, tok)) |
if (scope) |
return(0); |
rew_elem(mdoc, tok); |
scope = 0; |
scope = 0; |
if (tok == MDOC_Fn) |
if (tok == MDOC_Fn) |
mayopen = 0; |
mayopen = 0; |
Line 1042 in_line(MACRO_PROT_ARGS) |
|
Line 1038 in_line(MACRO_PROT_ARGS) |
|
* having to parse out spaces. |
* having to parse out spaces. |
*/ |
*/ |
if (scope && MDOC_Fl == tok) { |
if (scope && MDOC_Fl == tok) { |
if ( ! rew_elem(mdoc, tok)) |
rew_elem(mdoc, tok); |
return(0); |
|
scope = 0; |
scope = 0; |
} |
} |
} |
} |
|
|
if (scope && ! rew_elem(mdoc, tok)) |
if (scope) |
return(0); |
rew_elem(mdoc, tok); |
|
|
/* |
/* |
* If no elements have been collected and we're allowed to have |
* If no elements have been collected and we're allowed to have |
Line 1060 in_line(MACRO_PROT_ARGS) |
|
Line 1055 in_line(MACRO_PROT_ARGS) |
|
if (nc && 0 == cnt) { |
if (nc && 0 == cnt) { |
if ( ! mdoc_elem_alloc(mdoc, line, ppos, tok, arg)) |
if ( ! mdoc_elem_alloc(mdoc, line, ppos, tok, arg)) |
return(0); |
return(0); |
if ( ! rew_last(mdoc, mdoc->last)) |
rew_last(mdoc, mdoc->last); |
return(0); |
|
} else if ( ! nc && 0 == cnt) { |
} else if ( ! nc && 0 == cnt) { |
mdoc_argv_free(arg); |
mdoc_argv_free(arg); |
mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse, |
mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse, |
Line 1102 blk_full(MACRO_PROT_ARGS) |
|
Line 1096 blk_full(MACRO_PROT_ARGS) |
|
if ( ! mdoc_elem_alloc(mdoc, line, ppos, |
if ( ! mdoc_elem_alloc(mdoc, line, ppos, |
MDOC_br, NULL)) |
MDOC_br, NULL)) |
return(0); |
return(0); |
return(rew_elem(mdoc, MDOC_br)); |
rew_elem(mdoc, MDOC_br); |
|
return(1); |
} |
} |
} |
} |
|
|
Line 1643 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1638 in_line_argn(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
|
|
if (j == maxargs && ! flushed) { |
if (j == maxargs && ! flushed) { |
if ( ! rew_elem(mdoc, tok)) |
rew_elem(mdoc, tok); |
return(0); |
|
flushed = 1; |
flushed = 1; |
} |
} |
|
|
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p); |
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p); |
|
|
if (MDOC_MAX != ntok) { |
if (MDOC_MAX != ntok) { |
if ( ! flushed && ! rew_elem(mdoc, tok)) |
if ( ! flushed) |
return(0); |
rew_elem(mdoc, tok); |
flushed = 1; |
flushed = 1; |
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
return(0); |
return(0); |
Line 1664 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1658 in_line_argn(MACRO_PROT_ARGS) |
|
ARGS_QWORD != ac && |
ARGS_QWORD != ac && |
! flushed && |
! flushed && |
DELIM_NONE != mdoc_isdelim(p)) { |
DELIM_NONE != mdoc_isdelim(p)) { |
if ( ! rew_elem(mdoc, tok)) |
rew_elem(mdoc, tok); |
return(0); |
|
flushed = 1; |
flushed = 1; |
} |
} |
|
|
Line 1680 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1673 in_line_argn(MACRO_PROT_ARGS) |
|
|
|
/* Close out in a consistent state. */ |
/* Close out in a consistent state. */ |
|
|
if ( ! flushed && ! rew_elem(mdoc, tok)) |
if ( ! flushed) |
return(0); |
rew_elem(mdoc, tok); |
if ( ! nl) |
if ( ! nl) |
return(1); |
return(1); |
return(append_delims(mdoc, line, pos, buf)); |
return(append_delims(mdoc, line, pos, buf)); |
Line 1745 in_line_eoln(MACRO_PROT_ARGS) |
|
Line 1738 in_line_eoln(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
continue; |
continue; |
} |
} |
|
rew_elem(mdoc, tok); |
if ( ! rew_elem(mdoc, tok)) |
|
return(0); |
|
return(mdoc_macro(mdoc, ntok, line, la, pos, buf)); |
return(mdoc_macro(mdoc, ntok, line, la, pos, buf)); |
} |
} |
|
|
/* Close out (no delimiters). */ |
/* Close out (no delimiters). */ |
|
|
return(rew_elem(mdoc, tok)); |
rew_elem(mdoc, tok); |
|
return(1); |
} |
} |
|
|
static int |
static int |