]>
git.cameronkatri.com Git - mandoc.git/blob - man_validate.c
1 /* $Id: man_validate.c,v 1.1 2009/03/25 15:17:49 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
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
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.
19 #include <sys/types.h>
28 /* FIXME: validate text. */
30 #define POSTARGS struct man *m, const struct man_node *n
32 typedef int (*v_post
)(POSTARGS
);
38 static int count(POSTARGS
);
39 static int check_eq0(POSTARGS
);
40 static int check_ge1(POSTARGS
);
41 static int check_ge2(POSTARGS
);
42 static int check_le1(POSTARGS
);
43 static int check_le2(POSTARGS
);
44 static int check_le5(POSTARGS
);
46 static v_post posts_le1
[] = { check_le1
, NULL
};
47 static v_post posts_le2
[] = { check_le2
, NULL
};
48 static v_post posts_ge1
[] = { check_ge1
, NULL
};
49 static v_post posts_eq0
[] = { check_eq0
, NULL
};
50 static v_post posts_ge2_le5
[] = { check_ge2
, check_le5
, NULL
};
52 static const struct man_valid man_valids
[MAN_MAX
] = {
54 { posts_ge2_le5
}, /* TH */
55 { posts_ge1
}, /* SH */
56 { posts_ge1
}, /* SS */
57 { posts_le1
}, /* TP */
58 { posts_eq0
}, /* LP */
59 { posts_eq0
}, /* PP */
60 { posts_eq0
}, /* P */
61 { posts_le2
}, /* IP */
62 { posts_le1
}, /* HP */
77 man_valid_post(struct man
*m
)
81 if (MAN_VALID
& m
->last
->flags
)
84 m
->last
->flags
|= MAN_VALID
;
86 switch (m
->last
->type
) {
95 if (NULL
== (cp
= man_valids
[m
->last
->tok
].posts
))
98 if ( ! (*cp
)(m
, m
->last
))
110 for (i
= 0; n
; n
= n
->next
, i
++)
116 #define INEQ_DEFINE(x, ineq, name) \
118 check_##name(POSTARGS) \
121 if ((c = count(m, n->child)) ineq (x)) \
123 return(man_vwarn(m, n->line, n->pos, \
124 "expected line arguments %s %d, have %d", \
128 INEQ_DEFINE(0, ==, eq0
)
129 INEQ_DEFINE(1, >=, ge1
)
130 INEQ_DEFINE(2, >=, ge2
)
131 INEQ_DEFINE(1, <=, le1
)
132 INEQ_DEFINE(2, <=, le2
)
133 INEQ_DEFINE(5, <=, le5
)