roff_validate.c revision 1.1.1.1 1 1.1 christos /* Id: roff_validate.c,v 1.9 2017/06/14 22:51:25 schwarze Exp */
2 1.1 christos /*
3 1.1 christos * Copyright (c) 2010, 2017 Ingo Schwarze <schwarze (at) openbsd.org>
4 1.1 christos *
5 1.1 christos * Permission to use, copy, modify, and distribute this software for any
6 1.1 christos * purpose with or without fee is hereby granted, provided that the above
7 1.1 christos * copyright notice and this permission notice appear in all copies.
8 1.1 christos *
9 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 1.1 christos */
17 1.1 christos #include <sys/types.h>
18 1.1 christos
19 1.1 christos #include <assert.h>
20 1.1 christos #include <stddef.h>
21 1.1 christos
22 1.1 christos #include "mandoc.h"
23 1.1 christos #include "roff.h"
24 1.1 christos #include "libmandoc.h"
25 1.1 christos #include "roff_int.h"
26 1.1 christos
27 1.1 christos #define ROFF_VALID_ARGS struct roff_man *man, struct roff_node *n
28 1.1 christos
29 1.1 christos typedef void (*roff_valid_fp)(ROFF_VALID_ARGS);
30 1.1 christos
31 1.1 christos static void roff_valid_ft(ROFF_VALID_ARGS);
32 1.1 christos
33 1.1 christos static const roff_valid_fp roff_valids[ROFF_MAX] = {
34 1.1 christos NULL, /* br */
35 1.1 christos NULL, /* ce */
36 1.1 christos roff_valid_ft, /* ft */
37 1.1 christos NULL, /* ll */
38 1.1 christos NULL, /* mc */
39 1.1 christos NULL, /* po */
40 1.1 christos NULL, /* rj */
41 1.1 christos NULL, /* sp */
42 1.1 christos NULL, /* ta */
43 1.1 christos NULL, /* ti */
44 1.1 christos };
45 1.1 christos
46 1.1 christos
47 1.1 christos void
48 1.1 christos roff_validate(struct roff_man *man)
49 1.1 christos {
50 1.1 christos struct roff_node *n;
51 1.1 christos
52 1.1 christos n = man->last;
53 1.1 christos assert(n->tok < ROFF_MAX);
54 1.1 christos if (roff_valids[n->tok] != NULL)
55 1.1 christos (*roff_valids[n->tok])(man, n);
56 1.1 christos }
57 1.1 christos
58 1.1 christos static void
59 1.1 christos roff_valid_ft(ROFF_VALID_ARGS)
60 1.1 christos {
61 1.1 christos char *cp;
62 1.1 christos
63 1.1 christos if (n->child == NULL) {
64 1.1 christos man->next = ROFF_NEXT_CHILD;
65 1.1 christos roff_word_alloc(man, n->line, n->pos, "P");
66 1.1 christos man->last = n;
67 1.1 christos return;
68 1.1 christos }
69 1.1 christos
70 1.1 christos cp = n->child->string;
71 1.1 christos switch (*cp) {
72 1.1 christos case '1':
73 1.1 christos case '2':
74 1.1 christos case '3':
75 1.1 christos case '4':
76 1.1 christos case 'I':
77 1.1 christos case 'P':
78 1.1 christos case 'R':
79 1.1 christos if (cp[1] == '\0')
80 1.1 christos return;
81 1.1 christos break;
82 1.1 christos case 'B':
83 1.1 christos if (cp[1] == '\0' || (cp[1] == 'I' && cp[2] == '\0'))
84 1.1 christos return;
85 1.1 christos break;
86 1.1 christos case 'C':
87 1.1 christos if (cp[1] == 'W' && cp[2] == '\0')
88 1.1 christos return;
89 1.1 christos break;
90 1.1 christos default:
91 1.1 christos break;
92 1.1 christos }
93 1.1 christos
94 1.1 christos mandoc_vmsg(MANDOCERR_FT_BAD, man->parse,
95 1.1 christos n->line, n->pos, "ft %s", cp);
96 1.1 christos roff_node_delete(man, n);
97 1.1 christos }
98