]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
Tiny EOS patch. Back-end cues front-end through flag. Front-end cues output engine...
[mandoc.git] / mdoc.h
1 /* $Id: mdoc.h,v 1.77 2010/05/12 16:01:01 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 /*
21 * This library implements a validating scanner/parser for ``mdoc'' roff
22 * macro documents, a.k.a. BSD manual page documents. The mdoc.c file
23 * drives the parser, while macro.c describes the macro ontologies.
24 * validate.c pre- and post-validates parsed macros, and action.c
25 * performs actions on parsed and validated macros.
26 */
27
28 /* What follows is a list of ALL possible macros. */
29
30 enum mdoct {
31 MDOC_Ap = 0,
32 MDOC_Dd,
33 MDOC_Dt,
34 MDOC_Os,
35 MDOC_Sh,
36 MDOC_Ss,
37 MDOC_Pp,
38 MDOC_D1,
39 MDOC_Dl,
40 MDOC_Bd,
41 MDOC_Ed,
42 MDOC_Bl,
43 MDOC_El,
44 MDOC_It,
45 MDOC_Ad,
46 MDOC_An,
47 MDOC_Ar,
48 MDOC_Cd,
49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b,
138 MDOC_Lp,
139 MDOC_Lk,
140 MDOC_Mt,
141 MDOC_Brq,
142 MDOC_Bro,
143 MDOC_Brc,
144 MDOC__C,
145 MDOC_Es,
146 MDOC_En,
147 MDOC_Dx,
148 MDOC__Q,
149 MDOC_br,
150 MDOC_sp,
151 MDOC__U,
152 MDOC_MAX
153 };
154
155 /* What follows is a list of ALL possible macro arguments. */
156
157 #define MDOC_Split 0
158 #define MDOC_Nosplit 1
159 #define MDOC_Ragged 2
160 #define MDOC_Unfilled 3
161 #define MDOC_Literal 4
162 #define MDOC_File 5
163 #define MDOC_Offset 6
164 #define MDOC_Bullet 7
165 #define MDOC_Dash 8
166 #define MDOC_Hyphen 9
167 #define MDOC_Item 10
168 #define MDOC_Enum 11
169 #define MDOC_Tag 12
170 #define MDOC_Diag 13
171 #define MDOC_Hang 14
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
177 #define MDOC_Std 20
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_Centred 26
184 #define MDOC_ARG_MAX 27
185
186 /* Type of a syntax node. */
187 enum mdoc_type {
188 MDOC_TEXT,
189 MDOC_ELEM,
190 MDOC_HEAD,
191 MDOC_TAIL,
192 MDOC_BODY,
193 MDOC_BLOCK,
194 MDOC_ROOT
195 };
196
197 /* Section (named/unnamed) of `Sh'. */
198 enum mdoc_sec {
199 SEC_NONE, /* No section, yet. */
200 SEC_NAME,
201 SEC_LIBRARY,
202 SEC_SYNOPSIS,
203 SEC_DESCRIPTION,
204 SEC_IMPLEMENTATION,
205 SEC_RETURN_VALUES,
206 SEC_ENVIRONMENT,
207 SEC_FILES,
208 SEC_EXIT_STATUS,
209 SEC_EXAMPLES,
210 SEC_DIAGNOSTICS,
211 SEC_COMPATIBILITY,
212 SEC_ERRORS,
213 SEC_SEE_ALSO,
214 SEC_STANDARDS,
215 SEC_HISTORY,
216 SEC_AUTHORS,
217 SEC_CAVEATS,
218 SEC_BUGS,
219 SEC_SECURITY,
220 SEC_CUSTOM, /* User-defined. */
221 SEC__MAX
222 };
223
224 /* Information from prologue. */
225 struct mdoc_meta {
226 int msec;
227 char *vol;
228 char *arch;
229 time_t date;
230 char *title;
231 char *os;
232 char *name;
233 };
234
235 /* An argument to a macro (multiple values = `It -column'). */
236 struct mdoc_argv {
237 int arg;
238 int line;
239 int pos;
240 size_t sz;
241 char **value;
242 };
243
244 struct mdoc_arg {
245 size_t argc;
246 struct mdoc_argv *argv;
247 unsigned int refcnt;
248 };
249
250 /* Node in AST. */
251 struct mdoc_node {
252 struct mdoc_node *parent;
253 struct mdoc_node *child;
254 struct mdoc_node *next;
255 struct mdoc_node *prev;
256 int nchild;
257 int line;
258 int pos;
259 enum mdoct tok;
260 int flags;
261 #define MDOC_VALID (1 << 0)
262 #define MDOC_ACTED (1 << 1)
263 #define MDOC_EOS (1 << 2)
264 enum mdoc_type type;
265 enum mdoc_sec sec;
266
267 struct mdoc_arg *args; /* BLOCK/ELEM */
268 #ifdef UGLY
269 struct mdoc_node *pending; /* BLOCK */
270 #endif
271 struct mdoc_node *head; /* BLOCK */
272 struct mdoc_node *body; /* BLOCK */
273 struct mdoc_node *tail; /* BLOCK */
274 char *string; /* TEXT */
275 };
276
277 #define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */
278 #define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */
279 #define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */
280
281 /* Call-backs for parse messages. */
282
283 struct mdoc_cb {
284 int (*mdoc_err)(void *, int, int, const char *);
285 int (*mdoc_warn)(void *, int, int, const char *);
286 };
287
288 /* See mdoc.3 for documentation. */
289
290 extern const char *const *mdoc_macronames;
291 extern const char *const *mdoc_argnames;
292
293 __BEGIN_DECLS
294
295 struct mdoc;
296
297 /* See mdoc.3 for documentation. */
298
299 void mdoc_free(struct mdoc *);
300 struct mdoc *mdoc_alloc(void *, int, const struct mdoc_cb *);
301 void mdoc_reset(struct mdoc *);
302 int mdoc_parseln(struct mdoc *, int, char *buf);
303 const struct mdoc_node *mdoc_node(const struct mdoc *);
304 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
305 int mdoc_endparse(struct mdoc *);
306
307 __END_DECLS
308
309 #endif /*!MDOC_H*/