]> git.cameronkatri.com Git - mandoc.git/blob - roff_validate.c
Move .sp to the roff modules. Enough infrastructure is in place
[mandoc.git] / roff_validate.c
1 /* $OpenBSD: roff_html.c,v 1.1 2017/05/04 22:07:44 schwarze Exp $ */
2 /*
3 * Copyright (c) 2010, 2017 Ingo Schwarze <schwarze@openbsd.org>
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 above
7 * copyright notice and this permission notice appear in all copies.
8 *
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.
16 */
17 #include <sys/types.h>
18
19 #include <assert.h>
20 #include <stddef.h>
21
22 #include "mandoc.h"
23 #include "roff.h"
24 #include "libmandoc.h"
25 #include "roff_int.h"
26
27 #define ROFF_VALID_ARGS struct roff_man *man, struct roff_node *n
28
29 typedef void (*roff_valid_fp)(ROFF_VALID_ARGS);
30
31 static void roff_valid_ft(ROFF_VALID_ARGS);
32
33 static const roff_valid_fp roff_valids[ROFF_MAX] = {
34 NULL, /* br */
35 roff_valid_ft, /* ft */
36 NULL, /* ll */
37 NULL, /* sp */
38 };
39
40
41 void
42 roff_validate(struct roff_man *man)
43 {
44 struct roff_node *n;
45
46 n = man->last;
47 assert(n->tok < ROFF_MAX);
48 if (roff_valids[n->tok] != NULL)
49 (*roff_valids[n->tok])(man, n);
50 }
51
52 static void
53 roff_valid_ft(ROFF_VALID_ARGS)
54 {
55 char *cp;
56
57 if (n->child == NULL) {
58 man->next = ROFF_NEXT_CHILD;
59 roff_word_alloc(man, n->line, n->pos, "P");
60 man->last = n;
61 return;
62 }
63
64 cp = n->child->string;
65 switch (*cp) {
66 case '1':
67 case '2':
68 case '3':
69 case '4':
70 case 'I':
71 case 'P':
72 case 'R':
73 if (cp[1] == '\0')
74 return;
75 break;
76 case 'B':
77 if (cp[1] == '\0' || (cp[1] == 'I' && cp[2] == '\0'))
78 return;
79 break;
80 case 'C':
81 if (cp[1] == 'W' && cp[2] == '\0')
82 return;
83 break;
84 default:
85 break;
86 }
87
88 mandoc_vmsg(MANDOCERR_FT_BAD, man->parse,
89 n->line, n->pos, "ft %s", cp);
90 roff_node_delete(man, n);
91 }