=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.43 retrieving revision 1.46 diff -u -p -r1.43 -r1.46 --- mandoc/mdoc.c 2009/01/20 20:56:21 1.43 +++ mandoc/mdoc.c 2009/02/22 14:31:08 1.46 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.43 2009/01/20 20:56:21 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.46 2009/02/22 14:31:08 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -212,12 +212,14 @@ static void argfree(size_t, struct mdoc_arg *); static void argcpy(struct mdoc_arg *, const struct mdoc_arg *); +static struct mdoc_node *mdoc_node_alloc(const struct mdoc *); static int mdoc_node_append(struct mdoc *, struct mdoc_node *); static void mdoc_elem_free(struct mdoc_elem *); static void mdoc_text_free(struct mdoc_text *); + const struct mdoc_node * mdoc_node(struct mdoc *mdoc) { @@ -305,8 +307,8 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf) mdoc->linetok = 0; if ('.' != *buf) { - if ( ! (MDOC_BODYPARSE & mdoc->flags)) - return(mdoc_perr(mdoc, line, 0, "text disallowed")); + if (SEC_PROLOGUE == mdoc->lastnamed) + return(mdoc_perr(mdoc, line, 0, "text disallowed in document prologue")); if ( ! mdoc_word_alloc(mdoc, line, 0, buf)) return(0); mdoc->next = MDOC_NEXT_SIBLING; @@ -407,9 +409,12 @@ mdoc_macro(struct mdoc *mdoc, int tok, assert(mdoc_macros[tok].fp); - if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && - ! (MDOC_BODYPARSE & mdoc->flags)) - return(mdoc_perr(mdoc, ln, ppos, "macro disallowed: not in document body")); + if (MDOC_PROLOGUE & mdoc_macros[tok].flags && + SEC_PROLOGUE != mdoc->lastnamed) + return(mdoc_perr(mdoc, ln, ppos, "macro disallowed in document body")); + if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && + SEC_PROLOGUE == mdoc->lastnamed) + return(mdoc_perr(mdoc, ln, ppos, "macro disallowed in document prologue")); if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) return(mdoc_perr(mdoc, ln, ppos, "macro not callable")); return((*mdoc_macros[tok].fp)(mdoc, tok, ln, ppos, pos, buf)); @@ -507,6 +512,18 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node * } +static struct mdoc_node * +mdoc_node_alloc(const struct mdoc *mdoc) +{ + struct mdoc_node *p; + + p = xcalloc(1, sizeof(struct mdoc_node)); + p->sec = mdoc->lastsec; + + return(p); +} + + int mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, int tok) { @@ -515,7 +532,7 @@ mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, assert(mdoc->first); assert(mdoc->last); - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); p->line = line; p->pos = pos; @@ -534,7 +551,7 @@ mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, assert(mdoc->first); assert(mdoc->last); - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); p->line = line; p->pos = pos; @@ -553,7 +570,7 @@ mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, assert(mdoc->first); assert(mdoc->last); - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); p->line = line; p->pos = pos; @@ -569,7 +586,7 @@ mdoc_root_alloc(struct mdoc *mdoc) { struct mdoc_node *p; - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); p->type = MDOC_ROOT; @@ -583,7 +600,7 @@ mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, { struct mdoc_node *p; - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); p->pos = pos; p->line = line; @@ -602,7 +619,7 @@ mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, { struct mdoc_node *p; - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); p->line = line; p->pos = pos; @@ -621,7 +638,8 @@ mdoc_word_alloc(struct mdoc *mdoc, { struct mdoc_node *p; - p = xcalloc(1, sizeof(struct mdoc_node)); + p = mdoc_node_alloc(mdoc); + p->line = line; p->pos = pos; p->type = MDOC_TEXT;