=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- src/usr.bin/mandoc/mdoc.c 2009/08/22 17:21:24 1.23 +++ src/usr.bin/mandoc/mdoc.c 2009/08/22 19:43:33 1.24 @@ -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 * @@ -29,7 +29,6 @@ "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 @@ "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 @@ 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_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 @@ 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 @@ 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 @@ 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 @@ m->flags |= MDOC_HALT; return(0); } + +