]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
89f80d4973d28c7796a6199b78de2c90df71f5dd
[mandoc.git] / mdoc.h
1 /* $Id: mdoc.h,v 1.62 2009/07/06 09:21:24 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 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 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 #ifndef MDOC_H
18 #define MDOC_H
19
20 #include <time.h>
21
22 /*
23 * This library implements a validating scanner/parser for ``mdoc'' roff
24 * macro documents, a.k.a. BSD manual page documents. The mdoc.c file
25 * drives the parser, while macro.c describes the macro ontologies.
26 * validate.c pre- and post-validates parsed macros, and action.c
27 * performs actions on parsed and validated macros.
28 */
29
30 /* What follows is a list of ALL possible macros. */
31
32 #define MDOC_Ap 0
33 #define MDOC_Dd 1
34 #define MDOC_Dt 2
35 #define MDOC_Os 3
36 #define MDOC_Sh 4
37 #define MDOC_Ss 5
38 #define MDOC_Pp 6
39 #define MDOC_D1 7
40 #define MDOC_Dl 8
41 #define MDOC_Bd 9
42 #define MDOC_Ed 10
43 #define MDOC_Bl 11
44 #define MDOC_El 12
45 #define MDOC_It 13
46 #define MDOC_Ad 14
47 #define MDOC_An 15
48 #define MDOC_Ar 16
49 #define MDOC_Cd 17
50 #define MDOC_Cm 18
51 #define MDOC_Dv 19
52 #define MDOC_Er 20
53 #define MDOC_Ev 21
54 #define MDOC_Ex 22
55 #define MDOC_Fa 23
56 #define MDOC_Fd 24
57 #define MDOC_Fl 25
58 #define MDOC_Fn 26
59 #define MDOC_Ft 27
60 #define MDOC_Ic 28
61 #define MDOC_In 29
62 #define MDOC_Li 30
63 #define MDOC_Nd 31
64 #define MDOC_Nm 32
65 #define MDOC_Op 33
66 #define MDOC_Ot 34
67 #define MDOC_Pa 35
68 #define MDOC_Rv 36
69 #define MDOC_St 37
70 #define MDOC_Va 38
71 #define MDOC_Vt 39
72 #define MDOC_Xr 40
73 #define MDOC__A 41
74 #define MDOC__B 42
75 #define MDOC__D 43
76 #define MDOC__I 44
77 #define MDOC__J 45
78 #define MDOC__N 46
79 #define MDOC__O 47
80 #define MDOC__P 48
81 #define MDOC__R 49
82 #define MDOC__T 50
83 #define MDOC__V 51
84 #define MDOC_Ac 52
85 #define MDOC_Ao 53
86 #define MDOC_Aq 54
87 #define MDOC_At 55
88 #define MDOC_Bc 56
89 #define MDOC_Bf 57
90 #define MDOC_Bo 58
91 #define MDOC_Bq 59
92 #define MDOC_Bsx 60
93 #define MDOC_Bx 61
94 #define MDOC_Db 62
95 #define MDOC_Dc 63
96 #define MDOC_Do 64
97 #define MDOC_Dq 65
98 #define MDOC_Ec 66
99 #define MDOC_Ef 67
100 #define MDOC_Em 68
101 #define MDOC_Eo 69
102 #define MDOC_Fx 70
103 #define MDOC_Ms 71
104 #define MDOC_No 72
105 #define MDOC_Ns 73
106 #define MDOC_Nx 74
107 #define MDOC_Ox 75
108 #define MDOC_Pc 76
109 #define MDOC_Pf 77
110 #define MDOC_Po 78
111 #define MDOC_Pq 79
112 #define MDOC_Qc 80
113 #define MDOC_Ql 81
114 #define MDOC_Qo 82
115 #define MDOC_Qq 83
116 #define MDOC_Re 84
117 #define MDOC_Rs 85
118 #define MDOC_Sc 86
119 #define MDOC_So 87
120 #define MDOC_Sq 88
121 #define MDOC_Sm 89
122 #define MDOC_Sx 90
123 #define MDOC_Sy 91
124 #define MDOC_Tn 92
125 #define MDOC_Ux 93
126 #define MDOC_Xc 94
127 #define MDOC_Xo 95
128 #define MDOC_Fo 96
129 #define MDOC_Fc 97
130 #define MDOC_Oo 98
131 #define MDOC_Oc 99
132 #define MDOC_Bk 100
133 #define MDOC_Ek 101
134 #define MDOC_Bt 102
135 #define MDOC_Hf 103
136 #define MDOC_Fr 104
137 #define MDOC_Ud 105
138 #define MDOC_Lb 106
139 #define MDOC_Lp 107
140 #define MDOC_Lk 108
141 #define MDOC_Mt 109
142 #define MDOC_Brq 110
143 #define MDOC_Bro 111
144 #define MDOC_Brc 112
145 #define MDOC__C 113
146 #define MDOC_Es 114
147 #define MDOC_En 115
148 #define MDOC_Dx 116
149 #define MDOC__Q 117
150 #define MDOC_MAX 118
151
152 /* What follows is a list of ALL possible macro arguments. */
153
154 #define MDOC_Split 0
155 #define MDOC_Nosplit 1
156 #define MDOC_Ragged 2
157 #define MDOC_Unfilled 3
158 #define MDOC_Literal 4
159 #define MDOC_File 5
160 #define MDOC_Offset 6
161 #define MDOC_Bullet 7
162 #define MDOC_Dash 8
163 #define MDOC_Hyphen 9
164 #define MDOC_Item 10
165 #define MDOC_Enum 11
166 #define MDOC_Tag 12
167 #define MDOC_Diag 13
168 #define MDOC_Hang 14
169 #define MDOC_Ohang 15
170 #define MDOC_Inset 16
171 #define MDOC_Column 17
172 #define MDOC_Width 18
173 #define MDOC_Compact 19
174 #define MDOC_Std 20
175 #define MDOC_Filled 21
176 #define MDOC_Words 22
177 #define MDOC_Emphasis 23
178 #define MDOC_Symbolic 24
179 #define MDOC_Nested 25
180 #define MDOC_ARG_MAX 26
181
182 /* Type of a syntax node. */
183 enum mdoc_type {
184 MDOC_TEXT,
185 MDOC_ELEM,
186 MDOC_HEAD,
187 MDOC_TAIL,
188 MDOC_BODY,
189 MDOC_BLOCK,
190 MDOC_ROOT
191 };
192
193 /* Section (named/unnamed) of `Sh'. */
194 enum mdoc_sec {
195 SEC_NONE, /* No section, yet. */
196 SEC_NAME,
197 SEC_LIBRARY,
198 SEC_SYNOPSIS,
199 SEC_DESCRIPTION,
200 SEC_IMPLEMENTATION,
201 SEC_RETURN_VALUES,
202 SEC_ENVIRONMENT,
203 SEC_FILES,
204 SEC_EXAMPLES,
205 SEC_DIAGNOSTICS,
206 SEC_COMPATIBILITY,
207 SEC_ERRORS,
208 SEC_SEE_ALSO,
209 SEC_STANDARDS,
210 SEC_HISTORY,
211 SEC_AUTHORS,
212 SEC_CAVEATS,
213 SEC_BUGS,
214 SEC_CUSTOM /* User-defined. */
215 };
216
217 /* Information from prologue. */
218 struct mdoc_meta {
219 int msec;
220 char *vol;
221 char *arch;
222 time_t date;
223 char *title;
224 char *os;
225 char *name;
226 };
227
228 /* An argument to a macro (multiple values = `It -column'). */
229 struct mdoc_argv {
230 int arg;
231 int line;
232 int pos;
233 size_t sz;
234 char **value;
235 };
236
237 struct mdoc_arg {
238 size_t argc;
239 struct mdoc_argv *argv;
240 unsigned int refcnt;
241 };
242
243 /* Node in AST. */
244 struct mdoc_node {
245 struct mdoc_node *parent;
246 struct mdoc_node *child;
247 struct mdoc_node *next;
248 struct mdoc_node *prev;
249 int nchild;
250 int line;
251 int pos;
252 int tok;
253 int flags;
254 #define MDOC_VALID (1 << 0)
255 #define MDOC_ACTED (1 << 1)
256 enum mdoc_type type;
257 enum mdoc_sec sec;
258
259 /* FIXME: union/struct this with #defines. */
260 struct mdoc_arg *args; /* BLOCK/ELEM */
261 struct mdoc_node *head; /* BLOCK */
262 struct mdoc_node *body; /* BLOCK */
263 struct mdoc_node *tail; /* BLOCK */
264 char *string; /* TEXT */
265 };
266
267 #define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */
268 #define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */
269 #define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */
270 #define MDOC_IGN_CHARS (1 << 3) /* Ignore disallowed chars. */
271
272 /* Call-backs for parse messages. */
273 /* FIXME: unify somehow with man_cb. */
274 struct mdoc_cb {
275 int (*mdoc_err)(void *, int, int, const char *);
276 int (*mdoc_warn)(void *, int, int, const char *);
277 };
278
279 /* See mdoc.3 for documentation. */
280
281 extern const char *const *mdoc_macronames;
282 extern const char *const *mdoc_argnames;
283
284 __BEGIN_DECLS
285
286 struct mdoc;
287
288 /* See mdoc.3 for documentation. */
289
290 void mdoc_free(struct mdoc *);
291 struct mdoc *mdoc_alloc(void *, int, const struct mdoc_cb *);
292 int mdoc_reset(struct mdoc *);
293 int mdoc_parseln(struct mdoc *, int, char *buf);
294 const struct mdoc_node *mdoc_node(const struct mdoc *);
295 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
296 int mdoc_endparse(struct mdoc *);
297
298 const char *mdoc_a2att(const char *);
299 const char *mdoc_a2lib(const char *);
300 const char *mdoc_a2st(const char *);
301
302 __END_DECLS
303
304 #endif /*!MDOC_H*/