]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
*** empty log message ***
[mandoc.git] / mdoc.h
1 /* $Id: mdoc.h,v 1.12 2009/01/02 14:06:16 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008 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
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
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.
18 */
19 #ifndef MDOC_H
20 #define MDOC_H
21
22 #define MDOC_LINEARG_MAX 8
23
24 #define MDOC___ 0
25 #define MDOC_Dd 1
26 #define MDOC_Dt 2
27 #define MDOC_Os 3
28 #define MDOC_Sh 4
29 #define MDOC_Ss 5
30 #define MDOC_Pp 6
31 #define MDOC_D1 7
32 #define MDOC_Dl 8
33 #define MDOC_Bd 9
34 #define MDOC_Ed 10
35 #define MDOC_Bl 11
36 #define MDOC_El 12
37 #define MDOC_It 13
38 #define MDOC_Ad 14
39 #define MDOC_An 15
40 #define MDOC_Ar 16
41 #define MDOC_Cd 17
42 #define MDOC_Cm 18
43 #define MDOC_Dv 19
44 #define MDOC_Er 20
45 #define MDOC_Ev 21
46 #define MDOC_Ex 22
47 #define MDOC_Fa 23
48 #define MDOC_Fd 24
49 #define MDOC_Fl 25
50 #define MDOC_Fn 26
51 #define MDOC_Ft 27
52 #define MDOC_Ic 28
53 #define MDOC_In 29
54 #define MDOC_Li 30
55 #define MDOC_Nd 31
56 #define MDOC_Nm 32
57 #define MDOC_Op 33
58 #define MDOC_Ot 34
59 #define MDOC_Pa 35
60 #define MDOC_Rv 36
61 #define MDOC_St 37
62 #define MDOC_Va 38
63 #define MDOC_Vt 39
64 #define MDOC_Xr 40
65 #define MDOC__A 41
66 #define MDOC__B 42
67 #define MDOC__D 43
68 #define MDOC__I 44
69 #define MDOC__J 45
70 #define MDOC__N 46
71 #define MDOC__O 47
72 #define MDOC__P 48
73 #define MDOC__R 49
74 #define MDOC__T 50
75 #define MDOC__V 51
76 #define MDOC_Ac 52
77 #define MDOC_Ao 53
78 #define MDOC_Aq 54
79 #define MDOC_At 55
80 #define MDOC_Bc 56
81 #define MDOC_Bf 57
82 #define MDOC_Bo 58
83 #define MDOC_Bq 59
84 #define MDOC_Bsx 60
85 #define MDOC_Bx 61
86 #define MDOC_Db 62
87 #define MDOC_Dc 63
88 #define MDOC_Do 64
89 #define MDOC_Dq 65
90 #define MDOC_Ec 66
91 #define MDOC_Ef 67
92 #define MDOC_Em 68
93 #define MDOC_Eo 69
94 #define MDOC_Fx 70
95 #define MDOC_Ms 71
96 #define MDOC_No 72
97 #define MDOC_Ns 73
98 #define MDOC_Nx 74
99 #define MDOC_Ox 75
100 #define MDOC_Pc 76
101 #define MDOC_Pf 77
102 #define MDOC_Po 78
103 #define MDOC_Pq 79
104 #define MDOC_Qc 80
105 #define MDOC_Ql 81
106 #define MDOC_Qo 82
107 #define MDOC_Qq 83
108 #define MDOC_Re 84
109 #define MDOC_Rs 85
110 #define MDOC_Sc 86
111 #define MDOC_So 87
112 #define MDOC_Sq 88
113 #define MDOC_Sm 89
114 #define MDOC_Sx 90
115 #define MDOC_Sy 91
116 #define MDOC_Tn 92
117 #define MDOC_Ux 93
118 #define MDOC_Xc 94
119 #define MDOC_Xo 95
120 #define MDOC_Fo 96
121 #define MDOC_Fc 97
122 #define MDOC_Oo 98
123 #define MDOC_Oc 99
124 #define MDOC_Bk 100
125 #define MDOC_Ek 101
126 #define MDOC_Bt 102
127 #define MDOC_Hf 103
128 #define MDOC_Fr 104
129 #define MDOC_Ud 105
130 #define MDOC_MAX 106
131
132 #define MDOC_Split 0
133 #define MDOC_Nosplit 1
134 #define MDOC_Ragged 2
135 #define MDOC_Unfilled 3
136 #define MDOC_Literal 4
137 #define MDOC_File 5
138 #define MDOC_Offset 6
139 #define MDOC_Bullet 7
140 #define MDOC_Dash 8
141 #define MDOC_Hyphen 9
142 #define MDOC_Item 10
143 #define MDOC_Enum 11
144 #define MDOC_Tag 12
145 #define MDOC_Diag 13
146 #define MDOC_Hang 14
147 #define MDOC_Ohang 15
148 #define MDOC_Inset 16
149 #define MDOC_Column 17
150 #define MDOC_Width 18
151 #define MDOC_Compact 19
152 #define MDOC_Std 20
153 #define MDOC_p1003_1_88 21
154 #define MDOC_p1003_1_90 22
155 #define MDOC_p1003_1_96 23
156 #define MDOC_p1003_1_2001 24
157 #define MDOC_p1003_1_2004 25
158 #define MDOC_p1003_1 26
159 #define MDOC_p1003_1b 27
160 #define MDOC_p1003_1b_93 28
161 #define MDOC_p1003_1c_95 29
162 #define MDOC_p1003_1g_2000 30
163 #define MDOC_p1003_2_92 31
164 #define MDOC_p1387_2_95 32
165 #define MDOC_p1003_2 33
166 #define MDOC_p1387_2 34
167 #define MDOC_isoC_90 35
168 #define MDOC_isoC_amd1 36
169 #define MDOC_isoC_tcor1 37
170 #define MDOC_isoC_tcor2 38
171 #define MDOC_isoC_99 39
172 #define MDOC_ansiC 40
173 #define MDOC_ansiC_89 41
174 #define MDOC_ansiC_99 42
175 #define MDOC_ieee754 43
176 #define MDOC_iso8802_3 44
177 #define MDOC_xpg3 45
178 #define MDOC_xpg4 46
179 #define MDOC_xpg4_2 47
180 #define MDOC_xpg4_3 48
181 #define MDOC_xbd5 49
182 #define MDOC_xcu5 50
183 #define MDOC_xsh5 51
184 #define MDOC_xns5 52
185 #define MDOC_xns5_2d2_0 53
186 #define MDOC_xcurses4_2 54
187 #define MDOC_susv2 55
188 #define MDOC_susv3 56
189 #define MDOC_svid4 57
190 #define MDOC_Filled 58
191 #define MDOC_Words 59
192 #define MDOC_Emphasis 60
193 #define MDOC_Symbolic 61
194 #define MDOC_ARG_MAX 62
195
196 enum mdoc_err {
197 ERR_SYNTAX_QUOTE, /* NOTUSED */
198 ERR_SYNTAX_UNQUOTE,
199 ERR_SYNTAX_NOPUNCT,
200 ERR_SYNTAX_WS,
201 ERR_SYNTAX_ARG,
202 ERR_SYNTAX_ARGFORM,
203 ERR_SYNTAX_ARGVAL,
204 ERR_SYNTAX_ARGBAD,
205 ERR_SYNTAX_ARGMANY,
206 ERR_MACRO_NOTSUP,
207 ERR_MACRO_NOTCALL,
208 ERR_SCOPE_BREAK,
209 ERR_SCOPE_NOCTX,
210 ERR_SCOPE_NONEST,
211 ERR_SEC_PROLOGUE,
212 ERR_SEC_NPROLOGUE,
213 ERR_SEC_PROLOGUE_OO,
214 ERR_SEC_PROLOGUE_REP,
215 ERR_SEC_NAME,
216 ERR_ARGS_EQ0,
217 ERR_ARGS_EQ1,
218 ERR_ARGS_GE1,
219 ERR_ARGS_LE2,
220 ERR_ARGS_MANY,
221 ERR_CHILD_HEAD
222 };
223
224 enum mdoc_att {
225 ATT_DEFAULT = 0,
226 ATT_v1,
227 ATT_v2,
228 ATT_v3,
229 ATT_v4,
230 ATT_v5,
231 ATT_v6,
232 ATT_v7,
233 ATT_32v,
234 ATT_V1,
235 ATT_V2,
236 ATT_V3,
237 ATT_V4
238 };
239
240 enum mdoc_warn {
241 WARN_SYNTAX_WS_EOLN,
242 WARN_SYNTAX_MACLIKE,
243 WARN_SYNTAX_ARGLIKE,
244 WARN_SYNTAX_QUOTED,
245 WARN_IGN_AFTER_BLK,
246 WARN_IGN_BEFORE_BLK,
247 WARN_IGN_OBSOLETE,
248 WARN_SEC_OO,
249 WARN_ARGS_GE1,
250 WARN_ARGS_EQ0,
251 WARN_COMPAT_TROFF
252 };
253
254 struct mdoc_arg {
255 int arg;
256 size_t sz;
257 char **value;
258 };
259
260 enum mdoc_type {
261 MDOC_TEXT,
262 MDOC_ELEM,
263 MDOC_HEAD,
264 MDOC_BODY,
265 MDOC_BLOCK
266 };
267
268 enum mdoc_msec {
269 MSEC_DEFAULT = 0,
270 MSEC_1,
271 MSEC_2,
272 MSEC_3,
273 MSEC_3f,
274 MSEC_3p,
275 MSEC_4,
276 MSEC_5,
277 MSEC_6,
278 MSEC_7,
279 MSEC_8,
280 MSEC_9,
281 MSEC_X11,
282 MSEC_X11R6,
283 MSEC_local,
284 MSEC_n,
285 MSEC_unass,
286 MSEC_draft,
287 MSEC_paper
288 };
289
290 enum mdoc_sec {
291 SEC_PROLOGUE = 0,
292 SEC_BODY,
293 SEC_NAME,
294 SEC_SYNOPSIS,
295 SEC_DESCRIPTION,
296 SEC_RETURN_VALUES,
297 SEC_ENVIRONMENT,
298 SEC_FILES,
299 SEC_EXAMPLES,
300 SEC_DIAGNOSTICS,
301 SEC_ERRORS,
302 SEC_SEE_ALSO,
303 SEC_STANDARDS,
304 SEC_HISTORY,
305 SEC_AUTHORS,
306 SEC_CAVEATS,
307 SEC_BUGS,
308 SEC_CUSTOM
309 };
310
311 enum mdoc_vol {
312 VOL_DEFAULT = 0,
313 VOL_AMD,
314 VOL_IND,
315 VOL_KM,
316 VOL_LOCAL,
317 VOL_PRM,
318 VOL_PS1,
319 VOL_SMM,
320 VOL_URM,
321 VOL_USD
322 };
323
324 enum mdoc_arch {
325 ARCH_DEFAULT = 0,
326 ARCH_alpha,
327 ARCH_amd64,
328 ARCH_amiga,
329 ARCH_arc,
330 ARCH_armish,
331 ARCH_aviion,
332 ARCH_hp300,
333 ARCH_hppa,
334 ARCH_hppa64,
335 ARCH_i386,
336 ARCH_landisk,
337 ARCH_luna88k,
338 ARCH_mac68k,
339 ARCH_macppc,
340 ARCH_mvme68k,
341 ARCH_mvme88k,
342 ARCH_mvmeppc,
343 ARCH_pmax,
344 ARCH_sgi,
345 ARCH_socppc,
346 ARCH_sparc,
347 ARCH_sparc64,
348 ARCH_sun3,
349 ARCH_vax,
350 ARCH_zaurus
351 };
352
353 struct mdoc_meta {
354 enum mdoc_msec msec;
355 enum mdoc_vol vol;
356 enum mdoc_arch arch;
357 time_t date;
358 #define META_TITLE_SZ (64)
359 char title[META_TITLE_SZ];
360 #define META_OS_SZ (64)
361 char os[META_OS_SZ];
362 };
363
364 struct mdoc_text {
365 char *string;
366 };
367
368 struct mdoc_block {
369 int tok;
370 size_t argc;
371 struct mdoc_arg *argv;
372 };
373
374 struct mdoc_head {
375 size_t sz;
376 char **args;
377 int tok;
378 };
379
380 struct mdoc_body {
381 int tok;
382 };
383
384 struct mdoc_elem {
385 size_t sz;
386 char **args;
387 int tok;
388 size_t argc;
389 struct mdoc_arg *argv;
390 };
391
392 union mdoc_data {
393 struct mdoc_text text;
394 struct mdoc_elem elem;
395 struct mdoc_body body;
396 struct mdoc_head head;
397 struct mdoc_block block;
398 };
399
400 struct mdoc_node {
401 struct mdoc_node *parent;
402 struct mdoc_node *child;
403 struct mdoc_node *next;
404 struct mdoc_node *prev;
405 enum mdoc_type type;
406 union mdoc_data data;
407 };
408
409 struct mdoc_cb {
410 int (*mdoc_err)(void *, int, int, enum mdoc_err);
411 int (*mdoc_warn)(void *, int, int, enum mdoc_warn);
412 void (*mdoc_msg)(void *, int, const char *);
413 };
414
415 extern const char *const *mdoc_macronames;
416 extern const char *const *mdoc_argnames;
417
418 __BEGIN_DECLS
419
420 struct mdoc;
421
422 void mdoc_free(struct mdoc *);
423 struct mdoc *mdoc_alloc(void *data, const struct mdoc_cb *);
424 int mdoc_parseln(struct mdoc *, char *buf);
425 const struct mdoc_node
426 *mdoc_result(struct mdoc *);
427
428 __END_DECLS
429
430 #endif /*!MDOC_H*/