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