]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
1 /* $Id: mdoc.h,v 1.43 2009/03/09 13:04:01 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.
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.
30 /* What follows is a list of ALL possible macros. */
32 /* TODO: Brq et al. */
145 /* What follows is a list of ALL possible macro arguments. */
148 #define MDOC_Nosplit 1
149 #define MDOC_Ragged 2
150 #define MDOC_Unfilled 3
151 #define MDOC_Literal 4
153 #define MDOC_Offset 6
154 #define MDOC_Bullet 7
156 #define MDOC_Hyphen 9
162 #define MDOC_Ohang 15
163 #define MDOC_Inset 16
164 #define MDOC_Column 17
165 #define MDOC_Width 18
166 #define MDOC_Compact 19
168 #define MDOC_Filled 21
169 #define MDOC_Words 22
170 #define MDOC_Emphasis 23
171 #define MDOC_Symbolic 24
172 #define MDOC_ARG_MAX 25
174 /* Warnings are either syntax or groff-compatibility. */
180 /* Type of a syntax node. */
191 /* Section (named/unnamed) of `Sh'. */
199 SEC_IMPLEMENTATION
= 6,
200 SEC_RETURN_VALUES
= 7,
204 SEC_DIAGNOSTICS
= 11,
205 SEC_COMPATIBILITY
= 12,
216 /* Information from prologue. */
227 /* An argument to a macro (multiple values = `It -column'). */
238 struct mdoc_argv
*argv
;
244 struct mdoc_node
*parent
;
245 struct mdoc_node
*child
;
246 struct mdoc_node
*next
;
247 struct mdoc_node
*prev
;
252 #define MDOC_VALID (1 << 0)
253 #define MDOC_ACTED (1 << 1)
257 /* FIXME: union/struct this with #defines. */
258 struct mdoc_arg
*args
; /* BLOCK/ELEM */
259 struct mdoc_node
*head
; /* BLOCK */
260 struct mdoc_node
*body
; /* BLOCK */
261 struct mdoc_node
*tail
; /* BLOCK */
262 char *string
; /* TEXT */
265 #define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */
266 #define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */
267 #define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */
269 /* Call-backs for parse messages. */
271 void (*mdoc_msg
)(void *, int, int, const char *);
272 int (*mdoc_err
)(void *, int, int, const char *);
273 int (*mdoc_warn
)(void *, int, int,
274 enum mdoc_warn
, const char *);
277 /* Global table of macro names (`Bd', `Ed', etc.). */
278 extern const char *const *mdoc_macronames
;
280 /* Global table of argument names (`column', `tag', etc.). */
281 extern const char *const *mdoc_argnames
;
287 /* Free memory allocated with mdoc_alloc. */
288 void mdoc_free(struct mdoc
*);
290 /* Allocate a new parser instance. */
291 struct mdoc
*mdoc_alloc(void *, int, const struct mdoc_cb
*);
293 /* Set parse options. */
294 void mdoc_setflags(struct mdoc
*, int);
296 /* Parse a single line in a stream (boolean retval). */
297 int mdoc_parseln(struct mdoc
*, int, char *buf
);
299 /* Get result first node (after mdoc_endparse!). */
300 const struct mdoc_node
*mdoc_node(const struct mdoc
*);
302 /* Get result meta-information (after mdoc_endparse!). */
303 const struct mdoc_meta
*mdoc_meta(const struct mdoc
*);
305 /* Signal end of parse sequence (boolean retval). */
306 int mdoc_endparse(struct mdoc
*);
308 /* The following are utility functions. */
310 const char *mdoc_a2att(const char *);
311 const char *mdoc_a2lib(const char *);
312 const char *mdoc_a2st(const char *);
314 int mdoc_isdelim(const char *);