diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-08-22 19:43:34 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-08-22 19:43:34 +0000 |
commit | 4e44fe60b2248295d7b0c1a4c9bd3b5d431bfe00 (patch) | |
tree | d978d4e72d731ebde4ac980b4c35ebe46f53ee91 /usr.bin/mandoc/mdoc.c | |
parent | 45e35385f518ea3ad6e1f97089159d36527facaf (diff) |
sync to 1.9.0: polishing the core code of mdoc macro handling
1) If a macro is not parsed, do not parse it. Of course, without
parsing it, we cannot produce "macro-like parameter" warnings,
but these were useless anyway.
2) If a macro is not callable, do not print a useless warning when
it occurs as a parameter, just display the raw characters.
3) Below .Bl -column, check whether macros are callable.
4) Like groff, allow whitespace after the initial dot on macro lines.
Diffstat (limited to 'usr.bin/mandoc/mdoc.c')
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 13611c01067..061b0a5d6d8 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.23 2009/08/22 17:21:24 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.24 2009/08/22 19:43:33 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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,13 +69,11 @@ 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 */ "unterminated quoted phrase", /* EQUOTPHR */ "closure macro without prior context", /* ENOCTX */ - "invalid whitespace after control character", /* ESPACE */ "no description found for library" /* ELIB */ }; @@ -349,7 +346,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)); @@ -357,9 +357,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)); } @@ -668,7 +665,7 @@ macrowarn(struct mdoc *m, int ln, const char *buf) int parsemacro(struct mdoc *m, int ln, char *buf) { - int i, c; + int i, j, c, ppos; char mac[5]; /* Empty lines are ignored. */ @@ -676,27 +673,32 @@ parsemacro(struct mdoc *m, int ln, char *buf) if (0 == buf[1]) return(1); - if (' ' == buf[1]) { - i = 2; + i = 1; + + /* Accept whitespace after the initial control char. */ + + if (' ' == buf[i]) { + i++; while (buf[i] && ' ' == buf[i]) i++; if (0 == buf[i]) return(1); - return(mdoc_perr(m, ln, 1, ESPACE)); } + ppos = i; + /* Copy the first word into a nil-terminated buffer. */ - for (i = 1; i < 5; i++) { - if (0 == (mac[i - 1] = buf[i])) + for (j = 0; j < 4; j++, i++) { + if (0 == (mac[j] = buf[i])) break; else if (' ' == buf[i]) break; } - mac[i - 1] = 0; + mac[j] = 0; - if (i == 5 || i <= 2) { + if (j == 4 || j < 2) { if ( ! macrowarn(m, ln, mac)) goto err; return(1); @@ -713,9 +715,11 @@ parsemacro(struct mdoc *m, int ln, char *buf) while (buf[i] && ' ' == buf[i]) i++; - /* Begin recursive parse sequence. */ - - if ( ! mdoc_macro(m, c, ln, 1, &i, buf)) + /* + * Begin recursive parse sequence. Since we're at the start of + * the line, we don't need to do callable/parseable checks. + */ + if ( ! mdoc_macro(m, c, ln, ppos, &i, buf)) goto err; return(1); @@ -725,3 +729,5 @@ err: /* Error out. */ m->flags |= MDOC_HALT; return(0); } + + |