=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.150 retrieving revision 1.154 diff -u -p -r1.150 -r1.154 --- mandoc/mdoc.c 2010/06/27 16:18:13 1.150 +++ mandoc/mdoc.c 2010/07/01 22:56:17 1.154 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.150 2010/06/27 16:18:13 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.154 2010/07/01 22:56:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -239,6 +239,20 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int of return(0); m->flags |= MDOC_NEWLINE; + + /* + * Let the roff nS register switch SYNOPSIS mode early, + * such that the parser knows at all times + * whether this mode is on or off. + * Note that this mode is also switched by the Sh macro. + */ + if (m->regs->regs[(int)REG_nS].set) { + if (m->regs->regs[(int)REG_nS].v.u) + m->flags |= MDOC_SYNOPSIS; + else + m->flags &= ~MDOC_SYNOPSIS; + } + return(('.' == buf[offs] || '\'' == buf[offs]) ? mdoc_pmacro(m, ln, buf, offs) : mdoc_ptext(m, ln, buf, offs)); @@ -332,6 +346,8 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p) p->parent->tail = p; break; case (MDOC_BODY): + if (p->end) + break; assert(MDOC_BLOCK == p->parent->type); p->parent->body = p; break; @@ -371,15 +387,14 @@ node_alloc(struct mdoc *m, int line, int pos, /* Flag analysis. */ + if (MDOC_SYNOPSIS & m->flags) + p->flags |= MDOC_SYNPRETTY; + else + p->flags &= ~MDOC_SYNPRETTY; if (MDOC_NEWLINE & m->flags) p->flags |= MDOC_LINE; m->flags &= ~MDOC_NEWLINE; - /* Section analysis. */ - - if (SEC_SYNOPSIS == p->sec) - p->flags |= MDOC_SYNPRETTY; - return(p); } @@ -427,6 +442,22 @@ mdoc_body_alloc(struct mdoc *m, int line, int pos, enu int +mdoc_endbody_alloc(struct mdoc *m, int line, int pos, enum mdoct tok, + struct mdoc_node *body, enum mdoc_endbody end) +{ + struct mdoc_node *p; + + p = node_alloc(m, line, pos, tok, MDOC_BODY); + p->pending = body; + p->end = end; + if ( ! node_append(m, p)) + return(0); + m->next = MDOC_NEXT_SIBLING; + return(1); +} + + +int mdoc_block_alloc(struct mdoc *m, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { @@ -483,10 +514,18 @@ mdoc_word_alloc(struct mdoc *m, int line, int pos, con } +/* FIXME: put in mdoc_node_delete(). */ void mdoc_node_free(struct mdoc_node *p) { + if (MDOC_Bd == p->tok && MDOC_BLOCK == p->type) + if (p->data.Bd) + free(p->data.Bd); + if (MDOC_Bl == p->tok && MDOC_BLOCK == p->type) + if (p->data.Bl) + free(p->data.Bl); + if (p->string) free(p->string); if (p->args) @@ -579,7 +618,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int of */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && - LIST_column == n->data.Bl.type) { + LIST_column == n->data.Bl->type) { /* `Bl' is open without any children. */ m->flags |= MDOC_FREECOL; return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf)); @@ -588,7 +627,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int of if (MDOC_It == n->tok && MDOC_BLOCK == n->type && NULL != n->parent && MDOC_Bl == n->parent->tok && - LIST_column == n->parent->data.Bl.type) { + LIST_column == n->parent->data.Bl->type) { /* `Bl' has block-level `It' children. */ m->flags |= MDOC_FREECOL; return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf)); @@ -794,7 +833,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int off */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && - LIST_column == n->data.Bl.type) { + LIST_column == n->data.Bl->type) { m->flags |= MDOC_FREECOL; if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err; @@ -810,7 +849,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int off if (MDOC_It == n->tok && MDOC_BLOCK == n->type && NULL != n->parent && MDOC_Bl == n->parent->tok && - LIST_column == n->parent->data.Bl.type) { + LIST_column == n->parent->data.Bl->type) { m->flags |= MDOC_FREECOL; if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err;