]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
1 /* $Id: mdoc.h,v 1.53 2009/03/23 14:22:11 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
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.
25 * This library implements a validating scanner/parser for ``mdoc'' roff
26 * macro documents, a.k.a. BSD manual page documents. The mdoc.c file
27 * drives the parser, while macro.c describes the macro ontologies.
28 * validate.c pre- and post-validates parsed macros, and action.c
29 * performs actions on parsed and validated macros.
32 /* What follows is a list of ALL possible macros. */
155 /* What follows is a list of ALL possible macro arguments. */
158 #define MDOC_Nosplit 1
159 #define MDOC_Ragged 2
160 #define MDOC_Unfilled 3
161 #define MDOC_Literal 4
163 #define MDOC_Offset 6
164 #define MDOC_Bullet 7
166 #define MDOC_Hyphen 9
172 #define MDOC_Ohang 15
173 #define MDOC_Inset 16
174 #define MDOC_Column 17
175 #define MDOC_Width 18
176 #define MDOC_Compact 19
178 #define MDOC_Filled 21
179 #define MDOC_Words 22
180 #define MDOC_Emphasis 23
181 #define MDOC_Symbolic 24
182 #define MDOC_Nested 25
183 #define MDOC_ARG_MAX 26
185 /* Warnings are either syntax or groff-compatibility. */
191 /* Type of a syntax node. */
202 /* Section (named/unnamed) of `Sh'. */
210 SEC_IMPLEMENTATION
= 6,
211 SEC_RETURN_VALUES
= 7,
215 SEC_DIAGNOSTICS
= 11,
216 SEC_COMPATIBILITY
= 12,
227 /* Information from prologue. */
238 /* An argument to a macro (multiple values = `It -column'). */
249 struct mdoc_argv
*argv
;
255 struct mdoc_node
*parent
;
256 struct mdoc_node
*child
;
257 struct mdoc_node
*next
;
258 struct mdoc_node
*prev
;
263 #define MDOC_VALID (1 << 0)
264 #define MDOC_ACTED (1 << 1)
268 /* FIXME: union/struct this with #defines. */
269 struct mdoc_arg
*args
; /* BLOCK/ELEM */
270 struct mdoc_node
*head
; /* BLOCK */
271 struct mdoc_node
*body
; /* BLOCK */
272 struct mdoc_node
*tail
; /* BLOCK */
273 char *string
; /* TEXT */
276 #define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */
277 #define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */
278 #define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */
280 /* Call-backs for parse messages. */
282 void (*mdoc_msg
)(void *, int, int, const char *);
283 int (*mdoc_err
)(void *, int, int, const char *);
284 int (*mdoc_warn
)(void *, int, int,
285 enum mdoc_warn
, const char *);
288 /* Global table of macro names (`Bd', `Ed', etc.). */
289 extern const char *const *mdoc_macronames
;
291 /* Global table of argument names (`column', `tag', etc.). */
292 extern const char *const *mdoc_argnames
;
298 /* Free memory allocated with mdoc_alloc. */
299 void mdoc_free(struct mdoc
*);
301 /* Allocate a new parser instance. */
302 struct mdoc
*mdoc_alloc(void *, int, const struct mdoc_cb
*);
304 /* Gets system ready for another parse. */
305 void mdoc_reset(struct mdoc
*);
307 /* Parse a single line in a stream (boolean retval). */
308 int mdoc_parseln(struct mdoc
*, int, char *buf
);
310 /* Get result first node (after mdoc_endparse!). */
311 const struct mdoc_node
*mdoc_node(const struct mdoc
*);
313 /* Get result meta-information (after mdoc_endparse!). */
314 const struct mdoc_meta
*mdoc_meta(const struct mdoc
*);
316 /* Signal end of parse sequence (boolean retval). */
317 int mdoc_endparse(struct mdoc
*);
319 /* The following are utility functions. */
321 const char *mdoc_a2att(const char *);
322 const char *mdoc_a2lib(const char *);
323 const char *mdoc_a2st(const char *);