]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_validate.c
4bc9d861885602cc695631f0b4a7473dd3ad9244
1 /* $Id: mdoc_validate.c,v 1.130 2010/11/30 10:32:05 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
32 #include "libmandoc.h"
34 /* FIXME: .Bl -diag can't have non-text children in HEAD. */
36 #define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n
37 #define POST_ARGS struct mdoc *mdoc
51 typedef int (*v_pre
)(PRE_ARGS
);
52 typedef int (*v_post
)(POST_ARGS
);
59 static int check_count(struct mdoc
*, enum mdoc_type
,
60 enum check_lvl
, enum check_ineq
, int);
61 static int check_parent(PRE_ARGS
, enum mdoct
, enum mdoc_type
);
62 static int check_stdarg(PRE_ARGS
);
63 static int check_text(struct mdoc
*, int, int, char *);
64 static int check_argv(struct mdoc
*,
65 struct mdoc_node
*, struct mdoc_argv
*);
66 static int check_args(struct mdoc
*, struct mdoc_node
*);
68 static int ebool(POST_ARGS
);
69 static int berr_ge1(POST_ARGS
);
70 static int bwarn_ge1(POST_ARGS
);
71 static int eerr_eq0(POST_ARGS
);
72 static int eerr_eq1(POST_ARGS
);
73 static int eerr_ge1(POST_ARGS
);
74 static int eerr_le1(POST_ARGS
);
75 static int ewarn_eq0(POST_ARGS
);
76 static int ewarn_ge1(POST_ARGS
);
77 static int herr_eq0(POST_ARGS
);
78 static int herr_ge1(POST_ARGS
);
79 static int hwarn_eq0(POST_ARGS
);
80 static int hwarn_eq1(POST_ARGS
);
81 static int hwarn_le1(POST_ARGS
);
83 static int post_an(POST_ARGS
);
84 static int post_at(POST_ARGS
);
85 static int post_bf(POST_ARGS
);
86 static int post_bl(POST_ARGS
);
87 static int post_bl_head(POST_ARGS
);
88 static int post_defaults(POST_ARGS
);
89 static int post_literal(POST_ARGS
);
90 static int post_eoln(POST_ARGS
);
91 static int post_dt(POST_ARGS
);
92 static int post_it(POST_ARGS
);
93 static int post_lb(POST_ARGS
);
94 static int post_nm(POST_ARGS
);
95 static int post_root(POST_ARGS
);
96 static int post_rs(POST_ARGS
);
97 static int post_sh(POST_ARGS
);
98 static int post_sh_body(POST_ARGS
);
99 static int post_sh_head(POST_ARGS
);
100 static int post_st(POST_ARGS
);
101 static int post_vt(POST_ARGS
);
102 static int pre_an(PRE_ARGS
);
103 static int pre_bd(PRE_ARGS
);
104 static int pre_bl(PRE_ARGS
);
105 static int pre_dd(PRE_ARGS
);
106 static int pre_display(PRE_ARGS
);
107 static int pre_dt(PRE_ARGS
);
108 static int pre_it(PRE_ARGS
);
109 static int pre_literal(PRE_ARGS
);
110 static int pre_os(PRE_ARGS
);
111 static int pre_par(PRE_ARGS
);
112 static int pre_rv(PRE_ARGS
);
113 static int pre_sh(PRE_ARGS
);
114 static int pre_ss(PRE_ARGS
);
116 static v_post posts_an
[] = { post_an
, NULL
};
117 static v_post posts_at
[] = { post_at
, post_defaults
, NULL
};
118 static v_post posts_bd
[] = { post_literal
, hwarn_eq0
, bwarn_ge1
, NULL
};
119 static v_post posts_bf
[] = { hwarn_le1
, post_bf
, NULL
};
120 static v_post posts_bk
[] = { hwarn_eq0
, bwarn_ge1
, NULL
};
121 static v_post posts_bl
[] = { bwarn_ge1
, post_bl
, NULL
};
122 static v_post posts_bool
[] = { eerr_eq1
, ebool
, NULL
};
123 static v_post posts_eoln
[] = { post_eoln
, NULL
};
124 static v_post posts_defaults
[] = { post_defaults
, NULL
};
125 static v_post posts_dl
[] = { post_literal
, bwarn_ge1
, herr_eq0
, NULL
};
126 static v_post posts_dt
[] = { post_dt
, NULL
};
127 static v_post posts_fo
[] = { hwarn_eq1
, bwarn_ge1
, NULL
};
128 static v_post posts_it
[] = { post_it
, NULL
};
129 static v_post posts_lb
[] = { eerr_eq1
, post_lb
, NULL
};
130 static v_post posts_nd
[] = { berr_ge1
, NULL
};
131 static v_post posts_nm
[] = { post_nm
, NULL
};
132 static v_post posts_notext
[] = { ewarn_eq0
, NULL
};
133 static v_post posts_rs
[] = { berr_ge1
, herr_eq0
, post_rs
, NULL
};
134 static v_post posts_sh
[] = { herr_ge1
, bwarn_ge1
, post_sh
, NULL
};
135 static v_post posts_sp
[] = { eerr_le1
, NULL
};
136 static v_post posts_ss
[] = { herr_ge1
, NULL
};
137 static v_post posts_st
[] = { eerr_eq1
, post_st
, NULL
};
138 static v_post posts_text
[] = { eerr_ge1
, NULL
};
139 static v_post posts_text1
[] = { eerr_eq1
, NULL
};
140 static v_post posts_vt
[] = { post_vt
, NULL
};
141 static v_post posts_wline
[] = { bwarn_ge1
, herr_eq0
, NULL
};
142 static v_post posts_wtext
[] = { ewarn_ge1
, NULL
};
143 static v_pre pres_an
[] = { pre_an
, NULL
};
144 static v_pre pres_bd
[] = { pre_display
, pre_bd
, pre_literal
, pre_par
, NULL
};
145 static v_pre pres_bl
[] = { pre_bl
, pre_par
, NULL
};
146 static v_pre pres_d1
[] = { pre_display
, NULL
};
147 static v_pre pres_dl
[] = { pre_literal
, pre_display
, NULL
};
148 static v_pre pres_dd
[] = { pre_dd
, NULL
};
149 static v_pre pres_dt
[] = { pre_dt
, NULL
};
150 static v_pre pres_er
[] = { NULL
, NULL
};
151 static v_pre pres_ex
[] = { NULL
, NULL
};
152 static v_pre pres_fd
[] = { NULL
, NULL
};
153 static v_pre pres_it
[] = { pre_it
, NULL
};
154 static v_pre pres_os
[] = { pre_os
, NULL
};
155 static v_pre pres_pp
[] = { pre_par
, NULL
};
156 static v_pre pres_rv
[] = { pre_rv
, NULL
};
157 static v_pre pres_sh
[] = { pre_sh
, NULL
};
158 static v_pre pres_ss
[] = { pre_ss
, NULL
};
160 const struct valids mdoc_valids
[MDOC_MAX
] = {
161 { NULL
, NULL
}, /* Ap */
162 { pres_dd
, posts_wtext
}, /* Dd */
163 { pres_dt
, posts_dt
}, /* Dt */
164 { pres_os
, NULL
}, /* Os */
165 { pres_sh
, posts_sh
}, /* Sh */
166 { pres_ss
, posts_ss
}, /* Ss */
167 { pres_pp
, posts_notext
}, /* Pp */
168 { pres_d1
, posts_wline
}, /* D1 */
169 { pres_dl
, posts_dl
}, /* Dl */
170 { pres_bd
, posts_bd
}, /* Bd */
171 { NULL
, NULL
}, /* Ed */
172 { pres_bl
, posts_bl
}, /* Bl */
173 { NULL
, NULL
}, /* El */
174 { pres_it
, posts_it
}, /* It */
175 { NULL
, posts_text
}, /* Ad */
176 { pres_an
, posts_an
}, /* An */
177 { NULL
, posts_defaults
}, /* Ar */
178 { NULL
, posts_text
}, /* Cd */
179 { NULL
, NULL
}, /* Cm */
180 { NULL
, NULL
}, /* Dv */
181 { pres_er
, posts_text
}, /* Er */
182 { NULL
, NULL
}, /* Ev */
183 { pres_ex
, NULL
}, /* Ex */
184 { NULL
, NULL
}, /* Fa */
185 { pres_fd
, posts_wtext
}, /* Fd */
186 { NULL
, NULL
}, /* Fl */
187 { NULL
, posts_text
}, /* Fn */
188 { NULL
, posts_wtext
}, /* Ft */
189 { NULL
, posts_text
}, /* Ic */
190 { NULL
, posts_text1
}, /* In */
191 { NULL
, posts_defaults
}, /* Li */
192 { NULL
, posts_nd
}, /* Nd */
193 { NULL
, posts_nm
}, /* Nm */
194 { NULL
, posts_wline
}, /* Op */
195 { NULL
, NULL
}, /* Ot */
196 { NULL
, posts_defaults
}, /* Pa */
197 { pres_rv
, NULL
}, /* Rv */
198 { NULL
, posts_st
}, /* St */
199 { NULL
, NULL
}, /* Va */
200 { NULL
, posts_vt
}, /* Vt */
201 { NULL
, posts_wtext
}, /* Xr */
202 { NULL
, posts_text
}, /* %A */
203 { NULL
, posts_text
}, /* %B */ /* FIXME: can be used outside Rs/Re. */
204 { NULL
, posts_text
}, /* %D */ /* FIXME: check date with mandoc_a2time(). */
205 { NULL
, posts_text
}, /* %I */
206 { NULL
, posts_text
}, /* %J */
207 { NULL
, posts_text
}, /* %N */
208 { NULL
, posts_text
}, /* %O */
209 { NULL
, posts_text
}, /* %P */
210 { NULL
, posts_text
}, /* %R */
211 { NULL
, posts_text
}, /* %T */ /* FIXME: can be used outside Rs/Re. */
212 { NULL
, posts_text
}, /* %V */
213 { NULL
, NULL
}, /* Ac */
214 { NULL
, NULL
}, /* Ao */
215 { NULL
, posts_wline
}, /* Aq */
216 { NULL
, posts_at
}, /* At */
217 { NULL
, NULL
}, /* Bc */
218 { NULL
, posts_bf
}, /* Bf */
219 { NULL
, NULL
}, /* Bo */
220 { NULL
, posts_wline
}, /* Bq */
221 { NULL
, NULL
}, /* Bsx */
222 { NULL
, NULL
}, /* Bx */
223 { NULL
, posts_bool
}, /* Db */
224 { NULL
, NULL
}, /* Dc */
225 { NULL
, NULL
}, /* Do */
226 { NULL
, posts_wline
}, /* Dq */
227 { NULL
, NULL
}, /* Ec */
228 { NULL
, NULL
}, /* Ef */
229 { NULL
, NULL
}, /* Em */
230 { NULL
, NULL
}, /* Eo */
231 { NULL
, NULL
}, /* Fx */
232 { NULL
, posts_text
}, /* Ms */
233 { NULL
, posts_notext
}, /* No */
234 { NULL
, posts_notext
}, /* Ns */
235 { NULL
, NULL
}, /* Nx */
236 { NULL
, NULL
}, /* Ox */
237 { NULL
, NULL
}, /* Pc */
238 { NULL
, posts_text1
}, /* Pf */
239 { NULL
, NULL
}, /* Po */
240 { NULL
, posts_wline
}, /* Pq */
241 { NULL
, NULL
}, /* Qc */
242 { NULL
, posts_wline
}, /* Ql */
243 { NULL
, NULL
}, /* Qo */
244 { NULL
, posts_wline
}, /* Qq */
245 { NULL
, NULL
}, /* Re */
246 { NULL
, posts_rs
}, /* Rs */
247 { NULL
, NULL
}, /* Sc */
248 { NULL
, NULL
}, /* So */
249 { NULL
, posts_wline
}, /* Sq */
250 { NULL
, posts_bool
}, /* Sm */
251 { NULL
, posts_text
}, /* Sx */
252 { NULL
, posts_text
}, /* Sy */
253 { NULL
, posts_text
}, /* Tn */
254 { NULL
, NULL
}, /* Ux */
255 { NULL
, NULL
}, /* Xc */
256 { NULL
, NULL
}, /* Xo */
257 { NULL
, posts_fo
}, /* Fo */
258 { NULL
, NULL
}, /* Fc */
259 { NULL
, NULL
}, /* Oo */
260 { NULL
, NULL
}, /* Oc */
261 { NULL
, posts_bk
}, /* Bk */
262 { NULL
, NULL
}, /* Ek */
263 { NULL
, posts_eoln
}, /* Bt */
264 { NULL
, NULL
}, /* Hf */
265 { NULL
, NULL
}, /* Fr */
266 { NULL
, posts_eoln
}, /* Ud */
267 { NULL
, posts_lb
}, /* Lb */
268 { NULL
, posts_notext
}, /* Lp */
269 { NULL
, posts_text
}, /* Lk */
270 { NULL
, posts_defaults
}, /* Mt */
271 { NULL
, posts_wline
}, /* Brq */
272 { NULL
, NULL
}, /* Bro */
273 { NULL
, NULL
}, /* Brc */
274 { NULL
, posts_text
}, /* %C */
275 { NULL
, NULL
}, /* Es */
276 { NULL
, NULL
}, /* En */
277 { NULL
, NULL
}, /* Dx */
278 { NULL
, posts_text
}, /* %Q */
279 { NULL
, posts_notext
}, /* br */
280 { pres_pp
, posts_sp
}, /* sp */
281 { NULL
, posts_text1
}, /* %U */
282 { NULL
, NULL
}, /* Ta */
285 #define RSORD_MAX 14 /* Number of `Rs' blocks. */
287 static const enum mdoct rsord
[RSORD_MAX
] = {
306 mdoc_valid_pre(struct mdoc
*mdoc
, struct mdoc_node
*n
)
312 if (MDOC_TEXT
== n
->type
) {
316 return(check_text(mdoc
, line
, pos
, tp
));
319 if ( ! check_args(mdoc
, n
))
321 if (NULL
== mdoc_valids
[n
->tok
].pre
)
323 for (p
= mdoc_valids
[n
->tok
].pre
; *p
; p
++)
324 if ( ! (*p
)(mdoc
, n
))
331 mdoc_valid_post(struct mdoc
*mdoc
)
335 if (MDOC_VALID
& mdoc
->last
->flags
)
337 mdoc
->last
->flags
|= MDOC_VALID
;
339 if (MDOC_TEXT
== mdoc
->last
->type
)
341 if (MDOC_ROOT
== mdoc
->last
->type
)
342 return(post_root(mdoc
));
344 if (NULL
== mdoc_valids
[mdoc
->last
->tok
].post
)
346 for (p
= mdoc_valids
[mdoc
->last
->tok
].post
; *p
; p
++)
354 check_count(struct mdoc
*m
, enum mdoc_type type
,
355 enum check_lvl lvl
, enum check_ineq ineq
, int val
)
359 if (m
->last
->type
!= type
)
365 if (m
->last
->nchild
< val
)
370 if (m
->last
->nchild
> val
)
375 if (val
== m
->last
->nchild
)
380 if (CHECK_WARN
== lvl
) {
381 return(mdoc_vmsg(m
, MANDOCERR_ARGCOUNT
,
382 m
->last
->line
, m
->last
->pos
,
383 "want %s%d children (have %d)",
384 p
, val
, m
->last
->nchild
));
387 return(mdoc_vmsg(m
, MANDOCERR_ARGCOUNT
,
388 m
->last
->line
, m
->last
->pos
,
389 "require %s%d children (have %d)",
390 p
, val
, m
->last
->nchild
));
397 return(check_count(mdoc
, MDOC_BODY
, CHECK_FATAL
, CHECK_GT
, 0));
403 return(check_count(mdoc
, MDOC_BODY
, CHECK_WARN
, CHECK_GT
, 0));
409 return(check_count(mdoc
, MDOC_ELEM
, CHECK_FATAL
, CHECK_EQ
, 0));
415 return(check_count(mdoc
, MDOC_ELEM
, CHECK_FATAL
, CHECK_EQ
, 1));
421 return(check_count(mdoc
, MDOC_ELEM
, CHECK_FATAL
, CHECK_GT
, 0));
427 return(check_count(mdoc
, MDOC_ELEM
, CHECK_FATAL
, CHECK_LT
, 2));
433 return(check_count(mdoc
, MDOC_ELEM
, CHECK_WARN
, CHECK_EQ
, 0));
439 return(check_count(mdoc
, MDOC_ELEM
, CHECK_WARN
, CHECK_GT
, 0));
445 return(check_count(mdoc
, MDOC_HEAD
, CHECK_FATAL
, CHECK_EQ
, 0));
451 return(check_count(mdoc
, MDOC_HEAD
, CHECK_FATAL
, CHECK_GT
, 0));
457 return(check_count(mdoc
, MDOC_HEAD
, CHECK_WARN
, CHECK_EQ
, 0));
463 return(check_count(mdoc
, MDOC_HEAD
, CHECK_WARN
, CHECK_EQ
, 1));
469 return(check_count(mdoc
, MDOC_HEAD
, CHECK_WARN
, CHECK_LT
, 2));
474 check_stdarg(PRE_ARGS
)
477 if (n
->args
&& 1 == n
->args
->argc
)
478 if (MDOC_Std
== n
->args
->argv
[0].arg
)
480 return(mdoc_nmsg(mdoc
, n
, MANDOCERR_NOARGV
));
485 check_args(struct mdoc
*m
, struct mdoc_node
*n
)
492 assert(n
->args
->argc
);
493 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
494 if ( ! check_argv(m
, n
, &n
->args
->argv
[i
]))
502 check_argv(struct mdoc
*m
, struct mdoc_node
*n
, struct mdoc_argv
*v
)
506 for (i
= 0; i
< (int)v
->sz
; i
++)
507 if ( ! check_text(m
, v
->line
, v
->pos
, v
->value
[i
]))
510 if (MDOC_Std
== v
->arg
) {
511 if (v
->sz
|| m
->meta
.name
)
513 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_NONAME
))
522 check_text(struct mdoc
*m
, int ln
, int pos
, char *p
)
527 for ( ; *p
; p
++, pos
++) {
528 sz
= strcspn(p
, "\t\\");
537 if (MDOC_LITERAL
& m
->flags
)
539 if (mdoc_pmsg(m
, ln
, pos
, MANDOCERR_BADTAB
))
544 /* Check the special character. */
546 c
= mandoc_special(p
);
551 mdoc_pmsg(m
, ln
, pos
, MANDOCERR_BADESCAPE
);
559 check_parent(PRE_ARGS
, enum mdoct tok
, enum mdoc_type t
)
563 if ((MDOC_ROOT
== t
|| tok
== n
->parent
->tok
) &&
564 (t
== n
->parent
->type
))
567 mdoc_vmsg(mdoc
, MANDOCERR_SYNTCHILD
,
568 n
->line
, n
->pos
, "want parent %s",
569 MDOC_ROOT
== t
? "<root>" :
570 mdoc_macronames
[tok
]);
576 pre_display(PRE_ARGS
)
578 struct mdoc_node
*node
;
580 /* Display elements (`Bd', `D1'...) cannot be nested. */
582 if (MDOC_BLOCK
!= n
->type
)
586 for (node
= mdoc
->last
->parent
; node
; node
= node
->parent
)
587 if (MDOC_BLOCK
== node
->type
)
588 if (MDOC_Bd
== node
->tok
)
594 mdoc_nmsg(mdoc
, n
, MANDOCERR_NESTEDDISP
);
603 const char *offs
, *width
;
605 struct mdoc_node
*np
;
607 if (MDOC_BLOCK
!= n
->type
) {
608 if (ENDBODY_NOT
!= n
->end
) {
610 np
= n
->pending
->parent
;
615 assert(MDOC_BLOCK
== np
->type
);
616 assert(MDOC_Bl
== np
->tok
);
618 n
->data
.Bl
= np
->data
.Bl
;
623 * First figure out which kind of list to use: bind ourselves to
624 * the first mentioned list type and warn about any remaining
625 * ones. If we find no list type, we default to LIST_item.
628 assert(NULL
== n
->data
.Bl
);
629 n
->data
.Bl
= mandoc_calloc(1, sizeof(struct mdoc_bl
));
632 for (i
= 0; n
->args
&& i
< (int)n
->args
->argc
; i
++) {
636 switch (n
->args
->argv
[i
].arg
) {
637 /* Set list types. */
671 /* Set list arguments. */
673 dup
= n
->data
.Bl
->comp
;
677 dup
= (NULL
!= n
->data
.Bl
->width
);
678 width
= n
->args
->argv
[i
].value
[0];
681 /* NB: this can be empty! */
682 if (n
->args
->argv
[i
].sz
) {
683 offs
= n
->args
->argv
[i
].value
[0];
684 dup
= (NULL
!= n
->data
.Bl
->offs
);
687 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_IGNARGV
))
694 /* Check: duplicate auxiliary arguments. */
696 if (dup
&& ! mdoc_nmsg(mdoc
, n
, MANDOCERR_ARGVREP
))
700 n
->data
.Bl
->comp
= comp
;
702 n
->data
.Bl
->offs
= offs
;
704 n
->data
.Bl
->width
= width
;
706 /* Check: multiple list types. */
708 if (LIST__NONE
!= lt
&& n
->data
.Bl
->type
!= LIST__NONE
)
709 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_LISTREP
))
712 /* Assign list type. */
714 if (LIST__NONE
!= lt
&& n
->data
.Bl
->type
== LIST__NONE
) {
715 n
->data
.Bl
->type
= lt
;
716 /* Set column information, too. */
717 if (LIST_column
== lt
) {
720 n
->data
.Bl
->cols
= (const char **)
721 n
->args
->argv
[i
].value
;
725 /* The list type should come first. */
727 if (n
->data
.Bl
->type
== LIST__NONE
)
728 if (n
->data
.Bl
->width
||
731 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_LISTFIRST
))
737 /* Allow lists to default to LIST_item. */
739 if (LIST__NONE
== n
->data
.Bl
->type
) {
740 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_LISTTYPE
))
742 n
->data
.Bl
->type
= LIST_item
;
746 * Validate the width field. Some list types don't need width
747 * types and should be warned about them. Others should have it
748 * and must also be warned.
751 switch (n
->data
.Bl
->type
) {
753 if (n
->data
.Bl
->width
)
755 if (mdoc_nmsg(mdoc
, n
, MANDOCERR_NOWIDTHARG
))
767 if (NULL
== n
->data
.Bl
->width
)
769 if (mdoc_nmsg(mdoc
, n
, MANDOCERR_WIDTHARG
))
786 struct mdoc_node
*np
;
788 if (MDOC_BLOCK
!= n
->type
) {
789 if (ENDBODY_NOT
!= n
->end
) {
791 np
= n
->pending
->parent
;
796 assert(MDOC_BLOCK
== np
->type
);
797 assert(MDOC_Bd
== np
->tok
);
799 n
->data
.Bd
= np
->data
.Bd
;
803 assert(NULL
== n
->data
.Bd
);
804 n
->data
.Bd
= mandoc_calloc(1, sizeof(struct mdoc_bd
));
807 for (i
= 0; n
->args
&& i
< (int)n
->args
->argc
; i
++) {
812 switch (n
->args
->argv
[i
].arg
) {
819 case (MDOC_Unfilled
):
829 mdoc_nmsg(mdoc
, n
, MANDOCERR_BADDISP
);
832 /* NB: this can be empty! */
833 if (n
->args
->argv
[i
].sz
) {
834 offs
= n
->args
->argv
[i
].value
[0];
835 dup
= (NULL
!= n
->data
.Bd
->offs
);
838 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_IGNARGV
))
843 dup
= n
->data
.Bd
->comp
;
850 /* Check whether we have duplicates. */
852 if (dup
&& ! mdoc_nmsg(mdoc
, n
, MANDOCERR_ARGVREP
))
855 /* Make our auxiliary assignments. */
858 n
->data
.Bd
->offs
= offs
;
860 n
->data
.Bd
->comp
= comp
;
862 /* Check whether a type has already been assigned. */
864 if (DISP__NONE
!= dt
&& n
->data
.Bd
->type
!= DISP__NONE
)
865 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_DISPREP
))
868 /* Make our type assignment. */
870 if (DISP__NONE
!= dt
&& n
->data
.Bd
->type
== DISP__NONE
)
871 n
->data
.Bd
->type
= dt
;
874 if (DISP__NONE
== n
->data
.Bd
->type
) {
875 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_DISPTYPE
))
877 n
->data
.Bd
->type
= DISP_ragged
;
888 if (MDOC_BLOCK
!= n
->type
)
890 return(check_parent(mdoc
, n
, MDOC_Sh
, MDOC_BODY
));
898 if (MDOC_BLOCK
!= n
->type
)
901 mdoc
->regs
->regs
[(int)REG_nS
].set
= 0;
902 return(check_parent(mdoc
, n
, MDOC_MAX
, MDOC_ROOT
));
910 if (MDOC_BLOCK
!= n
->type
)
913 * FIXME: this can probably be lifted if we make the It into
914 * something else on-the-fly?
916 return(check_parent(mdoc
, n
, MDOC_Bl
, MDOC_BODY
));
928 for (i
= 1; i
< (int)n
->args
->argc
; i
++)
929 if ( ! mdoc_pmsg(mdoc
, n
->args
->argv
[i
].line
,
930 n
->args
->argv
[i
].pos
, MANDOCERR_IGNARGV
))
933 if (MDOC_Split
== n
->args
->argv
[0].arg
)
934 n
->data
.An
.auth
= AUTH_split
;
935 else if (MDOC_Nosplit
== n
->args
->argv
[0].arg
)
936 n
->data
.An
.auth
= AUTH_nosplit
;
948 return(check_stdarg(mdoc
, n
));
955 const struct mdoc_node
*nn
;
958 if (NULL
!= (nn
= mdoc
->last
->child
))
959 for (p
= nn
->string
; *p
; p
++) {
960 if (toupper((u_char
)*p
) == *p
)
962 if ( ! mdoc_nmsg(mdoc
, nn
, MANDOCERR_UPPERCASE
))
975 if (0 == mdoc
->meta
.date
|| mdoc
->meta
.os
)
976 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_PROLOGOOO
))
978 if (mdoc
->meta
.title
)
979 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_PROLOGREP
))
989 if (NULL
== mdoc
->meta
.title
|| 0 == mdoc
->meta
.date
)
990 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_PROLOGOOO
))
993 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_PROLOGREP
))
1003 if (mdoc
->meta
.title
|| mdoc
->meta
.os
)
1004 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_PROLOGOOO
))
1006 if (mdoc
->meta
.date
)
1007 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_PROLOGREP
))
1016 struct mdoc_node
*np
;
1020 * Unlike other data pointers, these are "housed" by the HEAD
1021 * element, which contains the goods.
1024 if (MDOC_HEAD
!= mdoc
->last
->type
) {
1025 if (ENDBODY_NOT
!= mdoc
->last
->end
) {
1026 assert(mdoc
->last
->pending
);
1027 np
= mdoc
->last
->pending
->parent
->head
;
1028 } else if (MDOC_BLOCK
!= mdoc
->last
->type
) {
1029 np
= mdoc
->last
->parent
->head
;
1031 np
= mdoc
->last
->head
;
1034 assert(MDOC_HEAD
== np
->type
);
1035 assert(MDOC_Bf
== np
->tok
);
1036 assert(np
->data
.Bf
);
1037 mdoc
->last
->data
.Bf
= np
->data
.Bf
;
1042 assert(MDOC_BLOCK
== np
->parent
->type
);
1043 assert(MDOC_Bf
== np
->parent
->tok
);
1044 np
->data
.Bf
= mandoc_calloc(1, sizeof(struct mdoc_bf
));
1047 * Cannot have both argument and parameter.
1048 * If neither is specified, let it through with a warning.
1051 if (np
->parent
->args
&& np
->child
) {
1052 mdoc_nmsg(mdoc
, np
, MANDOCERR_SYNTARGVCOUNT
);
1054 } else if (NULL
== np
->parent
->args
&& NULL
== np
->child
)
1055 return(mdoc_nmsg(mdoc
, np
, MANDOCERR_FONTTYPE
));
1057 /* Extract argument into data. */
1059 if (np
->parent
->args
) {
1060 arg
= np
->parent
->args
->argv
[0].arg
;
1061 if (MDOC_Emphasis
== arg
)
1062 np
->data
.Bf
->font
= FONT_Em
;
1063 else if (MDOC_Literal
== arg
)
1064 np
->data
.Bf
->font
= FONT_Li
;
1065 else if (MDOC_Symbolic
== arg
)
1066 np
->data
.Bf
->font
= FONT_Sy
;
1072 /* Extract parameter into data. */
1074 if (0 == strcmp(np
->child
->string
, "Em"))
1075 np
->data
.Bf
->font
= FONT_Em
;
1076 else if (0 == strcmp(np
->child
->string
, "Li"))
1077 np
->data
.Bf
->font
= FONT_Li
;
1078 else if (0 == strcmp(np
->child
->string
, "Sy"))
1079 np
->data
.Bf
->font
= FONT_Sy
;
1080 else if ( ! mdoc_nmsg(mdoc
, np
, MANDOCERR_FONTTYPE
))
1093 assert(mdoc
->last
->child
);
1094 assert(MDOC_TEXT
== mdoc
->last
->child
->type
);
1096 p
= mdoc_a2lib(mdoc
->last
->child
->string
);
1098 /* If lookup ok, replace with table value. */
1101 free(mdoc
->last
->child
->string
);
1102 mdoc
->last
->child
->string
= mandoc_strdup(p
);
1106 /* If not, use "library ``xxxx''. */
1108 sz
= strlen(mdoc
->last
->child
->string
) +
1109 2 + strlen("\\(lqlibrary\\(rq");
1110 buf
= mandoc_malloc(sz
);
1111 snprintf(buf
, sz
, "library \\(lq%s\\(rq",
1112 mdoc
->last
->child
->string
);
1113 free(mdoc
->last
->child
->string
);
1114 mdoc
->last
->child
->string
= buf
;
1119 post_eoln(POST_ARGS
)
1122 if (NULL
== mdoc
->last
->child
)
1124 return(mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_ARGSLOST
));
1131 const struct mdoc_node
*n
;
1134 * The Vt macro comes in both ELEM and BLOCK form, both of which
1135 * have different syntaxes (yet more context-sensitive
1136 * behaviour). ELEM types must have a child; BLOCK types,
1137 * specifically the BODY, should only have TEXT children.
1140 if (MDOC_ELEM
== mdoc
->last
->type
)
1141 return(eerr_ge1(mdoc
));
1142 if (MDOC_BODY
!= mdoc
->last
->type
)
1145 for (n
= mdoc
->last
->child
; n
; n
= n
->next
)
1146 if (MDOC_TEXT
!= n
->type
)
1147 if ( ! mdoc_nmsg(mdoc
, n
, MANDOCERR_CHILD
))
1157 struct mdoc_node
*nn
;
1160 /* If no child specified, make sure we have the meta name. */
1162 if (NULL
== mdoc
->last
->child
&& NULL
== mdoc
->meta
.name
) {
1163 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_NONAME
);
1165 } else if (mdoc
->meta
.name
)
1168 /* If no meta name, set it from the child. */
1172 for (nn
= mdoc
->last
->child
; nn
; nn
= nn
->next
) {
1173 /* XXX - copied from concat(). */
1174 assert(MDOC_TEXT
== nn
->type
);
1176 if (strlcat(buf
, nn
->string
, BUFSIZ
) >= BUFSIZ
) {
1177 mdoc_nmsg(mdoc
, nn
, MANDOCERR_MEM
);
1181 if (NULL
== nn
->next
)
1184 if (strlcat(buf
, " ", BUFSIZ
) >= BUFSIZ
) {
1185 mdoc_nmsg(mdoc
, nn
, MANDOCERR_MEM
);
1190 mdoc
->meta
.name
= mandoc_strdup(buf
);
1195 post_literal(POST_ARGS
)
1199 * The `Dl' (note "el" not "one") and `Bd' macros unset the
1200 * MDOC_LITERAL flag as they leave. Note that `Bd' only sets
1201 * this in literal mode, but it doesn't hurt to just switch it
1202 * off in general since displays can't be nested.
1205 if (MDOC_BODY
== mdoc
->last
->type
)
1206 mdoc
->last
->flags
&= ~MDOC_LITERAL
;
1212 post_defaults(POST_ARGS
)
1214 struct mdoc_node
*nn
;
1217 * The `Ar' defaults to "file ..." if no value is provided as an
1218 * argument; the `Mt' and `Pa' macros use "~"; the `Li' just
1219 * gets an empty string.
1222 if (mdoc
->last
->child
)
1226 mdoc
->next
= MDOC_NEXT_CHILD
;
1230 if ( ! mdoc_word_alloc(mdoc
, nn
->line
, nn
->pos
, "file"))
1232 if ( ! mdoc_word_alloc(mdoc
, nn
->line
, nn
->pos
, "..."))
1236 if ( ! mdoc_word_alloc(mdoc
, nn
->line
, nn
->pos
, "AT&T"))
1238 if ( ! mdoc_word_alloc(mdoc
, nn
->line
, nn
->pos
, "UNIX"))
1242 if ( ! mdoc_word_alloc(mdoc
, nn
->line
, nn
->pos
, ""))
1248 if ( ! mdoc_word_alloc(mdoc
, nn
->line
, nn
->pos
, "~"))
1268 * If we have a child, look it up in the standard keys. If a
1269 * key exist, use that instead of the child; if it doesn't,
1270 * prefix "AT&T UNIX " to the existing data.
1273 if (NULL
== mdoc
->last
->child
)
1276 assert(MDOC_TEXT
== mdoc
->last
->child
->type
);
1277 p
= mdoc_a2att(mdoc
->last
->child
->string
);
1280 free(mdoc
->last
->child
->string
);
1281 mdoc
->last
->child
->string
= mandoc_strdup(p
);
1283 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_BADATT
);
1285 q
= mdoc
->last
->child
->string
;
1286 sz
= strlen(p
) + strlen(q
) + 1;
1287 buf
= mandoc_malloc(sz
);
1288 strlcpy(buf
, p
, sz
);
1289 strlcat(buf
, q
, sz
);
1290 free(mdoc
->last
->child
->string
);
1291 mdoc
->last
->child
->string
= buf
;
1300 struct mdoc_node
*np
;
1303 if (AUTH__NONE
!= np
->data
.An
.auth
&& np
->child
)
1304 return(eerr_eq0(mdoc
));
1306 * FIXME: make this ewarn and make sure that the front-ends
1307 * don't print the arguments.
1309 if (AUTH__NONE
!= np
->data
.An
.auth
|| np
->child
)
1311 return(mdoc_nmsg(mdoc
, np
, MANDOCERR_NOARGS
));
1320 struct mdoc_node
*n
, *c
;
1323 if (MDOC_BLOCK
!= mdoc
->last
->type
)
1326 n
= mdoc
->last
->parent
->parent
;
1328 lt
= n
->data
.Bl
->type
;
1330 if (LIST__NONE
== lt
) {
1331 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_LISTTYPE
);
1337 if (mdoc
->last
->head
->child
)
1339 /* FIXME: give this a dummy value. */
1340 if ( ! mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_NOARGS
))
1350 if (NULL
== mdoc
->last
->head
->child
)
1351 if ( ! mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_NOARGS
))
1361 if (NULL
== mdoc
->last
->body
->child
)
1362 if ( ! mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_NOBODY
))
1366 if (mdoc
->last
->head
->child
)
1367 if ( ! mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_ARGSLOST
))
1371 cols
= (int)n
->data
.Bl
->ncols
;
1373 assert(NULL
== mdoc
->last
->head
->child
);
1375 if (NULL
== mdoc
->last
->body
->child
)
1376 if ( ! mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_NOBODY
))
1379 for (i
= 0, c
= mdoc
->last
->child
; c
; c
= c
->next
)
1380 if (MDOC_BODY
== c
->type
)
1384 er
= MANDOCERR_ARGCOUNT
;
1385 else if (i
== cols
|| i
== cols
+ 1)
1388 er
= MANDOCERR_SYNTARGCOUNT
;
1390 rc
= mdoc_vmsg(mdoc
, er
,
1391 mdoc
->last
->line
, mdoc
->last
->pos
,
1392 "columns == %d (have %d)", cols
, i
);
1403 post_bl_head(POST_ARGS
)
1405 struct mdoc_node
*np
, *nn
, *nnp
;
1408 if (LIST_column
!= mdoc
->last
->data
.Bl
->type
)
1409 /* FIXME: this should be ERROR class... */
1410 return(hwarn_eq0(mdoc
));
1413 * Convert old-style lists, where the column width specifiers
1414 * trail as macro parameters, to the new-style ("normal-form")
1415 * lists where they're argument values following -column.
1418 /* First, disallow both types and allow normal-form. */
1421 * TODO: technically, we can accept both and just merge the two
1422 * lists, but I'll leave that for another day.
1425 if (mdoc
->last
->data
.Bl
->ncols
&& mdoc
->last
->nchild
) {
1426 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_COLUMNS
);
1428 } else if (NULL
== mdoc
->last
->child
)
1431 np
= mdoc
->last
->parent
;
1434 for (j
= 0; j
< (int)np
->args
->argc
; j
++)
1435 if (MDOC_Column
== np
->args
->argv
[j
].arg
)
1438 assert(j
< (int)np
->args
->argc
);
1439 assert(0 == np
->args
->argv
[j
].sz
);
1442 * Accomodate for new-style groff column syntax. Shuffle the
1443 * child nodes, all of which must be TEXT, as arguments for the
1444 * column field. Then, delete the head children.
1447 np
->args
->argv
[j
].sz
= (size_t)mdoc
->last
->nchild
;
1448 np
->args
->argv
[j
].value
= mandoc_malloc
1449 ((size_t)mdoc
->last
->nchild
* sizeof(char *));
1451 mdoc
->last
->data
.Bl
->ncols
= np
->args
->argv
[j
].sz
;
1452 mdoc
->last
->data
.Bl
->cols
= (const char **)np
->args
->argv
[j
].value
;
1454 for (i
= 0, nn
= mdoc
->last
->child
; nn
; i
++) {
1455 np
->args
->argv
[j
].value
[i
] = nn
->string
;
1459 mdoc_node_delete(NULL
, nnp
);
1462 mdoc
->last
->nchild
= 0;
1463 mdoc
->last
->child
= NULL
;
1471 struct mdoc_node
*n
;
1473 if (MDOC_HEAD
== mdoc
->last
->type
)
1474 return(post_bl_head(mdoc
));
1475 if (MDOC_BODY
!= mdoc
->last
->type
)
1477 if (NULL
== mdoc
->last
->child
)
1481 * We only allow certain children of `Bl'. This is usually on
1482 * `It', but apparently `Sm' occurs here and there, so we let
1483 * that one through, too.
1487 for (n
= mdoc
->last
->child
; n
; n
= n
->next
) {
1488 if (MDOC_BLOCK
== n
->type
&& MDOC_It
== n
->tok
)
1490 if (MDOC_Sm
== n
->tok
)
1492 mdoc_nmsg(mdoc
, n
, MANDOCERR_SYNTCHILD
);
1501 ebool(struct mdoc
*mdoc
)
1503 struct mdoc_node
*n
;
1506 for (n
= mdoc
->last
->child
; n
; n
= n
->next
) {
1507 if (MDOC_TEXT
!= n
->type
)
1509 if (0 == strcmp(n
->string
, "on"))
1511 if (0 == strcmp(n
->string
, "off"))
1518 return(mdoc_nmsg(mdoc
, n
, MANDOCERR_BADBOOL
));
1523 post_root(POST_ARGS
)
1526 if (NULL
== mdoc
->first
->child
)
1527 mdoc_nmsg(mdoc
, mdoc
->first
, MANDOCERR_NODOCBODY
);
1528 else if ( ! (MDOC_PBODY
& mdoc
->flags
))
1529 mdoc_nmsg(mdoc
, mdoc
->first
, MANDOCERR_NODOCPROLOG
);
1530 else if (MDOC_BLOCK
!= mdoc
->first
->child
->type
)
1531 mdoc_nmsg(mdoc
, mdoc
->first
, MANDOCERR_NODOCBODY
);
1532 else if (MDOC_Sh
!= mdoc
->first
->child
->tok
)
1533 mdoc_nmsg(mdoc
, mdoc
->first
, MANDOCERR_NODOCBODY
);
1545 assert(MDOC_TEXT
== mdoc
->last
->child
->type
);
1547 p
= mdoc_a2st(mdoc
->last
->child
->string
);
1550 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_BADSTANDARD
);
1551 mdoc_node_delete(mdoc
, mdoc
->last
);
1553 free(mdoc
->last
->child
->string
);
1554 mdoc
->last
->child
->string
= mandoc_strdup(p
);
1563 struct mdoc_node
*nn
, *next
, *prev
;
1566 if (MDOC_BODY
!= mdoc
->last
->type
)
1570 * Make sure only certain types of nodes are allowed within the
1571 * the `Rs' body. Delete offending nodes and raise a warning.
1572 * Do this before re-ordering for the sake of clarity.
1576 for (nn
= mdoc
->last
->child
; nn
; nn
= next
) {
1577 for (i
= 0; i
< RSORD_MAX
; i
++)
1578 if (nn
->tok
== rsord
[i
])
1581 if (i
< RSORD_MAX
) {
1587 mdoc_nmsg(mdoc
, nn
, MANDOCERR_CHILD
);
1588 mdoc_node_delete(mdoc
, nn
);
1592 * The full `Rs' block needs special handling to order the
1593 * sub-elements according to `rsord'. Pick through each element
1594 * and correctly order it. This is a insertion sort.
1598 for (nn
= mdoc
->last
->child
->next
; nn
; nn
= next
) {
1599 /* Determine order of `nn'. */
1600 for (i
= 0; i
< RSORD_MAX
; i
++)
1601 if (rsord
[i
] == nn
->tok
)
1605 * Remove `nn' from the chain. This somewhat
1606 * repeats mdoc_node_unlink(), but since we're
1607 * just re-ordering, there's no need for the
1608 * full unlink process.
1611 if (NULL
!= (next
= nn
->next
))
1612 next
->prev
= nn
->prev
;
1614 if (NULL
!= (prev
= nn
->prev
))
1615 prev
->next
= nn
->next
;
1617 nn
->prev
= nn
->next
= NULL
;
1620 * Scan back until we reach a node that's
1621 * ordered before `nn'.
1624 for ( ; prev
; prev
= prev
->prev
) {
1625 /* Determine order of `prev'. */
1626 for (j
= 0; j
< RSORD_MAX
; j
++)
1627 if (rsord
[j
] == prev
->tok
)
1635 * Set `nn' back into its correct place in front
1636 * of the `prev' node.
1643 prev
->next
->prev
= nn
;
1644 nn
->next
= prev
->next
;
1647 mdoc
->last
->child
->prev
= nn
;
1648 nn
->next
= mdoc
->last
->child
;
1649 mdoc
->last
->child
= nn
;
1661 if (MDOC_HEAD
== mdoc
->last
->type
)
1662 return(post_sh_head(mdoc
));
1663 if (MDOC_BODY
== mdoc
->last
->type
)
1664 return(post_sh_body(mdoc
));
1671 post_sh_body(POST_ARGS
)
1673 struct mdoc_node
*n
;
1675 if (SEC_NAME
!= mdoc
->lastsec
)
1679 * Warn if the NAME section doesn't contain the `Nm' and `Nd'
1680 * macros (can have multiple `Nm' and one `Nd'). Note that the
1681 * children of the BODY declaration can also be "text".
1684 if (NULL
== (n
= mdoc
->last
->child
))
1685 return(mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_BADNAMESEC
));
1687 for ( ; n
&& n
->next
; n
= n
->next
) {
1688 if (MDOC_ELEM
== n
->type
&& MDOC_Nm
== n
->tok
)
1690 if (MDOC_TEXT
== n
->type
)
1692 if ( ! mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_BADNAMESEC
))
1697 if (MDOC_BLOCK
== n
->type
&& MDOC_Nd
== n
->tok
)
1699 return(mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_BADNAMESEC
));
1704 post_sh_head(POST_ARGS
)
1708 struct mdoc_node
*n
;
1711 * Process a new section. Sections are either "named" or
1712 * "custom". Custom sections are user-defined, while named ones
1713 * follow a conventional order and may only appear in certain
1719 /* FIXME: use dynamic buffer... */
1721 for (n
= mdoc
->last
->child
; n
; n
= n
->next
) {
1722 /* XXX - copied from concat(). */
1723 assert(MDOC_TEXT
== n
->type
);
1725 if (strlcat(buf
, n
->string
, BUFSIZ
) >= BUFSIZ
) {
1726 mdoc_nmsg(mdoc
, n
, MANDOCERR_MEM
);
1730 if (NULL
== n
->next
)
1733 if (strlcat(buf
, " ", BUFSIZ
) >= BUFSIZ
) {
1734 mdoc_nmsg(mdoc
, n
, MANDOCERR_MEM
);
1739 sec
= mdoc_str2sec(buf
);
1741 /* The NAME should be first. */
1743 if (SEC_NAME
!= sec
&& SEC_NONE
== mdoc
->lastnamed
)
1744 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_NAMESECFIRST
);
1746 /* The SYNOPSIS gets special attention in other areas. */
1748 if (SEC_SYNOPSIS
== sec
)
1749 mdoc
->flags
|= MDOC_SYNOPSIS
;
1751 mdoc
->flags
&= ~MDOC_SYNOPSIS
;
1753 /* Mark our last section. */
1755 mdoc
->lastsec
= sec
;
1757 /* We don't care about custom sections after this. */
1759 if (SEC_CUSTOM
== sec
)
1763 * Check whether our non-custom section is being repeated or is
1767 if (sec
== mdoc
->lastnamed
)
1768 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_SECREP
);
1770 if (sec
< mdoc
->lastnamed
)
1771 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_SECOOO
);
1773 /* Mark the last named section. */
1775 mdoc
->lastnamed
= sec
;
1777 /* Check particular section/manual conventions. */
1779 assert(mdoc
->meta
.msec
);
1782 case (SEC_RETURN_VALUES
):
1787 if (*mdoc
->meta
.msec
== '2')
1789 if (*mdoc
->meta
.msec
== '3')
1791 if (*mdoc
->meta
.msec
== '9')
1793 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_SECMSEC
);
1806 if (NULL
== mdoc
->last
)
1810 * Don't allow prior `Lp' or `Pp' prior to a paragraph-type
1811 * block: `Lp', `Pp', or non-compact `Bd' or `Bl'.
1814 if (MDOC_Pp
!= mdoc
->last
->tok
&& MDOC_Lp
!= mdoc
->last
->tok
)
1817 if (MDOC_Bl
== n
->tok
&& n
->data
.Bl
->comp
)
1819 if (MDOC_Bd
== n
->tok
&& n
->data
.Bd
->comp
)
1822 mdoc_nmsg(mdoc
, mdoc
->last
, MANDOCERR_IGNPAR
);
1823 mdoc_node_delete(mdoc
, mdoc
->last
);
1828 pre_literal(PRE_ARGS
)
1831 if (MDOC_BODY
!= n
->type
)
1835 * The `Dl' (note "el" not "one") and `Bd -literal' and `Bd
1836 * -unfilled' macros set MDOC_LITERAL on entrance to the body.
1841 mdoc
->flags
|= MDOC_LITERAL
;
1845 if (DISP_literal
== n
->data
.Bd
->type
)
1846 mdoc
->flags
|= MDOC_LITERAL
;
1847 if (DISP_unfilled
== n
->data
.Bd
->type
)
1848 mdoc
->flags
|= MDOC_LITERAL
;