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