Annotation of mandoc/mdoc_validate.c, Revision 1.20
1.20 ! kristaps 1: /* $Id: mdoc_validate.c,v 1.19 2009/07/04 10:41:29 kristaps Exp $ */
1.1 kristaps 2: /*
1.7 kristaps 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.5 kristaps 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.5 kristaps 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>
1.2 kristaps 23: #include <string.h>
1.1 kristaps 24:
25: #include "libmdoc.h"
1.18 kristaps 26: #include "libmandoc.h"
1.1 kristaps 27:
28: /* FIXME: .Bl -diag can't have non-text children in HEAD. */
29: /* TODO: ignoring Pp (it's superfluous in some invocations). */
30:
31: #define PRE_ARGS struct mdoc *mdoc, const struct mdoc_node *n
32: #define POST_ARGS struct mdoc *mdoc
33:
34: enum merr {
1.2 kristaps 35: ETOOLONG,
1.1 kristaps 36: EESCAPE,
37: EPRINT,
38: ENODATA,
39: ENOPROLOGUE,
40: ELINE,
41: EATT,
42: ENAME,
43: ELISTTYPE,
44: EDISPTYPE,
45: EMULTIDISP,
1.12 kristaps 46: ESECNAME,
1.1 kristaps 47: EMULTILIST,
48: EARGREP,
49: EBOOL,
1.14 kristaps 50: ECOLMIS,
1.1 kristaps 51: ENESTDISP
52: };
53:
54: enum mwarn {
1.4 kristaps 55: WPRINT,
1.8 kristaps 56: WNOWIDTH,
57: WMISSWIDTH,
1.1 kristaps 58: WESCAPE,
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);
1.4 kristaps 101: static int warn_print(struct mdoc *, int, int);
1.2 kristaps 102: static int warn_count(struct mdoc *, const char *,
1.1 kristaps 103: int, const char *, int);
1.2 kristaps 104: static int err_count(struct mdoc *, const char *,
1.1 kristaps 105: int, const char *, int);
106: static int pre_an(PRE_ARGS);
107: static int pre_bd(PRE_ARGS);
108: static int pre_bl(PRE_ARGS);
109: static int pre_cd(PRE_ARGS);
110: static int pre_dd(PRE_ARGS);
111: static int pre_display(PRE_ARGS);
112: static int pre_dt(PRE_ARGS);
113: static int pre_er(PRE_ARGS);
114: static int pre_ex(PRE_ARGS);
115: static int pre_fd(PRE_ARGS);
116: static int pre_it(PRE_ARGS);
117: static int pre_lb(PRE_ARGS);
118: static int pre_os(PRE_ARGS);
119: static int pre_rv(PRE_ARGS);
120: static int pre_sh(PRE_ARGS);
121: static int pre_ss(PRE_ARGS);
122: static int herr_ge1(POST_ARGS);
123: static int hwarn_le1(POST_ARGS);
124: static int herr_eq0(POST_ARGS);
125: static int eerr_eq0(POST_ARGS);
126: static int eerr_le2(POST_ARGS);
127: static int eerr_eq1(POST_ARGS);
128: static int eerr_ge1(POST_ARGS);
129: static int ewarn_eq0(POST_ARGS);
130: static int ewarn_eq1(POST_ARGS);
131: static int bwarn_ge1(POST_ARGS);
132: static int hwarn_eq1(POST_ARGS);
133: static int ewarn_ge1(POST_ARGS);
134: static int ebool(POST_ARGS);
135: static int post_an(POST_ARGS);
136: static int post_args(POST_ARGS);
137: static int post_at(POST_ARGS);
138: static int post_bf(POST_ARGS);
139: static int post_bl(POST_ARGS);
1.14 kristaps 140: static int post_bl_head(POST_ARGS);
1.1 kristaps 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:
1.2 kristaps 149: #define vwarn(m, t) nwarn((m), (m)->last, (t))
150: #define verr(m, t) nerr((m), (m)->last, (t))
1.1 kristaps 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.12 kristaps 158: static v_pre pres_dd[] = { pre_dd, NULL };
1.1 kristaps 159: static v_pre pres_d1[] = { pre_display, NULL };
1.12 kristaps 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.12 kristaps 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 };
1.14 kristaps 177: static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL };
1.1 kristaps 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.10 kristaps 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.9 kristaps 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:
1.2 kristaps 316: #ifdef __linux__
317: extern size_t strlcat(char *, const char *, size_t);
318: #endif
319:
320:
1.1 kristaps 321: int
322: mdoc_valid_pre(struct mdoc *mdoc,
323: const struct mdoc_node *n)
324: {
325: v_pre *p;
326: int line, pos;
327: const char *tp;
328:
329: if (MDOC_TEXT == n->type) {
330: tp = n->string;
331: line = n->line;
332: pos = n->pos;
333: return(check_text(mdoc, line, pos, tp));
334: }
335:
336: if ( ! check_args(mdoc, n))
337: return(0);
338: if (NULL == mdoc_valids[n->tok].pre)
339: return(1);
340: for (p = mdoc_valids[n->tok].pre; *p; p++)
341: if ( ! (*p)(mdoc, n))
342: return(0);
343: return(1);
344: }
345:
346:
347: int
348: mdoc_valid_post(struct mdoc *mdoc)
349: {
350: v_post *p;
351:
352: /*
353: * This check occurs after the macro's children have been filled
354: * in: postfix validation. Since this happens when we're
355: * rewinding the scope tree, it's possible to have multiple
356: * invocations (as by design, for now), we set bit MDOC_VALID to
357: * indicate that we've validated.
358: */
359:
360: if (MDOC_VALID & mdoc->last->flags)
361: return(1);
362: mdoc->last->flags |= MDOC_VALID;
363:
364: if (MDOC_TEXT == mdoc->last->type)
365: return(1);
366: if (MDOC_ROOT == mdoc->last->type)
367: return(post_root(mdoc));
368:
369: if (NULL == mdoc_valids[mdoc->last->tok].post)
370: return(1);
371: for (p = mdoc_valids[mdoc->last->tok].post; *p; p++)
372: if ( ! (*p)(mdoc))
373: return(0);
374:
375: return(1);
376: }
377:
378:
379: static int
380: perr(struct mdoc *m, int line, int pos, enum merr type)
381: {
382: char *p;
383:
384: p = NULL;
385: switch (type) {
1.2 kristaps 386: case (ETOOLONG):
387: p = "text argument too long";
388: break;
1.1 kristaps 389: case (EESCAPE):
390: p = "invalid escape sequence";
391: break;
392: case (EPRINT):
393: p = "invalid character";
394: break;
395: case (ENESTDISP):
396: p = "displays may not be nested";
397: break;
398: case (EBOOL):
399: p = "expected boolean value";
400: break;
401: case (EARGREP):
402: p = "argument repeated";
403: break;
404: case (EMULTIDISP):
405: p = "multiple display types specified";
406: break;
407: case (EMULTILIST):
408: p = "multiple list types specified";
409: break;
410: case (ELISTTYPE):
411: p = "missing list type";
412: break;
413: case (EDISPTYPE):
414: p = "missing display type";
415: break;
1.12 kristaps 416: case (ESECNAME):
417: p = "the NAME section must come first";
418: break;
1.1 kristaps 419: case (ELINE):
420: p = "expected line arguments";
421: break;
422: case (ENOPROLOGUE):
423: p = "document has no prologue";
424: break;
425: case (ENODATA):
426: p = "document has no data";
427: break;
1.14 kristaps 428: case (ECOLMIS):
429: p = "column syntax style mismatch";
430: break;
1.1 kristaps 431: case (EATT):
432: p = "expected valid AT&T symbol";
433: break;
434: case (ENAME):
435: p = "default name not yet set";
436: break;
437: }
438: assert(p);
439: return(mdoc_perr(m, line, pos, p));
440: }
441:
442:
443: static int
444: pwarn(struct mdoc *m, int line, int pos, enum mwarn type)
445: {
446: char *p;
447:
448: p = NULL;
1.20 ! kristaps 449:
1.1 kristaps 450: switch (type) {
451: case (WBADMSEC):
452: p = "inappropriate manual section";
453: break;
454: case (WBADSEC):
455: p = "inappropriate document section";
456: break;
457: case (WARGVAL):
458: p = "argument value suggested";
459: break;
460: case (WPROLREP):
461: p = "prologue macros repeated";
462: break;
463: case (WPROLOOO):
464: p = "prologue macros out-of-order";
465: break;
1.8 kristaps 466: case (WNOWIDTH):
467: p = "superfluous width argument";
468: break;
469: case (WMISSWIDTH):
470: p = "missing width argument";
471: break;
1.4 kristaps 472: case (WPRINT):
473: p = "invalid character";
474: break;
1.1 kristaps 475: case (WESCAPE):
476: p = "invalid escape sequence";
477: break;
478: case (WNOLINE):
479: p = "suggested no line arguments";
480: break;
481: case (WLINE):
482: p = "suggested line arguments";
483: break;
484: case (WMULTILINE):
485: p = "suggested multi-line arguments";
486: break;
487: case (WNOMULTILINE):
488: p = "suggested no multi-line arguments";
489: break;
490: case (WWRONGMSEC):
491: p = "document section in wrong manual section";
492: break;
493: case (WSECOOO):
494: p = "document section out of conventional order";
495: break;
496: case (WSECREP):
497: p = "document section repeated";
498: break;
499: case (WBADSTAND):
500: p = "unknown standard";
501: break;
502: case (WNAMESECINC):
503: p = "NAME section contents incomplete/badly-ordered";
504: break;
505: }
1.20 ! kristaps 506:
1.1 kristaps 507: assert(p);
1.20 ! kristaps 508: return(mdoc_pwarn(m, line, pos, p));
1.1 kristaps 509: }
510:
511:
1.4 kristaps 512: static int
513: warn_print(struct mdoc *m, int ln, int pos)
514: {
515: if (MDOC_IGN_CHARS & m->pflags)
516: return(pwarn(m, ln, pos, WPRINT));
517: return(perr(m, ln, pos, EPRINT));
518: }
519:
1.1 kristaps 520:
521: static inline int
522: warn_count(struct mdoc *m, const char *k,
523: int want, const char *v, int has)
524: {
525:
1.20 ! kristaps 526: return(mdoc_warn(m, "suggests %s %s %d (has %d)",
! 527: v, k, want, has));
1.1 kristaps 528: }
529:
530:
531: static inline int
532: err_count(struct mdoc *m, const char *k,
533: int want, const char *v, int has)
534: {
535:
536: return(mdoc_err(m,
537: "requires %s %s %d (has %d)", v, k, want, has));
538: }
539:
540:
541: /*
542: * Build these up with macros because they're basically the same check
543: * for different inequalities. Yes, this could be done with functions,
544: * but this is reasonable for now.
545: */
546:
547: #define CHECK_CHILD_DEFN(lvl, name, ineq) \
548: static int \
549: lvl##_child_##name(struct mdoc *mdoc, const char *p, int sz) \
550: { \
1.16 kristaps 551: if (mdoc->last->nchild ineq sz) \
1.1 kristaps 552: return(1); \
1.16 kristaps 553: return(lvl##_count(mdoc, #ineq, sz, p, mdoc->last->nchild)); \
1.1 kristaps 554: }
555:
556: #define CHECK_BODY_DEFN(name, lvl, func, num) \
557: static int \
558: b##lvl##_##name(POST_ARGS) \
559: { \
560: if (MDOC_BODY != mdoc->last->type) \
561: return(1); \
562: return(func(mdoc, "multi-line arguments", (num))); \
563: }
564:
565: #define CHECK_ELEM_DEFN(name, lvl, func, num) \
566: static int \
567: e##lvl##_##name(POST_ARGS) \
568: { \
569: assert(MDOC_ELEM == mdoc->last->type); \
570: return(func(mdoc, "line arguments", (num))); \
571: }
572:
573: #define CHECK_HEAD_DEFN(name, lvl, func, num) \
574: static int \
575: h##lvl##_##name(POST_ARGS) \
576: { \
577: if (MDOC_HEAD != mdoc->last->type) \
578: return(1); \
579: return(func(mdoc, "line arguments", (num))); \
580: }
581:
582:
583: CHECK_CHILD_DEFN(warn, gt, >) /* warn_child_gt() */
584: CHECK_CHILD_DEFN(err, gt, >) /* err_child_gt() */
585: CHECK_CHILD_DEFN(warn, eq, ==) /* warn_child_eq() */
586: CHECK_CHILD_DEFN(err, eq, ==) /* err_child_eq() */
587: CHECK_CHILD_DEFN(err, lt, <) /* err_child_lt() */
588: CHECK_CHILD_DEFN(warn, lt, <) /* warn_child_lt() */
589: CHECK_BODY_DEFN(ge1, warn, warn_child_gt, 0) /* bwarn_ge1() */
590: CHECK_ELEM_DEFN(eq1, warn, warn_child_eq, 1) /* ewarn_eq1() */
591: CHECK_ELEM_DEFN(eq0, warn, warn_child_eq, 0) /* ewarn_eq0() */
592: CHECK_ELEM_DEFN(ge1, warn, warn_child_gt, 0) /* ewarn_gt1() */
593: CHECK_ELEM_DEFN(eq1, err, err_child_eq, 1) /* eerr_eq1() */
594: CHECK_ELEM_DEFN(le2, err, err_child_lt, 3) /* eerr_le2() */
595: CHECK_ELEM_DEFN(eq0, err, err_child_eq, 0) /* eerr_eq0() */
596: CHECK_ELEM_DEFN(ge1, err, err_child_gt, 0) /* eerr_ge1() */
597: CHECK_HEAD_DEFN(eq0, err, err_child_eq, 0) /* herr_eq0() */
598: CHECK_HEAD_DEFN(le1, warn, warn_child_lt, 2) /* hwarn_le1() */
599: CHECK_HEAD_DEFN(ge1, err, err_child_gt, 0) /* herr_ge1() */
600: CHECK_HEAD_DEFN(eq1, warn, warn_child_eq, 1) /* hwarn_eq1() */
601:
602:
603: static int
604: check_stdarg(PRE_ARGS)
605: {
606:
607: if (n->args && 1 == n->args->argc)
608: if (MDOC_Std == n->args->argv[0].arg)
609: return(1);
610: return(nwarn(mdoc, n, WARGVAL));
611: }
612:
613:
614: static int
615: check_sec(PRE_ARGS, ...)
616: {
617: enum mdoc_sec sec;
618: va_list ap;
619:
620: va_start(ap, n);
621:
622: for (;;) {
623: /* LINTED */
624: sec = (enum mdoc_sec)va_arg(ap, int);
625: if (SEC_CUSTOM == sec)
626: break;
627: if (sec != mdoc->lastsec)
628: continue;
629: va_end(ap);
630: return(1);
631: }
632:
633: va_end(ap);
634: return(nwarn(mdoc, n, WBADSEC));
635: }
636:
637:
638: static int
639: check_msec(PRE_ARGS, ...)
640: {
641: va_list ap;
642: int msec;
643:
644: va_start(ap, n);
645: for (;;) {
646: /* LINTED */
647: if (0 == (msec = va_arg(ap, int)))
648: break;
649: if (msec != mdoc->meta.msec)
650: continue;
651: va_end(ap);
652: return(1);
653: }
654:
655: va_end(ap);
656: return(nwarn(mdoc, n, WBADMSEC));
657: }
658:
659:
660: static int
661: check_args(struct mdoc *m, const struct mdoc_node *n)
662: {
663: int i;
664:
665: if (NULL == n->args)
666: return(1);
667:
668: assert(n->args->argc);
669: for (i = 0; i < (int)n->args->argc; i++)
670: if ( ! check_argv(m, n, &n->args->argv[i]))
671: return(0);
672:
673: return(1);
674: }
675:
676:
677: static int
678: check_argv(struct mdoc *m, const struct mdoc_node *n,
679: const struct mdoc_argv *v)
680: {
681: int i;
682:
683: for (i = 0; i < (int)v->sz; i++)
684: if ( ! check_text(m, v->line, v->pos, v->value[i]))
685: return(0);
686:
687: if (MDOC_Std == v->arg) {
688: /* `Nm' name must be set. */
689: if (v->sz || m->meta.name)
690: return(1);
691: return(nerr(m, n, ENAME));
692: }
693:
694: return(1);
695: }
696:
697:
698: static int
699: check_text(struct mdoc *mdoc, int line, int pos, const char *p)
700: {
1.18 kristaps 701: int c;
1.1 kristaps 702:
1.18 kristaps 703: for ( ; *p; p++, pos++) {
1.1 kristaps 704: if ('\t' == *p) {
705: if ( ! (MDOC_LITERAL & mdoc->flags))
1.4 kristaps 706: if ( ! warn_print(mdoc, line, pos))
707: return(0);
1.1 kristaps 708: } else if ( ! isprint((u_char)*p))
1.4 kristaps 709: if ( ! warn_print(mdoc, line, pos))
710: return(0);
1.1 kristaps 711:
712: if ('\\' != *p)
713: continue;
714:
1.18 kristaps 715: c = mandoc_special(p);
1.1 kristaps 716: if (c) {
1.18 kristaps 717: p += c - 1;
718: pos += c - 1;
1.1 kristaps 719: continue;
720: }
721: if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags))
722: return(perr(mdoc, line, pos, EESCAPE));
723: if ( ! pwarn(mdoc, line, pos, WESCAPE))
724: return(0);
725: }
726:
727: return(1);
728: }
729:
730:
731:
732:
733: static int
734: check_parent(PRE_ARGS, int tok, enum mdoc_type t)
735: {
736:
737: assert(n->parent);
738: if ((MDOC_ROOT == t || tok == n->parent->tok) &&
739: (t == n->parent->type))
740: return(1);
741:
742: return(mdoc_nerr(mdoc, n, "require parent %s",
743: MDOC_ROOT == t ? "<root>" : mdoc_macronames[tok]));
744: }
745:
746:
747:
748: static int
749: pre_display(PRE_ARGS)
750: {
751: struct mdoc_node *node;
752:
753: /* Display elements (`Bd', `D1'...) cannot be nested. */
754:
755: if (MDOC_BLOCK != n->type)
756: return(1);
757:
758: /* LINTED */
759: for (node = mdoc->last->parent; node; node = node->parent)
760: if (MDOC_BLOCK == node->type)
761: if (MDOC_Bd == node->tok)
762: break;
763: if (NULL == node)
764: return(1);
765:
766: return(nerr(mdoc, n, ENESTDISP));
767: }
768:
769:
770: static int
771: pre_bl(PRE_ARGS)
772: {
1.15 kristaps 773: int pos, type, width, offset;
1.1 kristaps 774:
775: if (MDOC_BLOCK != n->type)
776: return(1);
777: if (NULL == n->args)
778: return(nerr(mdoc, n, ELISTTYPE));
779:
780: /* Make sure that only one type of list is specified. */
781:
1.15 kristaps 782: type = offset = width = -1;
1.1 kristaps 783:
784: /* LINTED */
1.8 kristaps 785: for (pos = 0; pos < (int)n->args->argc; pos++)
786: switch (n->args->argv[pos].arg) {
1.1 kristaps 787: case (MDOC_Bullet):
788: /* FALLTHROUGH */
789: case (MDOC_Dash):
790: /* FALLTHROUGH */
791: case (MDOC_Enum):
792: /* FALLTHROUGH */
793: case (MDOC_Hyphen):
794: /* FALLTHROUGH */
795: case (MDOC_Item):
796: /* FALLTHROUGH */
797: case (MDOC_Tag):
798: /* FALLTHROUGH */
799: case (MDOC_Diag):
800: /* FALLTHROUGH */
801: case (MDOC_Hang):
802: /* FALLTHROUGH */
803: case (MDOC_Ohang):
804: /* FALLTHROUGH */
805: case (MDOC_Inset):
806: /* FALLTHROUGH */
807: case (MDOC_Column):
1.8 kristaps 808: if (-1 != type)
809: return(nerr(mdoc, n, EMULTILIST));
810: type = n->args->argv[pos].arg;
811: break;
1.1 kristaps 812: case (MDOC_Width):
1.8 kristaps 813: if (-1 != width)
814: return(nerr(mdoc, n, EARGREP));
815: width = n->args->argv[pos].arg;
816: break;
1.1 kristaps 817: case (MDOC_Offset):
1.8 kristaps 818: if (-1 != offset)
819: return(nerr(mdoc, n, EARGREP));
820: offset = n->args->argv[pos].arg;
821: break;
1.1 kristaps 822: default:
823: break;
824: }
825:
826: if (-1 == type)
827: return(nerr(mdoc, n, ELISTTYPE));
828:
1.8 kristaps 829: /*
830: * Validate the width field. Some list types don't need width
831: * types and should be warned about them. Others should have it
832: * and must also be warned.
833: */
834:
1.1 kristaps 835: switch (type) {
1.8 kristaps 836: case (MDOC_Tag):
837: if (-1 == width && ! nwarn(mdoc, n, WMISSWIDTH))
838: return(0);
839: break;
1.1 kristaps 840: case (MDOC_Column):
841: /* FALLTHROUGH */
842: case (MDOC_Diag):
843: /* FALLTHROUGH */
844: case (MDOC_Inset):
845: /* FALLTHROUGH */
846: case (MDOC_Item):
1.8 kristaps 847: if (-1 != width && ! nwarn(mdoc, n, WNOWIDTH))
848: return(0);
849: break;
850: default:
851: break;
852: }
853:
1.1 kristaps 854: return(1);
855: }
856:
857:
858: static int
859: pre_bd(PRE_ARGS)
860: {
861: int i, type, err;
862:
863: if (MDOC_BLOCK != n->type)
864: return(1);
865: if (NULL == n->args)
866: return(nerr(mdoc, n, EDISPTYPE));
867:
868: /* Make sure that only one type of display is specified. */
869:
870: /* LINTED */
871: for (i = 0, err = type = 0; ! err &&
872: i < (int)n->args->argc; i++)
873: switch (n->args->argv[i].arg) {
874: case (MDOC_Ragged):
875: /* FALLTHROUGH */
876: case (MDOC_Unfilled):
877: /* FALLTHROUGH */
878: case (MDOC_Filled):
879: /* FALLTHROUGH */
880: case (MDOC_Literal):
881: /* FALLTHROUGH */
882: case (MDOC_File):
883: if (0 == type++)
884: break;
885: return(nerr(mdoc, n, EMULTIDISP));
886: default:
887: break;
888: }
889:
890: if (type)
891: return(1);
892: return(nerr(mdoc, n, EDISPTYPE));
893: }
894:
895:
896: static int
897: pre_ss(PRE_ARGS)
898: {
899:
900: if (MDOC_BLOCK != n->type)
901: return(1);
902: return(check_parent(mdoc, n, MDOC_Sh, MDOC_BODY));
903: }
904:
905:
906: static int
907: pre_sh(PRE_ARGS)
908: {
909:
910: if (MDOC_BLOCK != n->type)
911: return(1);
912: return(check_parent(mdoc, n, -1, MDOC_ROOT));
913: }
914:
915:
916: static int
917: pre_it(PRE_ARGS)
918: {
919:
920: if (MDOC_BLOCK != n->type)
921: return(1);
922: return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY));
923: }
924:
925:
926: static int
927: pre_an(PRE_ARGS)
928: {
929:
930: if (NULL == n->args || 1 == n->args->argc)
931: return(1);
932: return(mdoc_nerr(mdoc, n, "only one argument allowed"));
933: }
934:
935:
936: static int
937: pre_lb(PRE_ARGS)
938: {
939:
940: return(check_sec(mdoc, n, SEC_LIBRARY, SEC_CUSTOM));
941: }
942:
943:
944: static int
945: pre_rv(PRE_ARGS)
946: {
947:
948: if ( ! check_msec(mdoc, n, 2, 3, 0))
949: return(0);
950: return(check_stdarg(mdoc, n));
951: }
952:
953:
954: static int
955: pre_ex(PRE_ARGS)
956: {
957:
958: if ( ! check_msec(mdoc, n, 1, 6, 8, 0))
959: return(0);
960: return(check_stdarg(mdoc, n));
961: }
962:
963:
964: static int
965: pre_er(PRE_ARGS)
966: {
967:
1.6 kristaps 968: return(check_msec(mdoc, n, 2, 3, 9, 0));
1.1 kristaps 969: }
970:
971:
972: static int
973: pre_cd(PRE_ARGS)
974: {
975:
976: return(check_msec(mdoc, n, 4, 0));
977: }
978:
979:
980: static int
981: pre_dt(PRE_ARGS)
982: {
983:
984: if (0 == mdoc->meta.date || mdoc->meta.os)
985: if ( ! nwarn(mdoc, n, WPROLOOO))
986: return(0);
987: if (mdoc->meta.title)
988: if ( ! nwarn(mdoc, n, WPROLREP))
989: return(0);
990: return(1);
991: }
992:
993:
994: static int
995: pre_os(PRE_ARGS)
996: {
997:
998: if (NULL == mdoc->meta.title || 0 == mdoc->meta.date)
999: if ( ! nwarn(mdoc, n, WPROLOOO))
1000: return(0);
1001: if (mdoc->meta.os)
1002: if ( ! nwarn(mdoc, n, WPROLREP))
1003: return(0);
1004: return(1);
1005: }
1006:
1007:
1008: static int
1009: pre_dd(PRE_ARGS)
1010: {
1011:
1012: if (mdoc->meta.title || mdoc->meta.os)
1013: if ( ! nwarn(mdoc, n, WPROLOOO))
1014: return(0);
1015: if (mdoc->meta.date)
1016: if ( ! nwarn(mdoc, n, WPROLREP))
1017: return(0);
1018: return(1);
1019: }
1020:
1021:
1022: static int
1023: post_bf(POST_ARGS)
1024: {
1025: char *p;
1026: struct mdoc_node *head;
1027:
1028: if (MDOC_BLOCK != mdoc->last->type)
1029: return(1);
1030:
1031: head = mdoc->last->head;
1032:
1.12 kristaps 1033: if (mdoc->last->args && head->child)
1.13 kristaps 1034: return(mdoc_err(mdoc, "one argument expected"));
1035: else if (mdoc->last->args)
1036: return(1);
1.12 kristaps 1037:
1.13 kristaps 1038: if (NULL == head->child || MDOC_TEXT != head->child->type)
1039: return(mdoc_err(mdoc, "text argument expected"));
1.1 kristaps 1040:
1.13 kristaps 1041: p = head->child->string;
1.1 kristaps 1042:
1.13 kristaps 1043: if (0 == strcmp(p, "Em"))
1044: return(1);
1045: else if (0 == strcmp(p, "Li"))
1046: return(1);
1047: else if (0 == strcmp(p, "Sm"))
1048: return(1);
1.1 kristaps 1049:
1.13 kristaps 1050: return(mdoc_nerr(mdoc, head->child, "invalid font mode"));
1.1 kristaps 1051: }
1052:
1053:
1054: static int
1055: post_nm(POST_ARGS)
1056: {
1057:
1058: if (mdoc->last->child)
1059: return(1);
1060: if (mdoc->meta.name)
1061: return(1);
1.2 kristaps 1062: return(verr(mdoc, ENAME));
1.1 kristaps 1063: }
1064:
1065:
1066: static int
1067: post_at(POST_ARGS)
1068: {
1069:
1070: if (NULL == mdoc->last->child)
1071: return(1);
1072: if (MDOC_TEXT != mdoc->last->child->type)
1.2 kristaps 1073: return(verr(mdoc, EATT));
1.1 kristaps 1074: if (mdoc_a2att(mdoc->last->child->string))
1075: return(1);
1.2 kristaps 1076: return(verr(mdoc, EATT));
1.1 kristaps 1077: }
1078:
1079:
1080: static int
1081: post_an(POST_ARGS)
1082: {
1083:
1084: if (mdoc->last->args) {
1085: if (NULL == mdoc->last->child)
1086: return(1);
1.2 kristaps 1087: return(verr(mdoc, ELINE));
1.1 kristaps 1088: }
1089:
1090: if (mdoc->last->child)
1091: return(1);
1.2 kristaps 1092: return(verr(mdoc, ELINE));
1.1 kristaps 1093: }
1094:
1095:
1096: static int
1097: post_args(POST_ARGS)
1098: {
1099:
1100: if (mdoc->last->args)
1101: return(1);
1.2 kristaps 1102: return(verr(mdoc, ELINE));
1.1 kristaps 1103: }
1104:
1105:
1106: static int
1107: post_it(POST_ARGS)
1108: {
1109: int type, i, cols;
1110: struct mdoc_node *n, *c;
1111:
1112: if (MDOC_BLOCK != mdoc->last->type)
1113: return(1);
1114:
1115: n = mdoc->last->parent->parent;
1116: if (NULL == n->args)
1.2 kristaps 1117: return(verr(mdoc, ELISTTYPE));
1.1 kristaps 1118:
1119: /* Some types require block-head, some not. */
1120:
1121: /* LINTED */
1122: for (cols = type = -1, i = 0; -1 == type &&
1123: i < (int)n->args->argc; i++)
1124: switch (n->args->argv[i].arg) {
1125: case (MDOC_Tag):
1126: /* FALLTHROUGH */
1127: case (MDOC_Diag):
1128: /* FALLTHROUGH */
1129: case (MDOC_Hang):
1130: /* FALLTHROUGH */
1131: case (MDOC_Ohang):
1132: /* FALLTHROUGH */
1133: case (MDOC_Inset):
1134: /* FALLTHROUGH */
1135: case (MDOC_Bullet):
1136: /* FALLTHROUGH */
1137: case (MDOC_Dash):
1138: /* FALLTHROUGH */
1139: case (MDOC_Enum):
1140: /* FALLTHROUGH */
1141: case (MDOC_Hyphen):
1142: /* FALLTHROUGH */
1143: case (MDOC_Item):
1144: type = n->args->argv[i].arg;
1145: break;
1146: case (MDOC_Column):
1147: type = n->args->argv[i].arg;
1148: cols = (int)n->args->argv[i].sz;
1149: break;
1150: default:
1151: break;
1152: }
1153:
1154: if (-1 == type)
1.2 kristaps 1155: return(verr(mdoc, ELISTTYPE));
1.1 kristaps 1156:
1157: switch (type) {
1158: case (MDOC_Tag):
1159: if (NULL == mdoc->last->head->child)
1.2 kristaps 1160: if ( ! vwarn(mdoc, WLINE))
1.1 kristaps 1161: return(0);
1162: break;
1163: case (MDOC_Hang):
1164: /* FALLTHROUGH */
1165: case (MDOC_Ohang):
1166: /* FALLTHROUGH */
1167: case (MDOC_Inset):
1168: /* FALLTHROUGH */
1169: case (MDOC_Diag):
1170: if (NULL == mdoc->last->head->child)
1.2 kristaps 1171: if ( ! vwarn(mdoc, WLINE))
1.1 kristaps 1172: return(0);
1173: if (NULL == mdoc->last->body->child)
1.2 kristaps 1174: if ( ! vwarn(mdoc, WMULTILINE))
1.1 kristaps 1175: return(0);
1176: break;
1177: case (MDOC_Bullet):
1178: /* FALLTHROUGH */
1179: case (MDOC_Dash):
1180: /* FALLTHROUGH */
1181: case (MDOC_Enum):
1182: /* FALLTHROUGH */
1183: case (MDOC_Hyphen):
1184: /* FALLTHROUGH */
1185: case (MDOC_Item):
1186: if (mdoc->last->head->child)
1.2 kristaps 1187: if ( ! vwarn(mdoc, WNOLINE))
1.1 kristaps 1188: return(0);
1189: if (NULL == mdoc->last->body->child)
1.2 kristaps 1190: if ( ! vwarn(mdoc, WMULTILINE))
1.1 kristaps 1191: return(0);
1192: break;
1193: case (MDOC_Column):
1194: if (NULL == mdoc->last->head->child)
1.2 kristaps 1195: if ( ! vwarn(mdoc, WLINE))
1.1 kristaps 1196: return(0);
1197: if (mdoc->last->body->child)
1.2 kristaps 1198: if ( ! vwarn(mdoc, WNOMULTILINE))
1.1 kristaps 1199: return(0);
1200: c = mdoc->last->child;
1201: for (i = 0; c && MDOC_HEAD == c->type; c = c->next)
1202: i++;
1203: if (i == cols)
1204: break;
1205: return(mdoc_err(mdoc, "column mismatch (have "
1206: "%d, want %d)", i, cols));
1207: default:
1208: break;
1209: }
1210:
1211: return(1);
1212: }
1213:
1214:
1215: static int
1.14 kristaps 1216: post_bl_head(POST_ARGS)
1217: {
1218: int i;
1219: const struct mdoc_node *n;
1220:
1221: n = mdoc->last->parent;
1222: assert(n->args);
1223:
1224: for (i = 0; i < (int)n->args->argc; i++)
1225: if (n->args->argv[i].arg == MDOC_Column)
1226: break;
1227:
1228: if (i == (int)n->args->argc)
1229: return(1);
1230:
1231: if (n->args->argv[i].sz && mdoc->last->child)
1232: return(nerr(mdoc, n, ECOLMIS));
1233:
1234: return(1);
1235: }
1236:
1237:
1238: static int
1.1 kristaps 1239: post_bl(POST_ARGS)
1240: {
1241: struct mdoc_node *n;
1242:
1.14 kristaps 1243: if (MDOC_HEAD == mdoc->last->type)
1244: return(post_bl_head(mdoc));
1.1 kristaps 1245: if (MDOC_BODY != mdoc->last->type)
1246: return(1);
1247: if (NULL == mdoc->last->child)
1248: return(1);
1249:
1250: /* LINTED */
1251: for (n = mdoc->last->child; n; n = n->next) {
1252: if (MDOC_BLOCK == n->type)
1253: if (MDOC_It == n->tok)
1254: continue;
1255: return(mdoc_nerr(mdoc, n, "bad child of parent %s",
1256: mdoc_macronames[mdoc->last->tok]));
1257: }
1258:
1259: return(1);
1260: }
1261:
1262:
1263: static int
1264: ebool(struct mdoc *mdoc)
1265: {
1266: struct mdoc_node *n;
1267:
1268: /* LINTED */
1269: for (n = mdoc->last->child; n; n = n->next) {
1270: if (MDOC_TEXT != n->type)
1271: break;
1.2 kristaps 1272: if (0 == strcmp(n->string, "on"))
1.1 kristaps 1273: continue;
1.2 kristaps 1274: if (0 == strcmp(n->string, "off"))
1.1 kristaps 1275: continue;
1276: break;
1277: }
1278:
1279: if (NULL == n)
1280: return(1);
1281: return(nerr(mdoc, n, EBOOL));
1282: }
1283:
1284:
1285: static int
1286: post_root(POST_ARGS)
1287: {
1288:
1289: if (NULL == mdoc->first->child)
1.2 kristaps 1290: return(verr(mdoc, ENODATA));
1.12 kristaps 1291: if ( ! (MDOC_PBODY & mdoc->flags))
1.2 kristaps 1292: return(verr(mdoc, ENOPROLOGUE));
1.1 kristaps 1293:
1294: if (MDOC_BLOCK != mdoc->first->child->type)
1.2 kristaps 1295: return(verr(mdoc, ENODATA));
1.1 kristaps 1296: if (MDOC_Sh != mdoc->first->child->tok)
1.2 kristaps 1297: return(verr(mdoc, ENODATA));
1.1 kristaps 1298:
1299: return(1);
1300: }
1301:
1302:
1303: static int
1304: post_st(POST_ARGS)
1305: {
1306:
1307: if (mdoc_a2st(mdoc->last->child->string))
1308: return(1);
1.2 kristaps 1309: return(vwarn(mdoc, WBADSTAND));
1.1 kristaps 1310: }
1311:
1312:
1313: static int
1314: post_sh(POST_ARGS)
1315: {
1316:
1317: if (MDOC_HEAD == mdoc->last->type)
1318: return(post_sh_head(mdoc));
1319: if (MDOC_BODY == mdoc->last->type)
1320: return(post_sh_body(mdoc));
1321:
1322: return(1);
1323: }
1324:
1325:
1326: static int
1327: post_sh_body(POST_ARGS)
1328: {
1329: struct mdoc_node *n;
1330:
1331: if (SEC_NAME != mdoc->lastnamed)
1332: return(1);
1333:
1334: /*
1335: * Warn if the NAME section doesn't contain the `Nm' and `Nd'
1336: * macros (can have multiple `Nm' and one `Nd'). Note that the
1337: * children of the BODY declaration can also be "text".
1338: */
1339:
1340: if (NULL == (n = mdoc->last->child))
1.2 kristaps 1341: return(vwarn(mdoc, WNAMESECINC));
1.1 kristaps 1342:
1343: for ( ; n && n->next; n = n->next) {
1344: if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
1345: continue;
1346: if (MDOC_TEXT == n->type)
1347: continue;
1.2 kristaps 1348: if ( ! vwarn(mdoc, WNAMESECINC))
1.1 kristaps 1349: return(0);
1350: }
1351:
1352: if (MDOC_ELEM == n->type && MDOC_Nd == n->tok)
1353: return(1);
1.2 kristaps 1354: return(vwarn(mdoc, WNAMESECINC));
1.1 kristaps 1355: }
1356:
1357:
1358: static int
1359: post_sh_head(POST_ARGS)
1360: {
1.2 kristaps 1361: char buf[64];
1362: enum mdoc_sec sec;
1363: const struct mdoc_node *n;
1.1 kristaps 1364:
1365: /*
1366: * Process a new section. Sections are either "named" or
1367: * "custom"; custom sections are user-defined, while named ones
1368: * usually follow a conventional order and may only appear in
1369: * certain manual sections.
1370: */
1371:
1.12 kristaps 1372: buf[0] = 0;
1.1 kristaps 1373:
1.2 kristaps 1374: for (n = mdoc->last->child; n; n = n->next) {
1.12 kristaps 1375: /* XXX - copied from compact(). */
1.2 kristaps 1376: assert(MDOC_TEXT == n->type);
1.12 kristaps 1377:
1.2 kristaps 1378: if (strlcat(buf, n->string, 64) >= 64)
1379: return(nerr(mdoc, n, ETOOLONG));
1380: if (NULL == n->next)
1381: continue;
1382: if (strlcat(buf, " ", 64) >= 64)
1383: return(nerr(mdoc, n, ETOOLONG));
1384: }
1.1 kristaps 1385:
1386: sec = mdoc_atosec(buf);
1387:
1.12 kristaps 1388: /*
1389: * Check: NAME should always be first, CUSTOM has no roles,
1390: * non-CUSTOM has a conventional order to be followed.
1391: */
1.1 kristaps 1392:
1.12 kristaps 1393: if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
1394: return(verr(mdoc, ESECNAME));
1.1 kristaps 1395: if (SEC_CUSTOM == sec)
1396: return(1);
1397: if (sec == mdoc->lastnamed)
1.2 kristaps 1398: return(vwarn(mdoc, WSECREP));
1.1 kristaps 1399: if (sec < mdoc->lastnamed)
1.2 kristaps 1400: return(vwarn(mdoc, WSECOOO));
1.1 kristaps 1401:
1.12 kristaps 1402: /*
1403: * Check particular section/manual conventions. LIBRARY can
1404: * only occur in msec 2, 3 (TODO: are there more of these?).
1405: */
1.1 kristaps 1406:
1407: switch (sec) {
1408: case (SEC_LIBRARY):
1409: switch (mdoc->meta.msec) {
1410: case (2):
1411: /* FALLTHROUGH */
1412: case (3):
1413: break;
1414: default:
1.2 kristaps 1415: return(vwarn(mdoc, WWRONGMSEC));
1.1 kristaps 1416: }
1417: break;
1418: default:
1419: break;
1420: }
1421:
1422: return(1);
1423: }
1424:
1425:
1426: static int
1427: pre_fd(PRE_ARGS)
1428: {
1429:
1430: return(check_sec(mdoc, n, SEC_SYNOPSIS, SEC_CUSTOM));
1431: }
CVSweb