=================================================================== RCS file: /cvs/mandoc/Attic/macro.c,v retrieving revision 1.29 retrieving revision 1.33 diff -u -p -r1.29 -r1.33 --- mandoc/Attic/macro.c 2009/01/08 15:59:58 1.29 +++ mandoc/Attic/macro.c 2009/01/12 16:39:57 1.33 @@ -1,4 +1,4 @@ -/* $Id: macro.c,v 1.29 2009/01/08 15:59:58 kristaps Exp $ */ +/* $Id: macro.c,v 1.33 2009/01/12 16:39:57 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -37,16 +37,23 @@ static int rewind_body(struct mdoc *, int); static int rewind_last(struct mdoc *, struct mdoc_node *); static int append_delims(struct mdoc *, int, int, int *, char *); -static int lookup(struct mdoc *, int, const char *); +static int lookup(struct mdoc *, int, int, int, const char *); static int -lookup(struct mdoc *mdoc, int from, const char *p) +lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p) { + int res; - if ( ! (MDOC_PARSED & mdoc_macros[from].flags)) - return(MDOC_MAX); - return(mdoc_find(mdoc, p)); + res = mdoc_find(mdoc, p); + if (MDOC_PARSED & mdoc_macros[from].flags) + return(res); + if (MDOC_MAX == res) + return(res); + + if ( ! mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX_MACLIKE)) + return(-1); + return(MDOC_MAX); } @@ -55,8 +62,14 @@ rewind_last(struct mdoc *mdoc, struct mdoc_node *to) { assert(to); - if (mdoc->last == to) + mdoc->next = MDOC_NEXT_SIBLING; + if (mdoc->last == to) { + if ( ! mdoc_valid_post(mdoc)) + return(0); + if ( ! mdoc_action_post(mdoc)) + return(0); return(1); + } do { mdoc->last = mdoc->last->parent; @@ -67,7 +80,6 @@ rewind_last(struct mdoc *mdoc, struct mdoc_node *to) return(0); } while (mdoc->last != to); - mdoc->next = MDOC_NEXT_SIBLING; return(1); } @@ -81,7 +93,7 @@ rewind_elem(struct mdoc *mdoc, int tok) if (MDOC_ELEM != n->type) n = n->parent; assert(MDOC_ELEM == n->type); - assert(tok == n->data.elem.tok); + assert(tok == n->tok); return(rewind_last(mdoc, n)); } @@ -99,7 +111,7 @@ rewind_body(struct mdoc *mdoc, int tok) for (n = mdoc->last; n; n = n->parent) { if (MDOC_BODY != n->type) continue; - if (tok == (t = n->data.head.tok)) + if (tok == (t = n->tok)) break; if ( ! (MDOC_EXPLICIT & mdoc_macros[t].flags)) continue; @@ -123,7 +135,7 @@ rewind_head(struct mdoc *mdoc, int tok) for (n = mdoc->last; n; n = n->parent) { if (MDOC_HEAD != n->type) continue; - if (tok == (t = n->data.head.tok)) + if (tok == (t = n->tok)) break; if ( ! (MDOC_EXPLICIT & mdoc_macros[t].flags)) continue; @@ -141,13 +153,13 @@ rewind_expblock(struct mdoc *mdoc, int tok) struct mdoc_node *n; int t; - assert(mdoc->last); + n = mdoc->last ? mdoc->last->parent : NULL; /* LINTED */ - for (n = mdoc->last; n; n = n->parent) { + for ( ; n; n = n->parent) { if (MDOC_BLOCK != n->type) continue; - if (tok == (t = n->data.block.tok)) + if (tok == (t = n->tok)) break; if (MDOC_NESTED & mdoc_macros[t].flags) continue; @@ -171,11 +183,11 @@ rewind_impblock(struct mdoc *mdoc, int tok) for ( ; n; n = n->parent) { if (MDOC_BLOCK != n->type) continue; - if (tok == (t = n->data.block.tok)) + if (tok == (t = n->tok)) break; if ( ! (MDOC_EXPLICIT & mdoc_macros[t].flags)) continue; - if (MDOC_NESTED & mdoc_macros[t].flags) + if (MDOC_NESTED & mdoc_macros[tok].flags) return(1); return(mdoc_verr(mdoc, n, ERR_SCOPE_BREAK)); } @@ -281,7 +293,7 @@ macro_close_explicit(MACRO_PROT_ARGS) } if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) { - if (buf[*pos]) + if (0 == buf[*pos]) return(rewind_expblock(mdoc, tt)); return(mdoc_perr(mdoc, line, ppos, ERR_ARGS_EQ0)); } @@ -315,7 +327,9 @@ macro_close_explicit(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { + if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + return(0); + else if (MDOC_MAX != c) { if ( ! flushed) { if ( ! rewind_expblock(mdoc, tt)) return(0); @@ -324,7 +338,7 @@ macro_close_explicit(MACRO_PROT_ARGS) if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf)) return(0); break; - } + } if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); @@ -417,7 +431,9 @@ macro_text(MACRO_PROT_ARGS) if (ARGS_PUNCT == c) break; - if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { + if (-1 == (c = lookup(mdoc, line, la, tok, p))) + return(0); + else if (MDOC_MAX != c) { if ( ! rewind_elem(mdoc, tok)) { mdoc_argv_free(argc, argv); return(0); @@ -463,7 +479,7 @@ macro_text(MACRO_PROT_ARGS) int macro_scoped(MACRO_PROT_ARGS) { - int c, lastarg, argc, j; + int c, lastarg, argc, j, fl; struct mdoc_arg argv[MDOC_LINEARG_MAX]; char *p; @@ -513,9 +529,13 @@ macro_scoped(MACRO_PROT_ARGS) return(0); mdoc->next = MDOC_NEXT_CHILD; + fl = ARGS_DELIM; + if (MDOC_TABSEP & mdoc_macros[tok].flags) + fl |= ARGS_TABSEP; + for (j = 0; j < MDOC_LINEARG_MAX; j++) { lastarg = *pos; - c = mdoc_args(mdoc, line, pos, buf, ARGS_DELIM, &p); + c = mdoc_args(mdoc, line, pos, buf, fl, &p); if (ARGS_ERROR == c) return(0); @@ -524,12 +544,14 @@ macro_scoped(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (MDOC_MAX == (c = lookup(mdoc, tok, p))) { + if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + return(0); + else if (MDOC_MAX == c) { if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); mdoc->next = MDOC_NEXT_SIBLING; continue; - } + } if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf)) return(0); @@ -584,12 +606,14 @@ macro_scoped_line(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (MDOC_MAX == (c = lookup(mdoc, tok, p))) { + if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + return(0); + else if (MDOC_MAX == c) { if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); mdoc->next = MDOC_NEXT_SIBLING; continue; - } + } if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf)) return(0); @@ -668,7 +692,9 @@ macro_constant_scoped(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { + if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + return(0); + else if (MDOC_MAX != c) { if ( ! flushed) { if ( ! rewind_head(mdoc, tok)) return(0); @@ -780,7 +806,9 @@ macro_constant_delimited(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { + if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + return(0); + else if (MDOC_MAX != c) { if ( ! flushed && ! rewind_elem(mdoc, tok)) return(0); flushed = 1;