=================================================================== RCS file: /cvs/mandoc/man.c,v retrieving revision 1.130 retrieving revision 1.137 diff -u -p -r1.130 -r1.137 --- mandoc/man.c 2014/05/07 14:14:17 1.130 +++ mandoc/man.c 2014/08/01 21:24:17 1.137 @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.130 2014/05/07 14:14:17 schwarze Exp $ */ +/* $Id: man.c,v 1.137 2014/08/01 21:24:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -68,7 +68,6 @@ const struct man_node * man_node(const struct man *man) { - assert( ! (MAN_HALT & man->flags)); return(man->first); } @@ -76,7 +75,6 @@ const struct man_meta * man_meta(const struct man *man) { - assert( ! (MAN_HALT & man->flags)); return(&man->meta); } @@ -116,11 +114,7 @@ int man_endparse(struct man *man) { - assert( ! (MAN_HALT & man->flags)); - if (man_macroend(man)) - return(1); - man->flags |= MAN_HALT; - return(0); + return(man_macroend(man)); } int @@ -129,8 +123,6 @@ man_parseln(struct man *man, int ln, char *buf, int of man->flags |= MAN_NEWLINE; - assert( ! (MAN_HALT & man->flags)); - return (roff_getcontrol(man->roff, buf, &offs) ? man_pmacro(man, ln, buf, offs) : man_ptext(man, ln, buf, offs)); @@ -194,10 +186,11 @@ man_node_append(struct man *man, struct man_node *p) assert(p->parent); p->parent->nchild++; - if ( ! man_valid_pre(man, p)) - return(0); - switch (p->type) { + case MAN_BLOCK: + if (p->tok == MAN_SH || p->tok == MAN_SS) + man->flags &= ~MAN_LITERAL; + break; case MAN_HEAD: assert(MAN_BLOCK == p->parent->type); p->parent->head = p; @@ -352,8 +345,6 @@ man_addeqn(struct man *man, const struct eqn *ep) { struct man_node *n; - assert( ! (MAN_HALT & man->flags)); - n = man_node_alloc(man, ep->ln, ep->pos, MAN_EQN, MAN_MAX); n->eqn = ep; @@ -369,8 +360,6 @@ man_addspan(struct man *man, const struct tbl_span *sp { struct man_node *n; - assert( ! (MAN_HALT & man->flags)); - n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX); n->span = sp; @@ -392,7 +381,7 @@ man_descope(struct man *man, int line, int offs) if (MAN_ELINE & man->flags) { man->flags &= ~MAN_ELINE; - if ( ! man_unscope(man, man->last->parent, MANDOCERR_MAX)) + if ( ! man_unscope(man, man->last->parent)) return(0); } @@ -400,7 +389,7 @@ man_descope(struct man *man, int line, int offs) return(1); man->flags &= ~MAN_BLINE; - if ( ! man_unscope(man, man->last->parent, MANDOCERR_MAX)) + if ( ! man_unscope(man, man->last->parent)) return(0); return(man_body_alloc(man, line, offs, man->last->tok)); } @@ -447,7 +436,8 @@ man_ptext(struct man *man, int line, char *buf, int of if (' ' == buf[i - 1] || '\t' == buf[i - 1]) { if (i > 1 && '\\' != buf[i - 2]) - man_pmsg(man, line, i - 1, MANDOCERR_EOLNSPACE); + mandoc_msg(MANDOCERR_SPACE_EOL, man->parse, + line, i - 1, NULL); for (--i; i && ' ' == buf[i]; i--) /* Spin back to non-space. */ ; @@ -477,13 +467,15 @@ man_ptext(struct man *man, int line, char *buf, int of static int man_pmacro(struct man *man, int ln, char *buf, int offs) { - int i, ppos; - enum mant tok; char mac[5]; struct man_node *n; + enum mant tok; + int i, ppos; + int bline; if ('"' == buf[offs]) { - man_pmsg(man, ln, offs, MANDOCERR_BADCOMMENT); + mandoc_msg(MANDOCERR_COMMENT_BAD, man->parse, + ln, offs, NULL); return(1); } else if ('\0' == buf[offs]) return(1); @@ -505,8 +497,8 @@ man_pmacro(struct man *man, int ln, char *buf, int off tok = (i > 0 && i < 4) ? man_hash_find(mac) : MAN_MAX; if (MAN_MAX == tok) { - mandoc_vmsg(MANDOCERR_MACRO, man->parse, ln, ppos, - "%s", buf + ppos - 1); + mandoc_msg(MANDOCERR_MACRO, man->parse, + ln, ppos, buf + ppos - 1); return(1); } @@ -521,7 +513,8 @@ man_pmacro(struct man *man, int ln, char *buf, int off */ if ('\0' == buf[offs] && ' ' == buf[offs - 1]) - man_pmsg(man, ln, offs - 1, MANDOCERR_EOLNSPACE); + mandoc_msg(MANDOCERR_SPACE_EOL, man->parse, + ln, offs - 1, NULL); /* * Remove prior ELINE macro, as it's being clobbered by a new @@ -539,7 +532,7 @@ man_pmacro(struct man *man, int ln, char *buf, int off if (MAN_NSCOPED & man_macros[n->tok].flags) n = n->parent; - mandoc_vmsg(MANDOCERR_LINESCOPE, man->parse, n->line, + mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, n->pos, "%s breaks %s", man_macronames[tok], man_macronames[n->tok]); @@ -570,7 +563,7 @@ man_pmacro(struct man *man, int ln, char *buf, int off assert(MAN_BLOCK == n->type); assert(MAN_SCOPED & man_macros[n->tok].flags); - mandoc_vmsg(MANDOCERR_LINESCOPE, man->parse, n->line, + mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, n->pos, "%s breaks %s", man_macronames[tok], man_macronames[n->tok]); @@ -578,20 +571,15 @@ man_pmacro(struct man *man, int ln, char *buf, int off man->flags &= ~MAN_BLINE; } - /* - * Save the fact that we're in the next-line for a block. In - * this way, embedded roff instructions can "remember" state - * when they exit. - */ + /* Remember whether we are in next-line scope for a block head. */ - if (MAN_BLINE & man->flags) - man->flags |= MAN_BPLINE; + bline = man->flags & MAN_BLINE; /* Call to handler... */ assert(man_macros[tok].fp); if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf)) - goto err; + return(0); /* In quick mode (for mandocdb), abort after the NAME section. */ @@ -603,47 +591,21 @@ man_pmacro(struct man *man, int ln, char *buf, int off } /* - * We weren't in a block-line scope when entering the - * above-parsed macro, so return. + * If we are in a next-line scope for a block head, + * close it out now and switch to the body, + * unless the next-line scope is allowed to continue. */ - if ( ! (MAN_BPLINE & man->flags)) { - man->flags &= ~MAN_ILINE; + if ( ! bline || man->flags & MAN_ELINE || + man_macros[tok].flags & MAN_NSCOPED) return(1); - } - man->flags &= ~MAN_BPLINE; - /* - * If we're in a block scope, then allow this macro to slip by - * without closing scope around it. - */ - - if (MAN_ILINE & man->flags) { - man->flags &= ~MAN_ILINE; - return(1); - } - - /* - * If we've opened a new next-line element scope, then return - * now, as the next line will close out the block scope. - */ - - if (MAN_ELINE & man->flags) - return(1); - - /* Close out the block scope opened in the prior line. */ - assert(MAN_BLINE & man->flags); man->flags &= ~MAN_BLINE; - if ( ! man_unscope(man, man->last->parent, MANDOCERR_MAX)) + if ( ! man_unscope(man, man->last->parent)) return(0); return(man_body_alloc(man, ln, ppos, man->last->tok)); - -err: /* Error out. */ - - man->flags |= MAN_HALT; - return(0); } /*