=================================================================== RCS file: /cvs/mandoc/man.c,v retrieving revision 1.32 retrieving revision 1.42 diff -u -p -r1.32 -r1.42 --- mandoc/man.c 2009/08/19 12:00:46 1.32 +++ mandoc/man.c 2009/10/24 05:45:04 1.42 @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.32 2009/08/19 12:00:46 kristaps Exp $ */ +/* $Id: man.c,v 1.42 2009/10/24 05:45:04 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -14,6 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include #include #include @@ -41,7 +43,9 @@ const char *const __man_merrnames[WERRMAX] = { "unknown macro", /* WMACRO */ "ill-formed macro", /* WMACROFORM */ "scope open on exit", /* WEXITSCOPE */ - "no scope context" /* WNOSCOPE */ + "no scope context", /* WNOSCOPE */ + "literal context already open", /* WOLITERAL */ + "no literal context open" /* WNLITERAL */ }; const char *const __man_macronames[MAN_MAX] = { @@ -52,7 +56,7 @@ const char *const __man_macronames[MAN_MAX] = { "R", "B", "I", "IR", "RI", "na", "i", "sp", "nf", "fi", "r", "RE", - "RS" + "RS", "DT", "UC", "PD" }; const char * const *man_macronames = __man_macronames; @@ -103,9 +107,6 @@ man_free(struct man *man) { man_free1(man); - - if (man->htab) - man_hash_free(man->htab); free(man); } @@ -123,14 +124,11 @@ man_alloc(void *data, int pflags, const struct man_cb return(NULL); } + man_hash_init(); + p->data = data; p->pflags = pflags; (void)memcpy(&p->cb, cb, sizeof(struct man_cb)); - - if (NULL == (p->htab = man_hash_alloc())) { - free(p); - return(NULL); - } return(p); } @@ -376,14 +374,15 @@ man_node_free(struct man_node *p) void man_node_freelist(struct man_node *p) { + struct man_node *n; if (p->child) man_node_freelist(p->child); - if (p->next) - man_node_freelist(p->next); - assert(0 == p->nchild); + n = p->next; man_node_free(p); + if (n) + man_node_freelist(n); } @@ -392,6 +391,14 @@ man_ptext(struct man *m, int line, char *buf) { int i, j; + /* Literal free-form text whitespace is preserved. */ + + if (MAN_LITERAL & m->flags) { + if ( ! man_word_alloc(m, line, 0, buf)) + return(0); + goto descope; + } + /* First de-chunk and allocate words. */ for (i = 0; ' ' == buf[i]; i++) @@ -433,8 +440,6 @@ descope: * out the block scope (also if applicable). */ - /* XXX - this should be in man_action.c. */ - if (MAN_ELINE & m->flags) { m->flags &= ~MAN_ELINE; if ( ! man_unscope(m, m->last->parent)) @@ -454,8 +459,9 @@ descope: int man_pmacro(struct man *m, int ln, char *buf) { - int i, j, c, ppos, fl; - char mac[5]; + int i, j, c, ppos, fl; + char mac[5]; + struct man_node *n; /* Comments and empties are quickly ignored. */ @@ -483,6 +489,12 @@ man_pmacro(struct man *m, int ln, char *buf) break; else if (' ' == buf[i]) break; + + /* Check for invalid characters. */ + + if (isgraph((u_char)buf[i])) + continue; + return(man_perr(m, ln, i, WNPRINT)); } mac[j] = 0; @@ -497,7 +509,7 @@ man_pmacro(struct man *m, int ln, char *buf) return(1); } - if (MAN_MAX == (c = man_hash_find(m->htab, mac))) { + if (MAN_MAX == (c = man_hash_find(mac))) { if ( ! (MAN_IGN_MACRO & m->pflags)) { (void)man_perr(m, ln, ppos, WMACRO); goto err; @@ -512,6 +524,32 @@ man_pmacro(struct man *m, int ln, char *buf) while (buf[i] && ' ' == buf[i]) i++; + /* Remove prior ELINE macro, if applicable. */ + + if (m->flags & MAN_ELINE) { + n = m->last; + assert(NULL == n->child); + assert(0 == n->nchild); + if ( ! man_nwarn(m, n, WLNSCOPE)) + return(0); + + if (n->prev) { + assert(n != n->parent->child); + assert(n == n->prev->next); + n->prev->next = NULL; + m->last = n->prev; + m->next = MAN_NEXT_SIBLING; + } else { + assert(n == n->parent->child); + n->parent->child = NULL; + m->last = n->parent; + m->next = MAN_NEXT_CHILD; + } + + man_node_free(n); + m->flags &= ~MAN_ELINE; + } + /* Begin recursive parse sequence. */ assert(man_macros[c].fp); @@ -532,8 +570,6 @@ out: return(1); /* Close out the block scope opened in the prior line. */ - - /* XXX - this should be in man_action.c. */ assert(MAN_BLINE & m->flags); m->flags &= ~MAN_BLINE;