=================================================================== RCS file: /cvs/mandoc/man.c,v retrieving revision 1.183 retrieving revision 1.188 diff -u -p -r1.183 -r1.188 --- mandoc/man.c 2018/12/31 04:55:46 1.183 +++ mandoc/man.c 2022/04/28 10:26:37 1.188 @@ -1,7 +1,7 @@ -/* $Id: man.c,v 1.183 2018/12/31 04:55:46 schwarze Exp $ */ +/* $Id: man.c,v 1.188 2022/04/28 10:26:37 schwarze Exp $ */ /* + * Copyright (c) 2013-2015,2017-2019,2022 Ingo Schwarze * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze * Copyright (c) 2011 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -70,6 +70,9 @@ man_hasc(char *start) return (ep - cp) % 2 ? NULL : ep; } +/* + * Rewind all open next-line scopes. + */ void man_descope(struct roff_man *man, int line, int offs, char *start) { @@ -92,9 +95,9 @@ man_descope(struct roff_man *man, int line, int offs, } if ( ! (man->flags & MAN_BLINE)) return; - man->flags &= ~MAN_BLINE; man_unscope(man, man->last->parent); roff_body_alloc(man, line, offs, man->last->tok); + man->flags &= ~(MAN_BLINE | ROFF_NONOFILL); } static int @@ -103,9 +106,9 @@ man_ptext(struct roff_man *man, int line, char *buf, i int i; char *ep; - /* Literal free-form text whitespace is preserved. */ + /* In no-fill mode, whitespace is preserved on text lines. */ - if (man->flags & MAN_LITERAL) { + if (man->flags & ROFF_NOFILL) { roff_word_alloc(man, line, offs, buf + offs); man_descope(man, line, offs, buf + offs); return 1; @@ -268,12 +271,16 @@ man_pmacro(struct roff_man *man, int ln, char *buf, in man_macro(tok)->flags & MAN_NSCOPED) return 1; - man->flags &= ~MAN_BLINE; man_unscope(man, man->last->parent); roff_body_alloc(man, ln, ppos, man->last->tok); + man->flags &= ~(MAN_BLINE | ROFF_NONOFILL); return 1; } +/* + * Rewind open next-line scopes + * unless the tok request or macro is allowed inside them. + */ void man_breakscope(struct roff_man *man, int tok) { @@ -294,10 +301,15 @@ man_breakscope(struct roff_man *man, int tok) (man_macro(n->tok)->flags & (MAN_NSCOPED | MAN_ESCOPED)) == MAN_NSCOPED) n = n->parent; - - mandoc_msg(MANDOCERR_BLK_LINE, n->line, n->pos, - "%s breaks %s", roff_name[tok], roff_name[n->tok]); - + for (;;) { + mandoc_msg(MANDOCERR_BLK_LINE, n->line, n->pos, + "%s breaks %s", roff_name[tok], roff_name[n->tok]); + if (n->parent->type != ROFFT_ELEM || + (man_macro(n->parent->tok)->flags & + MAN_ESCOPED) == 0) + break; + n = n->parent; + } roff_node_delete(man, n); man->flags &= ~MAN_ELINE; } @@ -308,12 +320,12 @@ man_breakscope(struct roff_man *man, int tok) */ if (man->flags & MAN_BLINE && - (tok == MAN_nf || tok == MAN_fi) && + (tok == ROFF_nf || tok == ROFF_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; + man->flags &= ~(MAN_BLINE | ROFF_NONOFILL); } /* @@ -322,8 +334,8 @@ man_breakscope(struct roff_man *man, int tok) * Delete the block that is being broken. */ - if (man->flags & MAN_BLINE && (tok < MAN_TH || - man_macro(tok)->flags & MAN_XSCOPE)) { + if (man->flags & MAN_BLINE && tok != ROFF_nf && tok != ROFF_fi && + (tok < MAN_TH || man_macro(tok)->flags & MAN_XSCOPE)) { n = man->last; if (n->type == ROFFT_TEXT) n = n->parent; @@ -340,30 +352,6 @@ man_breakscope(struct roff_man *man, int tok) "%s breaks %s", roff_name[tok], roff_name[n->tok]); roff_node_delete(man, n); - man->flags &= ~MAN_BLINE; + man->flags &= ~(MAN_BLINE | ROFF_NONOFILL); } -} - -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, 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, n->line, n->pos, "fi"); - man->flags &= ~MAN_LITERAL; - break; - default: - break; - } - man->last->flags |= NODE_VALID; }