version 1.165, 2015/02/02 04:04:45 |
version 1.166, 2015/02/02 04:26:44 |
Line 65 static enum rew rew_dohalt(enum mdoct, enum mdoc_type, |
|
Line 65 static enum rew rew_dohalt(enum mdoct, enum mdoc_type, |
|
const struct mdoc_node *); |
const struct mdoc_node *); |
static void rew_elem(struct mdoc *, enum mdoct); |
static void rew_elem(struct mdoc *, enum mdoct); |
static void rew_last(struct mdoc *, const struct mdoc_node *); |
static void rew_last(struct mdoc *, const struct mdoc_node *); |
|
static void rew_pending(struct mdoc *, const struct mdoc_node *); |
static void rew_sub(enum mdoc_type, struct mdoc *, |
static void rew_sub(enum mdoc_type, struct mdoc *, |
enum mdoct, int, int); |
enum mdoct, int, int); |
|
|
Line 263 lookup(struct mdoc *mdoc, enum mdoct from, int line, i |
|
Line 264 lookup(struct mdoc *mdoc, enum mdoct from, int line, i |
|
return(MDOC_MAX); |
return(MDOC_MAX); |
} |
} |
|
|
|
/* |
|
* Rewind up to and including a specific node. |
|
*/ |
static void |
static void |
rew_last(struct mdoc *mdoc, const struct mdoc_node *to) |
rew_last(struct mdoc *mdoc, const struct mdoc_node *to) |
{ |
{ |
Line 271 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
Line 275 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
assert(to); |
assert(to); |
mdoc->next = MDOC_NEXT_SIBLING; |
mdoc->next = MDOC_NEXT_SIBLING; |
while (mdoc->last != to) { |
while (mdoc->last != to) { |
|
if ( ! (mdoc->last->flags & MDOC_VALID)) |
|
mdoc->last->lastline = to->lastline - |
|
(mdoc->flags & MDOC_NEWLINE ? 1 : 0); |
/* |
/* |
* Save the parent here, because we may delete the |
* Save the parent here, because we may delete the |
* mdoc->last node in the post-validation phase and reset |
* mdoc->last node in the post-validation phase and reset |
Line 288 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
Line 295 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
} |
} |
|
|
/* |
/* |
|
* Rewind up to a specific block, including all blocks that broke it. |
|
*/ |
|
static void |
|
rew_pending(struct mdoc *mdoc, const struct mdoc_node *n) |
|
{ |
|
|
|
rew_last(mdoc, n); |
|
|
|
if (n->type != MDOC_BLOCK) |
|
return; |
|
|
|
while ((n = n->pending) != NULL) { |
|
rew_last(mdoc, n); |
|
if (n->type == MDOC_HEAD) |
|
mdoc_body_alloc(mdoc, n->line, n->pos, n->tok); |
|
} |
|
} |
|
|
|
/* |
* For a block closing macro, return the corresponding opening one. |
* For a block closing macro, return the corresponding opening one. |
* Otherwise, return the macro itself. |
* Otherwise, return the macro itself. |
*/ |
*/ |
Line 533 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
Line 559 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
*/ |
*/ |
broken->pending = breaker; |
broken->pending = breaker; |
breaker->flags |= MDOC_BREAK; |
breaker->flags |= MDOC_BREAK; |
|
if (breaker->body != NULL) |
|
breaker->body->flags |= MDOC_BREAK; |
mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos, |
mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos, |
"%s breaks %s", mdoc_macronames[tok], |
"%s breaks %s", mdoc_macronames[tok], |
mdoc_macronames[broken->tok]); |
mdoc_macronames[broken->tok]); |
Line 592 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
Line 620 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
break; |
break; |
} |
} |
assert(n); |
assert(n); |
rew_last(mdoc, n); |
rew_pending(mdoc, n); |
|
|
/* |
|
* The current block extends an enclosing block. |
|
* Now that the current block ends, close the enclosing block, too. |
|
*/ |
|
while ((n = n->pending) != NULL) { |
|
rew_last(mdoc, n); |
|
if (n->type == MDOC_HEAD) |
|
mdoc_body_alloc(mdoc, n->line, n->pos, n->tok); |
|
} |
|
} |
} |
|
|
/* |
/* |
Line 716 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 734 blk_exp_close(MACRO_PROT_ARGS) |
|
struct mdoc_node *body; /* Our own body. */ |
struct mdoc_node *body; /* Our own body. */ |
struct mdoc_node *endbody; /* Our own end marker. */ |
struct mdoc_node *endbody; /* Our own end marker. */ |
struct mdoc_node *later; /* A sub-block starting later. */ |
struct mdoc_node *later; /* A sub-block starting later. */ |
struct mdoc_node *n; /* For searching backwards. */ |
struct mdoc_node *n; /* Search back to our block. */ |
|
|
int flushed, have_it, j, lastarg, maxargs, nl; |
int have_it, j, lastarg, maxargs, nl; |
enum margserr ac; |
enum margserr ac; |
enum mdoct atok, ntok; |
enum mdoct atok, ntok; |
char *p; |
char *p; |
Line 752 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 770 blk_exp_close(MACRO_PROT_ARGS) |
|
/* Remember the start of our own body. */ |
/* Remember the start of our own body. */ |
|
|
if (n->type == MDOC_BODY && atok == n->tok) { |
if (n->type == MDOC_BODY && atok == n->tok) { |
if (n->end == ENDBODY_NOT) |
if (n->end == ENDBODY_NOT) { |
body = n; |
body = n; |
|
n->lastline = line; |
|
} |
continue; |
continue; |
} |
} |
|
|
Line 766 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 786 blk_exp_close(MACRO_PROT_ARGS) |
|
} |
} |
|
|
if (atok == n->tok) { |
if (atok == n->tok) { |
|
n->lastline = line; |
assert(body); |
assert(body); |
|
|
/* |
/* |
Line 791 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 812 blk_exp_close(MACRO_PROT_ARGS) |
|
* the scope - of the current block ends. |
* the scope - of the current block ends. |
*/ |
*/ |
|
|
mdoc_endbody_alloc(mdoc, line, ppos, |
endbody = mdoc_endbody_alloc(mdoc, line, ppos, |
atok, body, ENDBODY_SPACE); |
atok, body, ENDBODY_SPACE); |
|
|
/* |
/* |
* If a block closing macro taking arguments |
* If a block closing macro taking arguments |
* breaks another block, put the arguments |
* breaks another block, put the arguments |
* into the end marker and remeber the |
* into the end marker. |
* end marker in order to close it out. |
|
*/ |
*/ |
|
|
if (maxargs) { |
if (maxargs) |
endbody = mdoc->last; |
|
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = MDOC_NEXT_CHILD; |
} |
|
break; |
break; |
} |
} |
|
|
Line 818 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 836 blk_exp_close(MACRO_PROT_ARGS) |
|
! (mdoc_macros[later->tok].flags & MDOC_EXPLICIT)) |
! (mdoc_macros[later->tok].flags & MDOC_EXPLICIT)) |
later = n; |
later = n; |
} |
} |
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
|
|
|
|
if (body == NULL) { |
|
mandoc_msg(MANDOCERR_BLK_NOTOPEN, mdoc->parse, |
|
line, ppos, mdoc_macronames[tok]); |
|
if (maxargs && endbody == NULL) { |
|
/* |
|
* Stray .Ec without previous .Eo: |
|
* Break the output line, keep the arguments. |
|
*/ |
|
mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL); |
|
rew_elem(mdoc, MDOC_br); |
|
} |
|
} else if (endbody == NULL) { |
|
rew_last(mdoc, body); |
|
if (maxargs) |
|
mdoc_tail_alloc(mdoc, line, ppos, atok); |
|
} |
|
|
if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) { |
if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) { |
if (buf[*pos] != '\0') |
if (buf[*pos] != '\0') |
mandoc_vmsg(MANDOCERR_ARG_SKIP, |
mandoc_vmsg(MANDOCERR_ARG_SKIP, |
Line 830 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 864 blk_exp_close(MACRO_PROT_ARGS) |
|
return; |
return; |
} |
} |
|
|
if (maxargs && endbody == NULL) { |
if (endbody != NULL) |
if (n == NULL) { |
n = endbody; |
/* |
|
* Stray .Ec without previous .Eo: |
|
* Break the output line, ignore any arguments. |
|
*/ |
|
mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL); |
|
rew_elem(mdoc, MDOC_br); |
|
} else |
|
mdoc_tail_alloc(mdoc, line, ppos, atok); |
|
} |
|
|
|
flushed = n == NULL; |
|
for (j = 0; ; j++) { |
for (j = 0; ; j++) { |
lastarg = *pos; |
lastarg = *pos; |
|
|
if (j == maxargs && ! flushed) { |
if (j == maxargs && n != NULL) { |
if (endbody == NULL) |
rew_pending(mdoc, n); |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
n = NULL; |
else |
|
rew_last(mdoc, endbody); |
|
flushed = 1; |
|
} |
} |
|
|
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
Line 867 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 887 blk_exp_close(MACRO_PROT_ARGS) |
|
continue; |
continue; |
} |
} |
|
|
if ( ! flushed) { |
if (n != NULL) { |
if (endbody == NULL) |
rew_pending(mdoc, n); |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
n = NULL; |
else |
|
rew_last(mdoc, endbody); |
|
flushed = 1; |
|
} |
} |
mdoc->flags &= ~MDOC_NEWLINE; |
mdoc->flags &= ~MDOC_NEWLINE; |
mdoc_macro(mdoc, ntok, line, lastarg, pos, buf); |
mdoc_macro(mdoc, ntok, line, lastarg, pos, buf); |
break; |
break; |
} |
} |
|
|
if ( ! flushed) { |
if (n != NULL) |
if (endbody == NULL) |
rew_pending(mdoc, n); |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
|
else |
|
rew_last(mdoc, endbody); |
|
} |
|
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
} |
} |
Line 1327 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1340 blk_part_imp(MACRO_PROT_ARGS) |
|
rew_last(mdoc, body); |
rew_last(mdoc, body); |
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
rew_last(mdoc, blk); |
rew_pending(mdoc, blk); |
|
|
/* |
|
* The current block extends an enclosing block. |
|
* Now that the current block ends, close the enclosing block, too. |
|
*/ |
|
|
|
while ((blk = blk->pending) != NULL) { |
|
rew_last(mdoc, blk); |
|
if (blk->type == MDOC_HEAD) |
|
mdoc_body_alloc(mdoc, blk->line, blk->pos, blk->tok); |
|
} |
|
|
|
/* Move trailing .Ns out of scope. */ |
/* Move trailing .Ns out of scope. */ |
|
|