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