1*6167eca2Schristos /* Id: man_macro.c,v 1.144 2019/01/05 18:59:46 schwarze Exp */
24154958bSjoerg /*
3c5f73b34Sjoerg * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*6167eca2Schristos * Copyright (c) 2012-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
570f041f9Sjoerg * Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
64154958bSjoerg *
74154958bSjoerg * Permission to use, copy, modify, and distribute this software for any
84154958bSjoerg * purpose with or without fee is hereby granted, provided that the above
94154958bSjoerg * copyright notice and this permission notice appear in all copies.
104154958bSjoerg *
11f47368cfSchristos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
124154958bSjoerg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13f47368cfSchristos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
144154958bSjoerg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
154154958bSjoerg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
164154958bSjoerg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
174154958bSjoerg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
184154958bSjoerg */
19d5e63c8dSjoerg #include "config.h"
20fec65c98Schristos
21fec65c98Schristos #include <sys/types.h>
22d5e63c8dSjoerg
234154958bSjoerg #include <assert.h>
244154958bSjoerg #include <ctype.h>
25*6167eca2Schristos #include <stdio.h>
264154958bSjoerg #include <stdlib.h>
274154958bSjoerg #include <string.h>
284154958bSjoerg
290a84adc5Sjoerg #include "mandoc.h"
30f47368cfSchristos #include "roff.h"
31f47368cfSchristos #include "man.h"
3248741257Sjoerg #include "libmandoc.h"
33f47368cfSchristos #include "roff_int.h"
344154958bSjoerg #include "libman.h"
354154958bSjoerg
36fec65c98Schristos static void blk_close(MACRO_PROT_ARGS);
37fec65c98Schristos static void blk_exp(MACRO_PROT_ARGS);
38fec65c98Schristos static void blk_imp(MACRO_PROT_ARGS);
39fec65c98Schristos static void in_line_eoln(MACRO_PROT_ARGS);
40f47368cfSchristos static int man_args(struct roff_man *, int,
4148741257Sjoerg int *, char *, char **);
4214e7489eSchristos static void rew_scope(struct roff_man *, enum roff_tok);
434154958bSjoerg
44*6167eca2Schristos static const struct man_macro man_macros[MAN_MAX - MAN_TH] = {
45*6167eca2Schristos { in_line_eoln, MAN_XSCOPE }, /* TH */
46*6167eca2Schristos { blk_imp, MAN_XSCOPE | MAN_BSCOPED }, /* SH */
47*6167eca2Schristos { blk_imp, MAN_XSCOPE | MAN_BSCOPED }, /* SS */
48*6167eca2Schristos { blk_imp, MAN_XSCOPE | MAN_BSCOPED }, /* TP */
49*6167eca2Schristos { blk_imp, MAN_XSCOPE | MAN_BSCOPED }, /* TQ */
50*6167eca2Schristos { blk_imp, MAN_XSCOPE }, /* LP */
51*6167eca2Schristos { blk_imp, MAN_XSCOPE }, /* PP */
52*6167eca2Schristos { blk_imp, MAN_XSCOPE }, /* P */
53*6167eca2Schristos { blk_imp, MAN_XSCOPE }, /* IP */
54*6167eca2Schristos { blk_imp, MAN_XSCOPE }, /* HP */
55*6167eca2Schristos { in_line_eoln, MAN_NSCOPED | MAN_ESCOPED | MAN_JOIN }, /* SM */
56*6167eca2Schristos { in_line_eoln, MAN_NSCOPED | MAN_ESCOPED | MAN_JOIN }, /* SB */
574154958bSjoerg { in_line_eoln, 0 }, /* BI */
584154958bSjoerg { in_line_eoln, 0 }, /* IB */
594154958bSjoerg { in_line_eoln, 0 }, /* BR */
604154958bSjoerg { in_line_eoln, 0 }, /* RB */
61*6167eca2Schristos { in_line_eoln, MAN_NSCOPED | MAN_ESCOPED | MAN_JOIN }, /* R */
62*6167eca2Schristos { in_line_eoln, MAN_NSCOPED | MAN_ESCOPED | MAN_JOIN }, /* B */
63*6167eca2Schristos { in_line_eoln, MAN_NSCOPED | MAN_ESCOPED | MAN_JOIN }, /* I */
644154958bSjoerg { in_line_eoln, 0 }, /* IR */
654154958bSjoerg { in_line_eoln, 0 }, /* RI */
66*6167eca2Schristos { blk_close, MAN_XSCOPE }, /* RE */
67*6167eca2Schristos { blk_exp, MAN_XSCOPE }, /* RS */
684154958bSjoerg { in_line_eoln, 0 }, /* DT */
694154958bSjoerg { in_line_eoln, 0 }, /* UC */
70f47368cfSchristos { in_line_eoln, MAN_NSCOPED }, /* PD */
710a84adc5Sjoerg { in_line_eoln, 0 }, /* AT */
7214e7489eSchristos { in_line_eoln, MAN_NSCOPED }, /* in */
73*6167eca2Schristos { blk_imp, MAN_XSCOPE }, /* SY */
74*6167eca2Schristos { blk_close, MAN_XSCOPE }, /* YS */
75cf816816Sjoerg { in_line_eoln, 0 }, /* OP */
76*6167eca2Schristos { in_line_eoln, MAN_XSCOPE }, /* EX */
77*6167eca2Schristos { in_line_eoln, MAN_XSCOPE }, /* EE */
78*6167eca2Schristos { blk_exp, MAN_XSCOPE }, /* UR */
79*6167eca2Schristos { blk_close, MAN_XSCOPE }, /* UE */
80*6167eca2Schristos { blk_exp, MAN_XSCOPE }, /* MT */
81*6167eca2Schristos { blk_close, MAN_XSCOPE }, /* ME */
824154958bSjoerg };
834154958bSjoerg
844154958bSjoerg
85*6167eca2Schristos const struct man_macro *
man_macro(enum roff_tok tok)86*6167eca2Schristos man_macro(enum roff_tok tok)
87*6167eca2Schristos {
88*6167eca2Schristos assert(tok >= MAN_TH && tok <= MAN_MAX);
89*6167eca2Schristos return man_macros + (tok - MAN_TH);
90*6167eca2Schristos }
91*6167eca2Schristos
92fec65c98Schristos void
man_unscope(struct roff_man * man,const struct roff_node * to)93f47368cfSchristos man_unscope(struct roff_man *man, const struct roff_node *to)
944154958bSjoerg {
95f47368cfSchristos struct roff_node *n;
964154958bSjoerg
97fec65c98Schristos to = to->parent;
98fec65c98Schristos n = man->last;
99fec65c98Schristos while (n != to) {
1004154958bSjoerg
101fec65c98Schristos /* Reached the end of the document? */
102c5f73b34Sjoerg
10337ef69edSchristos if (to == NULL && ! (n->flags & NODE_VALID)) {
104fec65c98Schristos if (man->flags & (MAN_BLINE | MAN_ELINE) &&
105*6167eca2Schristos man_macro(n->tok)->flags &
106*6167eca2Schristos (MAN_BSCOPED | MAN_NSCOPED)) {
107*6167eca2Schristos mandoc_msg(MANDOCERR_BLK_LINE,
108*6167eca2Schristos n->line, n->pos,
10914e7489eSchristos "EOF breaks %s", roff_name[n->tok]);
110fec65c98Schristos if (man->flags & MAN_ELINE)
111fec65c98Schristos man->flags &= ~MAN_ELINE;
112fec65c98Schristos else {
113f47368cfSchristos assert(n->type == ROFFT_HEAD);
114fec65c98Schristos n = n->parent;
115fec65c98Schristos man->flags &= ~MAN_BLINE;
116fec65c98Schristos }
11770f041f9Sjoerg man->last = n;
118fec65c98Schristos n = n->parent;
119f47368cfSchristos roff_node_delete(man, man->last);
120fec65c98Schristos continue;
121fec65c98Schristos }
122f47368cfSchristos if (n->type == ROFFT_BLOCK &&
123*6167eca2Schristos man_macro(n->tok)->fp == blk_exp)
124fec65c98Schristos mandoc_msg(MANDOCERR_BLK_NOEND,
125*6167eca2Schristos n->line, n->pos, "%s",
12614e7489eSchristos roff_name[n->tok]);
1274154958bSjoerg }
1284154958bSjoerg
129fec65c98Schristos /*
130fec65c98Schristos * We might delete the man->last node
131fec65c98Schristos * in the post-validation phase.
132fec65c98Schristos * Save a pointer to the parent such that
133fec65c98Schristos * we know where to continue the iteration.
134fec65c98Schristos */
13531e1f4e3Sjoerg
136fec65c98Schristos man->last = n;
137fec65c98Schristos n = n->parent;
13837ef69edSchristos man->last->flags |= NODE_VALID;
1394154958bSjoerg }
1404154958bSjoerg
141fec65c98Schristos /*
142fec65c98Schristos * If we ended up at the parent of the node we were
143fec65c98Schristos * supposed to rewind to, that means the target node
144fec65c98Schristos * got deleted, so add the next node we parse as a child
145fec65c98Schristos * of the parent instead of as a sibling of the target.
146fec65c98Schristos */
147fec65c98Schristos
148fec65c98Schristos man->next = (man->last == to) ?
149f47368cfSchristos ROFF_NEXT_CHILD : ROFF_NEXT_SIBLING;
1504154958bSjoerg }
1514154958bSjoerg
1524154958bSjoerg /*
1534154958bSjoerg * Rewinding entails ascending the parse tree until a coherent point,
1544154958bSjoerg * for example, the `SH' macro will close out any intervening `SS'
1554154958bSjoerg * scopes. When a scope is closed, it must be validated and actioned.
1564154958bSjoerg */
157fec65c98Schristos static void
rew_scope(struct roff_man * man,enum roff_tok tok)15814e7489eSchristos rew_scope(struct roff_man *man, enum roff_tok tok)
1594154958bSjoerg {
160f47368cfSchristos struct roff_node *n;
1614154958bSjoerg
162f47368cfSchristos /* Preserve empty paragraphs before RS. */
163f47368cfSchristos
164f47368cfSchristos n = man->last;
165f47368cfSchristos if (tok == MAN_RS && n->child == NULL &&
166f47368cfSchristos (n->tok == MAN_P || n->tok == MAN_PP || n->tok == MAN_LP))
167fec65c98Schristos return;
1684154958bSjoerg
169f47368cfSchristos for (;;) {
170f47368cfSchristos if (n->type == ROFFT_ROOT)
171f47368cfSchristos return;
17237ef69edSchristos if (n->flags & NODE_VALID) {
173f47368cfSchristos n = n->parent;
174f47368cfSchristos continue;
175f47368cfSchristos }
176f47368cfSchristos if (n->type != ROFFT_BLOCK) {
177f47368cfSchristos if (n->parent->type == ROFFT_ROOT) {
178fec65c98Schristos man_unscope(man, n);
179f47368cfSchristos return;
180f47368cfSchristos } else {
181f47368cfSchristos n = n->parent;
182f47368cfSchristos continue;
183f47368cfSchristos }
184f47368cfSchristos }
185f47368cfSchristos if (tok != MAN_SH && (n->tok == MAN_SH ||
186f47368cfSchristos (tok != MAN_SS && (n->tok == MAN_SS ||
187*6167eca2Schristos man_macro(n->tok)->fp == blk_exp))))
188f47368cfSchristos return;
189f47368cfSchristos man_unscope(man, n);
190f47368cfSchristos n = man->last;
191f47368cfSchristos }
19231e1f4e3Sjoerg }
19331e1f4e3Sjoerg
19431e1f4e3Sjoerg
19531e1f4e3Sjoerg /*
19631e1f4e3Sjoerg * Close out a generic explicit macro.
19731e1f4e3Sjoerg */
198fec65c98Schristos void
blk_close(MACRO_PROT_ARGS)1994154958bSjoerg blk_close(MACRO_PROT_ARGS)
2004154958bSjoerg {
201*6167eca2Schristos enum roff_tok ctok, ntok;
202f47368cfSchristos const struct roff_node *nn;
203*6167eca2Schristos char *p, *ep;
204*6167eca2Schristos int cline, cpos, la, nrew, target;
2054154958bSjoerg
206fec65c98Schristos nrew = 1;
2074154958bSjoerg switch (tok) {
208fec65c98Schristos case MAN_RE:
2094154958bSjoerg ntok = MAN_RS;
210*6167eca2Schristos la = *pos;
211fec65c98Schristos if ( ! man_args(man, line, pos, buf, &p))
2124154958bSjoerg break;
213fec65c98Schristos for (nn = man->last->parent; nn; nn = nn->parent)
214f47368cfSchristos if (nn->tok == ntok && nn->type == ROFFT_BLOCK)
215fec65c98Schristos nrew++;
216*6167eca2Schristos target = strtol(p, &ep, 10);
217*6167eca2Schristos if (*ep != '\0')
218*6167eca2Schristos mandoc_msg(MANDOCERR_ARG_EXCESS, line,
219*6167eca2Schristos la + (buf[la] == '"') + (int)(ep - p),
220*6167eca2Schristos "RE ... %s", ep);
221*6167eca2Schristos free(p);
222fec65c98Schristos if (target == 0)
223fec65c98Schristos target = 1;
224fec65c98Schristos nrew -= target;
225fec65c98Schristos if (nrew < 1) {
226*6167eca2Schristos mandoc_msg(MANDOCERR_RE_NOTOPEN,
227fec65c98Schristos line, ppos, "RE %d", target);
228fec65c98Schristos return;
229fec65c98Schristos }
230fec65c98Schristos break;
231*6167eca2Schristos case MAN_YS:
232*6167eca2Schristos ntok = MAN_SY;
233*6167eca2Schristos break;
234fec65c98Schristos case MAN_UE:
23570f041f9Sjoerg ntok = MAN_UR;
23670f041f9Sjoerg break;
23714e7489eSchristos case MAN_ME:
23814e7489eSchristos ntok = MAN_MT;
23914e7489eSchristos break;
2404154958bSjoerg default:
2414154958bSjoerg abort();
2424154958bSjoerg }
2434154958bSjoerg
24470f041f9Sjoerg for (nn = man->last->parent; nn; nn = nn->parent)
245f47368cfSchristos if (nn->tok == ntok && nn->type == ROFFT_BLOCK && ! --nrew)
2464154958bSjoerg break;
2474154958bSjoerg
248fec65c98Schristos if (nn == NULL) {
249*6167eca2Schristos mandoc_msg(MANDOCERR_BLK_NOTOPEN,
250*6167eca2Schristos line, ppos, "%s", roff_name[tok]);
251f47368cfSchristos rew_scope(man, MAN_PP);
252*6167eca2Schristos if (tok == MAN_RE) {
253*6167eca2Schristos roff_elem_alloc(man, line, ppos, ROFF_br);
254*6167eca2Schristos man->last->flags |= NODE_LINE |
255*6167eca2Schristos NODE_VALID | NODE_ENDED;
256*6167eca2Schristos man->next = ROFF_NEXT_SIBLING;
257*6167eca2Schristos }
258*6167eca2Schristos return;
259*6167eca2Schristos }
260*6167eca2Schristos
261*6167eca2Schristos cline = man->last->line;
262*6167eca2Schristos cpos = man->last->pos;
263*6167eca2Schristos ctok = man->last->tok;
264fec65c98Schristos man_unscope(man, nn);
26531e1f4e3Sjoerg
26614e7489eSchristos if (tok == MAN_RE && nn->head->aux > 0)
267*6167eca2Schristos roff_setreg(man->roff, "an-margin", nn->head->aux, '-');
268*6167eca2Schristos
269*6167eca2Schristos /* Trailing text. */
270*6167eca2Schristos
271*6167eca2Schristos if (buf[*pos] != '\0') {
272*6167eca2Schristos roff_word_alloc(man, line, ppos, buf + *pos);
273*6167eca2Schristos man->last->flags |= NODE_DELIMC;
274*6167eca2Schristos if (mandoc_eos(man->last->string, strlen(man->last->string)))
275*6167eca2Schristos man->last->flags |= NODE_EOS;
276*6167eca2Schristos }
27714e7489eSchristos
278fec65c98Schristos /* Move a trailing paragraph behind the block. */
279fec65c98Schristos
280*6167eca2Schristos if (ctok == MAN_LP || ctok == MAN_PP || ctok == MAN_P) {
281fec65c98Schristos *pos = strlen(buf);
282*6167eca2Schristos blk_imp(man, ctok, cline, cpos, pos, buf);
283fec65c98Schristos }
284*6167eca2Schristos
285*6167eca2Schristos /* Synopsis blocks need an explicit end marker for spacing. */
286*6167eca2Schristos
287*6167eca2Schristos if (tok == MAN_YS && man->last == nn) {
288*6167eca2Schristos roff_elem_alloc(man, line, ppos, tok);
289*6167eca2Schristos man_unscope(man, man->last);
290fec65c98Schristos }
2914154958bSjoerg }
2924154958bSjoerg
293fec65c98Schristos void
blk_exp(MACRO_PROT_ARGS)29431e1f4e3Sjoerg blk_exp(MACRO_PROT_ARGS)
29531e1f4e3Sjoerg {
296f47368cfSchristos struct roff_node *head;
29731e1f4e3Sjoerg char *p;
298fec65c98Schristos int la;
29931e1f4e3Sjoerg
300*6167eca2Schristos if (tok == MAN_RS) {
301f47368cfSchristos rew_scope(man, tok);
302*6167eca2Schristos man->flags |= ROFF_NONOFILL;
303*6167eca2Schristos }
304f47368cfSchristos roff_block_alloc(man, line, ppos, tok);
305f47368cfSchristos head = roff_head_alloc(man, line, ppos, tok);
30631e1f4e3Sjoerg
30731e1f4e3Sjoerg la = *pos;
30814e7489eSchristos if (man_args(man, line, pos, buf, &p)) {
309f47368cfSchristos roff_word_alloc(man, line, la, p);
31014e7489eSchristos if (tok == MAN_RS) {
31114e7489eSchristos if (roff_getreg(man->roff, "an-margin") == 0)
31214e7489eSchristos roff_setreg(man->roff, "an-margin",
31314e7489eSchristos 7 * 24, '=');
31414e7489eSchristos if ((head->aux = strtod(p, NULL) * 24.0) > 0)
31514e7489eSchristos roff_setreg(man->roff, "an-margin",
31614e7489eSchristos head->aux, '+');
31714e7489eSchristos }
318*6167eca2Schristos free(p);
31914e7489eSchristos }
320fec65c98Schristos
321fec65c98Schristos if (buf[*pos] != '\0')
322*6167eca2Schristos mandoc_msg(MANDOCERR_ARG_EXCESS, line, *pos,
323*6167eca2Schristos "%s ... %s", roff_name[tok], buf + *pos);
324fec65c98Schristos
325fec65c98Schristos man_unscope(man, head);
326f47368cfSchristos roff_body_alloc(man, line, ppos, tok);
327*6167eca2Schristos man->flags &= ~ROFF_NONOFILL;
32831e1f4e3Sjoerg }
32931e1f4e3Sjoerg
3304154958bSjoerg /*
331f47368cfSchristos * Parse an implicit-block macro. These contain a ROFFT_HEAD and a
332f47368cfSchristos * ROFFT_BODY contained within a ROFFT_BLOCK. Rules for closing out other
3334154958bSjoerg * scopes, such as `SH' closing out an `SS', are defined in the rew
3344154958bSjoerg * routines.
3354154958bSjoerg */
336fec65c98Schristos void
blk_imp(MACRO_PROT_ARGS)3374154958bSjoerg blk_imp(MACRO_PROT_ARGS)
3384154958bSjoerg {
33948741257Sjoerg int la;
3404154958bSjoerg char *p;
341f47368cfSchristos struct roff_node *n;
3424154958bSjoerg
343f47368cfSchristos rew_scope(man, tok);
344*6167eca2Schristos man->flags |= ROFF_NONOFILL;
345*6167eca2Schristos if (tok == MAN_SH || tok == MAN_SS)
346*6167eca2Schristos man->flags &= ~ROFF_NOFILL;
347*6167eca2Schristos roff_block_alloc(man, line, ppos, tok);
348f47368cfSchristos n = roff_head_alloc(man, line, ppos, tok);
3494154958bSjoerg
3504154958bSjoerg /* Add line arguments. */
3514154958bSjoerg
3524154958bSjoerg for (;;) {
3534154958bSjoerg la = *pos;
35470f041f9Sjoerg if ( ! man_args(man, line, pos, buf, &p))
3554154958bSjoerg break;
356f47368cfSchristos roff_word_alloc(man, line, la, p);
357*6167eca2Schristos free(p);
3584154958bSjoerg }
3594154958bSjoerg
360f47368cfSchristos /*
361f47368cfSchristos * For macros having optional next-line scope,
362f47368cfSchristos * keep the head open if there were no arguments.
363*6167eca2Schristos * For `TP' and `TQ', always keep the head open.
364f47368cfSchristos */
3654154958bSjoerg
366*6167eca2Schristos if (man_macro(tok)->flags & MAN_BSCOPED &&
367*6167eca2Schristos (tok == MAN_TP || tok == MAN_TQ || n == man->last)) {
36870f041f9Sjoerg man->flags |= MAN_BLINE;
369fec65c98Schristos return;
3704154958bSjoerg }
371f47368cfSchristos
372f47368cfSchristos /* Close out the head and open the body. */
373f47368cfSchristos
374f47368cfSchristos man_unscope(man, n);
375f47368cfSchristos roff_body_alloc(man, line, ppos, tok);
376*6167eca2Schristos man->flags &= ~ROFF_NONOFILL;
3774154958bSjoerg }
3784154958bSjoerg
379fec65c98Schristos void
in_line_eoln(MACRO_PROT_ARGS)3804154958bSjoerg in_line_eoln(MACRO_PROT_ARGS)
3814154958bSjoerg {
38248741257Sjoerg int la;
3834154958bSjoerg char *p;
384f47368cfSchristos struct roff_node *n;
3854154958bSjoerg
386f47368cfSchristos roff_elem_alloc(man, line, ppos, tok);
38770f041f9Sjoerg n = man->last;
3884154958bSjoerg
389*6167eca2Schristos if (tok == MAN_EX)
390*6167eca2Schristos man->flags |= ROFF_NOFILL;
391*6167eca2Schristos else if (tok == MAN_EE)
392*6167eca2Schristos man->flags &= ~ROFF_NOFILL;
393*6167eca2Schristos
3944154958bSjoerg for (;;) {
39514e7489eSchristos if (buf[*pos] != '\0' && man->last != n && tok == MAN_PD) {
396*6167eca2Schristos mandoc_msg(MANDOCERR_ARG_EXCESS, line, *pos,
397*6167eca2Schristos "%s ... %s", roff_name[tok], buf + *pos);
398fec65c98Schristos break;
399fec65c98Schristos }
4004154958bSjoerg la = *pos;
40170f041f9Sjoerg if ( ! man_args(man, line, pos, buf, &p))
4024154958bSjoerg break;
403*6167eca2Schristos if (man_macro(tok)->flags & MAN_JOIN &&
404f47368cfSchristos man->last->type == ROFFT_TEXT)
405f47368cfSchristos roff_word_append(man, p);
406fec65c98Schristos else
407f47368cfSchristos roff_word_alloc(man, line, la, p);
408*6167eca2Schristos free(p);
4094154958bSjoerg }
4104154958bSjoerg
41131e1f4e3Sjoerg /*
41237ef69edSchristos * Append NODE_EOS in case the last snipped argument
41370f041f9Sjoerg * ends with a dot, e.g. `.IR syslog (3).'
41470f041f9Sjoerg */
41570f041f9Sjoerg
41670f041f9Sjoerg if (n != man->last &&
41770f041f9Sjoerg mandoc_eos(man->last->string, strlen(man->last->string)))
41837ef69edSchristos man->last->flags |= NODE_EOS;
41970f041f9Sjoerg
42070f041f9Sjoerg /*
421*6167eca2Schristos * If no arguments are specified and this is MAN_ESCOPED (i.e.,
42231e1f4e3Sjoerg * next-line scoped), then set our mode to indicate that we're
42331e1f4e3Sjoerg * waiting for terms to load into our context.
42431e1f4e3Sjoerg */
42531e1f4e3Sjoerg
426*6167eca2Schristos if (n == man->last && man_macro(tok)->flags & MAN_ESCOPED) {
42770f041f9Sjoerg man->flags |= MAN_ELINE;
428fec65c98Schristos return;
4294154958bSjoerg }
4304154958bSjoerg
431f47368cfSchristos assert(man->last->type != ROFFT_ROOT);
432f47368cfSchristos man->next = ROFF_NEXT_SIBLING;
433c5f73b34Sjoerg
434f47368cfSchristos /* Rewind our element scope. */
4354154958bSjoerg
43670f041f9Sjoerg for ( ; man->last; man->last = man->last->parent) {
437*6167eca2Schristos man->last->flags |= NODE_VALID;
43870f041f9Sjoerg if (man->last == n)
4394154958bSjoerg break;
4404154958bSjoerg }
441*6167eca2Schristos
442*6167eca2Schristos /* Rewind next-line scoped ancestors, if any. */
443*6167eca2Schristos
444*6167eca2Schristos if (man_macro(tok)->flags & MAN_ESCOPED)
445*6167eca2Schristos man_descope(man, line, ppos, NULL);
4464154958bSjoerg }
4474154958bSjoerg
448fec65c98Schristos void
man_endparse(struct roff_man * man)449f47368cfSchristos man_endparse(struct roff_man *man)
4504154958bSjoerg {
451*6167eca2Schristos man_unscope(man, man->meta.first);
4524154958bSjoerg }
4534154958bSjoerg
45448741257Sjoerg static int
man_args(struct roff_man * man,int line,int * pos,char * buf,char ** v)455f47368cfSchristos man_args(struct roff_man *man, int line, int *pos, char *buf, char **v)
45648741257Sjoerg {
45748741257Sjoerg char *start;
45848741257Sjoerg
45948741257Sjoerg assert(*pos);
46048741257Sjoerg *v = start = buf + *pos;
46148741257Sjoerg assert(' ' != *start);
46248741257Sjoerg
46348741257Sjoerg if ('\0' == *start)
464f47368cfSchristos return 0;
46548741257Sjoerg
466*6167eca2Schristos *v = roff_getarg(man->roff, v, line, pos);
467f47368cfSchristos return 1;
46848741257Sjoerg }
469