1 /* $Id: mdoc_macro.c,v 1.206 2015/10/20 02:01:32 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
32 #include "libmandoc.h"
36 static void blk_full(MACRO_PROT_ARGS
);
37 static void blk_exp_close(MACRO_PROT_ARGS
);
38 static void blk_part_exp(MACRO_PROT_ARGS
);
39 static void blk_part_imp(MACRO_PROT_ARGS
);
40 static void ctx_synopsis(MACRO_PROT_ARGS
);
41 static void in_line_eoln(MACRO_PROT_ARGS
);
42 static void in_line_argn(MACRO_PROT_ARGS
);
43 static void in_line(MACRO_PROT_ARGS
);
44 static void phrase_ta(MACRO_PROT_ARGS
);
46 static void append_delims(struct roff_man
*, int, int *, char *);
47 static void dword(struct roff_man
*, int, int, const char *,
49 static int find_pending(struct roff_man
*, int, int, int,
51 static int lookup(struct roff_man
*, int, int, int, const char *);
52 static int macro_or_word(MACRO_PROT_ARGS
, int);
53 static int parse_rest(struct roff_man
*, int, int, int *, char *);
54 static int rew_alt(int);
55 static void rew_elem(struct roff_man
*, int);
56 static void rew_last(struct roff_man
*, const struct roff_node
*);
57 static void rew_pending(struct roff_man
*,
58 const struct roff_node
*);
60 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
61 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ap */
62 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
63 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
64 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
65 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Sh */
66 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Ss */
67 { in_line_eoln
, 0 }, /* Pp */
68 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* D1 */
69 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* Dl */
70 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
71 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ed */
72 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
73 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* El */
74 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* It */
75 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
76 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* An */
77 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
78 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Cd */
79 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
80 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
81 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
82 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
83 { in_line_eoln
, 0 }, /* Ex */
84 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
85 { in_line_eoln
, 0 }, /* Fd */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ic */
90 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
91 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Li */
92 { blk_full
, MDOC_JOIN
}, /* Nd */
93 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
94 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
95 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ot */
96 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
97 { in_line_eoln
, 0 }, /* Rv */
98 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
99 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
100 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
101 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
102 { in_line_eoln
, MDOC_JOIN
}, /* %A */
103 { in_line_eoln
, MDOC_JOIN
}, /* %B */
104 { in_line_eoln
, MDOC_JOIN
}, /* %D */
105 { in_line_eoln
, MDOC_JOIN
}, /* %I */
106 { in_line_eoln
, MDOC_JOIN
}, /* %J */
107 { in_line_eoln
, 0 }, /* %N */
108 { in_line_eoln
, MDOC_JOIN
}, /* %O */
109 { in_line_eoln
, 0 }, /* %P */
110 { in_line_eoln
, MDOC_JOIN
}, /* %R */
111 { in_line_eoln
, MDOC_JOIN
}, /* %T */
112 { in_line_eoln
, 0 }, /* %V */
113 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
114 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ac */
115 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
116 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ao */
117 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Aq */
118 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
119 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
120 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bc */
121 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
122 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
123 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bo */
124 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Bq */
125 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
126 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
127 { in_line_eoln
, 0 }, /* Db */
128 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
129 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Dc */
130 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
131 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Do */
132 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Dq */
133 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ec */
134 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ef */
135 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Em */
136 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
137 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
138 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
139 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* No */
140 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
141 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ns */
142 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
143 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
144 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
145 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Pc */
146 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
147 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
148 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Po */
149 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Pq */
150 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
151 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qc */
152 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ql */
153 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
154 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qo */
155 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Qq */
156 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Re */
157 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
158 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
159 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Sc */
160 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
161 MDOC_EXPLICIT
| MDOC_JOIN
}, /* So */
162 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sq */
163 { in_line_argn
, 0 }, /* Sm */
164 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sx */
165 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sy */
166 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
167 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ux */
168 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
169 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
170 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
171 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
172 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Fc */
173 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
174 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oo */
175 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
176 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oc */
177 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
178 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ek */
179 { in_line_eoln
, 0 }, /* Bt */
180 { in_line_eoln
, 0 }, /* Hf */
181 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fr */
182 { in_line_eoln
, 0 }, /* Ud */
183 { in_line
, 0 }, /* Lb */
184 { in_line_eoln
, 0 }, /* Lp */
185 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
186 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
187 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Brq */
188 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
189 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bro */
190 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
191 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Brc */
192 { in_line_eoln
, MDOC_JOIN
}, /* %C */
193 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Es */
194 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* En */
195 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
196 { in_line_eoln
, MDOC_JOIN
}, /* %Q */
197 { in_line_eoln
, 0 }, /* br */
198 { in_line_eoln
, 0 }, /* sp */
199 { in_line_eoln
, 0 }, /* %U */
200 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ta */
201 { in_line_eoln
, MDOC_PROLOGUE
}, /* ll */
204 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
208 * This is called at the end of parsing. It must traverse up the tree,
209 * closing out open [implicit] scopes. Obviously, open explicit scopes
213 mdoc_endparse(struct roff_man
*mdoc
)
217 /* Scan for open explicit scopes. */
219 n
= mdoc
->last
->flags
& MDOC_VALID
?
220 mdoc
->last
->parent
: mdoc
->last
;
222 for ( ; n
; n
= n
->parent
)
223 if (n
->type
== ROFFT_BLOCK
&&
224 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
)
225 mandoc_msg(MANDOCERR_BLK_NOEND
, mdoc
->parse
,
226 n
->line
, n
->pos
, mdoc_macronames
[n
->tok
]);
228 /* Rewind to the first. */
230 rew_last(mdoc
, mdoc
->first
);
231 mdoc_state_reset(mdoc
);
235 * Look up the macro at *p called by "from",
236 * or as a line macro if from == TOKEN_NONE.
239 lookup(struct roff_man
*mdoc
, int from
, int line
, int ppos
, const char *p
)
243 if (mdoc
->flags
& MDOC_PHRASEQF
) {
244 mdoc
->flags
&= ~MDOC_PHRASEQF
;
247 if (from
== TOKEN_NONE
|| mdoc_macros
[from
].flags
& MDOC_PARSED
) {
248 res
= mdoc_hash_find(p
);
249 if (res
!= TOKEN_NONE
) {
250 if (mdoc_macros
[res
].flags
& MDOC_CALLABLE
)
252 if (res
!= MDOC_br
&& res
!= MDOC_sp
&& res
!= MDOC_ll
)
253 mandoc_msg(MANDOCERR_MACRO_CALL
,
254 mdoc
->parse
, line
, ppos
, p
);
261 * Rewind up to and including a specific node.
264 rew_last(struct roff_man
*mdoc
, const struct roff_node
*to
)
267 if (to
->flags
& MDOC_VALID
)
270 while (mdoc
->last
!= to
) {
271 mdoc_state(mdoc
, mdoc
->last
);
272 mdoc
->last
->flags
|= MDOC_VALID
| MDOC_ENDED
;
273 mdoc
->last
= mdoc
->last
->parent
;
275 mdoc_state(mdoc
, mdoc
->last
);
276 mdoc
->last
->flags
|= MDOC_VALID
| MDOC_ENDED
;
277 mdoc
->next
= ROFF_NEXT_SIBLING
;
281 * Rewind up to a specific block, including all blocks that broke it.
284 rew_pending(struct roff_man
*mdoc
, const struct roff_node
*n
)
290 if (mdoc
->last
== n
) {
293 roff_body_alloc(mdoc
, n
->line
, n
->pos
,
301 if ( ! (n
->flags
& MDOC_BROKEN
))
307 if ((n
= n
->parent
) == NULL
)
310 if (n
->type
== ROFFT_BLOCK
||
311 n
->type
== ROFFT_HEAD
) {
312 if (n
->flags
& MDOC_ENDED
)
322 * For a block closing macro, return the corresponding opening one.
323 * Otherwise, return the macro itself.
367 rew_elem(struct roff_man
*mdoc
, int tok
)
372 if (n
->type
!= ROFFT_ELEM
)
374 assert(n
->type
== ROFFT_ELEM
);
375 assert(tok
== n
->tok
);
380 * If there is an open sub-block of the target requiring
381 * explicit close-out, postpone closing out the target until
382 * the rew_pending() call closing out the sub-block.
385 find_pending(struct roff_man
*mdoc
, int tok
, int line
, int ppos
,
386 struct roff_node
*target
)
392 for (n
= mdoc
->last
; n
!= NULL
&& n
!= target
; n
= n
->parent
) {
393 if (n
->flags
& MDOC_ENDED
) {
394 if ( ! (n
->flags
& MDOC_VALID
))
395 n
->flags
|= MDOC_BROKEN
;
398 if (n
->type
== ROFFT_BLOCK
&&
399 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
401 n
->flags
= MDOC_BROKEN
;
402 if (target
->type
== ROFFT_HEAD
)
403 target
->flags
= MDOC_ENDED
;
404 else if ( ! (target
->flags
& MDOC_ENDED
)) {
405 mandoc_vmsg(MANDOCERR_BLK_NEST
,
406 mdoc
->parse
, line
, ppos
,
407 "%s breaks %s", mdoc_macronames
[tok
],
408 mdoc_macronames
[n
->tok
]);
409 mdoc_endbody_alloc(mdoc
, line
, ppos
,
410 tok
, target
, ENDBODY_NOSPACE
);
418 * Allocate a word and check whether it's punctuation or not.
419 * Punctuation consists of those tokens found in mdoc_isdelim().
422 dword(struct roff_man
*mdoc
, int line
, int col
, const char *p
,
423 enum mdelim d
, int may_append
)
430 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
431 d
== DELIM_NONE
&& mdoc
->last
->type
== ROFFT_TEXT
&&
432 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
433 roff_word_append(mdoc
, p
);
437 roff_word_alloc(mdoc
, line
, col
, p
);
440 * If the word consists of a bare delimiter,
441 * flag the new node accordingly,
442 * unless doing so was vetoed by the invoking macro.
443 * Always clear the veto, it is only valid for one word.
447 mdoc
->last
->flags
|= MDOC_DELIMO
;
448 else if (d
== DELIM_CLOSE
&&
449 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
450 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
451 mdoc
->last
->flags
|= MDOC_DELIMC
;
452 mdoc
->flags
&= ~MDOC_NODELIMC
;
456 append_delims(struct roff_man
*mdoc
, int line
, int *pos
, char *buf
)
461 if (buf
[*pos
] == '\0')
466 if (mdoc_args(mdoc
, line
, pos
, buf
, TOKEN_NONE
, &p
) ==
469 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
472 * If we encounter end-of-sentence symbols, then trigger
475 * XXX: it's easy to allow this to propagate outward to
476 * the last symbol, such that `. )' will cause the
477 * correct double-spacing. However, (1) groff isn't
478 * smart enough to do this and (2) it would require
479 * knowing which symbols break this behaviour, for
480 * example, `. ;' shouldn't propagate the double-space.
483 if (mandoc_eos(p
, strlen(p
)))
484 mdoc
->last
->flags
|= MDOC_EOS
;
490 * If it is a macro, call it and return 1.
491 * Otherwise, allocate it and return 0.
494 macro_or_word(MACRO_PROT_ARGS
, int parsed
)
503 else if (parsed
&& ! (mdoc
->flags
& MDOC_PHRASELIT
))
504 ntok
= lookup(mdoc
, tok
, line
, ppos
, p
);
506 if (ntok
== TOKEN_NONE
) {
507 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== TOKEN_NONE
||
508 mdoc_macros
[tok
].flags
& MDOC_JOIN
);
511 if (mdoc_macros
[tok
].fp
== in_line_eoln
)
513 mdoc_macro(mdoc
, ntok
, line
, ppos
, pos
, buf
);
514 if (tok
== TOKEN_NONE
)
515 append_delims(mdoc
, line
, pos
, buf
);
521 * Close out block partial/full explicit.
524 blk_exp_close(MACRO_PROT_ARGS
)
526 struct roff_node
*body
; /* Our own body. */
527 struct roff_node
*endbody
; /* Our own end marker. */
528 struct roff_node
*itblk
; /* An It block starting later. */
529 struct roff_node
*later
; /* A sub-block starting later. */
530 struct roff_node
*n
; /* Search back to our block. */
531 struct roff_node
*target
; /* For find_pending(). */
533 int j
, lastarg
, maxargs
, nl
, pending
;
538 nl
= MDOC_NEWLINE
& mdoc
->flags
;
545 mdoc
->flags
&= ~MDOC_KEEP
;
553 * Search backwards for beginnings of blocks,
554 * both of our own and of pending sub-blocks.
558 body
= endbody
= itblk
= later
= NULL
;
559 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
560 if (n
->flags
& MDOC_ENDED
) {
561 if ( ! (n
->flags
& MDOC_VALID
))
562 n
->flags
|= MDOC_BROKEN
;
566 /* Remember the start of our own body. */
568 if (n
->type
== ROFFT_BODY
&& atok
== n
->tok
) {
569 if (n
->end
== ENDBODY_NOT
)
574 if (n
->type
!= ROFFT_BLOCK
|| n
->tok
== MDOC_Nm
)
577 if (n
->tok
== MDOC_It
) {
582 if (atok
== n
->tok
) {
586 * Found the start of our own block.
587 * When there is no pending sub block,
588 * just proceed to closing out.
592 (tok
== MDOC_El
&& itblk
== NULL
))
596 * When there is a pending sub block, postpone
597 * closing out the current block until the
598 * rew_pending() closing out the sub-block.
599 * Mark the place where the formatting - but not
600 * the scope - of the current block ends.
603 mandoc_vmsg(MANDOCERR_BLK_NEST
, mdoc
->parse
,
604 line
, ppos
, "%s breaks %s",
605 mdoc_macronames
[atok
],
606 mdoc_macronames
[later
->tok
]);
608 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
609 atok
, body
, ENDBODY_SPACE
);
612 itblk
->flags
|= MDOC_ENDED
| MDOC_BROKEN
;
615 * If a block closing macro taking arguments
616 * breaks another block, put the arguments
617 * into the end marker.
621 mdoc
->next
= ROFF_NEXT_CHILD
;
625 /* Explicit blocks close out description lines. */
627 if (n
->tok
== MDOC_Nd
) {
632 /* Breaking an open sub block. */
634 n
->flags
|= MDOC_BROKEN
;
640 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, mdoc
->parse
,
641 line
, ppos
, mdoc_macronames
[tok
]);
643 later
->flags
&= ~MDOC_BROKEN
;
644 if (maxargs
&& endbody
== NULL
) {
646 * Stray .Ec without previous .Eo:
647 * Break the output line, keep the arguments.
649 roff_elem_alloc(mdoc
, line
, ppos
, MDOC_br
);
650 rew_elem(mdoc
, MDOC_br
);
652 } else if (endbody
== NULL
) {
653 rew_last(mdoc
, body
);
655 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
658 if ( ! (mdoc_macros
[tok
].flags
& MDOC_PARSED
)) {
659 if (buf
[*pos
] != '\0')
660 mandoc_vmsg(MANDOCERR_ARG_SKIP
,
661 mdoc
->parse
, line
, ppos
,
662 "%s %s", mdoc_macronames
[tok
],
664 if (endbody
== NULL
&& n
!= NULL
)
665 rew_pending(mdoc
, n
);
676 if (j
== maxargs
&& n
!= NULL
)
679 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
680 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
683 ntok
= ac
== ARGS_QWORD
? TOKEN_NONE
:
684 lookup(mdoc
, tok
, line
, lastarg
, p
);
686 if (ntok
== TOKEN_NONE
) {
687 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
688 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
694 mdoc
->flags
&= ~MDOC_NEWLINE
;
695 mdoc_macro(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
700 if (ntok
!= TOKEN_NONE
&& n
->flags
& MDOC_BROKEN
) {
703 target
= target
->parent
;
704 while ( ! (target
->flags
& MDOC_ENDED
));
705 pending
= find_pending(mdoc
, ntok
, line
, ppos
,
710 rew_pending(mdoc
, n
);
713 append_delims(mdoc
, line
, pos
, buf
);
717 in_line(MACRO_PROT_ARGS
)
719 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
723 struct mdoc_arg
*arg
;
726 nl
= MDOC_NEWLINE
& mdoc
->flags
;
729 * Whether we allow ignored elements (those without content,
730 * usually because of reserved words) to squeak by.
747 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
752 for (cnt
= scope
= 0;; ) {
754 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
757 * At the end of a macro line,
758 * opening delimiters do not suppress spacing.
761 if (ac
== ARGS_EOLN
) {
763 mdoc
->last
->flags
&= ~MDOC_DELIMO
;
768 * The rest of the macro line is only punctuation,
769 * to be handled by append_delims().
770 * If there were no other arguments,
771 * do not allow the first one to suppress spacing,
772 * even if it turns out to be a closing one.
775 if (ac
== ARGS_PUNCT
) {
776 if (cnt
== 0 && (nc
== 0 || tok
== MDOC_An
))
777 mdoc
->flags
|= MDOC_NODELIMC
;
781 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Fn
&& !cnt
)) ?
782 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
785 * In this case, we've located a submacro and must
786 * execute it. Close out scope, if open. If no
787 * elements have been generated, either create one (nc)
788 * or raise a warning.
791 if (ntok
!= TOKEN_NONE
) {
795 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
796 rew_last(mdoc
, mdoc
->last
);
797 } else if ( ! nc
&& ! cnt
) {
799 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
800 mdoc
->parse
, line
, ppos
,
801 mdoc_macronames
[tok
]);
803 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
805 append_delims(mdoc
, line
, pos
, buf
);
810 * Non-quote-enclosed punctuation. Set up our scope, if
811 * a word; rewind the scope, if a delimiter; then append
815 d
= ac
== ARGS_QWORD
? DELIM_NONE
: mdoc_isdelim(p
);
817 if (DELIM_NONE
!= d
) {
819 * If we encounter closing punctuation, no word
820 * has been emitted, no scope is open, and we're
821 * allowed to have an empty element, then start
824 if ((d
== DELIM_CLOSE
||
825 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
826 !cnt
&& !scope
&& nc
&& mayopen
) {
827 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
834 * Close out our scope, if one is open, before
842 } else if (mayopen
&& !scope
) {
843 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
848 dword(mdoc
, line
, la
, p
, d
,
849 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
852 * If the first argument is a closing delimiter,
853 * do not suppress spacing before it.
856 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
857 mdoc
->last
->flags
&= ~MDOC_DELIMC
;
861 * `Fl' macros have their scope re-opened with each new
862 * word so that the `-' can be added to each one without
863 * having to parse out spaces.
865 if (scope
&& tok
== MDOC_Fl
) {
875 * If no elements have been collected and we're allowed to have
876 * empties (nc), open a scope and close it out. Otherwise,
882 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
883 rew_last(mdoc
, mdoc
->last
);
886 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
887 line
, ppos
, mdoc_macronames
[tok
]);
891 append_delims(mdoc
, line
, pos
, buf
);
895 blk_full(MACRO_PROT_ARGS
)
898 struct mdoc_arg
*arg
;
899 struct roff_node
*blk
; /* Our own or a broken block. */
900 struct roff_node
*head
; /* Our own head. */
901 struct roff_node
*body
; /* Our own body. */
903 enum margserr ac
, lac
;
906 nl
= MDOC_NEWLINE
& mdoc
->flags
;
908 if (buf
[*pos
] == '\0' && (tok
== MDOC_Sh
|| tok
== MDOC_Ss
)) {
909 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
910 line
, ppos
, mdoc_macronames
[tok
]);
914 if ( ! (mdoc_macros
[tok
].flags
& MDOC_EXPLICIT
)) {
916 /* Here, tok is one of Sh Ss Nm Nd It. */
919 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
920 if (n
->flags
& MDOC_ENDED
) {
921 if ( ! (n
->flags
& MDOC_VALID
))
922 n
->flags
|= MDOC_BROKEN
;
925 if (n
->type
!= ROFFT_BLOCK
)
928 if (tok
== MDOC_It
&& n
->tok
== MDOC_Bl
) {
930 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
931 mdoc
->parse
, line
, ppos
,
933 mdoc_macronames
[blk
->tok
]);
934 rew_pending(mdoc
, blk
);
939 if (mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
943 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
944 mdoc
->parse
, line
, ppos
,
946 mdoc_macronames
[tok
],
947 mdoc_macronames
[n
->tok
]);
948 rew_pending(mdoc
, n
);
952 /* Delay in case it's astray. */
961 /* Here, n is one of Sh Ss Nm Nd It. */
963 if (tok
!= MDOC_Sh
&& (n
->tok
== MDOC_Sh
||
964 (tok
!= MDOC_Ss
&& (n
->tok
== MDOC_Ss
||
965 (tok
!= MDOC_It
&& n
->tok
== MDOC_It
)))))
968 /* Item breaking an explicit block. */
971 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
972 mdoc
->parse
, line
, ppos
,
974 mdoc_macronames
[blk
->tok
]);
975 rew_pending(mdoc
, blk
);
979 /* Close out prior implicit scopes. */
984 /* Skip items outside lists. */
986 if (tok
== MDOC_It
&& (n
== NULL
|| n
->tok
!= MDOC_Bl
)) {
987 mandoc_vmsg(MANDOCERR_IT_STRAY
, mdoc
->parse
,
988 line
, ppos
, "It %s", buf
+ *pos
);
989 roff_elem_alloc(mdoc
, line
, ppos
, MDOC_br
);
990 rew_elem(mdoc
, MDOC_br
);
996 * This routine accommodates implicitly- and explicitly-scoped
997 * macro openings. Implicit ones first close out prior scope
998 * (seen above). Delay opening the head until necessary to
999 * allow leading punctuation to print. Special consideration
1000 * for `It -column', which has phrase-part syntax instead of
1001 * regular child nodes.
1004 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1005 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
1009 * Exception: Heads of `It' macros in `-diag' lists are not
1010 * parsed, even though `It' macros in general are parsed.
1013 parsed
= tok
!= MDOC_It
||
1014 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
1015 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
1018 * The `Nd' macro has all arguments in its body: it's a hybrid
1019 * of block partial-explicit and full-implicit. Stupid.
1022 if (tok
== MDOC_Nd
) {
1023 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1024 rew_last(mdoc
, head
);
1025 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1029 mdoc
->flags
|= MDOC_KEEP
;
1035 * If we are right after a tab character,
1036 * do not parse the first word for macros.
1039 if (mdoc
->flags
& MDOC_PHRASEQN
) {
1040 mdoc
->flags
&= ~MDOC_PHRASEQN
;
1041 mdoc
->flags
|= MDOC_PHRASEQF
;
1046 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1047 if (ac
== ARGS_EOLN
) {
1048 if (lac
!= ARGS_PHRASE
||
1049 ! (mdoc
->flags
& MDOC_PHRASEQF
))
1053 * This line ends in a tab; start the next
1054 * column now, with a leading blank.
1058 rew_last(mdoc
, body
);
1059 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1060 roff_word_alloc(mdoc
, line
, ppos
, "\\&");
1064 if (tok
== MDOC_Bd
|| tok
== MDOC_Bk
) {
1065 mandoc_vmsg(MANDOCERR_ARG_EXCESS
,
1066 mdoc
->parse
, line
, la
, "%s ... %s",
1067 mdoc_macronames
[tok
], buf
+ la
);
1070 if (tok
== MDOC_Rs
) {
1071 mandoc_vmsg(MANDOCERR_ARG_SKIP
, mdoc
->parse
,
1072 line
, la
, "Rs %s", buf
+ la
);
1075 if (ac
== ARGS_PUNCT
)
1079 * Emit leading punctuation (i.e., punctuation before
1080 * the ROFFT_HEAD) for non-phrase types.
1084 ac
!= ARGS_PHRASE
&&
1086 mdoc_isdelim(p
) == DELIM_OPEN
) {
1087 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1091 /* Open a head if one hasn't been opened. */
1094 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1096 if (ac
== ARGS_PHRASE
) {
1099 * If we haven't opened a body yet, rewind the
1100 * head; if we have, rewind that instead.
1103 rew_last(mdoc
, body
== NULL
? head
: body
);
1104 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1106 /* Process to the tab or to the end of the line. */
1108 mdoc
->flags
|= MDOC_PHRASE
;
1109 parse_rest(mdoc
, TOKEN_NONE
, line
, &la
, buf
);
1110 mdoc
->flags
&= ~MDOC_PHRASE
;
1112 /* There may have been `Ta' macros. */
1114 while (body
->next
!= NULL
)
1119 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, parsed
))
1123 if (blk
->flags
& MDOC_VALID
)
1126 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1127 if (nl
&& tok
!= MDOC_Bd
&& tok
!= MDOC_Bl
&& tok
!= MDOC_Rs
)
1128 append_delims(mdoc
, line
, pos
, buf
);
1131 if (find_pending(mdoc
, tok
, line
, ppos
, head
))
1134 /* Close out scopes to remain in a consistent state. */
1136 rew_last(mdoc
, head
);
1137 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1139 if (mdoc
->flags
& MDOC_FREECOL
) {
1140 rew_last(mdoc
, body
);
1141 rew_last(mdoc
, blk
);
1142 mdoc
->flags
&= ~MDOC_FREECOL
;
1147 blk_part_imp(MACRO_PROT_ARGS
)
1152 struct roff_node
*blk
; /* saved block context */
1153 struct roff_node
*body
; /* saved body context */
1154 struct roff_node
*n
;
1156 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1159 * A macro that spans to the end of the line. This is generally
1160 * (but not necessarily) called as the first macro. The block
1161 * has a head as the immediate child, which is always empty,
1162 * followed by zero or more opening punctuation nodes, then the
1163 * body (which may be empty, depending on the macro), then zero
1164 * or more closing punctuation nodes.
1167 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1168 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1171 * Open the body scope "on-demand", that is, after we've
1172 * processed all our the leading delimiters (open parenthesis,
1176 for (body
= NULL
; ; ) {
1178 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1179 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1182 if (body
== NULL
&& ac
!= ARGS_QWORD
&&
1183 mdoc_isdelim(p
) == DELIM_OPEN
) {
1184 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1189 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1191 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1195 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1197 if (find_pending(mdoc
, tok
, line
, ppos
, body
))
1200 rew_last(mdoc
, body
);
1202 append_delims(mdoc
, line
, pos
, buf
);
1203 rew_pending(mdoc
, blk
);
1205 /* Move trailing .Ns out of scope. */
1207 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1209 if (n
&& n
->tok
== MDOC_Ns
)
1210 mdoc_node_relink(mdoc
, n
);
1214 blk_part_exp(MACRO_PROT_ARGS
)
1218 struct roff_node
*head
; /* keep track of head */
1221 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1224 * The opening of an explicit macro having zero or more leading
1225 * punctuation nodes; a head with optional single element (the
1226 * case of `Eo'); and a body that may be empty.
1229 roff_block_alloc(mdoc
, line
, ppos
, tok
);
1233 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1234 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1237 /* Flush out leading punctuation. */
1239 if (head
== NULL
&& ac
!= ARGS_QWORD
&&
1240 mdoc_isdelim(p
) == DELIM_OPEN
) {
1241 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1246 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1247 if (tok
== MDOC_Eo
) /* Not parsed. */
1248 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1249 rew_last(mdoc
, head
);
1250 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1255 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1259 /* Clean-up to leave in a consistent state. */
1262 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1263 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1266 append_delims(mdoc
, line
, pos
, buf
);
1270 in_line_argn(MACRO_PROT_ARGS
)
1272 struct mdoc_arg
*arg
;
1276 int state
; /* arg#; -1: not yet open; -2: closed */
1277 int la
, maxargs
, nl
;
1279 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1282 * A line macro that has a fixed number of arguments (maxargs).
1283 * Only open the scope once the first non-leading-punctuation is
1284 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1285 * keep it open until the maximum number of arguments are
1305 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1311 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1313 if (ac
== ARGS_WORD
&& state
== -1 &&
1314 ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1315 mdoc_isdelim(p
) == DELIM_OPEN
) {
1316 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1320 if (state
== -1 && tok
!= MDOC_In
&&
1321 tok
!= MDOC_St
&& tok
!= MDOC_Xr
) {
1322 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1326 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1327 if (abs(state
) < 2 && tok
== MDOC_Pf
)
1328 mandoc_vmsg(MANDOCERR_PF_SKIP
,
1329 mdoc
->parse
, line
, ppos
, "Pf %s",
1330 p
== NULL
? "at eol" : p
);
1334 if (state
== maxargs
) {
1335 rew_elem(mdoc
, tok
);
1339 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Pf
&& state
== 0)) ?
1340 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
1342 if (ntok
!= TOKEN_NONE
) {
1344 rew_elem(mdoc
, tok
);
1347 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
1351 if (ac
== ARGS_QWORD
||
1352 mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
||
1353 mdoc_isdelim(p
) == DELIM_NONE
) {
1355 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1357 } else if (state
>= 0)
1359 } else if (state
>= 0) {
1360 rew_elem(mdoc
, tok
);
1364 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1365 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
1369 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1370 line
, ppos
, mdoc_macronames
[tok
]);
1374 if (state
== 0 && tok
== MDOC_Pf
)
1375 append_delims(mdoc
, line
, pos
, buf
);
1377 rew_elem(mdoc
, tok
);
1379 append_delims(mdoc
, line
, pos
, buf
);
1383 in_line_eoln(MACRO_PROT_ARGS
)
1385 struct roff_node
*n
;
1386 struct mdoc_arg
*arg
;
1388 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1389 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1391 if (mdoc
->next
== ROFF_NEXT_SIBLING
)
1393 if (n
->tok
== MDOC_Nm
)
1394 rew_last(mdoc
, n
->parent
);
1397 if (buf
[*pos
] == '\0' &&
1398 (tok
== MDOC_Fd
|| mdoc_macronames
[tok
][0] == '%')) {
1399 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1400 line
, ppos
, mdoc_macronames
[tok
]);
1404 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1405 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1406 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1408 rew_elem(mdoc
, tok
);
1412 * The simplest argument parser available: Parse the remaining
1413 * words until the end of the phrase or line and return 0
1414 * or until the next macro, call that macro, and return 1.
1417 parse_rest(struct roff_man
*mdoc
, int tok
, int line
, int *pos
, char *buf
)
1423 if (mdoc_args(mdoc
, line
, pos
, buf
, tok
, NULL
) == ARGS_EOLN
)
1425 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1431 ctx_synopsis(MACRO_PROT_ARGS
)
1434 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1435 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1436 else if (tok
== MDOC_Nm
)
1437 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1439 assert(tok
== MDOC_Vt
);
1440 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1445 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1446 * They're unusual because they're basically free-form text until a
1447 * macro is encountered.
1450 phrase_ta(MACRO_PROT_ARGS
)
1452 struct roff_node
*body
, *n
;
1454 /* Make sure we are in a column list or ignore this macro. */
1457 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1458 if (n
->flags
& MDOC_ENDED
)
1460 if (n
->tok
== MDOC_It
&& n
->type
== ROFFT_BODY
)
1462 if (n
->tok
== MDOC_Bl
)
1466 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1467 mandoc_msg(MANDOCERR_TA_STRAY
, mdoc
->parse
,
1472 /* Advance to the next column. */
1474 rew_last(mdoc
, body
);
1475 roff_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1476 parse_rest(mdoc
, TOKEN_NONE
, line
, pos
, buf
);