]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.235 2022/04/14 16:43:44 schwarze Exp $ */
3 * Copyright (c) 2010, 2012-2021 Ingo Schwarze <schwarze@openbsd.org>
4 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
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>
30 #include "mandoc_dbg.h"
35 #include "libmandoc.h"
39 static void blk_full(MACRO_PROT_ARGS
);
40 static void blk_exp_close(MACRO_PROT_ARGS
);
41 static void blk_part_exp(MACRO_PROT_ARGS
);
42 static void blk_part_imp(MACRO_PROT_ARGS
);
43 static void ctx_synopsis(MACRO_PROT_ARGS
);
44 static void in_line_eoln(MACRO_PROT_ARGS
);
45 static void in_line_argn(MACRO_PROT_ARGS
);
46 static void in_line(MACRO_PROT_ARGS
);
47 static void phrase_ta(MACRO_PROT_ARGS
);
49 static void append_delims(struct roff_man
*, int, int *, char *);
50 static void dword(struct roff_man
*, int, int, const char *,
52 static int find_pending(struct roff_man
*, enum roff_tok
,
53 int, int, struct roff_node
*);
54 static int lookup(struct roff_man
*, int, int, int, const char *);
55 static int macro_or_word(MACRO_PROT_ARGS
, char *, int);
56 static void break_intermediate(struct roff_node
*,
58 static int parse_rest(struct roff_man
*, enum roff_tok
,
60 static enum roff_tok
rew_alt(enum roff_tok
);
61 static void rew_elem(struct roff_man
*, enum roff_tok
);
62 static void rew_last(struct roff_man
*, const struct roff_node
*);
63 static void rew_pending(struct roff_man
*,
64 const struct roff_node
*);
66 static const struct mdoc_macro mdoc_macros
[MDOC_MAX
- MDOC_Dd
] = {
67 { in_line_eoln
, MDOC_PROLOGUE
| MDOC_JOIN
}, /* Dd */
68 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
69 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
70 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Sh */
71 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Ss */
72 { in_line_eoln
, 0 }, /* Pp */
73 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* D1 */
74 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* Dl */
75 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
76 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ed */
77 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
78 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* El */
79 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* It */
80 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
81 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* An */
82 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
83 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ap */
84 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Cd */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
90 { in_line_eoln
, 0 }, /* Ex */
91 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
92 { in_line_eoln
, 0 }, /* Fd */
93 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
94 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
95 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
96 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ic */
97 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
98 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Li */
99 { blk_full
, MDOC_JOIN
}, /* Nd */
100 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
101 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
102 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ot */
103 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
104 { in_line_eoln
, 0 }, /* Rv */
105 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
106 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
107 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
108 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
109 { in_line_eoln
, MDOC_JOIN
}, /* %A */
110 { in_line_eoln
, MDOC_JOIN
}, /* %B */
111 { in_line_eoln
, MDOC_JOIN
}, /* %D */
112 { in_line_eoln
, MDOC_JOIN
}, /* %I */
113 { in_line_eoln
, MDOC_JOIN
}, /* %J */
114 { in_line_eoln
, 0 }, /* %N */
115 { in_line_eoln
, MDOC_JOIN
}, /* %O */
116 { in_line_eoln
, 0 }, /* %P */
117 { in_line_eoln
, MDOC_JOIN
}, /* %R */
118 { in_line_eoln
, MDOC_JOIN
}, /* %T */
119 { in_line_eoln
, 0 }, /* %V */
120 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
121 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ac */
122 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
123 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ao */
124 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Aq */
125 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
126 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
127 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bc */
128 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
129 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
130 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bo */
131 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Bq */
132 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
133 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
134 { in_line_eoln
, 0 }, /* Db */
135 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
136 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Dc */
137 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
138 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Do */
139 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Dq */
140 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ec */
141 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ef */
142 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Em */
143 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
144 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
145 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
146 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* No */
147 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
148 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ns */
149 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
150 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
151 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
152 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Pc */
153 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
154 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
155 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Po */
156 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Pq */
157 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
158 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qc */
159 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ql */
160 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
161 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qo */
162 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Qq */
163 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Re */
164 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
165 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
166 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Sc */
167 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
168 MDOC_EXPLICIT
| MDOC_JOIN
}, /* So */
169 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sq */
170 { in_line_argn
, 0 }, /* Sm */
171 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sx */
172 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sy */
173 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
174 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ux */
175 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
176 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
177 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
178 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
179 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Fc */
180 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
181 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oo */
182 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
183 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oc */
184 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
185 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ek */
186 { in_line_eoln
, 0 }, /* Bt */
187 { in_line_eoln
, 0 }, /* Hf */
188 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fr */
189 { in_line_eoln
, 0 }, /* Ud */
190 { in_line
, 0 }, /* Lb */
191 { in_line_eoln
, 0 }, /* Lp */
192 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
193 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
194 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Brq */
195 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
196 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bro */
197 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
198 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Brc */
199 { in_line_eoln
, MDOC_JOIN
}, /* %C */
200 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Es */
201 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* En */
202 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
203 { in_line_eoln
, MDOC_JOIN
}, /* %Q */
204 { in_line_eoln
, 0 }, /* %U */
205 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ta */
206 { in_line_eoln
, 0 }, /* Tg */
210 const struct mdoc_macro
*
211 mdoc_macro(enum roff_tok tok
)
213 assert(tok
>= MDOC_Dd
&& tok
< MDOC_MAX
);
214 return mdoc_macros
+ (tok
- MDOC_Dd
);
218 * This is called at the end of parsing. It must traverse up the tree,
219 * closing out open [implicit] scopes. Obviously, open explicit scopes
223 mdoc_endparse(struct roff_man
*mdoc
)
227 /* Scan for open explicit scopes. */
229 n
= mdoc
->last
->flags
& NODE_VALID
?
230 mdoc
->last
->parent
: mdoc
->last
;
232 for ( ; n
; n
= n
->parent
)
233 if (n
->type
== ROFFT_BLOCK
&&
234 mdoc_macro(n
->tok
)->flags
& MDOC_EXPLICIT
)
235 mandoc_msg(MANDOCERR_BLK_NOEND
,
236 n
->line
, n
->pos
, "%s", roff_name
[n
->tok
]);
238 /* Rewind to the first. */
240 rew_last(mdoc
, mdoc
->meta
.first
);
244 * Look up the macro at *p called by "from",
245 * or as a line macro if from == TOKEN_NONE.
248 lookup(struct roff_man
*mdoc
, int from
, int line
, int ppos
, const char *p
)
252 if (mdoc
->flags
& MDOC_PHRASEQF
) {
253 mdoc
->flags
&= ~MDOC_PHRASEQF
;
256 if (from
== TOKEN_NONE
|| mdoc_macro(from
)->flags
& MDOC_PARSED
) {
257 res
= roffhash_find(mdoc
->mdocmac
, p
, 0);
258 if (res
!= TOKEN_NONE
) {
259 if (mdoc_macro(res
)->flags
& MDOC_CALLABLE
)
261 mandoc_msg(MANDOCERR_MACRO_CALL
, line
, ppos
, "%s", p
);
268 * Rewind up to and including a specific node.
271 rew_last(struct roff_man
*mdoc
, const struct roff_node
*to
)
274 if (to
->flags
& NODE_VALID
)
277 while (mdoc
->last
!= to
) {
278 mdoc_state(mdoc
, mdoc
->last
);
279 mdoc
->last
->flags
|= NODE_VALID
| NODE_ENDED
;
280 mdoc
->last
= mdoc
->last
->parent
;
282 mdoc_state(mdoc
, mdoc
->last
);
283 mdoc
->last
->flags
|= NODE_VALID
| NODE_ENDED
;
284 mdoc
->next
= ROFF_NEXT_SIBLING
;
288 * Rewind up to a specific block, including all blocks that broke it.
291 rew_pending(struct roff_man
*mdoc
, const struct roff_node
*n
)
297 if (mdoc
->last
== n
) {
300 roff_body_alloc(mdoc
, n
->line
, n
->pos
,
302 if (n
->tok
== MDOC_Ss
)
303 mdoc
->flags
&= ~ROFF_NONOFILL
;
310 if ( ! (n
->flags
& NODE_BROKEN
))
316 if ((n
= n
->parent
) == NULL
)
319 if (n
->type
== ROFFT_BLOCK
||
320 n
->type
== ROFFT_HEAD
) {
321 if (n
->flags
& NODE_ENDED
)
331 * For a block closing macro, return the corresponding opening one.
332 * Otherwise, return the macro itself.
335 rew_alt(enum roff_tok tok
)
376 rew_elem(struct roff_man
*mdoc
, enum roff_tok tok
)
381 if (n
->type
!= ROFFT_ELEM
)
383 assert(n
->type
== ROFFT_ELEM
);
384 assert(tok
== n
->tok
);
389 break_intermediate(struct roff_node
*n
, struct roff_node
*breaker
)
392 n
->type
!= ROFFT_BLOCK
&& n
->type
!= ROFFT_HEAD
&&
393 (n
->type
!= ROFFT_BODY
|| n
->end
!= ENDBODY_NOT
))
395 while (n
!= breaker
) {
396 if ( ! (n
->flags
& NODE_VALID
))
397 n
->flags
|= NODE_BROKEN
;
403 * If there is an open sub-block of the target requiring
404 * explicit close-out, postpone closing out the target until
405 * the rew_pending() call closing out the sub-block.
408 find_pending(struct roff_man
*mdoc
, enum roff_tok tok
, int line
, int ppos
,
409 struct roff_node
*target
)
414 if (target
->flags
& NODE_VALID
)
418 for (n
= mdoc
->last
; n
!= NULL
&& n
!= target
; n
= n
->parent
) {
419 if (n
->flags
& NODE_ENDED
)
421 if (n
->type
== ROFFT_BLOCK
&&
422 mdoc_macro(n
->tok
)->flags
& MDOC_EXPLICIT
) {
424 break_intermediate(mdoc
->last
, target
);
425 if (target
->type
== ROFFT_HEAD
)
426 target
->flags
|= NODE_ENDED
;
427 else if ( ! (target
->flags
& NODE_ENDED
)) {
428 mandoc_msg(MANDOCERR_BLK_NEST
,
429 line
, ppos
, "%s breaks %s",
430 roff_name
[tok
], roff_name
[n
->tok
]);
431 mdoc_endbody_alloc(mdoc
, line
, ppos
,
440 * Allocate a word and check whether it's punctuation or not.
441 * Punctuation consists of those tokens found in mdoc_isdelim().
444 dword(struct roff_man
*mdoc
, int line
, int col
, const char *p
,
445 enum mdelim d
, int may_append
)
452 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
453 d
== DELIM_NONE
&& mdoc
->last
->type
== ROFFT_TEXT
&&
454 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
455 roff_word_append(mdoc
, p
);
459 roff_word_alloc(mdoc
, line
, col
, p
);
462 * If the word consists of a bare delimiter,
463 * flag the new node accordingly,
464 * unless doing so was vetoed by the invoking macro.
465 * Always clear the veto, it is only valid for one word.
469 mdoc
->last
->flags
|= NODE_DELIMO
;
470 else if (d
== DELIM_CLOSE
&&
471 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
472 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
473 mdoc
->last
->flags
|= NODE_DELIMC
;
474 mdoc
->flags
&= ~MDOC_NODELIMC
;
478 append_delims(struct roff_man
*mdoc
, int line
, int *pos
, char *buf
)
484 if (buf
[*pos
] == '\0')
489 ac
= mdoc_args(mdoc
, line
, pos
, buf
, TOKEN_NONE
, &p
);
492 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
495 * If we encounter end-of-sentence symbols, then trigger
498 * XXX: it's easy to allow this to propagate outward to
499 * the last symbol, such that `. )' will cause the
500 * correct double-spacing. However, (1) groff isn't
501 * smart enough to do this and (2) it would require
502 * knowing which symbols break this behaviour, for
503 * example, `. ;' shouldn't propagate the double-space.
506 if (mandoc_eos(p
, strlen(p
)))
507 mdoc
->last
->flags
|= NODE_EOS
;
508 if (ac
== ARGS_ALLOC
)
515 * If it is a macro, call it and return 1.
516 * Otherwise, allocate it and return 0.
519 macro_or_word(MACRO_PROT_ARGS
, char *p
, int parsed
)
523 ntok
= buf
[ppos
] == '"' || parsed
== 0 ||
524 mdoc
->flags
& MDOC_PHRASELIT
? TOKEN_NONE
:
525 lookup(mdoc
, tok
, line
, ppos
, p
);
527 if (ntok
== TOKEN_NONE
) {
528 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== TOKEN_NONE
||
529 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
532 if (tok
!= TOKEN_NONE
&&
533 mdoc_macro(tok
)->fp
== in_line_eoln
)
535 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
, line
, ppos
, pos
, buf
);
536 if (tok
== TOKEN_NONE
)
537 append_delims(mdoc
, line
, pos
, buf
);
543 * Close out block partial/full explicit.
546 blk_exp_close(MACRO_PROT_ARGS
)
548 struct roff_node
*body
; /* Our own body. */
549 struct roff_node
*endbody
; /* Our own end marker. */
550 struct roff_node
*itblk
; /* An It block starting later. */
551 struct roff_node
*later
; /* A sub-block starting later. */
552 struct roff_node
*n
; /* Search back to our block. */
553 struct roff_node
*target
; /* For find_pending(). */
555 int j
, lastarg
, maxargs
, nl
, pending
;
557 enum roff_tok atok
, ntok
;
560 nl
= MDOC_NEWLINE
& mdoc
->flags
;
567 mdoc
->flags
&= ~MDOC_KEEP
;
574 /* Search backwards for the beginning of our own body. */
578 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
579 if (n
->flags
& NODE_ENDED
|| n
->tok
!= atok
||
580 n
->type
!= ROFFT_BODY
|| n
->end
!= ENDBODY_NOT
)
587 * Search backwards for beginnings of blocks,
588 * both of our own and of pending sub-blocks.
591 endbody
= itblk
= later
= NULL
;
592 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
593 if (n
->flags
& NODE_ENDED
)
597 * Mismatching end macros can never break anything
598 * and we only care about the breaking of BLOCKs.
601 if (body
== NULL
|| n
->type
!= ROFFT_BLOCK
)
605 * SYNOPSIS name blocks can not be broken themselves,
606 * but they do get broken together with a broken child.
609 if (n
->tok
== MDOC_Nm
) {
611 n
->flags
|= NODE_BROKEN
| NODE_ENDED
;
615 if (n
->tok
== MDOC_It
) {
620 if (atok
== n
->tok
) {
623 * Found the start of our own block.
624 * When there is no pending sub block,
625 * just proceed to closing out.
629 (tok
== MDOC_El
&& itblk
== NULL
))
633 * When there is a pending sub block, postpone
634 * closing out the current block until the
635 * rew_pending() closing out the sub-block.
636 * Mark the place where the formatting - but not
637 * the scope - of the current block ends.
640 mandoc_msg(MANDOCERR_BLK_NEST
,
641 line
, ppos
, "%s breaks %s",
642 roff_name
[atok
], roff_name
[later
->tok
]);
644 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
648 itblk
->flags
|= NODE_ENDED
| NODE_BROKEN
;
651 * If a block closing macro taking arguments
652 * breaks another block, put the arguments
653 * into the end marker.
657 mdoc
->next
= ROFF_NEXT_CHILD
;
662 * Explicit blocks close out description lines, but
663 * even those can get broken together with a child.
666 if (n
->tok
== MDOC_Nd
) {
668 n
->flags
|= NODE_BROKEN
| NODE_ENDED
;
674 /* Breaking an open sub block. */
676 break_intermediate(mdoc
->last
, body
);
677 n
->flags
|= NODE_BROKEN
;
683 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, line
, ppos
,
684 "%s", roff_name
[tok
]);
685 if (maxargs
&& endbody
== NULL
) {
687 * Stray .Ec without previous .Eo:
688 * Break the output line, keep the arguments.
690 roff_elem_alloc(mdoc
, line
, ppos
, ROFF_br
);
691 rew_elem(mdoc
, ROFF_br
);
693 } else if (endbody
== NULL
) {
694 rew_last(mdoc
, body
);
696 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
699 if ((mdoc_macro(tok
)->flags
& MDOC_PARSED
) == 0) {
700 if (buf
[*pos
] != '\0')
701 mandoc_msg(MANDOCERR_ARG_SKIP
, line
, ppos
,
702 "%s %s", roff_name
[tok
], buf
+ *pos
);
703 if (endbody
== NULL
&& n
!= NULL
)
704 rew_pending(mdoc
, n
);
707 * Restore the fill mode that was set before the display.
708 * This needs to be done here rather than during validation
709 * such that subsequent nodes get the right flags.
712 if (tok
== MDOC_Ed
&& body
!= NULL
) {
713 if (body
->flags
& NODE_NOFILL
)
714 mdoc
->flags
|= ROFF_NOFILL
;
716 mdoc
->flags
&= ~ROFF_NOFILL
;
728 if (j
== maxargs
&& n
!= NULL
)
731 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
732 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
735 ntok
= lookup(mdoc
, tok
, line
, lastarg
, p
);
737 if (ntok
== TOKEN_NONE
) {
738 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
739 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
740 if (ac
== ARGS_ALLOC
)
744 if (ac
== ARGS_ALLOC
)
749 mdoc
->flags
&= ~MDOC_NEWLINE
;
750 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
756 if (ntok
!= TOKEN_NONE
&& n
->flags
& NODE_BROKEN
) {
759 target
= target
->parent
;
760 while ( ! (target
->flags
& NODE_ENDED
));
761 pending
= find_pending(mdoc
, ntok
, line
, ppos
, target
);
764 rew_pending(mdoc
, n
);
767 append_delims(mdoc
, line
, pos
, buf
);
771 in_line(MACRO_PROT_ARGS
)
773 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
777 struct mdoc_arg
*arg
;
780 nl
= MDOC_NEWLINE
& mdoc
->flags
;
783 * Whether we allow ignored elements (those without content,
784 * usually because of reserved words) to squeak by.
801 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
806 for (cnt
= scope
= 0;; ) {
808 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
811 * At the end of a macro line,
812 * opening delimiters do not suppress spacing.
815 if (ac
== ARGS_EOLN
) {
817 mdoc
->last
->flags
&= ~NODE_DELIMO
;
822 * The rest of the macro line is only punctuation,
823 * to be handled by append_delims().
824 * If there were no other arguments,
825 * do not allow the first one to suppress spacing,
826 * even if it turns out to be a closing one.
829 if (ac
== ARGS_PUNCT
) {
830 if (cnt
== 0 && (nc
== 0 || tok
== MDOC_An
))
831 mdoc
->flags
|= MDOC_NODELIMC
;
835 ntok
= (tok
== MDOC_Fn
&& !cnt
) ?
836 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
839 * In this case, we've located a submacro and must
840 * execute it. Close out scope, if open. If no
841 * elements have been generated, either create one (nc)
842 * or raise a warning.
845 if (ntok
!= TOKEN_NONE
) {
849 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
850 rew_last(mdoc
, mdoc
->last
);
851 } else if ( ! nc
&& ! cnt
) {
853 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
854 line
, ppos
, "%s", roff_name
[tok
]);
856 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
,
859 append_delims(mdoc
, line
, pos
, buf
);
860 if (ac
== ARGS_ALLOC
)
866 * Handle punctuation. Set up our scope, if a word;
867 * rewind the scope, if a delimiter; then append the word.
870 if ((d
= mdoc_isdelim(p
)) != DELIM_NONE
) {
872 * If we encounter closing punctuation, no word
873 * has been emitted, no scope is open, and we're
874 * allowed to have an empty element, then start
877 if ((d
== DELIM_CLOSE
||
878 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
879 !cnt
&& !scope
&& nc
&& mayopen
) {
880 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
887 * Close out our scope, if one is open, before
890 if (scope
&& tok
!= MDOC_Lk
) {
896 } else if (mayopen
&& !scope
) {
897 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
902 dword(mdoc
, line
, la
, p
, d
,
903 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
905 if (ac
== ARGS_ALLOC
)
909 * If the first argument is a closing delimiter,
910 * do not suppress spacing before it.
913 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
914 mdoc
->last
->flags
&= ~NODE_DELIMC
;
918 * `Fl' macros have their scope re-opened with each new
919 * word so that the `-' can be added to each one without
920 * having to parse out spaces.
922 if (scope
&& tok
== MDOC_Fl
) {
928 if (scope
&& tok
!= MDOC_Lk
) {
934 * If no elements have been collected and we're allowed to have
935 * empties (nc), open a scope and close it out. Otherwise,
941 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
942 rew_last(mdoc
, mdoc
->last
);
945 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
946 line
, ppos
, "%s", roff_name
[tok
]);
950 append_delims(mdoc
, line
, pos
, buf
);
956 blk_full(MACRO_PROT_ARGS
)
958 struct mdoc_arg
*arg
;
959 struct roff_node
*blk
; /* Our own or a broken block. */
960 struct roff_node
*head
; /* Our own head. */
961 struct roff_node
*body
; /* Our own body. */
965 int done
, la
, nl
, parsed
;
966 enum margserr ac
, lac
;
968 nl
= MDOC_NEWLINE
& mdoc
->flags
;
970 if (buf
[*pos
] == '\0' && (tok
== MDOC_Sh
|| tok
== MDOC_Ss
)) {
971 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
972 line
, ppos
, "%s", roff_name
[tok
]);
976 if ((mdoc_macro(tok
)->flags
& MDOC_EXPLICIT
) == 0) {
978 /* Here, tok is one of Sh Ss Nm Nd It. */
981 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
982 if (n
->flags
& NODE_ENDED
) {
983 if ( ! (n
->flags
& NODE_VALID
))
984 n
->flags
|= NODE_BROKEN
;
987 if (n
->type
!= ROFFT_BLOCK
)
990 if (tok
== MDOC_It
&& n
->tok
== MDOC_Bl
) {
992 mandoc_msg(MANDOCERR_BLK_BROKEN
,
993 line
, ppos
, "It breaks %s",
994 roff_name
[blk
->tok
]);
995 rew_pending(mdoc
, blk
);
1000 if (mdoc_macro(n
->tok
)->flags
& MDOC_EXPLICIT
) {
1004 mandoc_msg(MANDOCERR_BLK_BROKEN
,
1006 "%s breaks %s", roff_name
[tok
],
1008 rew_pending(mdoc
, n
);
1012 /* Delay in case it's astray. */
1021 /* Here, n is one of Sh Ss Nm Nd It. */
1023 if (tok
!= MDOC_Sh
&& (n
->tok
== MDOC_Sh
||
1024 (tok
!= MDOC_Ss
&& (n
->tok
== MDOC_Ss
||
1025 (tok
!= MDOC_It
&& n
->tok
== MDOC_It
)))))
1028 /* Item breaking an explicit block. */
1031 mandoc_msg(MANDOCERR_BLK_BROKEN
, line
, ppos
,
1032 "It breaks %s", roff_name
[blk
->tok
]);
1033 rew_pending(mdoc
, blk
);
1037 /* Close out prior implicit scopes. */
1039 rew_pending(mdoc
, n
);
1042 /* Skip items outside lists. */
1044 if (tok
== MDOC_It
&& (n
== NULL
|| n
->tok
!= MDOC_Bl
)) {
1045 mandoc_msg(MANDOCERR_IT_STRAY
,
1046 line
, ppos
, "It %s", buf
+ *pos
);
1047 roff_elem_alloc(mdoc
, line
, ppos
, ROFF_br
);
1048 rew_elem(mdoc
, ROFF_br
);
1054 * This routine accommodates implicitly- and explicitly-scoped
1055 * macro openings. Implicit ones first close out prior scope
1056 * (seen above). Delay opening the head until necessary to
1057 * allow leading punctuation to print. Special consideration
1058 * for `It -column', which has phrase-part syntax instead of
1059 * regular child nodes.
1064 mdoc
->flags
&= ~ROFF_NOFILL
;
1067 mdoc
->flags
|= ROFF_NONOFILL
;
1072 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1073 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
1077 * Exception: Heads of `It' macros in `-diag' lists are not
1078 * parsed, even though `It' macros in general are parsed.
1081 parsed
= tok
!= MDOC_It
||
1082 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
1083 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
1086 * The `Nd' macro has all arguments in its body: it's a hybrid
1087 * of block partial-explicit and full-implicit. Stupid.
1090 if (tok
== MDOC_Nd
) {
1091 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1092 rew_last(mdoc
, head
);
1093 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1097 mdoc
->flags
|= MDOC_KEEP
;
1103 * If we are right after a tab character,
1104 * do not parse the first word for macros.
1107 if (mdoc
->flags
& MDOC_PHRASEQN
) {
1108 mdoc
->flags
&= ~MDOC_PHRASEQN
;
1109 mdoc
->flags
|= MDOC_PHRASEQF
;
1114 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1115 if (ac
== ARGS_EOLN
) {
1116 if (lac
!= ARGS_PHRASE
||
1117 ! (mdoc
->flags
& MDOC_PHRASEQF
))
1121 * This line ends in a tab; start the next
1122 * column now, with a leading blank.
1126 rew_last(mdoc
, body
);
1127 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1128 roff_word_alloc(mdoc
, line
, ppos
, "\\&");
1132 if (tok
== MDOC_Bd
|| tok
== MDOC_Bk
) {
1133 mandoc_msg(MANDOCERR_ARG_EXCESS
, line
, la
,
1134 "%s ... %s", roff_name
[tok
], buf
+ la
);
1135 if (ac
== ARGS_ALLOC
)
1139 if (tok
== MDOC_Rs
) {
1140 mandoc_msg(MANDOCERR_ARG_SKIP
,
1141 line
, la
, "Rs %s", buf
+ la
);
1142 if (ac
== ARGS_ALLOC
)
1146 if (ac
== ARGS_PUNCT
)
1150 * Emit leading punctuation (i.e., punctuation before
1151 * the ROFFT_HEAD) for non-phrase types.
1155 ac
!= ARGS_PHRASE
&&
1156 mdoc_isdelim(p
) == DELIM_OPEN
) {
1157 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1158 if (ac
== ARGS_ALLOC
)
1163 /* Open a head if one hasn't been opened. */
1166 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1168 if (ac
== ARGS_PHRASE
) {
1171 * If we haven't opened a body yet, rewind the
1172 * head; if we have, rewind that instead.
1175 rew_last(mdoc
, body
== NULL
? head
: body
);
1176 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1178 /* Process to the tab or to the end of the line. */
1180 mdoc
->flags
|= MDOC_PHRASE
;
1181 parse_rest(mdoc
, TOKEN_NONE
, line
, &la
, buf
);
1182 mdoc
->flags
&= ~MDOC_PHRASE
;
1184 /* There may have been `Ta' macros. */
1186 while (body
->next
!= NULL
)
1191 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, parsed
);
1192 if (ac
== ARGS_ALLOC
)
1198 if (blk
->flags
& NODE_VALID
)
1201 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1202 if (nl
&& tok
!= MDOC_Bd
&& tok
!= MDOC_Bl
&& tok
!= MDOC_Rs
)
1203 append_delims(mdoc
, line
, pos
, buf
);
1206 if (find_pending(mdoc
, tok
, line
, ppos
, head
))
1209 /* Close out scopes to remain in a consistent state. */
1211 rew_last(mdoc
, head
);
1212 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1214 mdoc
->flags
&= ~ROFF_NONOFILL
;
1217 * Set up fill mode for display blocks.
1218 * This needs to be done here up front rather than during
1219 * validation such that child nodes get the right flags.
1222 if (tok
== MDOC_Bd
&& arg
!= NULL
) {
1223 for (iarg
= 0; iarg
< arg
->argc
; iarg
++) {
1224 switch (arg
->argv
[iarg
].arg
) {
1227 mdoc
->flags
|= ROFF_NOFILL
;
1232 mdoc
->flags
&= ~ROFF_NOFILL
;
1241 if (mdoc
->flags
& MDOC_FREECOL
) {
1242 rew_last(mdoc
, body
);
1243 rew_last(mdoc
, blk
);
1244 mdoc
->flags
&= ~MDOC_FREECOL
;
1249 blk_part_imp(MACRO_PROT_ARGS
)
1254 struct roff_node
*blk
; /* saved block context */
1255 struct roff_node
*body
; /* saved body context */
1256 struct roff_node
*n
;
1258 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1261 * A macro that spans to the end of the line. This is generally
1262 * (but not necessarily) called as the first macro. The block
1263 * has a head as the immediate child, which is always empty,
1264 * followed by zero or more opening punctuation nodes, then the
1265 * body (which may be empty, depending on the macro), then zero
1266 * or more closing punctuation nodes.
1269 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1270 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1273 * Open the body scope "on-demand", that is, after we've
1274 * processed all our the leading delimiters (open parenthesis,
1278 for (body
= NULL
; ; ) {
1280 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1281 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1284 if (body
== NULL
&& mdoc_isdelim(p
) == DELIM_OPEN
) {
1285 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1286 if (ac
== ARGS_ALLOC
)
1292 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1294 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, 1);
1295 if (ac
== ARGS_ALLOC
)
1301 body
= roff_body_alloc(mdoc
, line
, ppos
, tok
);
1303 if (find_pending(mdoc
, tok
, line
, ppos
, body
))
1306 rew_last(mdoc
, body
);
1308 append_delims(mdoc
, line
, pos
, buf
);
1309 rew_pending(mdoc
, blk
);
1311 /* Move trailing .Ns out of scope. */
1313 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1315 if (n
&& n
->tok
== MDOC_Ns
)
1316 roff_node_relink(mdoc
, n
);
1320 blk_part_exp(MACRO_PROT_ARGS
)
1324 struct roff_node
*head
; /* keep track of head */
1327 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1330 * The opening of an explicit macro having zero or more leading
1331 * punctuation nodes; a head with optional single element (the
1332 * case of `Eo'); and a body that may be empty.
1335 roff_block_alloc(mdoc
, line
, ppos
, tok
);
1339 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1340 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1343 /* Flush out leading punctuation. */
1345 if (head
== NULL
&& mdoc_isdelim(p
) == DELIM_OPEN
) {
1346 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1347 if (ac
== ARGS_ALLOC
)
1353 head
= roff_head_alloc(mdoc
, line
, ppos
, tok
);
1354 if (tok
== MDOC_Eo
) /* Not parsed. */
1355 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1356 rew_last(mdoc
, head
);
1357 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1358 if (tok
== MDOC_Eo
) {
1359 if (ac
== ARGS_ALLOC
)
1365 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, 1);
1366 if (ac
== ARGS_ALLOC
)
1372 /* Clean-up to leave in a consistent state. */
1375 rew_last(mdoc
, roff_head_alloc(mdoc
, line
, ppos
, tok
));
1376 roff_body_alloc(mdoc
, line
, ppos
, tok
);
1379 append_delims(mdoc
, line
, pos
, buf
);
1383 in_line_argn(MACRO_PROT_ARGS
)
1385 struct mdoc_arg
*arg
;
1389 int state
; /* arg#; -1: not yet open; -2: closed */
1390 int la
, maxargs
, nl
;
1392 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1395 * A line macro that has a fixed number of arguments (maxargs).
1396 * Only open the scope once the first non-leading-punctuation is
1397 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1398 * keep it open until the maximum number of arguments are
1418 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1424 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1426 if ((ac
== ARGS_WORD
|| ac
== ARGS_ALLOC
) && state
== -1 &&
1427 (mdoc_macro(tok
)->flags
& MDOC_IGNDELIM
) == 0 &&
1428 mdoc_isdelim(p
) == DELIM_OPEN
) {
1429 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1430 if (ac
== ARGS_ALLOC
)
1435 if (state
== -1 && tok
!= MDOC_In
&&
1436 tok
!= MDOC_St
&& tok
!= MDOC_Xr
) {
1437 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1441 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1442 if (abs(state
) < 2 && tok
== MDOC_Pf
)
1443 mandoc_msg(MANDOCERR_PF_SKIP
,
1444 line
, ppos
, "Pf %s",
1445 p
== NULL
? "at eol" : p
);
1449 if (state
== maxargs
) {
1450 rew_elem(mdoc
, tok
);
1454 ntok
= (tok
== MDOC_Pf
&& state
== 0) ?
1455 TOKEN_NONE
: lookup(mdoc
, tok
, line
, la
, p
);
1457 if (ntok
!= TOKEN_NONE
) {
1459 rew_elem(mdoc
, tok
);
1462 (*mdoc_macro(ntok
)->fp
)(mdoc
, ntok
,
1463 line
, la
, pos
, buf
);
1464 if (ac
== ARGS_ALLOC
)
1469 if (mdoc_macro(tok
)->flags
& MDOC_IGNDELIM
||
1470 mdoc_isdelim(p
) == DELIM_NONE
) {
1472 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1474 } else if (state
>= 0)
1476 } else if (state
>= 0) {
1477 rew_elem(mdoc
, tok
);
1481 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1482 mdoc_macro(tok
)->flags
& MDOC_JOIN
);
1483 if (ac
== ARGS_ALLOC
)
1485 p
= mdoc
->last
->string
;
1489 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
1490 line
, ppos
, "%s", roff_name
[tok
]);
1494 if (state
== 0 && tok
== MDOC_Pf
)
1495 append_delims(mdoc
, line
, pos
, buf
);
1497 rew_elem(mdoc
, tok
);
1499 append_delims(mdoc
, line
, pos
, buf
);
1503 in_line_eoln(MACRO_PROT_ARGS
)
1505 struct roff_node
*n
;
1506 struct mdoc_arg
*arg
;
1508 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1509 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1511 if (mdoc
->next
== ROFF_NEXT_SIBLING
)
1513 if (n
->tok
== MDOC_Nm
)
1514 rew_last(mdoc
, n
->parent
);
1519 mandoc_dbg_name(buf
);
1522 if (buf
[*pos
] == '\0' &&
1523 (tok
== MDOC_Fd
|| *roff_name
[tok
] == '%')) {
1524 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
1525 line
, ppos
, "%s", roff_name
[tok
]);
1529 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1530 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1531 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1533 rew_elem(mdoc
, tok
);
1537 * The simplest argument parser available: Parse the remaining
1538 * words until the end of the phrase or line and return 0
1539 * or until the next macro, call that macro, and return 1.
1542 parse_rest(struct roff_man
*mdoc
, enum roff_tok tok
,
1543 int line
, int *pos
, char *buf
)
1551 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1552 if (ac
== ARGS_EOLN
)
1554 done
= macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, p
, 1);
1555 if (ac
== ARGS_ALLOC
)
1563 ctx_synopsis(MACRO_PROT_ARGS
)
1566 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1567 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1568 else if (tok
== MDOC_Nm
)
1569 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1571 assert(tok
== MDOC_Vt
);
1572 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1577 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1578 * They're unusual because they're basically free-form text until a
1579 * macro is encountered.
1582 phrase_ta(MACRO_PROT_ARGS
)
1584 struct roff_node
*body
, *n
;
1586 /* Make sure we are in a column list or ignore this macro. */
1589 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1590 if (n
->flags
& NODE_ENDED
)
1592 if (n
->tok
== MDOC_It
&& n
->type
== ROFFT_BODY
)
1594 if (n
->tok
== MDOC_Bl
&& n
->end
== ENDBODY_NOT
)
1598 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1599 mandoc_msg(MANDOCERR_TA_STRAY
, line
, ppos
, "Ta");
1603 /* Advance to the next column. */
1605 rew_last(mdoc
, body
);
1606 roff_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1607 parse_rest(mdoc
, TOKEN_NONE
, line
, pos
, buf
);