=================================================================== RCS file: /cvs/mandoc/mdoc_macro.c,v retrieving revision 1.24 retrieving revision 1.31 diff -u -p -r1.24 -r1.31 --- mandoc/mdoc_macro.c 2009/07/19 21:26:27 1.24 +++ mandoc/mdoc_macro.c 2009/08/19 11:58:32 1.31 @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.24 2009/07/19 21:26:27 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.31 2009/08/19 11:58:32 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -45,9 +45,10 @@ static int rew_impblock(struct mdoc *, int, int, int static int rew_expblock(struct mdoc *, int, int, int); static int rew_subblock(enum mdoc_type, struct mdoc *, int, int, int); -static int rew_last(struct mdoc *, struct mdoc_node *); +static int rew_last(struct mdoc *, struct mdoc_node *); /* FIXME: make const */ static int append_delims(struct mdoc *, int, int *, char *); -static int lookup(struct mdoc *, int, int, int, const char *); +static int lookup(struct mdoc *, int, const char *); +static int lookup_raw(struct mdoc *, const char *); static int swarn(struct mdoc *, enum mdoc_type, int, int, const struct mdoc_node *); @@ -253,17 +254,24 @@ mdoc_macroend(struct mdoc *mdoc) } static int -lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p) +lookup(struct mdoc *mdoc, int from, const char *p) { + + if ( ! (MDOC_PARSED & mdoc_macros[from].flags)) + return(MDOC_MAX); + return(lookup_raw(mdoc, p)); +} + + +static int +lookup_raw(struct mdoc *mdoc, const char *p) +{ int res; - res = mdoc_hash_find(mdoc->htab, p); - if (MDOC_PARSED & mdoc_macros[from].flags) + if (MDOC_MAX == (res = mdoc_hash_find(mdoc->htab, p))) + return(MDOC_MAX); + if (MDOC_CALLABLE & mdoc_macros[res].flags) return(res); - if (MDOC_MAX == res) - return(res); - if ( ! mdoc_pwarn(mdoc, line, pos, EMACPARM)) - return(-1); return(MDOC_MAX); } @@ -591,6 +599,7 @@ rew_expblock(struct mdoc *mdoc, int tok, int line, int } +/* FIXME: can this be merged with subblock? */ static int rew_impblock(struct mdoc *mdoc, int tok, int line, int ppos) { @@ -636,7 +645,6 @@ append_delims(struct mdoc *mdoc, int line, int *pos, c assert(mdoc_isdelim(p)); if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } return(1); @@ -681,7 +689,7 @@ blk_exp_close(MACRO_PROT_ARGS) mdoc->next = MDOC_NEXT_CHILD; } - for (lastarg = ppos, flushed = j = 0; ; j++) { + for (flushed = j = 0; ; j++) { lastarg = *pos; if (j == maxargs && ! flushed) { @@ -699,9 +707,7 @@ blk_exp_close(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) - return(0); - else if (MDOC_MAX != c) { + if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { if ( ! flushed) { if ( ! rew_expblock(mdoc, tok, line, ppos)) @@ -715,7 +721,6 @@ blk_exp_close(MACRO_PROT_ARGS) if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } if ( ! flushed && ! rew_expblock(mdoc, tok, line, ppos)) @@ -742,13 +747,17 @@ in_line(MACRO_PROT_ARGS) * usually because of reserved words) to squeak by. */ switch (tok) { - case (MDOC_Nm): + case (MDOC_An): /* FALLTHROUGH */ + case (MDOC_Ar): + /* FALLTHROUGH */ case (MDOC_Fl): /* FALLTHROUGH */ case (MDOC_Lk): /* FALLTHROUGH */ - case (MDOC_Ar): + case (MDOC_Nm): + /* FALLTHROUGH */ + case (MDOC_Pa): nc = 1; break; default: @@ -756,7 +765,7 @@ in_line(MACRO_PROT_ARGS) break; } - for (la = ppos, arg = NULL;; ) { + for (arg = NULL;; ) { la = *pos; c = mdoc_argv(mdoc, line, tok, &arg, pos, buf); @@ -786,8 +795,7 @@ in_line(MACRO_PROT_ARGS) /* Quoted words shouldn't be looked-up. */ - c = ARGS_QWORD == w ? MDOC_MAX : - lookup(mdoc, line, la, tok, p); + c = ARGS_QWORD == w ? MDOC_MAX : lookup(mdoc, tok, p); /* * In this case, we've located a submacro and must @@ -796,7 +804,7 @@ in_line(MACRO_PROT_ARGS) * or raise a warning. */ - if (MDOC_MAX != c && -1 != c) { + if (MDOC_MAX != c) { if (0 == lastpunct && ! rew_elem(mdoc, tok)) return(0); if (nc && 0 == cnt) { @@ -816,8 +824,7 @@ in_line(MACRO_PROT_ARGS) if (ppos > 1) return(1); return(append_delims(mdoc, line, pos, buf)); - } else if (-1 == c) - return(0); + } /* * Non-quote-enclosed punctuation. Set up our scope, if @@ -843,7 +850,6 @@ in_line(MACRO_PROT_ARGS) cnt++; if ( ! mdoc_word_alloc(mdoc, line, la, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } if (0 == lastpunct && ! rew_elem(mdoc, tok)) @@ -984,13 +990,9 @@ blk_full(MACRO_PROT_ARGS) continue; } - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) - return(0); - - if (MDOC_MAX == c) { + if (MDOC_MAX == (c = lookup(mdoc, tok, p))) { if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; continue; } @@ -1042,7 +1044,7 @@ blk_part_imp(MACRO_PROT_ARGS) /* XXX - no known argument macros. */ - for (lastarg = ppos;; ) { + for (;;) { lastarg = *pos; c = mdoc_args(mdoc, line, pos, buf, tok, &p); assert(ARGS_PHRASE != c); @@ -1054,12 +1056,9 @@ blk_part_imp(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) - return(0); - else if (MDOC_MAX == c) { + if (MDOC_MAX == (c = lookup(mdoc, tok, p))) { if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; continue; } @@ -1103,7 +1102,6 @@ blk_part_exp(MACRO_PROT_ARGS) int lastarg, flushed, j, c, maxargs; char *p; - lastarg = ppos; flushed = 0; /* @@ -1159,9 +1157,7 @@ blk_part_exp(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) - return(0); - else if (MDOC_MAX != c) { + if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { if ( ! flushed) { if ( ! rew_subblock(MDOC_HEAD, mdoc, tok, line, ppos)) @@ -1190,7 +1186,6 @@ blk_part_exp(MACRO_PROT_ARGS) if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } if ( ! flushed) { @@ -1239,7 +1234,7 @@ in_line_argn(MACRO_PROT_ARGS) break; } - for (lastarg = ppos, arg = NULL;; ) { + for (arg = NULL;; ) { lastarg = *pos; c = mdoc_argv(mdoc, line, tok, &arg, pos, buf); @@ -1279,9 +1274,7 @@ in_line_argn(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) - return(0); - else if (MDOC_MAX != c) { + if (MDOC_MAX != (c = lookup(mdoc, tok, p))) { if ( ! flushed && ! rew_elem(mdoc, tok)) return(0); flushed = 1; @@ -1299,7 +1292,6 @@ in_line_argn(MACRO_PROT_ARGS) if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } if ( ! flushed && ! rew_elem(mdoc, tok)) @@ -1357,19 +1349,16 @@ in_line_eoln(MACRO_PROT_ARGS) if (ARGS_EOLN == w) break; - c = ARGS_QWORD == w ? MDOC_MAX : - lookup(mdoc, line, la, tok, p); + c = ARGS_QWORD == w ? MDOC_MAX : lookup(mdoc, tok, p); - if (MDOC_MAX != c && -1 != c) { + if (MDOC_MAX != c) { if ( ! rew_elem(mdoc, tok)) return(0); return(mdoc_macro(mdoc, c, line, la, pos, buf)); - } else if (-1 == c) - return(0); + } if ( ! mdoc_word_alloc(mdoc, line, la, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } return(rew_elem(mdoc, tok)); @@ -1407,19 +1396,16 @@ phrase(struct mdoc *mdoc, int line, int ppos, char *bu if (ARGS_EOLN == w) break; - c = ARGS_QWORD == w ? MDOC_MAX : - mdoc_hash_find(mdoc->htab, p); + c = ARGS_QWORD == w ? MDOC_MAX : lookup_raw(mdoc, p); - if (MDOC_MAX != c && -1 != c) { + if (MDOC_MAX != c) { if ( ! mdoc_macro(mdoc, c, line, la, &pos, buf)) return(0); return(append_delims(mdoc, line, &pos, buf)); - } else if (-1 == c) - return(0); + } if ( ! mdoc_word_alloc(mdoc, line, la, p)) return(0); - mdoc->next = MDOC_NEXT_SIBLING; } return(1);