man.c (7648bc9fee8dec6cb3c4941e0165a930fbe8dcb0) man.c (c1c95add8c80843ba15d784f95c361d795b1f593)
1/* $Id: man.c,v 1.187 2019/01/05 00:36:50 schwarze Exp $ */
1/* $Id: man.c,v 1.189 2022/08/16 23:01:09 schwarze Exp $ */
2/*
2/*
3 * Copyright (c) 2013-2015,2017-2019,2022 Ingo Schwarze <schwarze@openbsd.org>
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
5 * Copyright (c) 2011 Joerg Sonnenberger <joerg@netbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF

--- 52 unchanged lines hidden (view full) ---

65 if (ep < start || ep[0] != '\\' || ep[1] != 'c')
66 return NULL;
67 for (cp = ep; cp > start; cp--)
68 if (cp[-1] != '\\')
69 break;
70 return (ep - cp) % 2 ? NULL : ep;
71}
72
5 * Copyright (c) 2011 Joerg Sonnenberger <joerg@netbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF

--- 52 unchanged lines hidden (view full) ---

65 if (ep < start || ep[0] != '\\' || ep[1] != 'c')
66 return NULL;
67 for (cp = ep; cp > start; cp--)
68 if (cp[-1] != '\\')
69 break;
70 return (ep - cp) % 2 ? NULL : ep;
71}
72
73/*
74 * Rewind all open next-line scopes.
75 */
73void
74man_descope(struct roff_man *man, int line, int offs, char *start)
75{
76void
77man_descope(struct roff_man *man, int line, int offs, char *start)
78{
76 /* Trailing \c keeps next-line scope open. */
79 /* First close out all next-line element scopes, if any. */
77
80
78 if (start != NULL && man_hasc(start) != NULL)
79 return;
80
81 /*
82 * Co-ordinate what happens with having a next-line scope open:
83 * first close out the element scopes (if applicable),
84 * then close out the block scope (also if applicable).
85 */
86
87 if (man->flags & MAN_ELINE) {
88 while (man->last->parent->type != ROFFT_ROOT &&
89 man_macro(man->last->parent->tok)->flags & MAN_ESCOPED)
90 man_unscope(man, man->last->parent);
91 man->flags &= ~MAN_ELINE;
92 }
81 if (man->flags & MAN_ELINE) {
82 while (man->last->parent->type != ROFFT_ROOT &&
83 man_macro(man->last->parent->tok)->flags & MAN_ESCOPED)
84 man_unscope(man, man->last->parent);
85 man->flags &= ~MAN_ELINE;
86 }
87
88 /* Trailing \c keeps next-line block scope open. */
89
90 if (start != NULL && man_hasc(start) != NULL)
91 return;
92
93 /* Close out the next-line block scope, if there is one. */
94
93 if ( ! (man->flags & MAN_BLINE))
94 return;
95 man_unscope(man, man->last->parent);
96 roff_body_alloc(man, line, offs, man->last->tok);
97 man->flags &= ~(MAN_BLINE | ROFF_NONOFILL);
98}
99
100static int

--- 168 unchanged lines hidden (view full) ---

269 return 1;
270
271 man_unscope(man, man->last->parent);
272 roff_body_alloc(man, ln, ppos, man->last->tok);
273 man->flags &= ~(MAN_BLINE | ROFF_NONOFILL);
274 return 1;
275}
276
95 if ( ! (man->flags & MAN_BLINE))
96 return;
97 man_unscope(man, man->last->parent);
98 roff_body_alloc(man, line, offs, man->last->tok);
99 man->flags &= ~(MAN_BLINE | ROFF_NONOFILL);
100}
101
102static int

--- 168 unchanged lines hidden (view full) ---

271 return 1;
272
273 man_unscope(man, man->last->parent);
274 roff_body_alloc(man, ln, ppos, man->last->tok);
275 man->flags &= ~(MAN_BLINE | ROFF_NONOFILL);
276 return 1;
277}
278
279/*
280 * Rewind open next-line scopes
281 * unless the tok request or macro is allowed inside them.
282 */
277void
278man_breakscope(struct roff_man *man, int tok)
279{
280 struct roff_node *n;
281
282 /*
283 * An element next line scope is open,
284 * and the new macro is not allowed inside elements.

--- 4 unchanged lines hidden (view full) ---

289 (man_macro(tok)->flags & MAN_NSCOPED) == 0)) {
290 n = man->last;
291 if (n->type == ROFFT_TEXT)
292 n = n->parent;
293 if (n->tok < MAN_TH ||
294 (man_macro(n->tok)->flags & (MAN_NSCOPED | MAN_ESCOPED))
295 == MAN_NSCOPED)
296 n = n->parent;
283void
284man_breakscope(struct roff_man *man, int tok)
285{
286 struct roff_node *n;
287
288 /*
289 * An element next line scope is open,
290 * and the new macro is not allowed inside elements.

--- 4 unchanged lines hidden (view full) ---

295 (man_macro(tok)->flags & MAN_NSCOPED) == 0)) {
296 n = man->last;
297 if (n->type == ROFFT_TEXT)
298 n = n->parent;
299 if (n->tok < MAN_TH ||
300 (man_macro(n->tok)->flags & (MAN_NSCOPED | MAN_ESCOPED))
301 == MAN_NSCOPED)
302 n = n->parent;
297
298 mandoc_msg(MANDOCERR_BLK_LINE, n->line, n->pos,
299 "%s breaks %s", roff_name[tok], roff_name[n->tok]);
300
303 for (;;) {
304 mandoc_msg(MANDOCERR_BLK_LINE, n->line, n->pos,
305 "%s breaks %s", roff_name[tok], roff_name[n->tok]);
306 if (n->parent->type != ROFFT_ELEM ||
307 (man_macro(n->parent->tok)->flags &
308 MAN_ESCOPED) == 0)
309 break;
310 n = n->parent;
311 }
301 roff_node_delete(man, n);
302 man->flags &= ~MAN_ELINE;
303 }
304
305 /*
306 * Weird special case:
307 * Switching fill mode closes section headers.
308 */

--- 37 unchanged lines hidden ---
312 roff_node_delete(man, n);
313 man->flags &= ~MAN_ELINE;
314 }
315
316 /*
317 * Weird special case:
318 * Switching fill mode closes section headers.
319 */

--- 37 unchanged lines hidden ---