=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.179 retrieving revision 1.184 diff -u -p -r1.179 -r1.184 --- mandoc/mdoc.c 2011/02/06 22:05:20 1.179 +++ mandoc/mdoc.c 2011/03/17 11:30:23 1.184 @@ -1,6 +1,6 @@ -/* $Id: mdoc.c,v 1.179 2011/02/06 22:05:20 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.184 2011/03/17 11:30:23 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons + * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any @@ -98,10 +98,7 @@ static int node_append(struct mdoc *, struct mdoc_node *); static int mdoc_ptext(struct mdoc *, int, char *, int); static int mdoc_pmacro(struct mdoc *, int, char *, int); -static int mdoc_span_alloc(struct mdoc *, - const struct tbl_span *); - const struct mdoc_node * mdoc_node(const struct mdoc *m) { @@ -141,6 +138,8 @@ mdoc_free1(struct mdoc *mdoc) free(mdoc->meta.vol); if (mdoc->meta.msec) free(mdoc->meta.msec); + if (mdoc->meta.date) + free(mdoc->meta.date); } @@ -225,8 +224,33 @@ mdoc_endparse(struct mdoc *m) } int +mdoc_addeqn(struct mdoc *m, const struct eqn *ep) +{ + struct mdoc_node *n; + + assert( ! (MDOC_HALT & m->flags)); + + /* No text before an initial macro. */ + + if (SEC_NONE == m->lastnamed) { + mdoc_pmsg(m, ep->line, ep->pos, MANDOCERR_NOTEXT); + return(1); + } + + n = node_alloc(m, ep->line, ep->pos, MDOC_MAX, MDOC_EQN); + n->eqn = ep; + + if ( ! node_append(m, n)) + return(0); + + m->next = MDOC_NEXT_SIBLING; + return(1); +} + +int mdoc_addspan(struct mdoc *m, const struct tbl_span *sp) { + struct mdoc_node *n; assert( ! (MDOC_HALT & m->flags)); @@ -237,7 +261,14 @@ mdoc_addspan(struct mdoc *m, const struct tbl_span *sp return(1); } - return(mdoc_span_alloc(m, sp)); + n = node_alloc(m, sp->line, 0, MDOC_MAX, MDOC_TBL); + n->span = sp; + + if ( ! node_append(m, n)) + return(0); + + m->next = MDOC_NEXT_SIBLING; + return(1); } @@ -272,7 +303,7 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int of } -int +void mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t, int ln, int pos, const char *fmt, ...) { @@ -283,7 +314,7 @@ mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t, vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); - return((*mdoc->msg)(t, mdoc->data, ln, pos, buf)); + (*mdoc->msg)(t, mdoc->data, ln, pos, buf); } @@ -313,8 +344,9 @@ mdoc_macro(MACRO_PROT_ARGS) 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); + if (NULL == m->meta.date) + m->meta.date = mandoc_normdate(NULL, + m->msg, m->data, line, ppos); m->flags |= MDOC_PBODY; } @@ -544,22 +576,6 @@ mdoc_elem_alloc(struct mdoc *m, int line, int pos, m->next = MDOC_NEXT_CHILD; return(1); } - -static int -mdoc_span_alloc(struct mdoc *m, const struct tbl_span *sp) -{ - struct mdoc_node *n; - - n = node_alloc(m, sp->line, 0, MDOC_MAX, MDOC_TBL); - n->span = sp; - - if ( ! node_append(m, n)) - return(0); - - m->next = MDOC_NEXT_SIBLING; - return(1); -} - int mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)