diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2014-11-30 02:36:38 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2014-11-30 02:36:38 +0000 |
commit | 672fb7896ca2c19f7313864be8ddba51337a45c0 (patch) | |
tree | 526fb2a5840669c169364a7f3553d675b0a193ca /mdoc_macro.c | |
parent | 189a8d328ad3183232385bd1ceea6a0557c5cc1b (diff) | |
download | mandoc-672fb7896ca2c19f7313864be8ddba51337a45c0.tar.gz |
warn about attempts to call non-callable macros;
inspired by a similar warning in the groff_mdoc(7) macros
Diffstat (limited to 'mdoc_macro.c')
-rw-r--r-- | mdoc_macro.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/mdoc_macro.c b/mdoc_macro.c index 47ec5b8a..8554c2d4 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -53,7 +53,8 @@ static void phrase_ta(MACRO_PROT_ARGS); static void dword(struct mdoc *, int, int, const char *, enum mdelim, int); static void append_delims(struct mdoc *, int, int *, char *); -static enum mdoct lookup(enum mdoct, const char *); +static enum mdoct lookup(struct mdoc *, enum mdoct, + int, int, const char *); static int macro_or_word(MACRO_PROT_ARGS, int); static int make_pending(struct mdoc_node *, enum mdoct, struct mdoc *, int, int); @@ -245,14 +246,19 @@ mdoc_macroend(struct mdoc *mdoc) * or as a line macro if from == MDOC_MAX. */ static enum mdoct -lookup(enum mdoct from, const char *p) +lookup(struct mdoc *mdoc, enum mdoct from, int line, int ppos, const char *p) { enum mdoct res; if (from == MDOC_MAX || mdoc_macros[from].flags & MDOC_PARSED) { res = mdoc_hash_find(p); - if (res != MDOC_MAX && mdoc_macros[res].flags & MDOC_CALLABLE) - return(res); + if (res != MDOC_MAX) { + if (mdoc_macros[res].flags & MDOC_CALLABLE) + return(res); + if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll) + mandoc_msg(MANDOCERR_MACRO_CALL, + mdoc->parse, line, ppos, p); + } } return(MDOC_MAX); } @@ -671,7 +677,7 @@ macro_or_word(MACRO_PROT_ARGS, int parsed) else if (*p == '"') p++; else if (parsed) - ntok = lookup(tok, p); + ntok = lookup(mdoc, tok, line, ppos, p); if (ntok == MDOC_MAX) { dword(mdoc, line, ppos, p, DELIM_MAX, tok == MDOC_MAX || @@ -832,7 +838,8 @@ blk_exp_close(MACRO_PROT_ARGS) if (ac == ARGS_PUNCT || ac == ARGS_EOLN) break; - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); + ntok = ac == ARGS_QWORD ? MDOC_MAX : + lookup(mdoc, tok, line, lastarg, p); if (ntok == MDOC_MAX) { dword(mdoc, line, lastarg, p, DELIM_MAX, @@ -933,7 +940,7 @@ in_line(MACRO_PROT_ARGS) } ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ? - MDOC_MAX : lookup(tok, p); + MDOC_MAX : lookup(mdoc, tok, line, la, p); /* * In this case, we've located a submacro and must @@ -1440,7 +1447,8 @@ in_line_argn(MACRO_PROT_ARGS) flushed = 1; } - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); + ntok = ac == ARGS_QWORD ? MDOC_MAX : + lookup(mdoc, tok, line, la, p); if (ntok != MDOC_MAX) { if ( ! flushed) |