=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.116 retrieving revision 1.120 diff -u -p -r1.116 -r1.120 --- mandoc/mdoc.c 2010/01/07 10:24:43 1.116 +++ mandoc/mdoc.c 2010/04/05 08:59:46 1.120 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.116 2010/01/07 10:24:43 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.120 2010/04/05 08:59:46 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -26,6 +26,7 @@ #include #include #include +#include #include "libmdoc.h" #include "libmandoc.h" @@ -143,7 +144,7 @@ const char * const *mdoc_argnames = __mdoc_argnames; static void mdoc_free1(struct mdoc *); static void mdoc_alloc1(struct mdoc *); static struct mdoc_node *node_alloc(struct mdoc *, int, int, - int, enum mdoc_type); + enum mdoct, enum mdoc_type); static int node_append(struct mdoc *, struct mdoc_node *); static int parsetext(struct mdoc *, int, char *); @@ -341,16 +342,32 @@ mdoc_err(struct mdoc *m, int line, int pos, int iserr, int -mdoc_macro(struct mdoc *m, int tok, +mdoc_macro(struct mdoc *m, enum mdoct tok, int ln, int pp, int *pos, char *buf) { + + assert(tok < MDOC_MAX); /* * 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)); + MDOC_PBODY & m->flags) { + if ( ! mdoc_pwarn(m, ln, pp, EBODYPROL)) + return(0); + /* + * FIXME: do this in mdoc_action.c. + */ + if (NULL == m->meta.title) + m->meta.title = mandoc_strdup("unknown"); + if (NULL == m->meta.vol) + m->meta.vol = mandoc_strdup("local"); + if (NULL == m->meta.os) + m->meta.os = mandoc_strdup("local"); + if (0 == m->meta.date) + m->meta.date = time(NULL); + m->flags |= MDOC_PBODY; + } if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && ! (MDOC_PBODY & m->flags)) return(mdoc_perr(m, ln, pp, EBODYPROL)); @@ -424,8 +441,8 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p) static struct mdoc_node * -node_alloc(struct mdoc *m, int line, - int pos, int tok, enum mdoc_type type) +node_alloc(struct mdoc *m, int line, int pos, + enum mdoct tok, enum mdoc_type type) { struct mdoc_node *p; @@ -434,15 +451,14 @@ node_alloc(struct mdoc *m, int line, p->line = line; p->pos = pos; p->tok = tok; - if (MDOC_TEXT != (p->type = type)) - assert(p->tok >= 0); + p->type = type; return(p); } int -mdoc_tail_alloc(struct mdoc *m, int line, int pos, int tok) +mdoc_tail_alloc(struct mdoc *m, int line, int pos, enum mdoct tok) { struct mdoc_node *p; @@ -455,7 +471,7 @@ mdoc_tail_alloc(struct mdoc *m, int line, int pos, int int -mdoc_head_alloc(struct mdoc *m, int line, int pos, int tok) +mdoc_head_alloc(struct mdoc *m, int line, int pos, enum mdoct tok) { struct mdoc_node *p; @@ -471,7 +487,7 @@ mdoc_head_alloc(struct mdoc *m, int line, int pos, int int -mdoc_body_alloc(struct mdoc *m, int line, int pos, int tok) +mdoc_body_alloc(struct mdoc *m, int line, int pos, enum mdoct tok) { struct mdoc_node *p; @@ -485,7 +501,7 @@ mdoc_body_alloc(struct mdoc *m, int line, int pos, int int mdoc_block_alloc(struct mdoc *m, int line, int pos, - int tok, struct mdoc_arg *args) + enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; @@ -502,7 +518,7 @@ mdoc_block_alloc(struct mdoc *m, int line, int pos, int mdoc_elem_alloc(struct mdoc *m, int line, int pos, - int tok, struct mdoc_arg *args) + enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; @@ -599,8 +615,18 @@ parsetext(struct mdoc *m, int line, char *buf) for (i = 0; ' ' == buf[i]; i++) /* Skip leading whitespace. */ ; - if ('\0' == buf[i]) - return(mdoc_perr(m, line, 0, ENOBLANK)); + if ('\0' == buf[i]) { + if ( ! mdoc_pwarn(m, line, 0, ENOBLANK)) + return(0); + /* + * Assume that a `Pp' should be inserted in the case of + * a blank line. Technically, blank lines aren't + * allowed, but enough manuals assume this behaviour + * that we want to work around it. + */ + if ( ! mdoc_elem_alloc(m, line, 0, MDOC_Pp, NULL)) + return(0); + } /* * Break apart a free-form line into tokens. Spaces are