=================================================================== RCS file: /cvs/mandoc/mdoc_macro.c,v retrieving revision 1.46 retrieving revision 1.51 diff -u -p -r1.46 -r1.51 --- mandoc/mdoc_macro.c 2010/03/30 08:24:01 1.46 +++ mandoc/mdoc_macro.c 2010/04/05 08:45:29 1.51 @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.46 2010/03/30 08:24:01 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.51 2010/04/05 08:45:29 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -27,9 +27,11 @@ #include "libmdoc.h" -#define REWIND_REWIND (1 << 0) -#define REWIND_NOHALT (1 << 1) -#define REWIND_HALT (1 << 2) +enum rew { + REWIND_REWIND, + REWIND_NOHALT, + REWIND_HALT +}; static int ctx_synopsis(MACRO_PROT_ARGS); static int obsolete(MACRO_PROT_ARGS); @@ -42,13 +44,13 @@ static int blk_exp_close(MACRO_PROT_ARGS); static int blk_part_imp(MACRO_PROT_ARGS); static int phrase(struct mdoc *, int, int, char *); -static int rew_dohalt(int, enum mdoc_type, +static enum rew rew_dohalt(enum mdoct, enum mdoc_type, const struct mdoc_node *); -static int rew_alt(int); -static int rew_dobreak(int, const struct mdoc_node *); -static int rew_elem(struct mdoc *, int); +static enum mdoct rew_alt(enum mdoct); +static int rew_dobreak(enum mdoct, const struct mdoc_node *); +static int rew_elem(struct mdoc *, enum mdoct); static int rew_sub(enum mdoc_type, struct mdoc *, - int, int, int); + enum mdoct, int, int); static int rew_last(struct mdoc *, const struct mdoc_node *); static int append_delims(struct mdoc *, int, int *, char *); @@ -318,8 +320,8 @@ rew_last(struct mdoc *mdoc, const struct mdoc_node *to * Return the opening macro of a closing one, e.g., `Ec' has `Eo' as its * matching pair. */ -static int -rew_alt(int tok) +static enum mdoct +rew_alt(enum mdoct tok) { switch (tok) { case (MDOC_Ac): @@ -368,8 +370,9 @@ rew_alt(int tok) * close our current scope (REWIND_REWIND), or continue (REWIND_NOHALT). * The scope-closing and so on occurs in the various rew_* routines. */ -static int -rew_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p) +static enum rew +rew_dohalt(enum mdoct tok, enum mdoc_type type, + const struct mdoc_node *p) { if (MDOC_ROOT == p->type) @@ -508,7 +511,7 @@ rew_dohalt(int tok, enum mdoc_type type, const struct * REWIND_NOHALT). */ static int -rew_dobreak(int tok, const struct mdoc_node *p) +rew_dobreak(enum mdoct tok, const struct mdoc_node *p) { assert(MDOC_ROOT != p->type); @@ -537,7 +540,6 @@ rew_dobreak(int tok, const struct mdoc_node *p) return(1); break; case (MDOC_Oc): - /* XXX - experimental! */ if (MDOC_Op == p->tok) return(1); break; @@ -555,7 +557,7 @@ rew_dobreak(int tok, const struct mdoc_node *p) static int -rew_elem(struct mdoc *mdoc, int tok) +rew_elem(struct mdoc *mdoc, enum mdoct tok) { struct mdoc_node *n; @@ -571,10 +573,10 @@ rew_elem(struct mdoc *mdoc, int tok) static int rew_sub(enum mdoc_type t, struct mdoc *m, - int tok, int line, int ppos) + enum mdoct tok, int line, int ppos) { struct mdoc_node *n; - int c; + enum rew c; /* LINTED */ for (n = m->last; n; n = n->parent) { @@ -595,7 +597,25 @@ rew_sub(enum mdoc_type t, struct mdoc *m, } assert(n); - return(rew_last(m, n)); + if ( ! rew_last(m, n)) + return(0); + +#ifdef UGLY + /* + * The current block extends an enclosing block beyond a line + * break. Now that the current block ends, close the enclosing + * block, too. + */ + if (NULL != (n = n->pending)) { + assert(MDOC_HEAD == n->type); + if ( ! rew_last(m, n)) + return(0); + if ( ! mdoc_body_alloc(m, n->line, n->pos, n->tok)) + return(0); + } +#endif + + return(1); } @@ -800,7 +820,7 @@ in_line(MACRO_PROT_ARGS) * the word. */ - d = mdoc_isdelim(p); + d = ARGS_QWORD == w ? 0 : mdoc_isdelim(p); if (ARGS_QWORD != w && d) { if (0 == lastpunct && ! rew_elem(m, tok)) @@ -861,6 +881,10 @@ blk_full(MACRO_PROT_ARGS) int c, la; struct mdoc_arg *arg; struct mdoc_node *head; /* save of head macro */ + struct mdoc_node *body; /* save of body macro */ +#ifdef UGLY + struct mdoc_node *n; +#endif char *p; /* Close out prior implicit scope. */ @@ -902,7 +926,7 @@ blk_full(MACRO_PROT_ARGS) if ( ! mdoc_block_alloc(m, line, ppos, tok, arg)) return(0); - head = NULL; + head = body = NULL; /* * The `Nd' macro has all arguments in its body: it's a hybrid @@ -917,6 +941,7 @@ blk_full(MACRO_PROT_ARGS) return(0); if ( ! mdoc_body_alloc(m, line, ppos, tok)) return(0); + body = m->last; } for (;;) { @@ -931,6 +956,7 @@ blk_full(MACRO_PROT_ARGS) /* Don't emit leading punct. for phrases. */ if (NULL == head && ARGS_PHRASE != c && + ARGS_QWORD != c && 1 == mdoc_isdelim(p)) { if ( ! mdoc_word_alloc(m, line, la, p)) return(0); @@ -973,11 +999,29 @@ blk_full(MACRO_PROT_ARGS) if (1 == ppos && ! append_delims(m, line, pos, buf)) return(0); - /* See notes on `Nd' hybrid, above. */ + /* If we've already opened our body, exit now. */ - if (MDOC_Nd == tok) + if (NULL != body) return(1); +#ifdef UGLY + /* + * If there is an open (i.e., unvalidated) sub-block requiring + * explicit close-out, postpone switching the current block from + * head to body until the rew_sub() call closing out that + * sub-block. + */ + for (n = m->last; n && n != head; n = n->parent) { + if (MDOC_BLOCK == n->type && + MDOC_EXPLICIT & mdoc_macros[n->tok].flags && + ! (MDOC_VALID & n->flags)) { + assert( ! (MDOC_ACTED & n->flags)); + n->pending = head; + return(1); + } + } +#endif + /* Close out scopes to remain in a consistent state. */ if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) @@ -1036,7 +1080,8 @@ blk_part_imp(MACRO_PROT_ARGS) if (ARGS_PUNCT == c) break; - if (NULL == body && 1 == mdoc_isdelim(p)) { + if (NULL == body && ARGS_QWORD != c && + 1 == mdoc_isdelim(p)) { if ( ! mdoc_word_alloc(m, line, la, p)) return(0); continue; @@ -1070,9 +1115,8 @@ blk_part_imp(MACRO_PROT_ARGS) * If we can't rewind to our body, then our scope has already * been closed by another macro (like `Oc' closing `Op'). This * is ugly behaviour nodding its head to OpenBSD's overwhelming - * crufty use of `Op' breakage. XXX: DEPRECATE. + * crufty use of `Op' breakage. */ - for (n = m->last; n; n = n->parent) if (body == n) break; @@ -1129,7 +1173,8 @@ blk_part_exp(MACRO_PROT_ARGS) /* Flush out leading punctuation. */ - if (NULL == head && 1 == mdoc_isdelim(p)) { + if (NULL == head && ARGS_QWORD != c && + 1 == mdoc_isdelim(p)) { assert(NULL == body); if ( ! mdoc_word_alloc(m, line, la, p)) return(0); @@ -1265,6 +1310,7 @@ in_line_argn(MACRO_PROT_ARGS) break; if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) && + ARGS_QWORD != c && 0 == j && 1 == mdoc_isdelim(p)) { if ( ! mdoc_word_alloc(m, line, la, p)) return(0); @@ -1290,6 +1336,7 @@ in_line_argn(MACRO_PROT_ARGS) } if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) && + ARGS_QWORD != c && ! flushed && mdoc_isdelim(p)) { if ( ! rew_elem(m, tok)) return(0);