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