From 21ec3346fa05f739794d70ac162859e993391cc7 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 29 Jul 2009 08:46:06 +0000 Subject: Moved CALLABLE check to lookup_raw(). Made PARSABLE check occur prior to lookup(). Non-PARSEABLE macros no longer warn against having macro-like parameters. Non-CALLABLE macros no longer produce an error, just display their symbols (as in groff) (pointed out by joerg@netbsd.org). --- libmdoc.h | 4 +--- mdoc.c | 12 +++++------- mdoc_macro.c | 42 ++++++++++++++++++++++++------------------ mdoc_term.c | 7 +++++-- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/libmdoc.h b/libmdoc.h index 5a86094d..3d6bb7ab 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.21 2009/07/20 14:09:38 kristaps Exp $ */ +/* $Id: libmdoc.h,v 1.22 2009/07/29 08:46:06 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -47,7 +47,6 @@ enum merr { EQUOTTERM, EMALLOC, EARGVAL, - ENOCALL, EBODYPROL, EPROLBODY, ETEXTPROL, @@ -88,7 +87,6 @@ enum merr { ENOWIDTH, EUTSNAME, EOBS, - EMACPARM, EIMPBRK, EIGNE, EOPEN, diff --git a/mdoc.c b/mdoc.c index 86adead3..3cea98cf 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.96 2009/07/27 19:43:02 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.97 2009/07/29 08:46:06 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -29,7 +29,6 @@ const char *const __mdoc_merrnames[MERRMAX] = { "unterminated quoted parameter", /* EQUOTTERM */ "system: malloc error", /* EMALLOC */ "argument parameter suggested", /* EARGVAL */ - "macro not callable", /* ENOCALL */ "macro disallowed in prologue", /* EBODYPROL */ "macro disallowed in body", /* EPROLBODY */ "text disallowed in prologue", /* ETEXTPROL */ @@ -70,7 +69,6 @@ const char *const __mdoc_merrnames[MERRMAX] = { "superfluous width argument", /* ENOWIDTH */ "system: utsname error", /* EUTSNAME */ "obsolete macro", /* EOBS */ - "macro-like parameter", /* EMACPARM */ "end-of-line scope violation", /* EIMPBRK */ "empty macro ignored", /* EIGNE */ "unclosed explicit scope", /* EOPEN */ @@ -353,7 +351,10 @@ int mdoc_macro(struct mdoc *m, int tok, int ln, int pp, int *pos, char *buf) { - + /* + * If we're in the prologue, deny "body" macros. Similarly, if + * we're in the body, deny prologue calls. + */ if (MDOC_PROLOGUE & mdoc_macros[tok].flags && MDOC_PBODY & m->flags) return(mdoc_perr(m, ln, pp, EPROLBODY)); @@ -361,9 +362,6 @@ mdoc_macro(struct mdoc *m, int tok, ! (MDOC_PBODY & m->flags)) return(mdoc_perr(m, ln, pp, EBODYPROL)); - if (1 != pp && ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) - return(mdoc_perr(m, ln, pp, ENOCALL)); - return((*mdoc_macros[tok].fp)(m, tok, ln, pp, pos, buf)); } diff --git a/mdoc_macro.c b/mdoc_macro.c index 97b157be..999bff30 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.27 2009/07/25 16:03:03 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.28 2009/07/29 08:46:06 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -47,7 +47,8 @@ static int rew_subblock(enum mdoc_type, struct mdoc *, int, int, int); static int rew_last(struct mdoc *, struct mdoc_node *); 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) - return(res); - if (MDOC_MAX == res) + if (MDOC_MAX == (res = mdoc_hash_find(mdoc->htab, p))) + return(MDOC_MAX); + if (MDOC_CALLABLE & mdoc_macros[res].flags) return(res); - if ( ! mdoc_pwarn(mdoc, line, pos, EMACPARM)) - return(-1); return(MDOC_MAX); } @@ -699,7 +707,7 @@ blk_exp_close(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + if (-1 == (c = lookup(mdoc, tok, p))) return(0); else if (MDOC_MAX != c) { if ( ! flushed) { @@ -790,8 +798,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 @@ -988,7 +995,7 @@ blk_full(MACRO_PROT_ARGS) continue; } - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + if (-1 == (c = lookup(mdoc, tok, p))) return(0); if (MDOC_MAX == c) { @@ -1058,7 +1065,7 @@ blk_part_imp(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + if (-1 == (c = lookup(mdoc, tok, p))) return(0); else if (MDOC_MAX == c) { if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) @@ -1162,7 +1169,7 @@ blk_part_exp(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + if (-1 == (c = lookup(mdoc, tok, p))) return(0); else if (MDOC_MAX != c) { if ( ! flushed) { @@ -1282,7 +1289,7 @@ in_line_argn(MACRO_PROT_ARGS) if (ARGS_EOLN == c) break; - if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) + if (-1 == (c = lookup(mdoc, tok, p))) return(0); else if (MDOC_MAX != c) { if ( ! flushed && ! rew_elem(mdoc, tok)) @@ -1360,8 +1367,7 @@ 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 ( ! rew_elem(mdoc, tok)) diff --git a/mdoc_term.c b/mdoc_term.c index e805bce5..eff5b573 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.63 2009/07/25 16:03:03 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.64 2009/07/29 08:46:06 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -1398,7 +1398,10 @@ termp_fd_post(DECL_ARGS) static int termp_sh_pre(DECL_ARGS) { - + /* + * FIXME: using two `Sh' macros in sequence has no vspace + * between calls, only a newline. + */ switch (node->type) { case (MDOC_HEAD): term_vspace(p); -- cgit v1.2.3-56-ge451