1 /* $Id: mdoc.h,v 1.27 2009/01/19 17:51:33 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
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
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.
22 /* What follows is a list of ALL possible macros. */
132 /* What follows is a list of ALL possible macro arguments. */
135 #define MDOC_Nosplit 1
136 #define MDOC_Ragged 2
137 #define MDOC_Unfilled 3
138 #define MDOC_Literal 4
140 #define MDOC_Offset 6
141 #define MDOC_Bullet 7
143 #define MDOC_Hyphen 9
149 #define MDOC_Ohang 15
150 #define MDOC_Inset 16
151 #define MDOC_Column 17
152 #define MDOC_Width 18
153 #define MDOC_Compact 19
155 #define MDOC_p1003_1_88 21
156 #define MDOC_p1003_1_90 22
157 #define MDOC_p1003_1_96 23
158 #define MDOC_p1003_1_2001 24
159 #define MDOC_p1003_1_2004 25
160 #define MDOC_p1003_1 26
161 #define MDOC_p1003_1b 27
162 #define MDOC_p1003_1b_93 28
163 #define MDOC_p1003_1c_95 29
164 #define MDOC_p1003_1g_2000 30
165 #define MDOC_p1003_2_92 31
166 #define MDOC_p1387_2_95 32
167 #define MDOC_p1003_2 33
168 #define MDOC_p1387_2 34
169 #define MDOC_isoC_90 35
170 #define MDOC_isoC_amd1 36
171 #define MDOC_isoC_tcor1 37
172 #define MDOC_isoC_tcor2 38
173 #define MDOC_isoC_99 39
174 #define MDOC_ansiC 40
175 #define MDOC_ansiC_89 41
176 #define MDOC_ansiC_99 42
177 #define MDOC_ieee754 43
178 #define MDOC_iso8802_3 44
181 #define MDOC_xpg4_2 47
182 #define MDOC_xpg4_3 48
187 #define MDOC_xns5_2d2_0 53
188 #define MDOC_xcurses4_2 54
189 #define MDOC_susv2 55
190 #define MDOC_susv3 56
191 #define MDOC_svid4 57
192 #define MDOC_Filled 58
193 #define MDOC_Words 59
194 #define MDOC_Emphasis 60
195 #define MDOC_Symbolic 61
196 #define MDOC_ARG_MAX 62
199 WARN_SYNTAX
, /* Syntax warn (at line/col). */
200 WARN_COMPAT
/* Groff compat warn (at line/col). */
203 /* Possible values for the `At' macro. */
220 /* An argument to a macro (multiple values = `It -column'). */
230 * Simplified grammar of syntax tree:
232 * MDOC_ROOT: root of tree
233 * MDOC_TEXT: free-form text
234 * MDOC_ELEM: elem [args] MDOC_TEXT...
235 * MDOC_BLOCK, MDOC_HEAD, MDOC_BODY, MDOC_TAIL:
237 * MDOC_HEAD [args] (MDOC_TEXT|MDOC_ELEM|MDOC_BLOCK)...
238 * MDOC_BODY (MDOC_TEXT|MDOC_ELEM|MDOC_BLOCK)...
239 * MDOC_TAIL (optional) (MDOC_TEXT|MDOC_ELEM|MDOC_BLOCK)...
242 /* Type of a syntax node. */
253 /* Manual section. */
276 /* Section (named/unnamed) of `Ss'. */
298 /* Volume of `Dt'. */
312 /* Architecture of `Dt'. */
343 /* Meta-information from prologue. */
360 struct mdoc_arg
*argv
;
361 struct mdoc_node
*head
;
362 struct mdoc_node
*body
;
363 struct mdoc_node
*tail
;
370 struct mdoc_arg
*argv
;
374 struct mdoc_text text
;
375 struct mdoc_elem elem
;
376 struct mdoc_block block
;
379 /* Syntax node in parse tree. */
381 struct mdoc_node
*parent
;
382 struct mdoc_node
*child
;
383 struct mdoc_node
*next
;
384 struct mdoc_node
*prev
;
389 #define MDOC_VALID (1 << 0)
390 #define MDOC_ACTED (1 << 1)
392 union mdoc_data data
;
395 /* Call-backs for parse messages. */
397 void (*mdoc_msg
)(void *, int, int, const char *);
398 int (*mdoc_err
)(void *, int, int, const char *);
399 int (*mdoc_warn
)(void *, int, int,
400 enum mdoc_warn
, const char *);
403 extern const char *const *mdoc_macronames
;
404 extern const char *const *mdoc_argnames
;
410 /* Free memory allocated with mdoc_alloc. */
411 void mdoc_free(struct mdoc
*);
413 /* Allocate a new parser instance. */
414 struct mdoc
*mdoc_alloc(void *data
, const struct mdoc_cb
*);
416 /* Parse a single line (boolean retval). */
417 int mdoc_parseln(struct mdoc
*, int, char *buf
);
419 /* Get result first node. */
420 const struct mdoc_node
*mdoc_node(struct mdoc
*);
422 /* Get result meta-information. */
423 const struct mdoc_meta
*mdoc_meta(struct mdoc
*);
425 /* Signal end of parse sequence (boolean retval). */
426 int mdoc_endparse(struct mdoc
*);