]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_validate.c
Cached `Bl -offset' into mdoc_bl. Removed erroneous "-offset defaults
[mandoc.git] / mdoc_validate.c
1 /* $Id: mdoc_validate.c,v 1.98 2010/06/12 12:38:01 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
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.
8 *
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.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <limits.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "mandoc.h"
31 #include "libmdoc.h"
32 #include "libmandoc.h"
33
34 /* FIXME: .Bl -diag can't have non-text children in HEAD. */
35 /* TODO: ignoring Pp (it's superfluous in some invocations). */
36
37 #define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n
38 #define POST_ARGS struct mdoc *mdoc
39
40 typedef int (*v_pre)(PRE_ARGS);
41 typedef int (*v_post)(POST_ARGS);
42
43 struct valids {
44 v_pre *pre;
45 v_post *post;
46 };
47
48 static int check_parent(PRE_ARGS, enum mdoct, enum mdoc_type);
49 static int check_stdarg(PRE_ARGS);
50 static int check_text(struct mdoc *, int, int, char *);
51 static int check_argv(struct mdoc *,
52 struct mdoc_node *, struct mdoc_argv *);
53 static int check_args(struct mdoc *, struct mdoc_node *);
54 static int err_child_lt(struct mdoc *, const char *, int);
55 static int warn_child_lt(struct mdoc *, const char *, int);
56 static int err_child_gt(struct mdoc *, const char *, int);
57 static int warn_child_gt(struct mdoc *, const char *, int);
58 static int err_child_eq(struct mdoc *, const char *, int);
59 static int warn_child_eq(struct mdoc *, const char *, int);
60 static int warn_count(struct mdoc *, const char *,
61 int, const char *, int);
62 static int err_count(struct mdoc *, const char *,
63 int, const char *, int);
64
65 static int berr_ge1(POST_ARGS);
66 static int bwarn_ge1(POST_ARGS);
67 static int ebool(POST_ARGS);
68 static int eerr_eq0(POST_ARGS);
69 static int eerr_eq1(POST_ARGS);
70 static int eerr_ge1(POST_ARGS);
71 static int eerr_le1(POST_ARGS);
72 static int ewarn_ge1(POST_ARGS);
73 static int herr_eq0(POST_ARGS);
74 static int herr_ge1(POST_ARGS);
75 static int hwarn_eq1(POST_ARGS);
76 static int hwarn_eq0(POST_ARGS);
77 static int hwarn_le1(POST_ARGS);
78
79 static int post_an(POST_ARGS);
80 static int post_at(POST_ARGS);
81 static int post_bf(POST_ARGS);
82 static int post_bl(POST_ARGS);
83 static int post_bl_head(POST_ARGS);
84 static int post_dt(POST_ARGS);
85 static int post_it(POST_ARGS);
86 static int post_lb(POST_ARGS);
87 static int post_nm(POST_ARGS);
88 static int post_root(POST_ARGS);
89 static int post_rs(POST_ARGS);
90 static int post_sh(POST_ARGS);
91 static int post_sh_body(POST_ARGS);
92 static int post_sh_head(POST_ARGS);
93 static int post_st(POST_ARGS);
94 static int post_eoln(POST_ARGS);
95 static int post_vt(POST_ARGS);
96 static int pre_an(PRE_ARGS);
97 static int pre_bd(PRE_ARGS);
98 static int pre_bl(PRE_ARGS);
99 static int pre_dd(PRE_ARGS);
100 static int pre_display(PRE_ARGS);
101 static int pre_dt(PRE_ARGS);
102 static int pre_it(PRE_ARGS);
103 static int pre_os(PRE_ARGS);
104 static int pre_rv(PRE_ARGS);
105 static int pre_sh(PRE_ARGS);
106 static int pre_ss(PRE_ARGS);
107
108 static v_post posts_an[] = { post_an, NULL };
109 static v_post posts_at[] = { post_at, NULL };
110 static v_post posts_bd[] = { hwarn_eq0, bwarn_ge1, NULL };
111 static v_post posts_bf[] = { hwarn_le1, post_bf, NULL };
112 static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL };
113 static v_post posts_bool[] = { eerr_eq1, ebool, NULL };
114 static v_post posts_eoln[] = { post_eoln, NULL };
115 static v_post posts_dt[] = { post_dt, NULL };
116 static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
117 static v_post posts_it[] = { post_it, NULL };
118 static v_post posts_lb[] = { eerr_eq1, post_lb, NULL };
119 static v_post posts_nd[] = { berr_ge1, NULL };
120 static v_post posts_nm[] = { post_nm, NULL };
121 static v_post posts_notext[] = { eerr_eq0, NULL };
122 static v_post posts_rs[] = { berr_ge1, herr_eq0, post_rs, NULL };
123 static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };
124 static v_post posts_sp[] = { eerr_le1, NULL };
125 static v_post posts_ss[] = { herr_ge1, NULL };
126 static v_post posts_st[] = { eerr_eq1, post_st, NULL };
127 static v_post posts_text[] = { eerr_ge1, NULL };
128 static v_post posts_text1[] = { eerr_eq1, NULL };
129 static v_post posts_vt[] = { post_vt, NULL };
130 static v_post posts_wline[] = { bwarn_ge1, herr_eq0, NULL };
131 static v_post posts_wtext[] = { ewarn_ge1, NULL };
132 static v_pre pres_an[] = { pre_an, NULL };
133 static v_pre pres_bd[] = { pre_display, pre_bd, NULL };
134 static v_pre pres_bl[] = { pre_bl, NULL };
135 static v_pre pres_d1[] = { pre_display, NULL };
136 static v_pre pres_dd[] = { pre_dd, NULL };
137 static v_pre pres_dt[] = { pre_dt, NULL };
138 static v_pre pres_er[] = { NULL, NULL };
139 static v_pre pres_ex[] = { NULL, NULL };
140 static v_pre pres_fd[] = { NULL, NULL };
141 static v_pre pres_it[] = { pre_it, NULL };
142 static v_pre pres_os[] = { pre_os, NULL };
143 static v_pre pres_rv[] = { pre_rv, NULL };
144 static v_pre pres_sh[] = { pre_sh, NULL };
145 static v_pre pres_ss[] = { pre_ss, NULL };
146
147 const struct valids mdoc_valids[MDOC_MAX] = {
148 { NULL, NULL }, /* Ap */
149 { pres_dd, posts_text }, /* Dd */
150 { pres_dt, posts_dt }, /* Dt */
151 { pres_os, NULL }, /* Os */
152 { pres_sh, posts_sh }, /* Sh */
153 { pres_ss, posts_ss }, /* Ss */
154 { NULL, posts_notext }, /* Pp */
155 { pres_d1, posts_wline }, /* D1 */
156 { pres_d1, posts_wline }, /* Dl */
157 { pres_bd, posts_bd }, /* Bd */
158 { NULL, NULL }, /* Ed */
159 { pres_bl, posts_bl }, /* Bl */
160 { NULL, NULL }, /* El */
161 { pres_it, posts_it }, /* It */
162 { NULL, posts_text }, /* Ad */
163 { pres_an, posts_an }, /* An */
164 { NULL, NULL }, /* Ar */
165 { NULL, posts_text }, /* Cd */
166 { NULL, NULL }, /* Cm */
167 { NULL, NULL }, /* Dv */
168 { pres_er, posts_text }, /* Er */
169 { NULL, NULL }, /* Ev */
170 { pres_ex, NULL }, /* Ex */
171 { NULL, NULL }, /* Fa */
172 { pres_fd, posts_wtext }, /* Fd */
173 { NULL, NULL }, /* Fl */
174 { NULL, posts_text }, /* Fn */
175 { NULL, posts_wtext }, /* Ft */
176 { NULL, posts_text }, /* Ic */
177 { NULL, posts_text1 }, /* In */
178 { NULL, NULL }, /* Li */
179 { NULL, posts_nd }, /* Nd */
180 { NULL, posts_nm }, /* Nm */
181 { NULL, posts_wline }, /* Op */
182 { NULL, NULL }, /* Ot */
183 { NULL, NULL }, /* Pa */
184 { pres_rv, NULL }, /* Rv */
185 { NULL, posts_st }, /* St */
186 { NULL, NULL }, /* Va */
187 { NULL, posts_vt }, /* Vt */
188 { NULL, posts_wtext }, /* Xr */
189 { NULL, posts_text }, /* %A */
190 { NULL, posts_text }, /* %B */ /* FIXME: can be used outside Rs/Re. */
191 { NULL, posts_text }, /* %D */ /* FIXME: check date with mandoc_a2time(). */
192 { NULL, posts_text }, /* %I */
193 { NULL, posts_text }, /* %J */
194 { NULL, posts_text }, /* %N */
195 { NULL, posts_text }, /* %O */
196 { NULL, posts_text }, /* %P */
197 { NULL, posts_text }, /* %R */
198 { NULL, posts_text }, /* %T */ /* FIXME: can be used outside Rs/Re. */
199 { NULL, posts_text }, /* %V */
200 { NULL, NULL }, /* Ac */
201 { NULL, NULL }, /* Ao */
202 { NULL, posts_wline }, /* Aq */
203 { NULL, posts_at }, /* At */
204 { NULL, NULL }, /* Bc */
205 { NULL, posts_bf }, /* Bf */
206 { NULL, NULL }, /* Bo */
207 { NULL, posts_wline }, /* Bq */
208 { NULL, NULL }, /* Bsx */
209 { NULL, NULL }, /* Bx */
210 { NULL, posts_bool }, /* Db */
211 { NULL, NULL }, /* Dc */
212 { NULL, NULL }, /* Do */
213 { NULL, posts_wline }, /* Dq */
214 { NULL, NULL }, /* Ec */
215 { NULL, NULL }, /* Ef */
216 { NULL, NULL }, /* Em */
217 { NULL, NULL }, /* Eo */
218 { NULL, NULL }, /* Fx */
219 { NULL, posts_text }, /* Ms */
220 { NULL, posts_notext }, /* No */
221 { NULL, posts_notext }, /* Ns */
222 { NULL, NULL }, /* Nx */
223 { NULL, NULL }, /* Ox */
224 { NULL, NULL }, /* Pc */
225 { NULL, posts_text1 }, /* Pf */
226 { NULL, NULL }, /* Po */
227 { NULL, posts_wline }, /* Pq */
228 { NULL, NULL }, /* Qc */
229 { NULL, posts_wline }, /* Ql */
230 { NULL, NULL }, /* Qo */
231 { NULL, posts_wline }, /* Qq */
232 { NULL, NULL }, /* Re */
233 { NULL, posts_rs }, /* Rs */
234 { NULL, NULL }, /* Sc */
235 { NULL, NULL }, /* So */
236 { NULL, posts_wline }, /* Sq */
237 { NULL, posts_bool }, /* Sm */
238 { NULL, posts_text }, /* Sx */
239 { NULL, posts_text }, /* Sy */
240 { NULL, posts_text }, /* Tn */
241 { NULL, NULL }, /* Ux */
242 { NULL, NULL }, /* Xc */
243 { NULL, NULL }, /* Xo */
244 { NULL, posts_fo }, /* Fo */
245 { NULL, NULL }, /* Fc */
246 { NULL, NULL }, /* Oo */
247 { NULL, NULL }, /* Oc */
248 { NULL, posts_wline }, /* Bk */
249 { NULL, NULL }, /* Ek */
250 { NULL, posts_eoln }, /* Bt */
251 { NULL, NULL }, /* Hf */
252 { NULL, NULL }, /* Fr */
253 { NULL, posts_eoln }, /* Ud */
254 { NULL, posts_lb }, /* Lb */
255 { NULL, posts_notext }, /* Lp */
256 { NULL, posts_text }, /* Lk */
257 { NULL, posts_text }, /* Mt */
258 { NULL, posts_wline }, /* Brq */
259 { NULL, NULL }, /* Bro */
260 { NULL, NULL }, /* Brc */
261 { NULL, posts_text }, /* %C */
262 { NULL, NULL }, /* Es */
263 { NULL, NULL }, /* En */
264 { NULL, NULL }, /* Dx */
265 { NULL, posts_text }, /* %Q */
266 { NULL, posts_notext }, /* br */
267 { NULL, posts_sp }, /* sp */
268 { NULL, posts_text1 }, /* %U */
269 { NULL, NULL }, /* Ta */
270 };
271
272
273 int
274 mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
275 {
276 v_pre *p;
277 int line, pos;
278 char *tp;
279
280 if (MDOC_TEXT == n->type) {
281 tp = n->string;
282 line = n->line;
283 pos = n->pos;
284 return(check_text(mdoc, line, pos, tp));
285 }
286
287 if ( ! check_args(mdoc, n))
288 return(0);
289 if (NULL == mdoc_valids[n->tok].pre)
290 return(1);
291 for (p = mdoc_valids[n->tok].pre; *p; p++)
292 if ( ! (*p)(mdoc, n))
293 return(0);
294 return(1);
295 }
296
297
298 int
299 mdoc_valid_post(struct mdoc *mdoc)
300 {
301 v_post *p;
302
303 if (MDOC_VALID & mdoc->last->flags)
304 return(1);
305 mdoc->last->flags |= MDOC_VALID;
306
307 if (MDOC_TEXT == mdoc->last->type)
308 return(1);
309 if (MDOC_ROOT == mdoc->last->type)
310 return(post_root(mdoc));
311
312 if (NULL == mdoc_valids[mdoc->last->tok].post)
313 return(1);
314 for (p = mdoc_valids[mdoc->last->tok].post; *p; p++)
315 if ( ! (*p)(mdoc))
316 return(0);
317
318 return(1);
319 }
320
321
322 static inline int
323 warn_count(struct mdoc *m, const char *k,
324 int want, const char *v, int has)
325 {
326
327 return(mdoc_vmsg(m, MANDOCERR_ARGCOUNT,
328 m->last->line, m->last->pos,
329 "%s %s %d (have %d)", v, k, want, has));
330 }
331
332
333 static inline int
334 err_count(struct mdoc *m, const char *k,
335 int want, const char *v, int has)
336 {
337
338 mdoc_vmsg(m, MANDOCERR_SYNTARGCOUNT,
339 m->last->line, m->last->pos,
340 "%s %s %d (have %d)",
341 v, k, want, has);
342 return(0);
343 }
344
345
346 /*
347 * Build these up with macros because they're basically the same check
348 * for different inequalities. Yes, this could be done with functions,
349 * but this is reasonable for now.
350 */
351
352 #define CHECK_CHILD_DEFN(lvl, name, ineq) \
353 static int \
354 lvl##_child_##name(struct mdoc *mdoc, const char *p, int sz) \
355 { \
356 if (mdoc->last->nchild ineq sz) \
357 return(1); \
358 return(lvl##_count(mdoc, #ineq, sz, p, mdoc->last->nchild)); \
359 }
360
361 #define CHECK_BODY_DEFN(name, lvl, func, num) \
362 static int \
363 b##lvl##_##name(POST_ARGS) \
364 { \
365 if (MDOC_BODY != mdoc->last->type) \
366 return(1); \
367 return(func(mdoc, "multi-line arguments", (num))); \
368 }
369
370 #define CHECK_ELEM_DEFN(name, lvl, func, num) \
371 static int \
372 e##lvl##_##name(POST_ARGS) \
373 { \
374 assert(MDOC_ELEM == mdoc->last->type); \
375 return(func(mdoc, "line arguments", (num))); \
376 }
377
378 #define CHECK_HEAD_DEFN(name, lvl, func, num) \
379 static int \
380 h##lvl##_##name(POST_ARGS) \
381 { \
382 if (MDOC_HEAD != mdoc->last->type) \
383 return(1); \
384 return(func(mdoc, "line arguments", (num))); \
385 }
386
387
388 CHECK_CHILD_DEFN(warn, gt, >) /* warn_child_gt() */
389 CHECK_CHILD_DEFN(err, gt, >) /* err_child_gt() */
390 CHECK_CHILD_DEFN(warn, eq, ==) /* warn_child_eq() */
391 CHECK_CHILD_DEFN(err, eq, ==) /* err_child_eq() */
392 CHECK_CHILD_DEFN(err, lt, <) /* err_child_lt() */
393 CHECK_CHILD_DEFN(warn, lt, <) /* warn_child_lt() */
394 CHECK_BODY_DEFN(ge1, warn, warn_child_gt, 0) /* bwarn_ge1() */
395 CHECK_BODY_DEFN(ge1, err, err_child_gt, 0) /* berr_ge1() */
396 CHECK_ELEM_DEFN(ge1, warn, warn_child_gt, 0) /* ewarn_ge1() */
397 CHECK_ELEM_DEFN(eq1, err, err_child_eq, 1) /* eerr_eq1() */
398 CHECK_ELEM_DEFN(le1, err, err_child_lt, 2) /* eerr_le1() */
399 CHECK_ELEM_DEFN(eq0, err, err_child_eq, 0) /* eerr_eq0() */
400 CHECK_ELEM_DEFN(ge1, err, err_child_gt, 0) /* eerr_ge1() */
401 CHECK_HEAD_DEFN(eq0, err, err_child_eq, 0) /* herr_eq0() */
402 CHECK_HEAD_DEFN(le1, warn, warn_child_lt, 2) /* hwarn_le1() */
403 CHECK_HEAD_DEFN(ge1, err, err_child_gt, 0) /* herr_ge1() */
404 CHECK_HEAD_DEFN(eq1, warn, warn_child_eq, 1) /* hwarn_eq1() */
405 CHECK_HEAD_DEFN(eq0, warn, warn_child_eq, 0) /* hwarn_eq0() */
406
407
408 static int
409 check_stdarg(PRE_ARGS)
410 {
411
412 if (n->args && 1 == n->args->argc)
413 if (MDOC_Std == n->args->argv[0].arg)
414 return(1);
415 return(mdoc_nmsg(mdoc, n, MANDOCERR_NOARGV));
416 }
417
418
419 static int
420 check_args(struct mdoc *m, struct mdoc_node *n)
421 {
422 int i;
423
424 if (NULL == n->args)
425 return(1);
426
427 assert(n->args->argc);
428 for (i = 0; i < (int)n->args->argc; i++)
429 if ( ! check_argv(m, n, &n->args->argv[i]))
430 return(0);
431
432 return(1);
433 }
434
435
436 static int
437 check_argv(struct mdoc *m, struct mdoc_node *n, struct mdoc_argv *v)
438 {
439 int i;
440
441 for (i = 0; i < (int)v->sz; i++)
442 if ( ! check_text(m, v->line, v->pos, v->value[i]))
443 return(0);
444
445 if (MDOC_Std == v->arg) {
446 if (v->sz || m->meta.name)
447 return(1);
448 if ( ! mdoc_nmsg(m, n, MANDOCERR_NONAME))
449 return(0);
450 }
451
452 return(1);
453 }
454
455
456 static int
457 check_text(struct mdoc *mdoc, int line, int pos, char *p)
458 {
459 int c;
460
461 for ( ; *p; p++, pos++) {
462 if ('\t' == *p) {
463 if ( ! (MDOC_LITERAL & mdoc->flags))
464 if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR))
465 return(0);
466 } else if ( ! isprint((u_char)*p) && ASCII_HYPH != *p)
467 if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR))
468 return(0);
469
470 if ('\\' != *p)
471 continue;
472
473 c = mandoc_special(p);
474 if (c) {
475 p += c - 1;
476 pos += c - 1;
477 continue;
478 }
479
480 c = mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADESCAPE);
481 if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags) && ! c)
482 return(c);
483 }
484
485 return(1);
486 }
487
488
489
490
491 static int
492 check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
493 {
494
495 assert(n->parent);
496 if ((MDOC_ROOT == t || tok == n->parent->tok) &&
497 (t == n->parent->type))
498 return(1);
499
500 mdoc_vmsg(mdoc, MANDOCERR_SYNTCHILD,
501 n->line, n->pos, "want parent %s",
502 MDOC_ROOT == t ? "<root>" :
503 mdoc_macronames[tok]);
504 return(0);
505 }
506
507
508
509 static int
510 pre_display(PRE_ARGS)
511 {
512 struct mdoc_node *node;
513
514 /* Display elements (`Bd', `D1'...) cannot be nested. */
515
516 if (MDOC_BLOCK != n->type)
517 return(1);
518
519 /* LINTED */
520 for (node = mdoc->last->parent; node; node = node->parent)
521 if (MDOC_BLOCK == node->type)
522 if (MDOC_Bd == node->tok)
523 break;
524 if (NULL == node)
525 return(1);
526
527 mdoc_nmsg(mdoc, n, MANDOCERR_NESTEDDISP);
528 return(0);
529 }
530
531
532 static int
533 pre_bl(PRE_ARGS)
534 {
535 int i, width, comp, dup;
536 const char *offs;
537 enum mdoc_list lt;
538
539 if (MDOC_BLOCK != n->type) {
540 assert(n->parent);
541 assert(MDOC_BLOCK == n->parent->type);
542 assert(MDOC_Bl == n->parent->tok);
543 assert(LIST__NONE != n->parent->data.Bl.type);
544 memcpy(&n->data.Bl, &n->parent->data.Bl,
545 sizeof(struct mdoc_bl));
546 return(1);
547 }
548
549 /*
550 * First figure out which kind of list to use: bind ourselves to
551 * the first mentioned list type and warn about any remaining
552 * ones. If we find no list type, we default to LIST_item.
553 */
554
555 assert(LIST__NONE == n->data.Bl.type);
556 width = -1;
557
558 /* LINTED */
559 for (i = 0; n->args && i < (int)n->args->argc; i++) {
560 lt = LIST__NONE;
561 dup = comp = 0;
562 offs = NULL;
563 switch (n->args->argv[i].arg) {
564 /* Set list types. */
565 case (MDOC_Bullet):
566 lt = LIST_bullet;
567 break;
568 case (MDOC_Dash):
569 lt = LIST_dash;
570 break;
571 case (MDOC_Enum):
572 lt = LIST_enum;
573 break;
574 case (MDOC_Hyphen):
575 lt = LIST_hyphen;
576 break;
577 case (MDOC_Item):
578 lt = LIST_item;
579 break;
580 case (MDOC_Tag):
581 lt = LIST_tag;
582 break;
583 case (MDOC_Diag):
584 lt = LIST_diag;
585 break;
586 case (MDOC_Hang):
587 lt = LIST_hang;
588 break;
589 case (MDOC_Ohang):
590 lt = LIST_ohang;
591 break;
592 case (MDOC_Inset):
593 lt = LIST_inset;
594 break;
595 case (MDOC_Column):
596 lt = LIST_column;
597 break;
598 /* Set list arguments. */
599 case (MDOC_Compact):
600 dup = n->data.Bl.comp;
601 comp = 1;
602 break;
603 case (MDOC_Width):
604 if (width >= 0)
605 dup++;
606 width = i;
607 break;
608 case (MDOC_Offset):
609 /* NB: this can be empty! */
610 if (n->args->argv[i].sz) {
611 offs = n->args->argv[i].value[0];
612 dup = (NULL != n->data.Bd.offs);
613 break;
614 }
615 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))
616 return(0);
617 break;
618 }
619
620 /* Check: duplicate auxiliary arguments. */
621
622 if (dup && ! mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP))
623 return(0);
624
625 if (comp && ! dup)
626 n->data.Bl.comp = comp;
627 if (offs && ! dup)
628 n->data.Bl.offs = offs;
629
630 /* Check: multiple list types. */
631
632 if (LIST__NONE != lt && n->data.Bl.type != LIST__NONE)
633 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP))
634 return(0);
635
636 /* Assign list type. */
637
638 if (LIST__NONE != lt && n->data.Bl.type == LIST__NONE)
639 n->data.Bl.type = lt;
640
641 /* The list type should come first. */
642
643 if (n->data.Bl.type == LIST__NONE)
644 if (width >= 0 || n->data.Bl.offs || n->data.Bl.comp)
645 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST))
646 return(0);
647
648 continue;
649 }
650
651 /* Allow lists to default to LIST_item. */
652
653 if (LIST__NONE == n->data.Bl.type) {
654 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE))
655 return(0);
656 n->data.Bl.type = LIST_item;
657 }
658
659 /*
660 * Validate the width field. Some list types don't need width
661 * types and should be warned about them. Others should have it
662 * and must also be warned.
663 */
664
665 switch (n->data.Bl.type) {
666 case (LIST_tag):
667 if (width >= 0)
668 break;
669 if (mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG))
670 break;
671 return(0);
672 case (LIST_column):
673 /* FALLTHROUGH */
674 case (LIST_diag):
675 /* FALLTHROUGH */
676 case (LIST_ohang):
677 /* FALLTHROUGH */
678 case (LIST_inset):
679 /* FALLTHROUGH */
680 case (LIST_item):
681 if (width < 0)
682 break;
683 if (mdoc_nmsg(mdoc, n, MANDOCERR_WIDTHARG))
684 break;
685 return(0);
686 default:
687 break;
688 }
689
690 return(1);
691 }
692
693
694 static int
695 pre_bd(PRE_ARGS)
696 {
697 int i, dup, comp;
698 enum mdoc_disp dt;
699 const char *offs;
700
701 if (MDOC_BLOCK != n->type) {
702 assert(n->parent);
703 assert(MDOC_BLOCK == n->parent->type);
704 assert(MDOC_Bd == n->parent->tok);
705 assert(DISP__NONE != n->parent->data.Bd.type);
706 memcpy(&n->data.Bd, &n->parent->data.Bd,
707 sizeof(struct mdoc_bd));
708 return(1);
709 }
710
711 assert(DISP__NONE == n->data.Bd.type);
712
713 /* LINTED */
714 for (i = 0; n->args && i < (int)n->args->argc; i++) {
715 dt = DISP__NONE;
716 dup = comp = 0;
717 offs = NULL;
718
719 switch (n->args->argv[i].arg) {
720 case (MDOC_Centred):
721 dt = DISP_centred;
722 break;
723 case (MDOC_Ragged):
724 dt = DISP_ragged;
725 break;
726 case (MDOC_Unfilled):
727 dt = DISP_unfilled;
728 break;
729 case (MDOC_Filled):
730 dt = DISP_filled;
731 break;
732 case (MDOC_Literal):
733 dt = DISP_literal;
734 break;
735 case (MDOC_File):
736 mdoc_nmsg(mdoc, n, MANDOCERR_BADDISP);
737 return(0);
738 case (MDOC_Offset):
739 /* NB: this can be empty! */
740 if (n->args->argv[i].sz) {
741 offs = n->args->argv[i].value[0];
742 dup = (NULL != n->data.Bd.offs);
743 break;
744 }
745 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))
746 return(0);
747 break;
748 case (MDOC_Compact):
749 comp = 1;
750 dup = n->data.Bd.comp;
751 break;
752 default:
753 abort();
754 /* NOTREACHED */
755 }
756
757 /* Check whether we have duplicates. */
758
759 if (dup && ! mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP))
760 return(0);
761
762 /* Make our auxiliary assignments. */
763
764 if (offs && ! dup)
765 n->data.Bd.offs = offs;
766 if (comp && ! dup)
767 n->data.Bd.comp = comp;
768
769 /* Check whether a type has already been assigned. */
770
771 if (DISP__NONE != dt && n->data.Bd.type != DISP__NONE)
772 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP))
773 return(0);
774
775 /* Make our type assignment. */
776
777 if (DISP__NONE != dt && n->data.Bd.type == DISP__NONE)
778 n->data.Bd.type = dt;
779 }
780
781 if (DISP__NONE == n->data.Bd.type) {
782 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE))
783 return(0);
784 n->data.Bd.type = DISP_ragged;
785 }
786
787 return(1);
788 }
789
790
791 static int
792 pre_ss(PRE_ARGS)
793 {
794
795 if (MDOC_BLOCK != n->type)
796 return(1);
797 return(check_parent(mdoc, n, MDOC_Sh, MDOC_BODY));
798 }
799
800
801 static int
802 pre_sh(PRE_ARGS)
803 {
804
805 if (MDOC_BLOCK != n->type)
806 return(1);
807 return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT));
808 }
809
810
811 static int
812 pre_it(PRE_ARGS)
813 {
814
815 if (MDOC_BLOCK != n->type)
816 return(1);
817 /*
818 * FIXME: this can probably be lifted if we make the It into
819 * something else on-the-fly?
820 */
821 return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY));
822 }
823
824
825 static int
826 pre_an(PRE_ARGS)
827 {
828
829 if (NULL == n->args || 1 == n->args->argc)
830 return(1);
831 mdoc_vmsg(mdoc, MANDOCERR_SYNTARGCOUNT,
832 n->line, n->pos,
833 "line arguments == 1 (have %d)",
834 n->args->argc);
835 return(0);
836 }
837
838
839 static int
840 pre_rv(PRE_ARGS)
841 {
842
843 return(check_stdarg(mdoc, n));
844 }
845
846
847 static int
848 post_dt(POST_ARGS)
849 {
850 const struct mdoc_node *nn;
851 const char *p;
852
853 if (NULL != (nn = mdoc->last->child))
854 for (p = nn->string; *p; p++) {
855 if (toupper((u_char)*p) == *p)
856 continue;
857 if ( ! mdoc_nmsg(mdoc, nn, MANDOCERR_UPPERCASE))
858 return(0);
859 break;
860 }
861
862 return(1);
863 }
864
865
866 static int
867 pre_dt(PRE_ARGS)
868 {
869
870 if (0 == mdoc->meta.date || mdoc->meta.os)
871 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO))
872 return(0);
873 if (mdoc->meta.title)
874 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP))
875 return(0);
876 return(1);
877 }
878
879
880 static int
881 pre_os(PRE_ARGS)
882 {
883
884 if (NULL == mdoc->meta.title || 0 == mdoc->meta.date)
885 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO))
886 return(0);
887 if (mdoc->meta.os)
888 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP))
889 return(0);
890 return(1);
891 }
892
893
894 static int
895 pre_dd(PRE_ARGS)
896 {
897
898 if (mdoc->meta.title || mdoc->meta.os)
899 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO))
900 return(0);
901 if (mdoc->meta.date)
902 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP))
903 return(0);
904 return(1);
905 }
906
907
908 static int
909 post_bf(POST_ARGS)
910 {
911 char *p;
912 struct mdoc_node *head;
913
914 if (MDOC_BLOCK != mdoc->last->type)
915 return(1);
916
917 head = mdoc->last->head;
918
919 if (mdoc->last->args && head->child) {
920 /* FIXME: this should provide a default. */
921 mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SYNTARGVCOUNT);
922 return(0);
923 } else if (mdoc->last->args)
924 return(1);
925
926 if (NULL == head->child || MDOC_TEXT != head->child->type) {
927 /* FIXME: this should provide a default. */
928 mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SYNTARGVCOUNT);
929 return(0);
930 }
931
932 p = head->child->string;
933
934 if (0 == strcmp(p, "Em"))
935 return(1);
936 else if (0 == strcmp(p, "Li"))
937 return(1);
938 else if (0 == strcmp(p, "Sy"))
939 return(1);
940
941 mdoc_nmsg(mdoc, head, MANDOCERR_FONTTYPE);
942 return(0);
943 }
944
945
946 static int
947 post_lb(POST_ARGS)
948 {
949
950 if (mdoc_a2lib(mdoc->last->child->string))
951 return(1);
952 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADLIB));
953 }
954
955
956 static int
957 post_eoln(POST_ARGS)
958 {
959
960 if (NULL == mdoc->last->child)
961 return(1);
962 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST));
963 }
964
965
966 static int
967 post_vt(POST_ARGS)
968 {
969 const struct mdoc_node *n;
970
971 /*
972 * The Vt macro comes in both ELEM and BLOCK form, both of which
973 * have different syntaxes (yet more context-sensitive
974 * behaviour). ELEM types must have a child; BLOCK types,
975 * specifically the BODY, should only have TEXT children.
976 */
977
978 if (MDOC_ELEM == mdoc->last->type)
979 return(eerr_ge1(mdoc));
980 if (MDOC_BODY != mdoc->last->type)
981 return(1);
982
983 for (n = mdoc->last->child; n; n = n->next)
984 if (MDOC_TEXT != n->type)
985 if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_CHILD))
986 return(0);
987
988 return(1);
989 }
990
991
992 static int
993 post_nm(POST_ARGS)
994 {
995
996 if (mdoc->last->child)
997 return(1);
998 if (mdoc->meta.name)
999 return(1);
1000 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME));
1001 }
1002
1003
1004 static int
1005 post_at(POST_ARGS)
1006 {
1007
1008 if (NULL == mdoc->last->child)
1009 return(1);
1010 assert(MDOC_TEXT == mdoc->last->child->type);
1011 if (mdoc_a2att(mdoc->last->child->string))
1012 return(1);
1013 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADATT));
1014 }
1015
1016
1017 static int
1018 post_an(POST_ARGS)
1019 {
1020
1021 if (mdoc->last->args) {
1022 if (NULL == mdoc->last->child)
1023 return(1);
1024 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGCOUNT));
1025 }
1026
1027 if (mdoc->last->child)
1028 return(1);
1029 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS));
1030 }
1031
1032
1033 static int
1034 post_it(POST_ARGS)
1035 {
1036 int i, cols, rc;
1037 enum mdoc_list lt;
1038 struct mdoc_node *n, *c;
1039 enum mandocerr er;
1040
1041 if (MDOC_BLOCK != mdoc->last->type)
1042 return(1);
1043
1044 n = mdoc->last->parent->parent;
1045 lt = n->data.Bl.type;
1046
1047 if (LIST__NONE == lt) {
1048 mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
1049 return(0);
1050 }
1051
1052 switch (lt) {
1053 case (LIST_tag):
1054 if (mdoc->last->head->child)
1055 break;
1056 /* FIXME: give this a dummy value. */
1057 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
1058 return(0);
1059 break;
1060 case (LIST_hang):
1061 /* FALLTHROUGH */
1062 case (LIST_ohang):
1063 /* FALLTHROUGH */
1064 case (LIST_inset):
1065 /* FALLTHROUGH */
1066 case (LIST_diag):
1067 if (NULL == mdoc->last->head->child)
1068 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
1069 return(0);
1070 if (NULL == mdoc->last->body->child)
1071 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
1072 return(0);
1073 break;
1074 case (LIST_bullet):
1075 /* FALLTHROUGH */
1076 case (LIST_dash):
1077 /* FALLTHROUGH */
1078 case (LIST_enum):
1079 /* FALLTHROUGH */
1080 case (LIST_hyphen):
1081 /* FALLTHROUGH */
1082 case (LIST_item):
1083 if (mdoc->last->head->child)
1084 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST))
1085 return(0);
1086 if (NULL == mdoc->last->body->child)
1087 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
1088 return(0);
1089 break;
1090 case (LIST_column):
1091 cols = -1;
1092 for (i = 0; i < (int)n->args->argc; i++)
1093 if (MDOC_Column == n->args->argv[i].arg) {
1094 cols = (int)n->args->argv[i].sz;
1095 break;
1096 }
1097
1098 assert(-1 != cols);
1099 assert(NULL == mdoc->last->head->child);
1100
1101 if (NULL == mdoc->last->body->child)
1102 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
1103 return(0);
1104
1105 for (i = 0, c = mdoc->last->child; c; c = c->next)
1106 if (MDOC_BODY == c->type)
1107 i++;
1108
1109 if (i < cols)
1110 er = MANDOCERR_ARGCOUNT;
1111 else if (i == cols || i == cols + 1)
1112 break;
1113 else
1114 er = MANDOCERR_SYNTARGCOUNT;
1115
1116 rc = mdoc_vmsg(mdoc, er,
1117 mdoc->last->line, mdoc->last->pos,
1118 "columns == %d (have %d)", cols, i);
1119 return(rc);
1120 default:
1121 break;
1122 }
1123
1124 return(1);
1125 }
1126
1127
1128 static int
1129 post_bl_head(POST_ARGS)
1130 {
1131 int i;
1132 struct mdoc_node *n;
1133
1134 assert(mdoc->last->parent);
1135 n = mdoc->last->parent;
1136
1137 if (LIST_column == n->data.Bl.type) {
1138 for (i = 0; i < (int)n->args->argc; i++)
1139 if (MDOC_Column == n->args->argv[i].arg)
1140 break;
1141 assert(i < (int)n->args->argc);
1142
1143 if (n->args->argv[i].sz && mdoc->last->nchild) {
1144 mdoc_nmsg(mdoc, n, MANDOCERR_COLUMNS);
1145 return(0);
1146 }
1147 return(1);
1148 }
1149
1150 if (0 == (i = mdoc->last->nchild))
1151 return(1);
1152 return(warn_count(mdoc, "==", 0, "line arguments", i));
1153 }
1154
1155
1156 static int
1157 post_bl(POST_ARGS)
1158 {
1159 struct mdoc_node *n;
1160
1161 if (MDOC_HEAD == mdoc->last->type)
1162 return(post_bl_head(mdoc));
1163 if (MDOC_BODY != mdoc->last->type)
1164 return(1);
1165 if (NULL == mdoc->last->child)
1166 return(1);
1167
1168 /*
1169 * We only allow certain children of `Bl'. This is usually on
1170 * `It', but apparently `Sm' occurs here and there, so we let
1171 * that one through, too.
1172 */
1173
1174 /* LINTED */
1175 for (n = mdoc->last->child; n; n = n->next) {
1176 if (MDOC_BLOCK == n->type && MDOC_It == n->tok)
1177 continue;
1178 if (MDOC_Sm == n->tok)
1179 continue;
1180 mdoc_nmsg(mdoc, n, MANDOCERR_SYNTCHILD);
1181 return(0);
1182 }
1183
1184 return(1);
1185 }
1186
1187
1188 static int
1189 ebool(struct mdoc *mdoc)
1190 {
1191 struct mdoc_node *n;
1192
1193 /* LINTED */
1194 for (n = mdoc->last->child; n; n = n->next) {
1195 if (MDOC_TEXT != n->type)
1196 break;
1197 if (0 == strcmp(n->string, "on"))
1198 continue;
1199 if (0 == strcmp(n->string, "off"))
1200 continue;
1201 break;
1202 }
1203
1204 if (NULL == n)
1205 return(1);
1206 return(mdoc_nmsg(mdoc, n, MANDOCERR_BADBOOL));
1207 }
1208
1209
1210 static int
1211 post_root(POST_ARGS)
1212 {
1213
1214 if (NULL == mdoc->first->child)
1215 mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY);
1216 else if ( ! (MDOC_PBODY & mdoc->flags))
1217 mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG);
1218 else if (MDOC_BLOCK != mdoc->first->child->type)
1219 mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY);
1220 else if (MDOC_Sh != mdoc->first->child->tok)
1221 mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY);
1222 else
1223 return(1);
1224
1225 return(0);
1226 }
1227
1228
1229 static int
1230 post_st(POST_ARGS)
1231 {
1232
1233 if (mdoc_a2st(mdoc->last->child->string))
1234 return(1);
1235 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADSTANDARD));
1236 }
1237
1238
1239 static int
1240 post_rs(POST_ARGS)
1241 {
1242 struct mdoc_node *nn;
1243
1244 if (MDOC_BODY != mdoc->last->type)
1245 return(1);
1246
1247 for (nn = mdoc->last->child; nn; nn = nn->next)
1248 switch (nn->tok) {
1249 case(MDOC__U):
1250 /* FALLTHROUGH */
1251 case(MDOC__Q):
1252 /* FALLTHROUGH */
1253 case(MDOC__C):
1254 /* FALLTHROUGH */
1255 case(MDOC__A):
1256 /* FALLTHROUGH */
1257 case(MDOC__B):
1258 /* FALLTHROUGH */
1259 case(MDOC__D):
1260 /* FALLTHROUGH */
1261 case(MDOC__I):
1262 /* FALLTHROUGH */
1263 case(MDOC__J):
1264 /* FALLTHROUGH */
1265 case(MDOC__N):
1266 /* FALLTHROUGH */
1267 case(MDOC__O):
1268 /* FALLTHROUGH */
1269 case(MDOC__P):
1270 /* FALLTHROUGH */
1271 case(MDOC__R):
1272 /* FALLTHROUGH */
1273 case(MDOC__T):
1274 /* FALLTHROUGH */
1275 case(MDOC__V):
1276 break;
1277 default:
1278 mdoc_nmsg(mdoc, nn, MANDOCERR_SYNTCHILD);
1279 return(0);
1280 }
1281
1282 return(1);
1283 }
1284
1285
1286 static int
1287 post_sh(POST_ARGS)
1288 {
1289
1290 if (MDOC_HEAD == mdoc->last->type)
1291 return(post_sh_head(mdoc));
1292 if (MDOC_BODY == mdoc->last->type)
1293 return(post_sh_body(mdoc));
1294
1295 return(1);
1296 }
1297
1298
1299 static int
1300 post_sh_body(POST_ARGS)
1301 {
1302 struct mdoc_node *n;
1303
1304 if (SEC_NAME != mdoc->lastsec)
1305 return(1);
1306
1307 /*
1308 * Warn if the NAME section doesn't contain the `Nm' and `Nd'
1309 * macros (can have multiple `Nm' and one `Nd'). Note that the
1310 * children of the BODY declaration can also be "text".
1311 */
1312
1313 if (NULL == (n = mdoc->last->child))
1314 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC));
1315
1316 for ( ; n && n->next; n = n->next) {
1317 if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
1318 continue;
1319 if (MDOC_TEXT == n->type)
1320 continue;
1321 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC))
1322 return(0);
1323 }
1324
1325 assert(n);
1326 if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok)
1327 return(1);
1328 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC));
1329 }
1330
1331
1332 static int
1333 post_sh_head(POST_ARGS)
1334 {
1335 char buf[BUFSIZ];
1336 enum mdoc_sec sec;
1337 const struct mdoc_node *n;
1338
1339 /*
1340 * Process a new section. Sections are either "named" or
1341 * "custom"; custom sections are user-defined, while named ones
1342 * usually follow a conventional order and may only appear in
1343 * certain manual sections.
1344 */
1345
1346 buf[0] = '\0';
1347
1348 /*
1349 * FIXME: yes, these can use a dynamic buffer, but I don't do so
1350 * in the interests of simplicity.
1351 */
1352
1353 for (n = mdoc->last->child; n; n = n->next) {
1354 /* XXX - copied from compact(). */
1355 assert(MDOC_TEXT == n->type);
1356
1357 if (strlcat(buf, n->string, BUFSIZ) >= BUFSIZ) {
1358 mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
1359 return(0);
1360 }
1361 if (NULL == n->next)
1362 continue;
1363 if (strlcat(buf, " ", BUFSIZ) >= BUFSIZ) {
1364 mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
1365 return(0);
1366 }
1367 }
1368
1369 sec = mdoc_str2sec(buf);
1370
1371 /*
1372 * Check: NAME should always be first, CUSTOM has no roles,
1373 * non-CUSTOM has a conventional order to be followed.
1374 */
1375
1376 if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
1377 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NAMESECFIRST))
1378 return(0);
1379
1380 if (SEC_CUSTOM == sec)
1381 return(1);
1382
1383 if (sec == mdoc->lastnamed)
1384 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECREP))
1385 return(0);
1386
1387 if (sec < mdoc->lastnamed)
1388 if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECOOO))
1389 return(0);
1390
1391 /*
1392 * Check particular section/manual conventions. LIBRARY can
1393 * only occur in manual section 2, 3, and 9.
1394 */
1395
1396 switch (sec) {
1397 case (SEC_LIBRARY):
1398 assert(mdoc->meta.msec);
1399 if (*mdoc->meta.msec == '2')
1400 break;
1401 if (*mdoc->meta.msec == '3')
1402 break;
1403 if (*mdoc->meta.msec == '9')
1404 break;
1405 return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECMSEC));
1406 default:
1407 break;
1408 }
1409
1410 return(1);
1411 }