=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.176 retrieving revision 1.182 diff -u -p -r1.176 -r1.182 --- mandoc/mdoc.c 2011/01/01 12:59:17 1.176 +++ mandoc/mdoc.c 2011/03/07 01:35:51 1.182 @@ -1,6 +1,6 @@ -/* $Id: mdoc.c,v 1.176 2011/01/01 12:59:17 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.182 2011/03/07 01:35:51 schwarze 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,15 +98,13 @@ 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) { - return(MDOC_HALT & m->flags ? NULL : m->first); + assert( ! (MDOC_HALT & m->flags)); + return(m->first); } @@ -114,7 +112,8 @@ const struct mdoc_meta * mdoc_meta(const struct mdoc *m) { - return(MDOC_HALT & m->flags ? NULL : &m->meta); + assert( ! (MDOC_HALT & m->flags)); + return(&m->meta); } @@ -215,30 +214,59 @@ int mdoc_endparse(struct mdoc *m) { - if (MDOC_HALT & m->flags) - return(0); - else if (mdoc_macroend(m)) + assert( ! (MDOC_HALT & m->flags)); + if (mdoc_macroend(m)) return(1); m->flags |= MDOC_HALT; return(0); } int -mdoc_addspan(struct mdoc *m, const struct tbl_span *sp) +mdoc_addeqn(struct mdoc *m, const struct eqn *ep) { + struct mdoc_node *n; - if (MDOC_HALT & m->flags) + 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)); + /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) { - /* FIXME: grab from span. */ - mdoc_pmsg(m, 0, 0, MANDOCERR_NOTEXT); + mdoc_pmsg(m, sp->line, 0, MANDOCERR_NOTEXT); 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); } @@ -250,8 +278,7 @@ int mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) { - if (MDOC_HALT & m->flags) - return(0); + assert( ! (MDOC_HALT & m->flags)); m->flags |= MDOC_NEWLINE; @@ -315,8 +342,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; } @@ -546,23 +574,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; - - /* FIXME: grab from tbl_span. */ - n = node_alloc(m, 0, 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)