]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
First step of adding register support. This is inspired by a significant
[mandoc.git] / mdoc.h
1 /* $Id: mdoc.h,v 1.91 2010/06/26 15:22:19 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
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 MDOC_Cm,
50 M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
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_Ta,
153 MDOC_MAX
154 };
155
156 /* What follows is a list of ALL possible macro arguments. */
157
158 /* FIXME: make this into an enum. */
159 #define MDOC_Split 0
160 #define MDOC_Nosplit 1
161 #define MDOC_Ragged 2
162 #define MDOC_Unfilled 3
163 #define MDOC_Literal 4
164 #define MDOC_File 5
165 #define MDOC_Offset 6
166 #define MDOC_Bullet 7
167 #define MDOC_Dash 8
168 #define MDOC_Hyphen 9
169 #define MDOC_Item 10
170 #define MDOC_Enum 11
171 #define MDOC_Tag 12
172 #define MDOC_Diag 13
173 #define MDOC_Hang 14
174 #define MDOC_Ohang 15
175 #define MDOC_Inset 16
176 #define MDOC_Column 17
177 #define MDOC_Width 18
178 #define MDOC_Compact 19
179 #define MDOC_Std 20
180 #define MDOC_Filled 21
181 #define MDOC_Words 22
182 #define MDOC_Emphasis 23
183 #define MDOC_Symbolic 24
184 #define MDOC_Nested 25
185 #define MDOC_Centred 26
186 #define MDOC_ARG_MAX 27
187
188 /* Type of a syntax node. */
189 enum mdoc_type {
190 MDOC_TEXT,
191 MDOC_ELEM,
192 MDOC_HEAD,
193 MDOC_TAIL,
194 MDOC_BODY,
195 MDOC_BLOCK,
196 MDOC_ROOT
197 };
198
199 /* Section (named/unnamed) of `Sh'. */
200 enum mdoc_sec {
201 SEC_NONE, /* No section, yet. */
202 SEC_NAME,
203 SEC_LIBRARY,
204 SEC_SYNOPSIS,
205 SEC_DESCRIPTION,
206 SEC_IMPLEMENTATION,
207 SEC_RETURN_VALUES,
208 SEC_ENVIRONMENT,
209 SEC_FILES,
210 SEC_EXIT_STATUS,
211 SEC_EXAMPLES,
212 SEC_DIAGNOSTICS,
213 SEC_COMPATIBILITY,
214 SEC_ERRORS,
215 SEC_SEE_ALSO,
216 SEC_STANDARDS,
217 SEC_HISTORY,
218 SEC_AUTHORS,
219 SEC_CAVEATS,
220 SEC_BUGS,
221 SEC_SECURITY,
222 SEC_CUSTOM, /* User-defined. */
223 SEC__MAX
224 };
225
226 /* Information from prologue. */
227 struct mdoc_meta {
228 char *msec;
229 char *vol;
230 char *arch;
231 time_t date;
232 char *title;
233 char *os;
234 char *name;
235 };
236
237 /* An argument to a macro (multiple values = `It -column'). */
238 struct mdoc_argv {
239 int arg;
240 int line;
241 int pos;
242 size_t sz;
243 char **value;
244 };
245
246 struct mdoc_arg {
247 size_t argc;
248 struct mdoc_argv *argv;
249 unsigned int refcnt;
250 };
251
252 enum mdoc_list {
253 LIST__NONE = 0,
254 LIST_bullet,
255 LIST_column,
256 LIST_dash,
257 LIST_diag,
258 LIST_enum,
259 LIST_hang,
260 LIST_hyphen,
261 LIST_inset,
262 LIST_item,
263 LIST_ohang,
264 LIST_tag
265 };
266
267 enum mdoc_disp {
268 DISP__NONE = 0,
269 DISP_centred,
270 DISP_ragged,
271 DISP_unfilled,
272 DISP_filled,
273 DISP_literal
274 };
275
276 struct mdoc_bd {
277 const char *offs; /* -offset */
278 enum mdoc_disp type; /* -ragged, etc. */
279 int comp; /* -compact */
280 };
281
282 struct mdoc_bl {
283 const char *width; /* -width */
284 const char *offs; /* -offset */
285 enum mdoc_list type; /* -tag, -enum, etc. */
286 int comp; /* -compact */
287 };
288
289 /* Node in AST. */
290 struct mdoc_node {
291 struct mdoc_node *parent; /* parent AST node */
292 struct mdoc_node *child; /* first child AST node */
293 struct mdoc_node *next; /* sibling AST node */
294 struct mdoc_node *prev; /* prior sibling AST node */
295 int nchild; /* number children */
296 int line; /* parse line */
297 int pos; /* parse column */
298 enum mdoct tok; /* tok or MDOC__MAX if none */
299 int flags;
300 #define MDOC_VALID (1 << 0) /* has been validated */
301 #define MDOC_ACTED (1 << 1) /* has been acted upon */
302 #define MDOC_EOS (1 << 2) /* at sentence boundary */
303 #define MDOC_LINE (1 << 3) /* first macro/text on line */
304 enum mdoc_type type; /* AST node type */
305 enum mdoc_sec sec; /* current named section */
306 struct mdoc_arg *args; /* BLOCK/ELEM */
307 #ifdef UGLY
308 struct mdoc_node *pending; /* BLOCK */
309 #endif
310 struct mdoc_node *head; /* BLOCK */
311 struct mdoc_node *body; /* BLOCK */
312 struct mdoc_node *tail; /* BLOCK */
313 char *string; /* TEXT */
314
315 union {
316 struct mdoc_bl Bl;
317 struct mdoc_bd Bd;
318 } data;
319 };
320
321 #define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */
322 #define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */
323 #define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */
324
325 /* See mdoc.3 for documentation. */
326
327 extern const char *const *mdoc_macronames;
328 extern const char *const *mdoc_argnames;
329
330 __BEGIN_DECLS
331
332 struct mdoc;
333
334 /* See mdoc.3 for documentation. */
335
336 void mdoc_free(struct mdoc *);
337 struct mdoc *mdoc_alloc(void *, int, mandocmsg);
338 void mdoc_reset(struct mdoc *);
339 int mdoc_parseln(struct mdoc *, int, char *, int);
340 const struct mdoc_node *mdoc_node(const struct mdoc *);
341 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
342 int mdoc_endparse(struct mdoc *);
343
344 __END_DECLS
345
346 #endif /*!MDOC_H*/