Annotation of mandoc/validate.c, Revision 1.67
1.67 ! kristaps 1: /* $Id: validate.c,v 1.66 2009/03/02 17:14:46 kristaps Exp $ */
1.1 kristaps 2: /*
3: * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the
7: * above copyright notice and this permission notice appear in all
8: * copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11: * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12: * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13: * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14: * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15: * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16: * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17: * PERFORMANCE OF THIS SOFTWARE.
18: */
19: #include <assert.h>
1.56 kristaps 20: #include <ctype.h>
1.8 kristaps 21: #include <stdlib.h>
1.1 kristaps 22:
23: #include "private.h"
24:
1.67 ! kristaps 25: /* FIXME: .Bl -diag can't have non-text children in HEAD. */
! 26:
1.44 kristaps 27: /*
28: * Pre- and post-validate macros as they're parsed. Pre-validation
29: * occurs when the macro has been detected and its arguments parsed.
30: * Post-validation occurs when all child macros have also been parsed.
31: * In the ELEMENT case, this is simply the parameters of the macro; in
32: * the BLOCK case, this is the HEAD, BODY, TAIL and so on.
33: */
34:
1.55 kristaps 35: #define PRE_ARGS struct mdoc *mdoc, const struct mdoc_node *n
36: #define POST_ARGS struct mdoc *mdoc
37:
38: typedef int (*v_pre)(PRE_ARGS);
39: typedef int (*v_post)(POST_ARGS);
1.14 kristaps 40:
1.64 kristaps 41: /* TODO: ignoring Pp (it's superfluous in some invocations). */
1.36 kristaps 42:
1.14 kristaps 43: struct valids {
1.24 kristaps 44: v_pre *pre;
1.17 kristaps 45: v_post *post;
1.14 kristaps 46: };
1.1 kristaps 47:
1.37 kristaps 48: /* Utility checks. */
49:
1.55 kristaps 50: static int check_parent(PRE_ARGS, int, enum mdoc_type);
51: static int check_msec(PRE_ARGS, int, enum mdoc_msec *);
52: static int check_stdarg(PRE_ARGS);
53:
54: static int check_text(struct mdoc *,
1.63 kristaps 55: int, int, const char *);
1.55 kristaps 56:
1.51 kristaps 57: static int err_child_lt(struct mdoc *, const char *, int);
1.59 kristaps 58: static int warn_child_lt(struct mdoc *, const char *, int);
1.51 kristaps 59: static int err_child_gt(struct mdoc *, const char *, int);
60: static int warn_child_gt(struct mdoc *, const char *, int);
61: static int err_child_eq(struct mdoc *, const char *, int);
62: static int warn_child_eq(struct mdoc *, const char *, int);
63:
64: /* Utility auxiliaries. */
65:
66: static inline int count_child(struct mdoc *);
67: static inline int warn_count(struct mdoc *, const char *,
68: int, const char *, int);
69: static inline int err_count(struct mdoc *, const char *,
70: int, const char *, int);
1.11 kristaps 71:
1.37 kristaps 72: /* Specific pre-child-parse routines. */
73:
1.55 kristaps 74: static int pre_display(PRE_ARGS);
75: static int pre_sh(PRE_ARGS);
76: static int pre_ss(PRE_ARGS);
77: static int pre_bd(PRE_ARGS);
78: static int pre_bl(PRE_ARGS);
79: static int pre_it(PRE_ARGS);
80: static int pre_cd(PRE_ARGS);
81: static int pre_er(PRE_ARGS);
82: static int pre_ex(PRE_ARGS);
83: static int pre_rv(PRE_ARGS);
84: static int pre_an(PRE_ARGS);
85: static int pre_st(PRE_ARGS);
86: static int pre_prologue(PRE_ARGS);
87: static int pre_prologue(PRE_ARGS);
88: static int pre_prologue(PRE_ARGS);
1.24 kristaps 89:
1.37 kristaps 90: /* Specific post-child-parse routines. */
91:
1.55 kristaps 92: static int herr_ge1(POST_ARGS);
1.59 kristaps 93: static int hwarn_le1(POST_ARGS);
1.55 kristaps 94: static int herr_eq0(POST_ARGS);
95: static int eerr_eq0(POST_ARGS);
96: static int eerr_le1(POST_ARGS);
97: static int eerr_le2(POST_ARGS);
98: static int eerr_eq1(POST_ARGS);
99: static int eerr_ge1(POST_ARGS);
100: static int ewarn_eq0(POST_ARGS);
101: static int ewarn_eq1(POST_ARGS);
102: static int bwarn_ge1(POST_ARGS);
1.58 kristaps 103: static int hwarn_eq1(POST_ARGS);
1.55 kristaps 104: static int ewarn_ge1(POST_ARGS);
105: static int ebool(POST_ARGS);
106:
107: static int post_sh(POST_ARGS);
108: static int post_sh_body(POST_ARGS);
109: static int post_sh_head(POST_ARGS);
1.57 kristaps 110: static int post_fd(POST_ARGS);
1.55 kristaps 111: static int post_bl(POST_ARGS);
112: static int post_it(POST_ARGS);
113: static int post_ex(POST_ARGS);
114: static int post_an(POST_ARGS);
115: static int post_at(POST_ARGS);
116: static int post_xr(POST_ARGS);
117: static int post_nm(POST_ARGS);
118: static int post_bf(POST_ARGS);
119: static int post_root(POST_ARGS);
1.37 kristaps 120:
121: /* Collections of pre-child-parse routines. */
1.17 kristaps 122:
1.24 kristaps 123: static v_pre pres_prologue[] = { pre_prologue, NULL };
124: static v_pre pres_d1[] = { pre_display, NULL };
125: static v_pre pres_bd[] = { pre_display, pre_bd, NULL };
126: static v_pre pres_bl[] = { pre_bl, NULL };
1.25 kristaps 127: static v_pre pres_it[] = { pre_it, NULL };
1.33 kristaps 128: static v_pre pres_ss[] = { pre_ss, NULL };
129: static v_pre pres_sh[] = { pre_sh, NULL };
130: static v_pre pres_cd[] = { pre_cd, NULL };
131: static v_pre pres_er[] = { pre_er, NULL };
132: static v_pre pres_ex[] = { pre_ex, NULL };
1.36 kristaps 133: static v_pre pres_rv[] = { pre_rv, NULL };
1.35 kristaps 134: static v_pre pres_an[] = { pre_an, NULL };
1.36 kristaps 135: static v_pre pres_st[] = { pre_st, NULL };
1.24 kristaps 136:
1.37 kristaps 137: /* Collections of post-child-parse routines. */
138:
139: static v_post posts_bool[] = { eerr_eq1, ebool, NULL };
140: static v_post posts_bd[] = { herr_eq0, bwarn_ge1, NULL };
141: static v_post posts_text[] = { eerr_ge1, NULL };
142: static v_post posts_wtext[] = { ewarn_ge1, NULL };
143: static v_post posts_notext[] = { eerr_eq0, NULL };
1.43 kristaps 144: static v_post posts_wline[] = { bwarn_ge1, herr_eq0, NULL };
1.37 kristaps 145: static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };
146: static v_post posts_bl[] = { herr_eq0, bwarn_ge1, post_bl, NULL };
1.25 kristaps 147: static v_post posts_it[] = { post_it, NULL };
1.39 kristaps 148: static v_post posts_in[] = { ewarn_eq1, NULL };
1.37 kristaps 149: static v_post posts_ss[] = { herr_ge1, NULL };
1.52 kristaps 150: static v_post posts_pf[] = { eerr_eq1, NULL };
1.37 kristaps 151: static v_post posts_pp[] = { ewarn_eq0, NULL };
152: static v_post posts_ex[] = { eerr_le1, post_ex, NULL };
1.35 kristaps 153: static v_post posts_an[] = { post_an, NULL };
1.37 kristaps 154: static v_post posts_at[] = { post_at, NULL };
155: static v_post posts_xr[] = { eerr_ge1, eerr_le2, post_xr, NULL };
156: static v_post posts_nm[] = { post_nm, NULL };
1.59 kristaps 157: static v_post posts_bf[] = { hwarn_le1, post_bf, NULL };
1.45 kristaps 158: static v_post posts_rs[] = { herr_eq0, bwarn_ge1, NULL };
1.58 kristaps 159: static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
1.45 kristaps 160: static v_post posts_bk[] = { herr_eq0, bwarn_ge1, NULL };
1.57 kristaps 161: static v_post posts_fd[] = { ewarn_ge1, post_fd, NULL };
1.9 kristaps 162:
1.37 kristaps 163: /* Per-macro pre- and post-child-check routine collections. */
1.12 kristaps 164:
1.9 kristaps 165: const struct valids mdoc_valids[MDOC_MAX] = {
1.51 kristaps 166: { NULL, NULL }, /* \" */
167: { pres_prologue, posts_text }, /* Dd */
168: { pres_prologue, NULL }, /* Dt */
169: { pres_prologue, NULL }, /* Os */
170: { pres_sh, posts_sh }, /* Sh */
171: { pres_ss, posts_ss }, /* Ss */
172: { NULL, posts_pp }, /* Pp */
173: { pres_d1, posts_wline }, /* D1 */
174: { pres_d1, posts_wline }, /* Dl */
175: { pres_bd, posts_bd }, /* Bd */
176: { NULL, NULL }, /* Ed */
177: { pres_bl, posts_bl }, /* Bl */
178: { NULL, NULL }, /* El */
179: { pres_it, posts_it }, /* It */
180: { NULL, posts_text }, /* Ad */
181: { pres_an, posts_an }, /* An */
182: { NULL, NULL }, /* Ar */
183: { pres_cd, posts_text }, /* Cd */
184: { NULL, NULL }, /* Cm */
185: { NULL, posts_text }, /* Dv */
186: { pres_er, posts_text }, /* Er */
187: { NULL, posts_text }, /* Ev */
188: { pres_ex, posts_ex }, /* Ex */
189: { NULL, posts_text }, /* Fa */
1.57 kristaps 190: { NULL, posts_fd }, /* Fd */
1.51 kristaps 191: { NULL, NULL }, /* Fl */
192: { NULL, posts_text }, /* Fn */
193: { NULL, posts_wtext }, /* Ft */
194: { NULL, posts_text }, /* Ic */
195: { NULL, posts_in }, /* In */
196: { NULL, posts_text }, /* Li */
197: { NULL, posts_wtext }, /* Nd */
198: { NULL, posts_nm }, /* Nm */
199: { NULL, posts_wline }, /* Op */
200: { NULL, NULL }, /* Ot */
201: { NULL, NULL }, /* Pa */
202: { pres_rv, posts_notext }, /* Rv */
203: { pres_st, posts_notext }, /* St */
204: { NULL, posts_text }, /* Va */
205: { NULL, posts_text }, /* Vt */
206: { NULL, posts_xr }, /* Xr */
207: { NULL, posts_text }, /* %A */
208: { NULL, posts_text }, /* %B */
209: { NULL, posts_text }, /* %D */
210: { NULL, posts_text }, /* %I */
211: { NULL, posts_text }, /* %J */
212: { NULL, posts_text }, /* %N */
213: { NULL, posts_text }, /* %O */
214: { NULL, posts_text }, /* %P */
215: { NULL, posts_text }, /* %R */
216: { NULL, posts_text }, /* %T */
217: { NULL, posts_text }, /* %V */
218: { NULL, NULL }, /* Ac */
219: { NULL, NULL }, /* Ao */
220: { NULL, posts_wline }, /* Aq */
221: { NULL, posts_at }, /* At */
222: { NULL, NULL }, /* Bc */
223: { NULL, posts_bf }, /* Bf */
224: { NULL, NULL }, /* Bo */
225: { NULL, posts_wline }, /* Bq */
226: { NULL, NULL }, /* Bsx */
227: { NULL, NULL }, /* Bx */
228: { NULL, posts_bool }, /* Db */
229: { NULL, NULL }, /* Dc */
230: { NULL, NULL }, /* Do */
231: { NULL, posts_wline }, /* Dq */
232: { NULL, NULL }, /* Ec */
233: { NULL, NULL }, /* Ef */
234: { NULL, posts_text }, /* Em */
235: { NULL, NULL }, /* Eo */
236: { NULL, NULL }, /* Fx */
237: { NULL, posts_text }, /* Ms */
238: { NULL, posts_notext }, /* No */
239: { NULL, posts_notext }, /* Ns */
240: { NULL, NULL }, /* Nx */
241: { NULL, NULL }, /* Ox */
242: { NULL, NULL }, /* Pc */
1.52 kristaps 243: { NULL, posts_pf }, /* Pf */
1.51 kristaps 244: { NULL, NULL }, /* Po */
245: { NULL, posts_wline }, /* Pq */
246: { NULL, NULL }, /* Qc */
247: { NULL, posts_wline }, /* Ql */
248: { NULL, NULL }, /* Qo */
249: { NULL, posts_wline }, /* Qq */
250: { NULL, NULL }, /* Re */
251: { NULL, posts_rs }, /* Rs */
252: { NULL, NULL }, /* Sc */
253: { NULL, NULL }, /* So */
254: { NULL, posts_wline }, /* Sq */
255: { NULL, posts_bool }, /* Sm */
256: { NULL, posts_text }, /* Sx */
257: { NULL, posts_text }, /* Sy */
258: { NULL, posts_text }, /* Tn */
259: { NULL, NULL }, /* Ux */
260: { NULL, NULL }, /* Xc */
261: { NULL, NULL }, /* Xo */
262: { NULL, posts_fo }, /* Fo */
263: { NULL, NULL }, /* Fc */
264: { NULL, NULL }, /* Oo */
265: { NULL, NULL }, /* Oc */
266: { NULL, posts_bk }, /* Bk */
267: { NULL, NULL }, /* Ek */
268: { NULL, posts_notext }, /* Bt */
269: { NULL, NULL }, /* Hf */
270: { NULL, NULL }, /* Fr */
271: { NULL, posts_notext }, /* Ud */
1.9 kristaps 272: };
1.6 kristaps 273:
274:
1.57 kristaps 275: int
276: mdoc_valid_pre(struct mdoc *mdoc,
277: const struct mdoc_node *node)
278: {
279: v_pre *p;
280: struct mdoc_arg *argv;
1.63 kristaps 281: size_t argc;
282: int line, pos, i, j;
1.57 kristaps 283: const char *tp;
284:
285: if (MDOC_TEXT == node->type) {
286: tp = node->data.text.string;
287: line = node->line;
288: pos = node->pos;
289: return(check_text(mdoc, line, pos, tp));
290: }
291:
292: if (MDOC_BLOCK == node->type || MDOC_ELEM == node->type) {
293: argv = MDOC_BLOCK == node->type ?
294: node->data.block.argv :
295: node->data.elem.argv;
296: argc = MDOC_BLOCK == node->type ?
297: node->data.block.argc :
298: node->data.elem.argc;
299:
1.63 kristaps 300: for (i = 0; i < (int)argc; i++) {
1.57 kristaps 301: if (0 == argv[i].sz)
302: continue;
1.63 kristaps 303: for (j = 0; j < (int)argv[i].sz; j++) {
1.57 kristaps 304: tp = argv[i].value[j];
305: line = argv[i].line;
306: pos = argv[i].pos;
307: if ( ! check_text(mdoc, line, pos, tp))
308: return(0);
309: }
310: }
311: }
312:
313: if (NULL == mdoc_valids[node->tok].pre)
314: return(1);
315: for (p = mdoc_valids[node->tok].pre; *p; p++)
316: if ( ! (*p)(mdoc, node))
317: return(0);
318: return(1);
319: }
320:
321:
322: int
323: mdoc_valid_post(struct mdoc *mdoc)
324: {
325: v_post *p;
326:
327: /*
328: * This check occurs after the macro's children have been filled
329: * in: postfix validation. Since this happens when we're
330: * rewinding the scope tree, it's possible to have multiple
331: * invocations (as by design, for now), we set bit MDOC_VALID to
332: * indicate that we've validated.
333: */
334:
335: if (MDOC_VALID & mdoc->last->flags)
336: return(1);
337: mdoc->last->flags |= MDOC_VALID;
338:
339: if (MDOC_TEXT == mdoc->last->type)
340: return(1);
341: if (MDOC_ROOT == mdoc->last->type)
342: return(post_root(mdoc));
343:
344: if (NULL == mdoc_valids[mdoc->last->tok].post)
345: return(1);
346: for (p = mdoc_valids[mdoc->last->tok].post; *p; p++)
347: if ( ! (*p)(mdoc))
348: return(0);
349:
350: return(1);
351: }
352:
353:
354:
1.51 kristaps 355: static inline int
356: warn_count(struct mdoc *m, const char *k,
357: int want, const char *v, int has)
358: {
359:
1.55 kristaps 360: return(mdoc_warn(m, WARN_SYNTAX,
1.58 kristaps 361: "suggests %s %s %d (has %d)",
362: v, k, want, has));
1.51 kristaps 363: }
364:
365:
366: static inline int
367: err_count(struct mdoc *m, const char *k,
368: int want, const char *v, int has)
369: {
370:
1.58 kristaps 371: return(mdoc_err(m, "requires %s %s %d (has %d)",
372: v, k, want, has));
1.51 kristaps 373: }
374:
375:
376: static inline int
377: count_child(struct mdoc *mdoc)
1.36 kristaps 378: {
1.51 kristaps 379: int i;
1.36 kristaps 380: struct mdoc_node *n;
381:
382: for (i = 0, n = mdoc->last->child; n; n = n->next, i++)
383: /* Do nothing */ ;
1.53 kristaps 384:
1.36 kristaps 385: return(i);
386: }
387:
388:
1.53 kristaps 389: /*
390: * Build these up with macros because they're basically the same check
391: * for different inequalities. Yes, this could be done with functions,
392: * but this is reasonable for now.
393: */
1.36 kristaps 394:
1.53 kristaps 395: #define CHECK_CHILD_DEFN(lvl, name, ineq) \
396: static int \
397: lvl##_child_##name(struct mdoc *mdoc, const char *p, int sz) \
398: { \
399: int i; \
400: if ((i = count_child(mdoc)) ineq sz) \
401: return(1); \
402: return(lvl##_count(mdoc, #ineq, sz, p, i)); \
403: }
404:
405: #define CHECK_BODY_DEFN(name, lvl, func, num) \
406: static int \
1.55 kristaps 407: b##lvl##_##name(POST_ARGS) \
1.53 kristaps 408: { \
409: if (MDOC_BODY != mdoc->last->type) \
410: return(1); \
411: return(func(mdoc, "multiline parameters", (num))); \
412: }
413:
414: #define CHECK_ELEM_DEFN(name, lvl, func, num) \
415: static int \
1.55 kristaps 416: e##lvl##_##name(POST_ARGS) \
1.53 kristaps 417: { \
418: assert(MDOC_ELEM == mdoc->last->type); \
419: return(func(mdoc, "line parameters", (num))); \
420: }
421:
422: #define CHECK_HEAD_DEFN(name, lvl, func, num) \
423: static int \
1.55 kristaps 424: h##lvl##_##name(POST_ARGS) \
1.53 kristaps 425: { \
426: if (MDOC_HEAD != mdoc->last->type) \
427: return(1); \
1.58 kristaps 428: return(func(mdoc, "line parameters", (num))); \
1.36 kristaps 429: }
430:
431:
1.53 kristaps 432: CHECK_CHILD_DEFN(warn, gt, >) /* warn_child_gt() */
433: CHECK_CHILD_DEFN(err, gt, >) /* err_child_gt() */
434: CHECK_CHILD_DEFN(warn, eq, ==) /* warn_child_eq() */
435: CHECK_CHILD_DEFN(err, eq, ==) /* err_child_eq() */
436: CHECK_CHILD_DEFN(err, lt, <) /* err_child_lt() */
1.59 kristaps 437: CHECK_CHILD_DEFN(warn, lt, <) /* warn_child_lt() */
1.53 kristaps 438: CHECK_BODY_DEFN(ge1, warn, warn_child_gt, 0) /* bwarn_ge1() */
439: CHECK_ELEM_DEFN(eq1, warn, warn_child_eq, 1) /* ewarn_eq1() */
440: CHECK_ELEM_DEFN(eq0, warn, warn_child_eq, 0) /* ewarn_eq0() */
441: CHECK_ELEM_DEFN(ge1, warn, warn_child_gt, 0) /* ewarn_gt1() */
442: CHECK_ELEM_DEFN(eq1, err, err_child_eq, 1) /* eerr_eq1() */
443: CHECK_ELEM_DEFN(le2, err, err_child_lt, 3) /* eerr_le2() */
444: CHECK_ELEM_DEFN(le1, err, err_child_lt, 2) /* eerr_le1() */
445: CHECK_ELEM_DEFN(eq0, err, err_child_eq, 0) /* eerr_eq0() */
446: CHECK_ELEM_DEFN(ge1, err, err_child_gt, 0) /* eerr_ge1() */
447: CHECK_HEAD_DEFN(eq0, err, err_child_eq, 0) /* herr_eq0() */
1.59 kristaps 448: CHECK_HEAD_DEFN(le1, warn, warn_child_lt, 2) /* hwarn_le1() */
1.53 kristaps 449: CHECK_HEAD_DEFN(ge1, err, err_child_gt, 0) /* herr_ge1() */
1.58 kristaps 450: CHECK_HEAD_DEFN(eq1, warn, warn_child_eq, 1) /* hwarn_eq1() */
1.36 kristaps 451:
452:
453: static int
1.55 kristaps 454: check_stdarg(PRE_ARGS)
1.36 kristaps 455: {
456:
1.55 kristaps 457: if (MDOC_Std == n->data.elem.argv[0].arg &&
458: 1 == n->data.elem.argc)
1.36 kristaps 459: return(1);
1.51 kristaps 460:
1.55 kristaps 461: return(mdoc_nwarn(mdoc, n, WARN_COMPAT,
1.53 kristaps 462: "one argument suggested"));
1.36 kristaps 463: }
464:
465:
466: static int
1.55 kristaps 467: check_msec(PRE_ARGS, int sz, enum mdoc_msec *msecs)
1.33 kristaps 468: {
469: int i;
470:
471: for (i = 0; i < sz; i++)
472: if (msecs[i] == mdoc->meta.msec)
473: return(1);
1.55 kristaps 474: return(mdoc_nwarn(mdoc, n, WARN_COMPAT,
475: "invalid manual section"));
476: }
477:
478:
479: static int
1.63 kristaps 480: check_text(struct mdoc *mdoc, int line, int pos, const char *p)
1.55 kristaps 481: {
482: size_t c;
483:
1.62 kristaps 484: /* XXX - indicate deprecated escapes \*(xx and \*x. */
485:
1.55 kristaps 486: for ( ; *p; p++) {
1.60 kristaps 487: if ( ! isprint((int)*p) && '\t' != *p)
1.56 kristaps 488: return(mdoc_perr(mdoc, line, pos,
1.66 kristaps 489: "invalid non-printing characters"));
1.55 kristaps 490: if ('\\' != *p)
491: continue;
492: if ((c = mdoc_isescape(p))) {
1.63 kristaps 493: p += (int)c - 1;
1.55 kristaps 494: continue;
495: }
1.65 kristaps 496: return(mdoc_perr(mdoc, line, pos,
497: "invalid escape sequence"));
1.55 kristaps 498: }
499:
500: return(1);
1.14 kristaps 501: }
502:
503:
1.55 kristaps 504:
505:
1.14 kristaps 506: static int
1.55 kristaps 507: check_parent(PRE_ARGS, int tok, enum mdoc_type t)
1.54 kristaps 508: {
509:
510: assert(n->parent);
511: if ((MDOC_ROOT == t || tok == n->parent->tok) &&
512: (t == n->parent->type))
513: return(1);
514:
515: return(mdoc_nerr(mdoc, n, "require parent %s",
516: MDOC_ROOT == t ? "<root>" : mdoc_macronames[tok]));
517: }
518:
519:
520:
521: static int
1.55 kristaps 522: pre_display(PRE_ARGS)
1.23 kristaps 523: {
1.55 kristaps 524: struct mdoc_node *node;
1.23 kristaps 525:
1.53 kristaps 526: /* Display elements (`Bd', `D1'...) cannot be nested. */
527:
1.55 kristaps 528: if (MDOC_BLOCK != n->type)
1.24 kristaps 529: return(1);
530:
1.38 kristaps 531: /* LINTED */
1.55 kristaps 532: for (node = mdoc->last->parent; node; node = node->parent)
533: if (MDOC_BLOCK == node->type)
534: if (MDOC_Bd == node->tok)
1.23 kristaps 535: break;
1.55 kristaps 536: if (NULL == node)
1.23 kristaps 537: return(1);
1.53 kristaps 538:
1.55 kristaps 539: return(mdoc_nerr(mdoc, n, "displays may not be nested"));
1.23 kristaps 540: }
541:
542:
543: static int
1.55 kristaps 544: pre_bl(PRE_ARGS)
1.24 kristaps 545: {
1.61 kristaps 546: int type, i, width, offset;
1.24 kristaps 547: struct mdoc_arg *argv;
1.53 kristaps 548: size_t argc;
1.24 kristaps 549:
1.55 kristaps 550: if (MDOC_BLOCK != n->type)
1.24 kristaps 551: return(1);
552:
1.55 kristaps 553: argc = n->data.block.argc;
1.24 kristaps 554:
1.53 kristaps 555: /* Make sure that only one type of list is specified. */
556:
1.61 kristaps 557: type = offset = width = -1;
558:
1.38 kristaps 559: /* LINTED */
1.61 kristaps 560: for (i = 0; i < (int)argc; i++) {
1.55 kristaps 561: argv = &n->data.block.argv[i];
1.53 kristaps 562:
1.24 kristaps 563: switch (argv->arg) {
564: case (MDOC_Bullet):
565: /* FALLTHROUGH */
566: case (MDOC_Dash):
567: /* FALLTHROUGH */
568: case (MDOC_Enum):
569: /* FALLTHROUGH */
570: case (MDOC_Hyphen):
571: /* FALLTHROUGH */
572: case (MDOC_Item):
573: /* FALLTHROUGH */
574: case (MDOC_Tag):
575: /* FALLTHROUGH */
576: case (MDOC_Diag):
577: /* FALLTHROUGH */
578: case (MDOC_Hang):
579: /* FALLTHROUGH */
580: case (MDOC_Ohang):
581: /* FALLTHROUGH */
582: case (MDOC_Inset):
1.26 kristaps 583: /* FALLTHROUGH */
584: case (MDOC_Column):
1.61 kristaps 585: if (-1 == type) {
586: type = argv->arg;
1.53 kristaps 587: break;
1.61 kristaps 588: }
1.53 kristaps 589: return(mdoc_perr(mdoc, argv->line, argv->pos,
590: "multiple types specified"));
1.61 kristaps 591: case (MDOC_Width):
592: if (-1 == width) {
593: width = argv->arg;
594: break;
595: }
596: return(mdoc_perr(mdoc, argv->line, argv->pos,
597: "multiple -%s arguments",
598: mdoc_argnames[MDOC_Width]));
599: case (MDOC_Offset):
600: if (-1 == offset) {
601: offset = argv->arg;
602: break;
603: }
604: return(mdoc_perr(mdoc, argv->line, argv->pos,
605: "multiple -%s arguments",
606: mdoc_argnames[MDOC_Offset]));
1.24 kristaps 607: default:
608: break;
609: }
610: }
1.53 kristaps 611:
1.61 kristaps 612: if (-1 == type)
613: return(mdoc_err(mdoc, "no type specified"));
614:
615: switch (type) {
616: case (MDOC_Column):
617: /* FALLTHROUGH */
618: case (MDOC_Diag):
619: /* FALLTHROUGH */
620: case (MDOC_Inset):
621: /* FALLTHROUGH */
622: case (MDOC_Item):
623: if (-1 == width)
624: break;
625: return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
626: "superfluous -%s argument",
627: mdoc_argnames[MDOC_Width]));
628: case (MDOC_Tag):
1.64 kristaps 629: if (-1 == width && ! mdoc_nwarn(mdoc, n, WARN_SYNTAX,
630: "suggest -%s argument",
631: mdoc_argnames[MDOC_Width]))
632: return(0);
633: break;
1.61 kristaps 634: default:
635: break;
636: }
637:
638: return(1);
1.24 kristaps 639: }
640:
641:
642: static int
1.55 kristaps 643: pre_bd(PRE_ARGS)
1.24 kristaps 644: {
1.53 kristaps 645: int type, err, i;
1.24 kristaps 646: struct mdoc_arg *argv;
1.53 kristaps 647: size_t argc;
1.24 kristaps 648:
1.55 kristaps 649: if (MDOC_BLOCK != n->type)
1.24 kristaps 650: return(1);
651:
1.55 kristaps 652: argc = n->data.block.argc;
1.24 kristaps 653:
1.53 kristaps 654: /* Make sure that only one type of display is specified. */
655:
1.38 kristaps 656: /* LINTED */
1.53 kristaps 657: for (i = 0, err = type = 0; ! err && i < (int)argc; i++) {
1.55 kristaps 658: argv = &n->data.block.argv[i];
1.53 kristaps 659:
1.24 kristaps 660: switch (argv->arg) {
661: case (MDOC_Ragged):
662: /* FALLTHROUGH */
663: case (MDOC_Unfilled):
664: /* FALLTHROUGH */
1.29 kristaps 665: case (MDOC_Filled):
666: /* FALLTHROUGH */
1.24 kristaps 667: case (MDOC_Literal):
668: /* FALLTHROUGH */
669: case (MDOC_File):
1.53 kristaps 670: if (0 == type++)
671: break;
672: return(mdoc_perr(mdoc, argv->line, argv->pos,
673: "multiple types specified"));
1.24 kristaps 674: default:
675: break;
676: }
677: }
1.53 kristaps 678:
679: if (type)
680: return(1);
681: return(mdoc_err(mdoc, "no type specified"));
1.24 kristaps 682: }
683:
684:
685: static int
1.55 kristaps 686: pre_ss(PRE_ARGS)
1.33 kristaps 687: {
688:
1.55 kristaps 689: if (MDOC_BLOCK != n->type)
1.33 kristaps 690: return(1);
1.55 kristaps 691: return(check_parent(mdoc, n, MDOC_Sh, MDOC_BODY));
1.33 kristaps 692: }
693:
694:
695: static int
1.55 kristaps 696: pre_sh(PRE_ARGS)
1.33 kristaps 697: {
698:
1.55 kristaps 699: if (MDOC_BLOCK != n->type)
1.33 kristaps 700: return(1);
1.55 kristaps 701: return(check_parent(mdoc, n, -1, MDOC_ROOT));
1.33 kristaps 702: }
703:
704:
705: static int
1.55 kristaps 706: pre_it(PRE_ARGS)
1.53 kristaps 707: {
708:
1.55 kristaps 709: if (MDOC_BLOCK != n->type)
1.53 kristaps 710: return(1);
1.55 kristaps 711: return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY));
1.53 kristaps 712: }
713:
714:
715: static int
1.55 kristaps 716: pre_st(PRE_ARGS)
1.36 kristaps 717: {
718:
1.55 kristaps 719: if (1 == n->data.elem.argc)
1.36 kristaps 720: return(1);
1.55 kristaps 721: return(mdoc_nerr(mdoc, n, "one argument required"));
1.36 kristaps 722: }
723:
724:
725: static int
1.55 kristaps 726: pre_an(PRE_ARGS)
1.35 kristaps 727: {
1.36 kristaps 728:
1.55 kristaps 729: if (1 >= n->data.elem.argc)
1.35 kristaps 730: return(1);
1.55 kristaps 731: return(mdoc_nerr(mdoc, n, "one argument allowed"));
1.35 kristaps 732: }
733:
734:
735: static int
1.55 kristaps 736: pre_rv(PRE_ARGS)
1.36 kristaps 737: {
1.53 kristaps 738: enum mdoc_msec msecs[] = { MSEC_2, MSEC_3 };
1.36 kristaps 739:
1.55 kristaps 740: if ( ! check_msec(mdoc, n, 2, msecs))
1.36 kristaps 741: return(0);
1.55 kristaps 742: return(check_stdarg(mdoc, n));
1.36 kristaps 743: }
744:
745:
746: static int
1.55 kristaps 747: pre_ex(PRE_ARGS)
1.33 kristaps 748: {
1.53 kristaps 749: enum mdoc_msec msecs[] = { MSEC_1, MSEC_6, MSEC_8 };
1.35 kristaps 750:
1.55 kristaps 751: if ( ! check_msec(mdoc, n, 3, msecs))
1.35 kristaps 752: return(0);
1.55 kristaps 753: return(check_stdarg(mdoc, n));
1.33 kristaps 754: }
755:
756:
757: static int
1.55 kristaps 758: pre_er(PRE_ARGS)
1.33 kristaps 759: {
1.53 kristaps 760: enum mdoc_msec msecs[] = { MSEC_2 };
1.33 kristaps 761:
1.55 kristaps 762: return(check_msec(mdoc, n, 1, msecs));
1.33 kristaps 763: }
764:
765:
766: static int
1.55 kristaps 767: pre_cd(PRE_ARGS)
1.33 kristaps 768: {
1.53 kristaps 769: enum mdoc_msec msecs[] = { MSEC_4 };
1.33 kristaps 770:
1.55 kristaps 771: return(check_msec(mdoc, n, 1, msecs));
1.33 kristaps 772: }
773:
774:
775: static int
1.55 kristaps 776: pre_prologue(PRE_ARGS)
1.20 kristaps 777: {
778:
1.46 kristaps 779: if (SEC_PROLOGUE != mdoc->lastnamed)
1.55 kristaps 780: return(mdoc_nerr(mdoc, n, "prologue only"));
1.20 kristaps 781:
782: /* Check for ordering. */
783:
1.55 kristaps 784: switch (n->tok) {
1.20 kristaps 785: case (MDOC_Os):
1.36 kristaps 786: if (mdoc->meta.title && mdoc->meta.date)
1.20 kristaps 787: break;
1.55 kristaps 788: return(mdoc_nerr(mdoc, n, "prologue out-of-order"));
1.20 kristaps 789: case (MDOC_Dt):
1.36 kristaps 790: if (NULL == mdoc->meta.title && mdoc->meta.date)
1.20 kristaps 791: break;
1.55 kristaps 792: return(mdoc_nerr(mdoc, n, "prologue out-of-order"));
1.20 kristaps 793: case (MDOC_Dd):
1.36 kristaps 794: if (NULL == mdoc->meta.title && 0 == mdoc->meta.date)
1.20 kristaps 795: break;
1.55 kristaps 796: return(mdoc_nerr(mdoc, n, "prologue out-of-order"));
1.20 kristaps 797: default:
798: abort();
799: /* NOTREACHED */
800: }
801:
802: /* Check for repetition. */
803:
1.55 kristaps 804: switch (n->tok) {
1.20 kristaps 805: case (MDOC_Os):
1.36 kristaps 806: if (NULL == mdoc->meta.os)
1.20 kristaps 807: return(1);
808: break;
809: case (MDOC_Dd):
810: if (0 == mdoc->meta.date)
811: return(1);
812: break;
813: case (MDOC_Dt):
1.36 kristaps 814: if (NULL == mdoc->meta.title)
1.20 kristaps 815: return(1);
816: break;
817: default:
818: abort();
819: /* NOTREACHED */
820: }
821:
1.55 kristaps 822: return(mdoc_nerr(mdoc, n, "prologue repetition"));
1.20 kristaps 823: }
824:
825:
1.35 kristaps 826: static int
1.55 kristaps 827: post_bf(POST_ARGS)
1.41 kristaps 828: {
829: char *p;
830: struct mdoc_node *head;
831:
832: if (MDOC_BLOCK != mdoc->last->type)
833: return(1);
1.53 kristaps 834:
1.41 kristaps 835: head = mdoc->last->data.block.head;
836:
837: if (0 == mdoc->last->data.block.argc) {
1.53 kristaps 838: if (NULL == head->child)
839: return(mdoc_err(mdoc, "argument expected"));
840:
841: p = head->child->data.text.string;
842: if (xstrcmp(p, "Em"))
843: return(1);
844: else if (xstrcmp(p, "Li"))
845: return(1);
846: else if (xstrcmp(p, "Sm"))
847: return(1);
848: return(mdoc_nerr(mdoc, head->child, "invalid font"));
1.41 kristaps 849: }
1.53 kristaps 850:
1.41 kristaps 851: if (head->child)
1.53 kristaps 852: return(mdoc_err(mdoc, "argument expected"));
853:
1.41 kristaps 854: if (1 == mdoc->last->data.block.argc)
855: return(1);
1.53 kristaps 856: return(mdoc_err(mdoc, "argument expected"));
1.41 kristaps 857: }
858:
859:
860: static int
1.55 kristaps 861: post_nm(POST_ARGS)
1.37 kristaps 862: {
863:
864: if (mdoc->last->child)
865: return(1);
866: if (mdoc->meta.name)
867: return(1);
1.53 kristaps 868: return(mdoc_err(mdoc, "not yet invoked with name"));
1.37 kristaps 869: }
870:
871:
872: static int
1.55 kristaps 873: post_xr(POST_ARGS)
1.36 kristaps 874: {
875: struct mdoc_node *n;
876:
877: if (NULL == (n = mdoc->last->child->next))
878: return(1);
879: if (MSEC_DEFAULT != mdoc_atomsec(n->data.text.string))
880: return(1);
881: return(mdoc_nerr(mdoc, n, "invalid manual section"));
882: }
883:
884:
885: static int
1.55 kristaps 886: post_at(POST_ARGS)
1.36 kristaps 887: {
888:
1.37 kristaps 889: if (NULL == mdoc->last->child)
890: return(1);
1.36 kristaps 891: if (ATT_DEFAULT != mdoc_atoatt(mdoc->last->child->data.text.string))
892: return(1);
1.53 kristaps 893: return(mdoc_err(mdoc, "require valid symbol"));
1.36 kristaps 894: }
895:
896:
897: static int
1.55 kristaps 898: post_an(POST_ARGS)
1.35 kristaps 899: {
900:
901: if (0 != mdoc->last->data.elem.argc) {
902: if (NULL == mdoc->last->child)
903: return(1);
1.53 kristaps 904: return(mdoc_err(mdoc, "argument(s) expected"));
1.35 kristaps 905: }
906:
907: if (mdoc->last->child)
908: return(1);
1.53 kristaps 909: return(mdoc_err(mdoc, "argument(s) expected"));
1.35 kristaps 910: }
911:
912:
913: static int
1.55 kristaps 914: post_ex(POST_ARGS)
1.35 kristaps 915: {
916:
917: if (0 == mdoc->last->data.elem.argc) {
918: if (mdoc->last->child)
919: return(1);
1.53 kristaps 920: return(mdoc_err(mdoc, "argument(s) expected"));
1.35 kristaps 921: }
922: if (mdoc->last->child)
1.53 kristaps 923: return(mdoc_err(mdoc, "argument(s) expected"));
1.35 kristaps 924: if (1 != mdoc->last->data.elem.argc)
1.53 kristaps 925: return(mdoc_err(mdoc, "argument(s) expected"));
1.35 kristaps 926: if (MDOC_Std != mdoc->last->data.elem.argv[0].arg)
1.53 kristaps 927: return(mdoc_err(mdoc, "argument(s) expected"));
928:
1.35 kristaps 929: return(1);
930: }
931:
932:
1.25 kristaps 933: static int
1.55 kristaps 934: post_it(POST_ARGS)
1.25 kristaps 935: {
1.53 kristaps 936: int type, sv, i;
1.25 kristaps 937: #define TYPE_NONE (0)
938: #define TYPE_BODY (1)
939: #define TYPE_HEAD (2)
1.47 kristaps 940: #define TYPE_OHEAD (3)
1.53 kristaps 941: size_t argc;
1.25 kristaps 942: struct mdoc_node *n;
943:
944: if (MDOC_BLOCK != mdoc->last->type)
945: return(1);
946:
1.53 kristaps 947: n = mdoc->last->parent->parent;
1.25 kristaps 948:
949: argc = n->data.block.argc;
950: type = TYPE_NONE;
1.38 kristaps 951: sv = -1;
1.26 kristaps 952:
953: /* Some types require block-head, some not. */
1.25 kristaps 954:
1.38 kristaps 955: /* LINTED */
1.53 kristaps 956: for (i = 0; TYPE_NONE == type && i < (int)argc; i++)
957: switch (n->data.block.argv[i].arg) {
1.25 kristaps 958: case (MDOC_Tag):
959: /* FALLTHROUGH */
960: case (MDOC_Diag):
961: /* FALLTHROUGH */
962: case (MDOC_Hang):
963: /* FALLTHROUGH */
964: case (MDOC_Ohang):
965: /* FALLTHROUGH */
966: case (MDOC_Inset):
967: type = TYPE_HEAD;
1.53 kristaps 968: sv = n->data.block.argv[i].arg;
1.25 kristaps 969: break;
970: case (MDOC_Bullet):
971: /* FALLTHROUGH */
972: case (MDOC_Dash):
973: /* FALLTHROUGH */
974: case (MDOC_Enum):
975: /* FALLTHROUGH */
976: case (MDOC_Hyphen):
977: /* FALLTHROUGH */
978: case (MDOC_Item):
1.47 kristaps 979: type = TYPE_BODY;
1.53 kristaps 980: sv = n->data.block.argv[i].arg;
1.47 kristaps 981: break;
1.25 kristaps 982: case (MDOC_Column):
1.47 kristaps 983: type = TYPE_OHEAD;
1.53 kristaps 984: sv = n->data.block.argv[i].arg;
1.25 kristaps 985: break;
986: default:
987: break;
988: }
989:
990: assert(TYPE_NONE != type);
991:
1.47 kristaps 992: n = mdoc->last->data.block.head;
993:
1.25 kristaps 994: if (TYPE_HEAD == type) {
1.33 kristaps 995: if (NULL == n->child)
1.53 kristaps 996: if ( ! mdoc_warn(mdoc, WARN_SYNTAX,
997: "argument(s) suggested"))
1.25 kristaps 998: return(0);
999:
1.33 kristaps 1000: n = mdoc->last->data.block.body;
1001: if (NULL == n->child)
1.53 kristaps 1002: if ( ! mdoc_warn(mdoc, WARN_SYNTAX,
1003: "multiline body suggested"))
1.25 kristaps 1004: return(0);
1005:
1.47 kristaps 1006: } else if (TYPE_BODY == type) {
1007: if (n->child)
1.53 kristaps 1008: if ( ! mdoc_warn(mdoc, WARN_SYNTAX,
1009: "no argument suggested"))
1.47 kristaps 1010: return(0);
1011:
1012: n = mdoc->last->data.block.body;
1013: if (NULL == n->child)
1.53 kristaps 1014: if ( ! mdoc_warn(mdoc, WARN_SYNTAX,
1015: "multiline body suggested"))
1.47 kristaps 1016: return(0);
1017: } else {
1018: if (NULL == n->child)
1.53 kristaps 1019: if ( ! mdoc_warn(mdoc, WARN_SYNTAX,
1020: "argument(s) suggested"))
1.47 kristaps 1021: return(0);
1022:
1023: n = mdoc->last->data.block.body;
1024: if (n->child)
1.53 kristaps 1025: if ( ! mdoc_warn(mdoc, WARN_SYNTAX,
1026: "no multiline body suggested"))
1.47 kristaps 1027: return(0);
1.25 kristaps 1028: }
1029:
1.47 kristaps 1030: if (MDOC_Column != sv)
1.26 kristaps 1031: return(1);
1032:
1.38 kristaps 1033: argc = mdoc->last->parent->parent->data.block.argv->sz;
1.26 kristaps 1034: n = mdoc->last->data.block.head->child;
1.25 kristaps 1035:
1.26 kristaps 1036: for (i = 0; n; n = n->next)
1037: i++;
1038:
1.53 kristaps 1039: if (i == (int)argc)
1.26 kristaps 1040: return(1);
1.53 kristaps 1041:
1042: return(mdoc_err(mdoc, "need %zu columns (have %d)", argc, i));
1.25 kristaps 1043: #undef TYPE_NONE
1044: #undef TYPE_BODY
1045: #undef TYPE_HEAD
1.47 kristaps 1046: #undef TYPE_OHEAD
1.25 kristaps 1047: }
1048:
1049:
1.24 kristaps 1050: static int
1.55 kristaps 1051: post_bl(POST_ARGS)
1.24 kristaps 1052: {
1.53 kristaps 1053: struct mdoc_node *n;
1.24 kristaps 1054:
1055: if (MDOC_BODY != mdoc->last->type)
1056: return(1);
1.64 kristaps 1057: if (NULL == (mdoc->last->child))
1058: return(1);
1059:
1060: /*
1061: * Only allow `It' macros to be the immediate descendants of the
1062: * `Bl' list.
1063: */
1.24 kristaps 1064:
1.38 kristaps 1065: /* LINTED */
1.24 kristaps 1066: for (n = mdoc->last->child; n; n = n->next) {
1067: if (MDOC_BLOCK == n->type)
1.25 kristaps 1068: if (MDOC_It == n->tok)
1.24 kristaps 1069: continue;
1.64 kristaps 1070:
1071: return(mdoc_nerr(mdoc, n, "bad child of parent %s",
1072: mdoc_macronames[mdoc->last->tok]));
1.24 kristaps 1073: }
1.53 kristaps 1074:
1.64 kristaps 1075: return(1);
1.24 kristaps 1076: }
1077:
1078:
1.34 kristaps 1079: static int
1.37 kristaps 1080: ebool(struct mdoc *mdoc)
1.34 kristaps 1081: {
1082: struct mdoc_node *n;
1083:
1.38 kristaps 1084: /* LINTED */
1.34 kristaps 1085: for (n = mdoc->last->child; n; n = n->next) {
1086: if (MDOC_TEXT != n->type)
1087: break;
1088: if (xstrcmp(n->data.text.string, "on"))
1089: continue;
1090: if (xstrcmp(n->data.text.string, "off"))
1091: continue;
1092: break;
1093: }
1.53 kristaps 1094:
1.34 kristaps 1095: if (NULL == n)
1096: return(1);
1.53 kristaps 1097: return(mdoc_nerr(mdoc, n, "expected boolean"));
1.37 kristaps 1098: }
1099:
1100:
1101: static int
1.55 kristaps 1102: post_root(POST_ARGS)
1.37 kristaps 1103: {
1104:
1.46 kristaps 1105: if (NULL == mdoc->first->child)
1.53 kristaps 1106: return(mdoc_err(mdoc, "document lacks data"));
1.46 kristaps 1107: if (SEC_PROLOGUE == mdoc->lastnamed)
1.53 kristaps 1108: return(mdoc_err(mdoc, "document lacks prologue"));
1109:
1.46 kristaps 1110: if (MDOC_BLOCK != mdoc->first->child->type)
1.54 kristaps 1111: return(mdoc_err(mdoc, "lacking post-prologue %s",
1.53 kristaps 1112: mdoc_macronames[MDOC_Sh]));
1.46 kristaps 1113: if (MDOC_Sh != mdoc->first->child->tok)
1.54 kristaps 1114: return(mdoc_err(mdoc, "lacking post-prologue %s",
1.53 kristaps 1115: mdoc_macronames[MDOC_Sh]));
1116:
1.37 kristaps 1117: return(1);
1.34 kristaps 1118: }
1119:
1120:
1.20 kristaps 1121: static int
1.55 kristaps 1122: post_sh(POST_ARGS)
1.14 kristaps 1123: {
1.46 kristaps 1124:
1125: if (MDOC_HEAD == mdoc->last->type)
1126: return(post_sh_head(mdoc));
1127: if (MDOC_BODY == mdoc->last->type)
1128: return(post_sh_body(mdoc));
1.53 kristaps 1129:
1.46 kristaps 1130: return(1);
1131: }
1132:
1133:
1134: static int
1.55 kristaps 1135: post_sh_body(POST_ARGS)
1.46 kristaps 1136: {
1137: struct mdoc_node *n;
1138:
1139: if (SEC_NAME != mdoc->lastnamed)
1140: return(1);
1141:
1.51 kristaps 1142: /*
1143: * Warn if the NAME section doesn't contain the `Nm' and `Nd'
1144: * macros (can have multiple `Nm' and one `Nd'). Note that the
1145: * children of the BODY declaration can also be "text".
1146: */
1147:
1.46 kristaps 1148: if (NULL == (n = mdoc->last->child))
1.54 kristaps 1149: return(mdoc_warn(mdoc, WARN_SYNTAX,
1150: "section should have %s and %s",
1.51 kristaps 1151: mdoc_macronames[MDOC_Nm],
1152: mdoc_macronames[MDOC_Nd]));
1153:
1154: for ( ; n && n->next; n = n->next) {
1155: if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
1156: continue;
1157: if (MDOC_TEXT == n->type)
1158: continue;
1.54 kristaps 1159: if ( ! (mdoc_nwarn(mdoc, n, WARN_SYNTAX,
1160: "section should have %s first",
1.51 kristaps 1161: mdoc_macronames[MDOC_Nm])))
1162: return(0);
1163: }
1164:
1165: if (MDOC_ELEM == n->type && MDOC_Nd == n->tok)
1.46 kristaps 1166: return(1);
1167:
1.54 kristaps 1168: return(mdoc_warn(mdoc, WARN_SYNTAX,
1169: "section should have %s last",
1.51 kristaps 1170: mdoc_macronames[MDOC_Nd]));
1.46 kristaps 1171: }
1172:
1173:
1174: static int
1.55 kristaps 1175: post_sh_head(POST_ARGS)
1.46 kristaps 1176: {
1.36 kristaps 1177: char buf[64];
1.21 kristaps 1178: enum mdoc_sec sec;
1179:
1.25 kristaps 1180: assert(MDOC_Sh == mdoc->last->tok);
1.21 kristaps 1181:
1.54 kristaps 1182: if ( ! xstrlcats(buf, mdoc->last->child, sizeof(buf)))
1183: return(mdoc_err(mdoc, "argument too long"));
1.14 kristaps 1184:
1.46 kristaps 1185: sec = mdoc_atosec(buf);
1186:
1187: if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec)
1.54 kristaps 1188: return(mdoc_warn(mdoc, WARN_SYNTAX,
1189: "section NAME should be first"));
1.46 kristaps 1190: if (SEC_CUSTOM == sec)
1.21 kristaps 1191: return(1);
1.46 kristaps 1192: if (sec == mdoc->lastnamed)
1.54 kristaps 1193: return(mdoc_warn(mdoc, WARN_SYNTAX,
1194: "section repeated"));
1.46 kristaps 1195: if (sec < mdoc->lastnamed)
1.54 kristaps 1196: return(mdoc_warn(mdoc, WARN_SYNTAX,
1197: "section out of order"));
1.46 kristaps 1198:
1199: return(1);
1.11 kristaps 1200: }
1201:
1202:
1.57 kristaps 1203: static int
1204: post_fd(POST_ARGS)
1.11 kristaps 1205: {
1.39 kristaps 1206:
1.57 kristaps 1207: if (SEC_SYNOPSIS == mdoc->last->sec)
1.25 kristaps 1208: return(1);
1.57 kristaps 1209: return(mdoc_warn(mdoc, WARN_COMPAT,
1210: "suggested only in section SYNOPSIS"));
1.11 kristaps 1211: }
CVSweb