X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/b515ea6c4c885e69aebc0e97046ef428a4c9903d..fa99e371284a414ce8b13892006df003d31a0e37:/man.c diff --git a/man.c b/man.c index 191afdd5..aea3872e 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.163 2015/04/23 16:17:44 schwarze Exp $ */ +/* $Id: man.c,v 1.168 2017/03/03 13:55:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -62,9 +62,9 @@ man_parseln(struct roff_man *man, int ln, char *buf, int offs) if (man->last->type != ROFFT_EQN || ln > man->last->line) man->flags |= MAN_NEWLINE; - return (roff_getcontrol(man->roff, buf, &offs) ? + return roff_getcontrol(man->roff, buf, &offs) ? man_pmacro(man, ln, buf, offs) : - man_ptext(man, ln, buf, offs)); + man_ptext(man, ln, buf, offs); } static void @@ -97,7 +97,7 @@ man_ptext(struct roff_man *man, int line, char *buf, int offs) if (man->flags & MAN_LITERAL) { roff_word_alloc(man, line, offs, buf + offs); man_descope(man, line, offs); - return(1); + return 1; } for (i = offs; buf[i] == ' '; i++) @@ -115,7 +115,7 @@ man_ptext(struct roff_man *man, int line, char *buf, int offs) roff_elem_alloc(man, line, offs, MAN_sp); man->next = ROFF_NEXT_SIBLING; } - return(1); + return 1; } /* @@ -149,10 +149,10 @@ man_ptext(struct roff_man *man, int line, char *buf, int offs) assert(i); if (mandoc_eos(buf, (size_t)i)) - man->last->flags |= MAN_EOS; + man->last->flags |= NODE_EOS; man_descope(man, line, offs); - return(1); + return 1; } static int @@ -183,7 +183,7 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) if (tok == TOKEN_NONE) { mandoc_msg(MANDOCERR_MACRO, man->parse, ln, ppos, buf + ppos - 1); - return(1); + return 1; } /* Skip a leading escape sequence or tab. */ @@ -203,7 +203,7 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) /* Jump to the next non-whitespace word. */ - while (buf[offs] && buf[offs] == ' ') + while (buf[offs] == ' ') offs++; /* @@ -234,7 +234,7 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) n = man->last; if (n->type == ROFFT_BODY && strcmp(n->prev->child->string, "NAME")) - return(2); + return 2; } /* @@ -245,14 +245,14 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) if ( ! bline || man->flags & MAN_ELINE || man_macros[tok].flags & MAN_NSCOPED) - return(1); + return 1; assert(man->flags & MAN_BLINE); man->flags &= ~MAN_BLINE; man_unscope(man, man->last->parent); roff_body_alloc(man, ln, ppos, man->last->tok); - return(1); + return 1; } void @@ -282,6 +282,20 @@ man_breakscope(struct roff_man *man, int tok) man->flags &= ~MAN_ELINE; } + /* + * Weird special case: + * Switching fill mode closes section headers. + */ + + if (man->flags & MAN_BLINE && + (tok == MAN_nf || tok == MAN_fi) && + (man->last->tok == MAN_SH || man->last->tok == MAN_SS)) { + n = man->last; + man_unscope(man, n); + roff_body_alloc(man, n->line, n->pos, n->tok); + man->flags &= ~MAN_BLINE; + } + /* * A block header next line scope is open, * and the new macro is not allowed inside block headers. @@ -316,5 +330,40 @@ man_mparse(const struct roff_man *man) { assert(man && man->parse); - return(man->parse); + return man->parse; +} + +void +man_state(struct roff_man *man, struct roff_node *n) +{ + + switch(n->tok) { + case MAN_nf: + case MAN_EX: + if (man->flags & MAN_LITERAL && ! (n->flags & NODE_VALID)) + mandoc_msg(MANDOCERR_NF_SKIP, man->parse, + n->line, n->pos, "nf"); + man->flags |= MAN_LITERAL; + break; + case MAN_fi: + case MAN_EE: + if ( ! (man->flags & MAN_LITERAL) && + ! (n->flags & NODE_VALID)) + mandoc_msg(MANDOCERR_FI_SKIP, man->parse, + n->line, n->pos, "fi"); + man->flags &= ~MAN_LITERAL; + break; + default: + break; + } + man->last->flags |= NODE_VALID; +} + +void +man_validate(struct roff_man *man) +{ + + man->last = man->first; + man_node_validate(man); + man->flags &= ~MAN_LITERAL; }