=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.151 retrieving revision 1.153 diff -u -p -r1.151 -r1.153 --- mandoc/mdoc.c 2010/06/27 16:36:22 1.151 +++ mandoc/mdoc.c 2010/07/01 22:35:54 1.153 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.151 2010/06/27 16:36:22 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.153 2010/07/01 22:35:54 schwarze 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,24 +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; - - /* Register analysis. */ - - if (m->regs->regs[(int)REG_nS].set) { - if (m->regs->regs[(int)REG_nS].v.u) - p->flags |= MDOC_SYNPRETTY; - else - p->flags &= ~MDOC_SYNPRETTY; - } - return(p); } @@ -431,6 +437,22 @@ mdoc_body_alloc(struct mdoc *m, int line, int pos, enu if ( ! node_append(m, p)) return(0); m->next = MDOC_NEXT_CHILD; + return(1); +} + + +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); }