]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.230 2018/12/31 04:55:46 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2018 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
*, enum roff_tok
,
50 int, int, struct roff_node
*);
51 static int lookup(struct roff_man
*, int, int, int, const char *);
52 static int macro_or_word(MACRO_PROT_ARGS
, char *, int);
53 static void break_intermediate(struct roff_node
*,
55 static int parse_rest(struct roff_man
*, enum roff_tok
,
57 static enum roff_tok
rew_alt(enum roff_tok
);
58 static void rew_elem(struct roff_man
*, enum roff_tok
);
59 static void rew_last(struct roff_man
*, const struct roff_node
*);
60 static void rew_pending(struct roff_man
*,
61 const struct roff_node
*);
63 static const struct mdoc_macro mdoc_macros
[MDOC_MAX
- MDOC_Dd
] = {
64 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
65 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
66 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
67 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Sh */
68 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Ss */
69 { in_line_eoln
, 0 }, /* Pp */
70 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* D1 */
71 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* Dl */
72 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
73 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ed */
74 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
75 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* El */
76 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* It */
77 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
78 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* An */
79 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
80 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ap */
81 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
82 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Cd */
83 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
84 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
87 { in_line_eoln
, 0 }, /* Ex */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
89 { in_line_eoln
, 0 }, /* Fd */
90 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
91 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
92 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
93 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ic */
94 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
95 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Li */
96 { blk_full
, MDOC_JOIN
}, /* Nd */
97 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
98 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
99 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ot */
100 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
101 { in_line_eoln
, 0 }, /* Rv */
102 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
103 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
104 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
105 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
106 { in_line_eoln
, MDOC_JOIN
}, /* %A */
107 { in_line_eoln
, MDOC_JOIN
}, /* %B */
108 { in_line_eoln
, MDOC_JOIN
}, /* %D */
109 { in_line_eoln
, MDOC_JOIN
}, /* %I */
110 { in_line_eoln
, MDOC_JOIN
}, /* %J */
111 { in_line_eoln
, 0 }, /* %N */
112 { in_line_eoln
, MDOC_JOIN
}, /* %O */
113 { in_line_eoln
, 0 }, /* %P */
114 { in_line_eoln
, MDOC_JOIN
}, /* %R */
115 { in_line_eoln
, MDOC_JOIN
}, /* %T */
116 { in_line_eoln
, 0 }, /* %V */
117 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
118 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ac */
119 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
120 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ao */
121 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Aq */
122 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
123 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
124 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bc */
125 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
126 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
127 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bo */
128 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Bq */
129 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
130 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
131 { in_line_eoln
, 0 }, /* Db */
132 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
133 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Dc */
134 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
135 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Do */
136 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Dq */
137 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ec */
138 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ef */
139 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Em */
140 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
141 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
142 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
143 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* No */
144 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
145 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ns */
146 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
147 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
148 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
149 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Pc */
150 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
151 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
152 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Po */
153 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Pq */
154 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
155 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qc */
156 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ql */
157 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
158 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qo */
159 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Qq */
160 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Re */
161 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
162 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
163 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Sc */
164 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
165 MDOC_EXPLICIT
| MDOC_JOIN
}, /* So */
166 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sq */
167 { in_line_argn
, 0 }, /* Sm */
168 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sx */
169 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sy */
170 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
171 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ux */
172 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
173 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
174 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
175 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
176 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Fc */
177 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
178 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oo */
179 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
180 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oc */
181 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
182 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ek */
183 { in_line_eoln
, 0 }, /* Bt */
184 { in_line_eoln
, 0 }, /* Hf */
185 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fr */
186 { in_line_eoln
, 0 }, /* Ud */
187 { in_line
, 0 }, /* Lb */
188 { in_line_eoln
, 0 }, /* Lp */
189 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
190 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
191 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Brq */
192 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
193 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bro */
194 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
195 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Brc */
196 { in_line_eoln
, MDOC_JOIN
}, /* %C */
197 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Es */
198 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* En */
199 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
200 { in_line_eoln
, MDOC_JOIN
}, /* %Q */
201 { in_line_eoln
, 0 }, /* %U */
202 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ta */
206 const struct mdoc_macro
*
207 mdoc_macro(enum roff_tok tok
)
209 assert(tok
>= MDOC_Dd
&& tok
< MDOC_MAX
);
210 return mdoc_macros
+ (tok
- MDOC_Dd
);
214 * This is called at the end of parsing. It must traverse up the tree,
215 * closing out open [implicit] scopes. Obviously, open explicit scopes
219 mdoc_endparse(struct roff_man
*mdoc
)
223 /* Scan for open explicit scopes. */
225 n
= mdoc
->last
->flags
& NODE_VALID
?
226 mdoc
->last
->parent
: mdoc
->last
;
228 for ( ; n
; n
= n
->parent
)
229 if (n
->type
== ROFFT_BLOCK
&&
230 mdoc_macro(n
->tok
)->flags
& MDOC_EXPLICIT
)
231 mandoc_msg(MANDOCERR_BLK_NOEND
,
232 n
->line
, n
->pos
, "%s", roff_name
[n
->tok
]);
234 /* Rewind to the first. */
236 rew_last(mdoc
, mdoc
->meta
.first
);
240 * Look up the macro at *p called by "from",
241 * or as a line macro if from == TOKEN_NONE.
244 lookup(struct roff_man
*mdoc
, int from
, int line
, int ppos
, const char *p
)
248 if (mdoc
->flags
& MDOC_PHRASEQF
) {
249 mdoc
->flags
&= ~MDOC_PHRASEQF
;
252 if (from
== TOKEN_NONE
|| mdoc_macro(from
)->flags
& MDOC_PARSED
) {
253 res
= roffhash_find(mdoc
->mdocmac
, p
, 0);
254 if (res
!= TOKEN_NONE
) {
255 if (mdoc_macro(res
)->flags
& MDOC_CALLABLE
)
257 mandoc_msg(MANDOCERR_MACRO_CALL
, line
, ppos
, "%s", p
);
264 * Rewind up to and including a specific node.
267 rew_last(struct roff_man
*mdoc
, const struct roff_node
*to
)
270 if (to
->flags
& NODE_VALID
)
273 while (mdoc
->last
!= to
) {
274 mdoc_state(mdoc
, mdoc
->last
);
275 mdoc
->last
->flags
|= NODE_VALID
| NODE_ENDED
;
276 mdoc
->last
= mdoc
->last
->parent
;
278 mdoc_state(mdoc
, mdoc
->last
);
279 mdoc
->last
->flags
|= NODE_VALID
| NODE_ENDED
;
280 mdoc
->next
= ROFF_NEXT_SIBLING
;
284 * Rewind up to a specific block, including all blocks that broke it.
287 rew_pending(struct roff_man
*mdoc
, const struct roff_node
*n
)
293 if (mdoc
->last
== n
) {
296 roff_body_alloc(mdoc
, n
->line
, n
->pos
,
304 if ( ! (n
->flags
& NODE_BROKEN
))
310 if ((n
= n
->parent
) == NULL
)
313 if (n
->type
== ROFFT_BLOCK
||
314 n
->type
== ROFFT_HEAD
) {
315 if (n
->flags
& NODE_ENDED
)
325 * For a block closing macro, return the corresponding opening one.
326 * Otherwise, return the macro itself.
329 rew_alt(enum roff_tok tok
)
370 rew_elem(struct roff_man
*mdoc
, enum roff_tok tok
)
375 if (n
->type
!= ROFFT_ELEM
)
377 assert(n
->type
== ROFFT_ELEM
);
378 assert(tok
== n
->tok
);
383 break_intermediate(struct roff_node
*n
, struct roff_node
*breaker
)
386 n
->type
!= ROFFT_BLOCK
&& n
->type
!= ROFFT_HEAD
&&
387 (n
->type
!= ROFFT_BODY
|| n
->end
!= ENDBODY_NOT
))
389 while (n
!= breaker
) {
390 if ( ! (n
->flags
& NODE_VALID
))
391 n
->flags
|= NODE_BROKEN
;
397 * If there is an open sub-block of the target requiring
398 * explicit close-out, postpone closing out the target until
399 * the rew_pending() call closing out the sub-block.
402 find_pending(struct roff_man
*mdoc
, enum roff_tok tok
, int line
, int ppos
,
403 struct roff_node
*target
)
408 if (target
->flags
& NODE_VALID
)
412 for (n
= mdoc
->last
; n
!= NULL
&& n
!= target
; n
= n
->parent
) {
413 if (n
->flags
& NODE_ENDED
)
415 if (n
->type
== ROFFT_BLOCK
&&
416 mdoc_macro(n
->tok
)->flags
& MDOC_EXPLICIT
) {
418 break_intermediate(mdoc
->last
, target
);
419 if (target
->type
== ROFFT_HEAD
)
420 target
->flags
|= NODE_ENDED
;
421 else if ( ! (target
->flags
& NODE_ENDED
)) {
422 mandoc_msg(MANDOCERR_BLK_NEST
,
423 line
, ppos
, "%s breaks %s",
424 roff_name
[tok
], roff_name
[n
->tok
]);
425 mdoc_endbody_alloc(mdoc
, line
, ppos
,
434 * Allocate a word and check whether it's punctuation or not.
435 * Punctuation consists of those tokens found in mdoc_isdelim().
438 dword(struct roff_man
*mdoc
, int line
, int col
, const char *p
,
439 enum mdelim d
, int may_append
)
446 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
447 d
== DELIM_NONE
&& mdoc
->last
->type
== ROFFT_TEXT
&&
448 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
449 roff_word_append(mdoc
, p
);
453 roff_word_alloc(mdoc
, line
, col
, p
);
456 * If the word consists of a bare delimiter,
457 * flag the new node accordingly,
458 * unless doing so was vetoed by the invoking macro.
459 * Always clear the veto, it is only valid for one word.
463 mdoc
->last
->flags
|= NODE_DELIMO
;
464 else if (d
== DELIM_CLOSE
&&
465 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
466 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
467 mdoc
->last
->flags
|= NODE_DELIMC
;
468 mdoc
->flags
&= ~MDOC_NODELIMC
;
472 append_delims(struct roff_man
*mdoc
, int line
, int *pos
, char *buf
)
478 if (buf
[*pos
] == '\0')
483 ac
= mdoc_args(mdoc
, line
, pos
, buf
, TOKEN_NONE
, &p
);
486 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
489 * If we encounter end-of-sentence symbols, then trigger
492 * XXX: it's easy to allow this to propagate outward to
493 * the last symbol, such that `. )' will cause the
494 * correct double-spacing. However, (1) groff isn't
495 * smart enough to do this and (2) it would require
496 * knowing which symbols break this behaviour, for
497 * example, `. ;' shouldn't propagate the double-space.
500 if (mandoc_eos(p
, strlen(p
)))
501 mdoc
->last
->flags
|= NODE_EOS
;
502 if (ac
== ARGS_ALLOC
)
509 * If it is a macro, call it and return 1.
510 * Otherwise, allocate it and return 0.
513 macro_or_word(MACRO_PROT_ARGS
, char *p
, int parsed
)
517 ntok
= buf
[ppos
] == '"' || parsed
== 0 ||
518 mdoc
->flags
& MDOC_PHRASELIT
? TOKEN_NONE
:
519 lookup(mdoc
, tok
, line
, ppos
, p
);
521 if (ntok
== TOKEN_NONE
) {
522 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== TOKEN_NONE
||
523 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
526 if (tok
!= TOKEN_NONE
&&
527 mdoc_macro(tok
)->fp
== in_line_eoln
)
529 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
, line
, ppos
, pos
, buf
);
530 if (tok
== TOKEN_NONE
)
531 append_delims(mdoc
, line
, pos
, buf
);
537 * Close out block partial/full explicit.
540 blk_exp_close(MACRO_PROT_ARGS
)
542 struct roff_node
*body
; /* Our own body. */
543 struct roff_node
*endbody
; /* Our own end marker. */
544 struct roff_node
*itblk
; /* An It block starting later. */
545 struct roff_node
*later
; /* A sub-block starting later. */
546 struct roff_node
*n
; /* Search back to our block. */
547 struct roff_node
*target
; /* For find_pending(). */
549 int j
, lastarg
, maxargs
, nl
, pending
;
551 enum roff_tok atok
, ntok
;
554 nl
= MDOC_NEWLINE
& mdoc
->flags
;
561 mdoc
->flags
&= ~MDOC_KEEP
;
568 /* Search backwards for the beginning of our own body. */
572 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
573 if (n
->flags
& NODE_ENDED
|| n
->tok
!= atok
||
574 n
->type
!= ROFFT_BODY
|| n
->end
!= ENDBODY_NOT
)
581 * Search backwards for beginnings of blocks,
582 * both of our own and of pending sub-blocks.
585 endbody
= itblk
= later
= NULL
;
586 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
587 if (n
->flags
& NODE_ENDED
)
591 * Mismatching end macros can never break anything
592 * and we only care about the breaking of BLOCKs.
595 if (body
== NULL
|| n
->type
!= ROFFT_BLOCK
)
599 * SYNOPSIS name blocks can not be broken themselves,
600 * but they do get broken together with a broken child.
603 if (n
->tok
== MDOC_Nm
) {
605 n
->flags
|= NODE_BROKEN
| NODE_ENDED
;
609 if (n
->tok
== MDOC_It
) {
614 if (atok
== n
->tok
) {
617 * Found the start of our own block.
618 * When there is no pending sub block,
619 * just proceed to closing out.
623 (tok
== MDOC_El
&& itblk
== NULL
))
627 * When there is a pending sub block, postpone
628 * closing out the current block until the
629 * rew_pending() closing out the sub-block.
630 * Mark the place where the formatting - but not
631 * the scope - of the current block ends.
634 mandoc_msg(MANDOCERR_BLK_NEST
,
635 line
, ppos
, "%s breaks %s",
636 roff_name
[atok
], roff_name
[later
->tok
]);
638 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
642 itblk
->flags
|= NODE_ENDED
| NODE_BROKEN
;
645 * If a block closing macro taking arguments
646 * breaks another block, put the arguments
647 * into the end marker.
651 mdoc
->next
= ROFF_NEXT_CHILD
;
656 * Explicit blocks close out description lines, but
657 * even those can get broken together with a child.
660 if (n
->tok
== MDOC_Nd
) {
662 n
->flags
|= NODE_BROKEN
| NODE_ENDED
;
668 /* Breaking an open sub block. */
670 break_intermediate(mdoc
->last
, body
);
671 n
->flags
|= NODE_BROKEN
;
677 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, line
, ppos
,
678 "%s", roff_name
[tok
]);
679 if (maxargs
&& endbody
== NULL
) {
681 * Stray .Ec without previous .Eo:
682 * Break the output line, keep the arguments.
684 roff_elem_alloc(mdoc
, line
, ppos
, ROFF_br
);
685 rew_elem(mdoc
, ROFF_br
);
687 } else if (endbody
== NULL
) {
688 rew_last(mdoc
, body
);
690 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
693 if ((mdoc_macro(tok
)->flags
& MDOC_PARSED
) == 0) {
694 if (buf
[*pos
] != '\0')
695 mandoc_msg(MANDOCERR_ARG_SKIP
, line
, ppos
,
696 "%s %s", roff_name
[tok
], buf
+ *pos
);
697 if (endbody
== NULL
&& n
!= NULL
)
698 rew_pending(mdoc
, n
);
709 if (j
== maxargs
&& n
!= NULL
)
712 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
713 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
716 ntok
= lookup(mdoc
, tok
, line
, lastarg
, p
);
718 if (ntok
== TOKEN_NONE
) {
719 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
720 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
721 if (ac
== ARGS_ALLOC
)
725 if (ac
== ARGS_ALLOC
)
730 mdoc
->flags
&= ~MDOC_NEWLINE
;
731 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
737 if (ntok
!= TOKEN_NONE
&& n
->flags
& NODE_BROKEN
) {
740 target
= target
->parent
;
741 while ( ! (target
->flags
& NODE_ENDED
));
742 pending
= find_pending(mdoc
, ntok
, line
, ppos
, target
);
745 rew_pending(mdoc
, n
);
748 append_delims(mdoc
, line
, pos
, buf
);
752 in_line(MACRO_PROT_ARGS
)
754 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
758 struct mdoc_arg
*arg
;
761 nl
= MDOC_NEWLINE
& mdoc
->flags
;
764 * Whether we allow ignored elements (those without content,
765 * usually because of reserved words) to squeak by.
782 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
787 for (cnt
= scope
= 0;; ) {
789 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
792 * At the end of a macro line,
793 * opening delimiters do not suppress spacing.
796 if (ac
== ARGS_EOLN
) {
798 mdoc
->last
->flags
&= ~NODE_DELIMO
;
803 * The rest of the macro line is only punctuation,
804 * to be handled by append_delims().
805 * If there were no other arguments,
806 * do not allow the first one to suppress spacing,
807 * even if it turns out to be a closing one.
810 if (ac
== ARGS_PUNCT
) {
811 if (cnt
== 0 && (nc
== 0 || tok
== MDOC_An
))
812 mdoc
->flags
|= MDOC_NODELIMC
;
816 ntok
= (tok
== MDOC_Fn
&& !cnt
) ?
817 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
820 * In this case, we've located a submacro and must
821 * execute it. Close out scope, if open. If no
822 * elements have been generated, either create one (nc)
823 * or raise a warning.
826 if (ntok
!= TOKEN_NONE
) {
830 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
831 rew_last(mdoc
, mdoc
->last
);
832 } else if ( ! nc
&& ! cnt
) {
834 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
835 line
, ppos
, "%s", roff_name
[tok
]);
837 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
,
840 append_delims(mdoc
, line
, pos
, buf
);
841 if (ac
== ARGS_ALLOC
)
847 * Handle punctuation. Set up our scope, if a word;
848 * rewind the scope, if a delimiter; then append the word.
851 if ((d
= mdoc_isdelim(p
)) != DELIM_NONE
) {
853 * If we encounter closing punctuation, no word
854 * has been emitted, no scope is open, and we're
855 * allowed to have an empty element, then start
858 if ((d
== DELIM_CLOSE
||
859 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
860 !cnt
&& !scope
&& nc
&& mayopen
) {
861 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
868 * Close out our scope, if one is open, before
871 if (scope
&& tok
!= MDOC_Lk
) {
877 } else if (mayopen
&& !scope
) {
878 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
883 dword(mdoc
, line
, la
, p
, d
,
884 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
886 if (ac
== ARGS_ALLOC
)
890 * If the first argument is a closing delimiter,
891 * do not suppress spacing before it.
894 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
895 mdoc
->last
->flags
&= ~NODE_DELIMC
;
899 * `Fl' macros have their scope re-opened with each new
900 * word so that the `-' can be added to each one without
901 * having to parse out spaces.
903 if (scope
&& tok
== MDOC_Fl
) {
909 if (scope
&& tok
!= MDOC_Lk
) {
915 * If no elements have been collected and we're allowed to have
916 * empties (nc), open a scope and close it out. Otherwise,
922 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
923 rew_last(mdoc
, mdoc
->last
);
926 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
927 line
, ppos
, "%s", roff_name
[tok
]);
931 append_delims(mdoc
, line
, pos
, buf
);
937 blk_full(MACRO_PROT_ARGS
)
939 int done
, la
, nl
, parsed
;
940 struct mdoc_arg
*arg
;
941 struct roff_node
*blk
; /* Our own or a broken block. */
942 struct roff_node
*head
; /* Our own head. */
943 struct roff_node
*body
; /* Our own body. */
945 enum margserr ac
, lac
;
948 nl
= MDOC_NEWLINE
& mdoc
->flags
;
950 if (buf
[*pos
] == '\0' && (tok
== MDOC_Sh
|| tok
== MDOC_Ss
)) {
951 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
952 line
, ppos
, "%s", roff_name
[tok
]);
956 if ((mdoc_macro(tok
)->flags
& MDOC_EXPLICIT
) == 0) {
958 /* Here, tok is one of Sh Ss Nm Nd It. */
961 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
962 if (n
->flags
& NODE_ENDED
) {
963 if ( ! (n
->flags
& NODE_VALID
))
964 n
->flags
|= NODE_BROKEN
;
967 if (n
->type
!= ROFFT_BLOCK
)
970 if (tok
== MDOC_It
&& n
->tok
== MDOC_Bl
) {
972 mandoc_msg(MANDOCERR_BLK_BROKEN
,
973 line
, ppos
, "It breaks %s",
974 roff_name
[blk
->tok
]);
975 rew_pending(mdoc
, blk
);
980 if (mdoc_macro(n
->tok
)->flags
& MDOC_EXPLICIT
) {
984 mandoc_msg(MANDOCERR_BLK_BROKEN
,
986 "%s breaks %s", roff_name
[tok
],
988 rew_pending(mdoc
, n
);
992 /* Delay in case it's astray. */
1001 /* Here, n is one of Sh Ss Nm Nd It. */
1003 if (tok
!= MDOC_Sh
&& (n
->tok
== MDOC_Sh
||
1004 (tok
!= MDOC_Ss
&& (n
->tok
== MDOC_Ss
||
1005 (tok
!= MDOC_It
&& n
->tok
== MDOC_It
)))))
1008 /* Item breaking an explicit block. */
1011 mandoc_msg(MANDOCERR_BLK_BROKEN
, line
, ppos
,
1012 "It breaks %s", roff_name
[blk
->tok
]);
1013 rew_pending(mdoc
, blk
);
1017 /* Close out prior implicit scopes. */
1019 rew_pending(mdoc
, n
);
1022 /* Skip items outside lists. */
1024 if (tok
== MDOC_It
&& (n
== NULL
|| n
->tok
!= MDOC_Bl
)) {
1025 mandoc_msg(MANDOCERR_IT_STRAY
,
1026 line
, ppos
, "It %s", buf
+ *pos
);
1027 roff_elem_alloc(mdoc
, line
, ppos
, ROFF_br
);
1028 rew_elem(mdoc
, ROFF_br
);
1034 * This routine accommodates implicitly- and explicitly-scoped
1035 * macro openings. Implicit ones first close out prior scope
1036 * (seen above). Delay opening the head until necessary to
1037 * allow leading punctuation to print. Special consideration
1038 * for `It -column', which has phrase-part syntax instead of
1039 * regular child nodes.
1042 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1043 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
1047 * Exception: Heads of `It' macros in `-diag' lists are not
1048 * parsed, even though `It' macros in general are parsed.
1051 parsed
= tok
!= MDOC_It
||
1052 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
1053 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
1056 * The `Nd' macro has all arguments in its body: it's a hybrid
1057 * of block partial-explicit and full-implicit. Stupid.
1060 if (tok
== MDOC_Nd
) {
1061 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1062 rew_last(mdoc
, head
);
1063 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1067 mdoc
->flags
|= MDOC_KEEP
;
1073 * If we are right after a tab character,
1074 * do not parse the first word for macros.
1077 if (mdoc
->flags
& MDOC_PHRASEQN
) {
1078 mdoc
->flags
&= ~MDOC_PHRASEQN
;
1079 mdoc
->flags
|= MDOC_PHRASEQF
;
1084 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1085 if (ac
== ARGS_EOLN
) {
1086 if (lac
!= ARGS_PHRASE
||
1087 ! (mdoc
->flags
& MDOC_PHRASEQF
))
1091 * This line ends in a tab; start the next
1092 * column now, with a leading blank.
1096 rew_last(mdoc
, body
);
1097 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1098 roff_word_alloc(mdoc
, line
, ppos
, "\\&");
1102 if (tok
== MDOC_Bd
|| tok
== MDOC_Bk
) {
1103 mandoc_msg(MANDOCERR_ARG_EXCESS
, line
, la
,
1104 "%s ... %s", roff_name
[tok
], buf
+ la
);
1105 if (ac
== ARGS_ALLOC
)
1109 if (tok
== MDOC_Rs
) {
1110 mandoc_msg(MANDOCERR_ARG_SKIP
,
1111 line
, la
, "Rs %s", buf
+ la
);
1112 if (ac
== ARGS_ALLOC
)
1116 if (ac
== ARGS_PUNCT
)
1120 * Emit leading punctuation (i.e., punctuation before
1121 * the ROFFT_HEAD) for non-phrase types.
1125 ac
!= ARGS_PHRASE
&&
1126 mdoc_isdelim(p
) == DELIM_OPEN
) {
1127 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1128 if (ac
== ARGS_ALLOC
)
1133 /* Open a head if one hasn't been opened. */
1136 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1138 if (ac
== ARGS_PHRASE
) {
1141 * If we haven't opened a body yet, rewind the
1142 * head; if we have, rewind that instead.
1145 rew_last(mdoc
, body
== NULL
? head
: body
);
1146 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1148 /* Process to the tab or to the end of the line. */
1150 mdoc
->flags
|= MDOC_PHRASE
;
1151 parse_rest(mdoc
, TOKEN_NONE
, line
, &la
, buf
);
1152 mdoc
->flags
&= ~MDOC_PHRASE
;
1154 /* There may have been `Ta' macros. */
1156 while (body
->next
!= NULL
)
1161 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, parsed
);
1162 if (ac
== ARGS_ALLOC
)
1168 if (blk
->flags
& NODE_VALID
)
1171 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1172 if (nl
&& tok
!= MDOC_Bd
&& tok
!= MDOC_Bl
&& tok
!= MDOC_Rs
)
1173 append_delims(mdoc
, line
, pos
, buf
);
1176 if (find_pending(mdoc
, tok
, line
, ppos
, head
))
1179 /* Close out scopes to remain in a consistent state. */
1181 rew_last(mdoc
, head
);
1182 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1184 if (mdoc
->flags
& MDOC_FREECOL
) {
1185 rew_last(mdoc
, body
);
1186 rew_last(mdoc
, blk
);
1187 mdoc
->flags
&= ~MDOC_FREECOL
;
1192 blk_part_imp(MACRO_PROT_ARGS
)
1197 struct roff_node
*blk
; /* saved block context */
1198 struct roff_node
*body
; /* saved body context */
1199 struct roff_node
*n
;
1201 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1204 * A macro that spans to the end of the line. This is generally
1205 * (but not necessarily) called as the first macro. The block
1206 * has a head as the immediate child, which is always empty,
1207 * followed by zero or more opening punctuation nodes, then the
1208 * body (which may be empty, depending on the macro), then zero
1209 * or more closing punctuation nodes.
1212 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1213 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1216 * Open the body scope "on-demand", that is, after we've
1217 * processed all our the leading delimiters (open parenthesis,
1221 for (body
= NULL
; ; ) {
1223 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1224 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1227 if (body
== NULL
&& mdoc_isdelim(p
) == DELIM_OPEN
) {
1228 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1229 if (ac
== ARGS_ALLOC
)
1235 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1237 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, 1);
1238 if (ac
== ARGS_ALLOC
)
1244 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1246 if (find_pending(mdoc
, tok
, line
, ppos
, body
))
1249 rew_last(mdoc
, body
);
1251 append_delims(mdoc
, line
, pos
, buf
);
1252 rew_pending(mdoc
, blk
);
1254 /* Move trailing .Ns out of scope. */
1256 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1258 if (n
&& n
->tok
== MDOC_Ns
)
1259 roff_node_relink(mdoc
, n
);
1263 blk_part_exp(MACRO_PROT_ARGS
)
1267 struct roff_node
*head
; /* keep track of head */
1270 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1273 * The opening of an explicit macro having zero or more leading
1274 * punctuation nodes; a head with optional single element (the
1275 * case of `Eo'); and a body that may be empty.
1278 roff_block_alloc(mdoc
, line
, ppos
, tok
);
1282 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1283 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1286 /* Flush out leading punctuation. */
1288 if (head
== NULL
&& mdoc_isdelim(p
) == DELIM_OPEN
) {
1289 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1290 if (ac
== ARGS_ALLOC
)
1296 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1297 if (tok
== MDOC_Eo
) /* Not parsed. */
1298 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1299 rew_last(mdoc
, head
);
1300 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1301 if (tok
== MDOC_Eo
) {
1302 if (ac
== ARGS_ALLOC
)
1308 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, 1);
1309 if (ac
== ARGS_ALLOC
)
1315 /* Clean-up to leave in a consistent state. */
1318 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1319 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1322 append_delims(mdoc
, line
, pos
, buf
);
1326 in_line_argn(MACRO_PROT_ARGS
)
1328 struct mdoc_arg
*arg
;
1332 int state
; /* arg#; -1: not yet open; -2: closed */
1333 int la
, maxargs
, nl
;
1335 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1338 * A line macro that has a fixed number of arguments (maxargs).
1339 * Only open the scope once the first non-leading-punctuation is
1340 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1341 * keep it open until the maximum number of arguments are
1361 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1367 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1369 if ((ac
== ARGS_WORD
|| ac
== ARGS_ALLOC
) && state
== -1 &&
1370 (mdoc_macro(tok
)->flags
& MDOC_IGNDELIM
) == 0 &&
1371 mdoc_isdelim(p
) == DELIM_OPEN
) {
1372 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1373 if (ac
== ARGS_ALLOC
)
1378 if (state
== -1 && tok
!= MDOC_In
&&
1379 tok
!= MDOC_St
&& tok
!= MDOC_Xr
) {
1380 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1384 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1385 if (abs(state
) < 2 && tok
== MDOC_Pf
)
1386 mandoc_msg(MANDOCERR_PF_SKIP
,
1387 line
, ppos
, "Pf %s",
1388 p
== NULL
? "at eol" : p
);
1392 if (state
== maxargs
) {
1393 rew_elem(mdoc
, tok
);
1397 ntok
= (tok
== MDOC_Pf
&& state
== 0) ?
1398 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
1400 if (ntok
!= TOKEN_NONE
) {
1402 rew_elem(mdoc
, tok
);
1405 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
,
1406 line
, la
, pos
, buf
);
1407 if (ac
== ARGS_ALLOC
)
1412 if (mdoc_macro(tok
)->flags
& MDOC_IGNDELIM
||
1413 mdoc_isdelim(p
) == DELIM_NONE
) {
1415 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1417 } else if (state
>= 0)
1419 } else if (state
>= 0) {
1420 rew_elem(mdoc
, tok
);
1424 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1425 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
1426 if (ac
== ARGS_ALLOC
)
1428 p
= mdoc
->last
->string
;
1432 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
1433 line
, ppos
, "%s", roff_name
[tok
]);
1437 if (state
== 0 && tok
== MDOC_Pf
)
1438 append_delims(mdoc
, line
, pos
, buf
);
1440 rew_elem(mdoc
, tok
);
1442 append_delims(mdoc
, line
, pos
, buf
);
1446 in_line_eoln(MACRO_PROT_ARGS
)
1448 struct roff_node
*n
;
1449 struct mdoc_arg
*arg
;
1451 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1452 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1454 if (mdoc
->next
== ROFF_NEXT_SIBLING
)
1456 if (n
->tok
== MDOC_Nm
)
1457 rew_last(mdoc
, n
->parent
);
1460 if (buf
[*pos
] == '\0' &&
1461 (tok
== MDOC_Fd
|| *roff_name
[tok
] == '%')) {
1462 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
1463 line
, ppos
, "%s", roff_name
[tok
]);
1467 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1468 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1469 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1471 rew_elem(mdoc
, tok
);
1475 * The simplest argument parser available: Parse the remaining
1476 * words until the end of the phrase or line and return 0
1477 * or until the next macro, call that macro, and return 1.
1480 parse_rest(struct roff_man
*mdoc
, enum roff_tok tok
,
1481 int line
, int *pos
, char *buf
)
1489 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1490 if (ac
== ARGS_EOLN
)
1492 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, 1);
1493 if (ac
== ARGS_ALLOC
)
1501 ctx_synopsis(MACRO_PROT_ARGS
)
1504 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1505 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1506 else if (tok
== MDOC_Nm
)
1507 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1509 assert(tok
== MDOC_Vt
);
1510 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1515 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1516 * They're unusual because they're basically free-form text until a
1517 * macro is encountered.
1520 phrase_ta(MACRO_PROT_ARGS
)
1522 struct roff_node
*body
, *n
;
1524 /* Make sure we are in a column list or ignore this macro. */
1527 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1528 if (n
->flags
& NODE_ENDED
)
1530 if (n
->tok
== MDOC_It
&& n
->type
== ROFFT_BODY
)
1532 if (n
->tok
== MDOC_Bl
&& n
->end
== ENDBODY_NOT
)
1536 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1537 mandoc_msg(MANDOCERR_TA_STRAY
, line
, ppos
, "Ta");
1541 /* Advance to the next column. */
1543 rew_last(mdoc
, body
);
1544 roff_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1545 parse_rest(mdoc
, TOKEN_NONE
, line
, pos
, buf
);