]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.201 2015/09/26 00:54:04 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
);
234 * Look up the macro at *p called by "from",
235 * or as a line macro if from == TOKEN_NONE.
238 lookup(struct roff_man
*mdoc
, int from
, int line
, int ppos
, const char *p
)
242 if (from
== TOKEN_NONE
|| mdoc_macros
[from
].flags
& MDOC_PARSED
) {
243 res
= mdoc_hash_find(p
);
244 if (res
!= TOKEN_NONE
) {
245 if (mdoc_macros
[res
].flags
& MDOC_CALLABLE
)
247 if (res
!= MDOC_br
&& res
!= MDOC_sp
&& res
!= MDOC_ll
)
248 mandoc_msg(MANDOCERR_MACRO_CALL
,
249 mdoc
->parse
, line
, ppos
, p
);
256 * Rewind up to and including a specific node.
259 rew_last(struct roff_man
*mdoc
, const struct roff_node
*to
)
261 struct roff_node
*np
;
263 if (to
->flags
& MDOC_VALID
)
266 while (mdoc
->last
!= to
) {
268 * Save the parent here, because we may delete the
269 * mdoc->last node in the post-validation phase and reset
270 * it to mdoc->last->parent, causing a step in the closing
273 np
= mdoc
->last
->parent
;
274 mdoc_valid_post(mdoc
);
278 mdoc
->next
= ROFF_NEXT_SIBLING
;
279 mdoc_valid_post(mdoc
);
283 * Rewind up to a specific block, including all blocks that broke it.
286 rew_pending(struct roff_man
*mdoc
, const struct roff_node
*n
)
292 if (mdoc
->last
== n
) {
295 roff_body_alloc(mdoc
, n
->line
, n
->pos
,
303 if ( ! (n
->flags
& MDOC_BROKEN
))
309 if ((n
= n
->parent
) == NULL
)
312 if (n
->type
== ROFFT_BLOCK
||
313 n
->type
== ROFFT_HEAD
) {
314 if (n
->flags
& MDOC_ENDED
)
324 * For a block closing macro, return the corresponding opening one.
325 * Otherwise, return the macro itself.
369 rew_elem(struct roff_man
*mdoc
, int tok
)
374 if (n
->type
!= ROFFT_ELEM
)
376 assert(n
->type
== ROFFT_ELEM
);
377 assert(tok
== n
->tok
);
382 * If there is an open sub-block of the target requiring
383 * explicit close-out, postpone closing out the target until
384 * the rew_pending() call closing out the sub-block.
387 find_pending(struct roff_man
*mdoc
, int tok
, int line
, int ppos
,
388 struct roff_node
*target
)
394 for (n
= mdoc
->last
; n
!= NULL
&& n
!= target
; n
= n
->parent
) {
395 if (n
->flags
& MDOC_ENDED
) {
396 if ( ! (n
->flags
& MDOC_VALID
))
397 n
->flags
|= MDOC_BROKEN
;
400 if (n
->type
== ROFFT_BLOCK
&&
401 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
403 n
->flags
= MDOC_BROKEN
;
404 if (target
->type
== ROFFT_HEAD
)
405 target
->flags
= MDOC_ENDED
;
406 else if ( ! (target
->flags
& MDOC_ENDED
)) {
407 mandoc_vmsg(MANDOCERR_BLK_NEST
,
408 mdoc
->parse
, line
, ppos
,
409 "%s breaks %s", mdoc_macronames
[tok
],
410 mdoc_macronames
[n
->tok
]);
411 mdoc_endbody_alloc(mdoc
, line
, ppos
,
412 tok
, target
, ENDBODY_NOSPACE
);
420 * Allocate a word and check whether it's punctuation or not.
421 * Punctuation consists of those tokens found in mdoc_isdelim().
424 dword(struct roff_man
*mdoc
, int line
, int col
, const char *p
,
425 enum mdelim d
, int may_append
)
432 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
433 d
== DELIM_NONE
&& mdoc
->last
->type
== ROFFT_TEXT
&&
434 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
435 roff_word_append(mdoc
, p
);
439 roff_word_alloc(mdoc
, line
, col
, p
);
442 * If the word consists of a bare delimiter,
443 * flag the new node accordingly,
444 * unless doing so was vetoed by the invoking macro.
445 * Always clear the veto, it is only valid for one word.
449 mdoc
->last
->flags
|= MDOC_DELIMO
;
450 else if (d
== DELIM_CLOSE
&&
451 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
452 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
453 mdoc
->last
->flags
|= MDOC_DELIMC
;
454 mdoc
->flags
&= ~MDOC_NODELIMC
;
458 append_delims(struct roff_man
*mdoc
, int line
, int *pos
, char *buf
)
463 if (buf
[*pos
] == '\0')
468 if (mdoc_args(mdoc
, line
, pos
, buf
, TOKEN_NONE
, &p
) ==
471 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
474 * If we encounter end-of-sentence symbols, then trigger
477 * XXX: it's easy to allow this to propagate outward to
478 * the last symbol, such that `. )' will cause the
479 * correct double-spacing. However, (1) groff isn't
480 * smart enough to do this and (2) it would require
481 * knowing which symbols break this behaviour, for
482 * example, `. ;' shouldn't propagate the double-space.
485 if (mandoc_eos(p
, strlen(p
)))
486 mdoc
->last
->flags
|= MDOC_EOS
;
492 * If it is a macro, call it and return 1.
493 * Otherwise, allocate it and return 0.
496 macro_or_word(MACRO_PROT_ARGS
, int parsed
)
505 else if (parsed
&& ! (mdoc
->flags
& MDOC_PHRASELIT
))
506 ntok
= lookup(mdoc
, tok
, line
, ppos
, p
);
508 if (ntok
== TOKEN_NONE
) {
509 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== TOKEN_NONE
||
510 mdoc_macros
[tok
].flags
& MDOC_JOIN
);
513 if (mdoc_macros
[tok
].fp
== in_line_eoln
)
515 mdoc_macro(mdoc
, ntok
, line
, ppos
, pos
, buf
);
516 if (tok
== TOKEN_NONE
)
517 append_delims(mdoc
, line
, pos
, buf
);
523 * Close out block partial/full explicit.
526 blk_exp_close(MACRO_PROT_ARGS
)
528 struct roff_node
*body
; /* Our own body. */
529 struct roff_node
*endbody
; /* Our own end marker. */
530 struct roff_node
*itblk
; /* An It block starting later. */
531 struct roff_node
*later
; /* A sub-block starting later. */
532 struct roff_node
*n
; /* Search back to our block. */
533 struct roff_node
*target
; /* For find_pending(). */
535 int j
, lastarg
, maxargs
, nl
, pending
;
540 nl
= MDOC_NEWLINE
& mdoc
->flags
;
547 mdoc
->flags
&= ~MDOC_KEEP
;
555 * Search backwards for beginnings of blocks,
556 * both of our own and of pending sub-blocks.
560 body
= endbody
= itblk
= later
= NULL
;
561 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
562 if (n
->flags
& MDOC_ENDED
) {
563 if ( ! (n
->flags
& MDOC_VALID
))
564 n
->flags
|= MDOC_BROKEN
;
568 /* Remember the start of our own body. */
570 if (n
->type
== ROFFT_BODY
&& atok
== n
->tok
) {
571 if (n
->end
== ENDBODY_NOT
)
576 if (n
->type
!= ROFFT_BLOCK
|| n
->tok
== MDOC_Nm
)
579 if (n
->tok
== MDOC_It
) {
584 if (atok
== n
->tok
) {
588 * Found the start of our own block.
589 * When there is no pending sub block,
590 * just proceed to closing out.
594 (tok
== MDOC_El
&& itblk
== NULL
))
598 * When there is a pending sub block, postpone
599 * closing out the current block until the
600 * rew_pending() closing out the sub-block.
601 * Mark the place where the formatting - but not
602 * the scope - of the current block ends.
605 mandoc_vmsg(MANDOCERR_BLK_NEST
, mdoc
->parse
,
606 line
, ppos
, "%s breaks %s",
607 mdoc_macronames
[atok
],
608 mdoc_macronames
[later
->tok
]);
610 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
611 atok
, body
, ENDBODY_SPACE
);
614 itblk
->flags
|= MDOC_ENDED
| MDOC_BROKEN
;
617 * If a block closing macro taking arguments
618 * breaks another block, put the arguments
619 * into the end marker.
623 mdoc
->next
= ROFF_NEXT_CHILD
;
627 /* Explicit blocks close out description lines. */
629 if (n
->tok
== MDOC_Nd
) {
634 /* Breaking an open sub block. */
636 n
->flags
|= MDOC_BROKEN
;
642 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, mdoc
->parse
,
643 line
, ppos
, mdoc_macronames
[tok
]);
645 later
->flags
&= ~MDOC_BROKEN
;
646 if (maxargs
&& endbody
== NULL
) {
648 * Stray .Ec without previous .Eo:
649 * Break the output line, keep the arguments.
651 roff_elem_alloc(mdoc
, line
, ppos
, MDOC_br
);
652 rew_elem(mdoc
, MDOC_br
);
654 } else if (endbody
== NULL
) {
655 rew_last(mdoc
, body
);
657 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
660 if ( ! (mdoc_macros
[tok
].flags
& MDOC_PARSED
)) {
661 if (buf
[*pos
] != '\0')
662 mandoc_vmsg(MANDOCERR_ARG_SKIP
,
663 mdoc
->parse
, line
, ppos
,
664 "%s %s", mdoc_macronames
[tok
],
666 if (endbody
== NULL
&& n
!= NULL
)
667 rew_pending(mdoc
, n
);
678 if (j
== maxargs
&& n
!= NULL
)
681 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
682 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
685 ntok
= ac
== ARGS_QWORD
? TOKEN_NONE
:
686 lookup(mdoc
, tok
, line
, lastarg
, p
);
688 if (ntok
== TOKEN_NONE
) {
689 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
690 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
696 mdoc
->flags
&= ~MDOC_NEWLINE
;
697 mdoc_macro(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
702 if (ntok
!= TOKEN_NONE
&& n
->flags
& MDOC_BROKEN
) {
705 target
= target
->parent
;
706 while ( ! (target
->flags
& MDOC_ENDED
));
707 pending
= find_pending(mdoc
, ntok
, line
, ppos
,
712 rew_pending(mdoc
, n
);
715 append_delims(mdoc
, line
, pos
, buf
);
719 in_line(MACRO_PROT_ARGS
)
721 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
725 struct mdoc_arg
*arg
;
728 nl
= MDOC_NEWLINE
& mdoc
->flags
;
731 * Whether we allow ignored elements (those without content,
732 * usually because of reserved words) to squeak by.
754 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
759 for (cnt
= scope
= 0;; ) {
761 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
764 * At the end of a macro line,
765 * opening delimiters do not suppress spacing.
768 if (ac
== ARGS_EOLN
) {
770 mdoc
->last
->flags
&= ~MDOC_DELIMO
;
775 * The rest of the macro line is only punctuation,
776 * to be handled by append_delims().
777 * If there were no other arguments,
778 * do not allow the first one to suppress spacing,
779 * even if it turns out to be a closing one.
782 if (ac
== ARGS_PUNCT
) {
783 if (cnt
== 0 && (nc
== 0 || tok
== MDOC_An
))
784 mdoc
->flags
|= MDOC_NODELIMC
;
788 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Fn
&& !cnt
)) ?
789 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
792 * In this case, we've located a submacro and must
793 * execute it. Close out scope, if open. If no
794 * elements have been generated, either create one (nc)
795 * or raise a warning.
798 if (ntok
!= TOKEN_NONE
) {
802 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
803 rew_last(mdoc
, mdoc
->last
);
804 } else if ( ! nc
&& ! cnt
) {
806 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
807 mdoc
->parse
, line
, ppos
,
808 mdoc_macronames
[tok
]);
810 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
812 append_delims(mdoc
, line
, pos
, buf
);
817 * Non-quote-enclosed punctuation. Set up our scope, if
818 * a word; rewind the scope, if a delimiter; then append
822 d
= ac
== ARGS_QWORD
? DELIM_NONE
: mdoc_isdelim(p
);
824 if (DELIM_NONE
!= d
) {
826 * If we encounter closing punctuation, no word
827 * has been emitted, no scope is open, and we're
828 * allowed to have an empty element, then start
831 if ((d
== DELIM_CLOSE
||
832 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
833 !cnt
&& !scope
&& nc
&& mayopen
) {
834 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
841 * Close out our scope, if one is open, before
849 } else if (mayopen
&& !scope
) {
850 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
855 dword(mdoc
, line
, la
, p
, d
,
856 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
859 * If the first argument is a closing delimiter,
860 * do not suppress spacing before it.
863 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
864 mdoc
->last
->flags
&= ~MDOC_DELIMC
;
868 * `Fl' macros have their scope re-opened with each new
869 * word so that the `-' can be added to each one without
870 * having to parse out spaces.
872 if (scope
&& tok
== MDOC_Fl
) {
882 * If no elements have been collected and we're allowed to have
883 * empties (nc), open a scope and close it out. Otherwise,
889 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
890 rew_last(mdoc
, mdoc
->last
);
893 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
894 line
, ppos
, mdoc_macronames
[tok
]);
898 append_delims(mdoc
, line
, pos
, buf
);
902 blk_full(MACRO_PROT_ARGS
)
905 struct mdoc_arg
*arg
;
906 struct roff_node
*blk
; /* Our own or a broken block. */
907 struct roff_node
*head
; /* Our own head. */
908 struct roff_node
*body
; /* Our own body. */
910 enum margserr ac
, lac
;
913 nl
= MDOC_NEWLINE
& mdoc
->flags
;
915 if (buf
[*pos
] == '\0' && (tok
== MDOC_Sh
|| tok
== MDOC_Ss
)) {
916 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
917 line
, ppos
, mdoc_macronames
[tok
]);
921 if ( ! (mdoc_macros
[tok
].flags
& MDOC_EXPLICIT
)) {
923 /* Here, tok is one of Sh Ss Nm Nd It. */
926 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
927 if (n
->flags
& MDOC_ENDED
) {
928 if ( ! (n
->flags
& MDOC_VALID
))
929 n
->flags
|= MDOC_BROKEN
;
932 if (n
->type
!= ROFFT_BLOCK
)
935 if (tok
== MDOC_It
&& n
->tok
== MDOC_Bl
) {
937 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
938 mdoc
->parse
, line
, ppos
,
940 mdoc_macronames
[blk
->tok
]);
941 rew_pending(mdoc
, blk
);
946 if (mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
951 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
952 mdoc
->parse
, line
, ppos
,
954 mdoc_macronames
[tok
],
955 mdoc_macronames
[n
->tok
]);
956 rew_pending(mdoc
, n
);
960 /* Delay in case it's astray. */
969 /* Here, n is one of Sh Ss Nm Nd It. */
971 if (tok
!= MDOC_Sh
&& (n
->tok
== MDOC_Sh
||
972 (tok
!= MDOC_Ss
&& (n
->tok
== MDOC_Ss
||
973 (tok
!= MDOC_It
&& n
->tok
== MDOC_It
)))))
976 /* Item breaking an explicit block. */
979 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
980 mdoc
->parse
, line
, ppos
,
982 mdoc_macronames
[blk
->tok
]);
983 rew_pending(mdoc
, blk
);
987 /* Close out prior implicit scopes. */
992 /* Skip items outside lists. */
994 if (tok
== MDOC_It
&& (n
== NULL
|| n
->tok
!= MDOC_Bl
)) {
995 mandoc_vmsg(MANDOCERR_IT_STRAY
, mdoc
->parse
,
996 line
, ppos
, "It %s", buf
+ *pos
);
997 roff_elem_alloc(mdoc
, line
, ppos
, MDOC_br
);
998 rew_elem(mdoc
, MDOC_br
);
1004 * This routine accommodates implicitly- and explicitly-scoped
1005 * macro openings. Implicit ones first close out prior scope
1006 * (seen above). Delay opening the head until necessary to
1007 * allow leading punctuation to print. Special consideration
1008 * for `It -column', which has phrase-part syntax instead of
1009 * regular child nodes.
1012 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1013 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
1017 * Exception: Heads of `It' macros in `-diag' lists are not
1018 * parsed, even though `It' macros in general are parsed.
1021 parsed
= tok
!= MDOC_It
||
1022 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
1023 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
1026 * The `Nd' macro has all arguments in its body: it's a hybrid
1027 * of block partial-explicit and full-implicit. Stupid.
1030 if (tok
== MDOC_Nd
) {
1031 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1032 rew_last(mdoc
, head
);
1033 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1037 mdoc
->flags
|= MDOC_KEEP
;
1043 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1044 if (ac
== ARGS_EOLN
) {
1045 if (lac
!= ARGS_PPHRASE
&& lac
!= ARGS_PHRASE
)
1048 * This is necessary: if the last token on a
1049 * line is a `Ta' or tab, then we'll get
1050 * ARGS_EOLN, so we must be smart enough to
1051 * reopen our scope if the last parse was a
1052 * phrase or partial phrase.
1055 rew_last(mdoc
, body
);
1056 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1059 if (tok
== MDOC_Bd
|| tok
== MDOC_Bk
) {
1060 mandoc_vmsg(MANDOCERR_ARG_EXCESS
,
1061 mdoc
->parse
, line
, la
, "%s ... %s",
1062 mdoc_macronames
[tok
], buf
+ la
);
1065 if (tok
== MDOC_Rs
) {
1066 mandoc_vmsg(MANDOCERR_ARG_SKIP
, mdoc
->parse
,
1067 line
, la
, "Rs %s", buf
+ la
);
1070 if (ac
== ARGS_PUNCT
)
1074 * Emit leading punctuation (i.e., punctuation before
1075 * the ROFFT_HEAD) for non-phrase types.
1080 ac
!= ARGS_PHRASE
&&
1081 ac
!= ARGS_PPHRASE
&&
1083 mdoc_isdelim(p
) == DELIM_OPEN
) {
1084 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1088 /* Open a head if one hasn't been opened. */
1091 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1093 if (ac
== ARGS_PHRASE
||
1095 ac
== ARGS_PPHRASE
) {
1098 * If we haven't opened a body yet, rewind the
1099 * head; if we have, rewind that instead.
1102 rew_last(mdoc
, body
== NULL
? head
: body
);
1103 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1106 * Process phrases: set whether we're in a
1107 * partial-phrase (this effects line handling)
1108 * then call down into the phrase parser.
1111 if (ac
== ARGS_PPHRASE
)
1112 mdoc
->flags
|= MDOC_PPHRASE
;
1113 if (ac
== ARGS_PEND
&& lac
== ARGS_PPHRASE
)
1114 mdoc
->flags
|= MDOC_PPHRASE
;
1115 parse_rest(mdoc
, TOKEN_NONE
, line
, &la
, buf
);
1116 mdoc
->flags
&= ~MDOC_PPHRASE
;
1120 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, parsed
))
1124 if (blk
->flags
& MDOC_VALID
)
1127 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1128 if (nl
&& tok
!= MDOC_Bd
&& tok
!= MDOC_Bl
&& tok
!= MDOC_Rs
)
1129 append_delims(mdoc
, line
, pos
, buf
);
1132 if (find_pending(mdoc
, tok
, line
, ppos
, head
))
1135 /* Close out scopes to remain in a consistent state. */
1137 rew_last(mdoc
, head
);
1138 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1140 if (mdoc
->flags
& MDOC_FREECOL
) {
1141 rew_last(mdoc
, body
);
1142 rew_last(mdoc
, blk
);
1143 mdoc
->flags
&= ~MDOC_FREECOL
;
1148 blk_part_imp(MACRO_PROT_ARGS
)
1153 struct roff_node
*blk
; /* saved block context */
1154 struct roff_node
*body
; /* saved body context */
1155 struct roff_node
*n
;
1157 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1160 * A macro that spans to the end of the line. This is generally
1161 * (but not necessarily) called as the first macro. The block
1162 * has a head as the immediate child, which is always empty,
1163 * followed by zero or more opening punctuation nodes, then the
1164 * body (which may be empty, depending on the macro), then zero
1165 * or more closing punctuation nodes.
1168 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1169 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1172 * Open the body scope "on-demand", that is, after we've
1173 * processed all our the leading delimiters (open parenthesis,
1177 for (body
= NULL
; ; ) {
1179 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1180 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1183 if (body
== NULL
&& ac
!= ARGS_QWORD
&&
1184 mdoc_isdelim(p
) == DELIM_OPEN
) {
1185 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1190 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1192 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1196 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1198 if (find_pending(mdoc
, tok
, line
, ppos
, body
))
1201 rew_last(mdoc
, body
);
1203 append_delims(mdoc
, line
, pos
, buf
);
1204 rew_pending(mdoc
, blk
);
1206 /* Move trailing .Ns out of scope. */
1208 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1210 if (n
&& n
->tok
== MDOC_Ns
)
1211 mdoc_node_relink(mdoc
, n
);
1215 blk_part_exp(MACRO_PROT_ARGS
)
1219 struct roff_node
*head
; /* keep track of head */
1222 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1225 * The opening of an explicit macro having zero or more leading
1226 * punctuation nodes; a head with optional single element (the
1227 * case of `Eo'); and a body that may be empty.
1230 roff_block_alloc(mdoc
, line
, ppos
, tok
);
1234 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1235 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1238 /* Flush out leading punctuation. */
1240 if (head
== NULL
&& ac
!= ARGS_QWORD
&&
1241 mdoc_isdelim(p
) == DELIM_OPEN
) {
1242 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1247 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1248 if (tok
== MDOC_Eo
) /* Not parsed. */
1249 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1250 rew_last(mdoc
, head
);
1251 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1256 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1260 /* Clean-up to leave in a consistent state. */
1263 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1264 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1267 append_delims(mdoc
, line
, pos
, buf
);
1271 in_line_argn(MACRO_PROT_ARGS
)
1273 struct mdoc_arg
*arg
;
1277 int state
; /* arg#; -1: not yet open; -2: closed */
1278 int la
, maxargs
, nl
;
1280 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1283 * A line macro that has a fixed number of arguments (maxargs).
1284 * Only open the scope once the first non-leading-punctuation is
1285 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1286 * keep it open until the maximum number of arguments are
1310 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1316 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1318 if (ac
== ARGS_WORD
&& state
== -1 &&
1319 ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1320 mdoc_isdelim(p
) == DELIM_OPEN
) {
1321 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1325 if (state
== -1 && tok
!= MDOC_In
&&
1326 tok
!= MDOC_St
&& tok
!= MDOC_Xr
) {
1327 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1331 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1332 if (abs(state
) < 2 && tok
== MDOC_Pf
)
1333 mandoc_vmsg(MANDOCERR_PF_SKIP
,
1334 mdoc
->parse
, line
, ppos
, "Pf %s",
1335 p
== NULL
? "at eol" : p
);
1339 if (state
== maxargs
) {
1340 rew_elem(mdoc
, tok
);
1344 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Pf
&& state
== 0)) ?
1345 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
1347 if (ntok
!= TOKEN_NONE
) {
1349 rew_elem(mdoc
, tok
);
1352 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
1356 if (ac
== ARGS_QWORD
||
1357 mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
||
1358 mdoc_isdelim(p
) == DELIM_NONE
) {
1360 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1362 } else if (state
>= 0)
1364 } else if (state
>= 0) {
1365 rew_elem(mdoc
, tok
);
1369 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1370 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
1374 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1375 line
, ppos
, mdoc_macronames
[tok
]);
1379 if (state
== 0 && tok
== MDOC_Pf
)
1380 append_delims(mdoc
, line
, pos
, buf
);
1382 rew_elem(mdoc
, tok
);
1384 append_delims(mdoc
, line
, pos
, buf
);
1388 in_line_eoln(MACRO_PROT_ARGS
)
1390 struct roff_node
*n
;
1391 struct mdoc_arg
*arg
;
1393 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1394 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1396 if (mdoc
->next
== ROFF_NEXT_SIBLING
)
1398 if (n
->tok
== MDOC_Nm
)
1399 rew_last(mdoc
, n
->parent
);
1402 if (buf
[*pos
] == '\0' &&
1403 (tok
== MDOC_Fd
|| mdoc_macronames
[tok
][0] == '%')) {
1404 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1405 line
, ppos
, mdoc_macronames
[tok
]);
1409 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1410 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1411 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1413 rew_elem(mdoc
, tok
);
1417 * The simplest argument parser available: Parse the remaining
1418 * words until the end of the phrase or line and return 0
1419 * or until the next macro, call that macro, and return 1.
1422 parse_rest(struct roff_man
*mdoc
, int tok
, int line
, int *pos
, char *buf
)
1428 if (mdoc_args(mdoc
, line
, pos
, buf
, tok
, NULL
) == ARGS_EOLN
)
1430 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1436 ctx_synopsis(MACRO_PROT_ARGS
)
1439 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1440 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1441 else if (tok
== MDOC_Nm
)
1442 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1444 assert(tok
== MDOC_Vt
);
1445 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1450 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1451 * They're unusual because they're basically free-form text until a
1452 * macro is encountered.
1455 phrase_ta(MACRO_PROT_ARGS
)
1457 struct roff_node
*body
, *n
;
1459 /* Make sure we are in a column list or ignore this macro. */
1462 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1463 if (n
->flags
& MDOC_ENDED
)
1465 if (n
->tok
== MDOC_It
&& n
->type
== ROFFT_BODY
)
1467 if (n
->tok
== MDOC_Bl
)
1471 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1472 mandoc_msg(MANDOCERR_TA_STRAY
, mdoc
->parse
,
1477 /* Advance to the next column. */
1479 rew_last(mdoc
, body
);
1480 roff_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1481 parse_rest(mdoc
, TOKEN_NONE
, line
, pos
, buf
);