]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
Remove duplicate UNCONST definition.
[mandoc.git] / mdoc.h
1 /* $Id: mdoc.h,v 1.118 2011/03/07 01:35:51 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 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 * What follows is a list of ALL possible macros.
22 */
23 enum mdoct {
24 MDOC_Ap = 0,
25 MDOC_Dd,
26 MDOC_Dt,
27 MDOC_Os,
28 MDOC_Sh,
29 MDOC_Ss,
30 MDOC_Pp,
31 MDOC_D1,
32 MDOC_Dl,
33 MDOC_Bd,
34 MDOC_Ed,
35 MDOC_Bl,
36 MDOC_El,
37 MDOC_It,
38 MDOC_Ad,
39 MDOC_An,
40 MDOC_Ar,
41 MDOC_Cd,
42 MDOC_Cm,
43 MDOC_Dv,
44 MDOC_Er,
45 MDOC_Ev,
46 MDOC_Ex,
47 MDOC_Fa,
48 MDOC_Fd,
49 MDOC_Fl,
50 MDOC_Fn,
51 MDOC_Ft,
52 MDOC_Ic,
53 MDOC_In,
54 M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OC_sp,
144 MDOC__U,
145 MDOC_Ta,
146 MDOC_MAX
147 };
148
149 /*
150 * What follows is a list of ALL possible macro arguments.
151 */
152 enum mdocargt {
153 MDOC_Split,
154 MDOC_Nosplit,
155 MDOC_Ragged,
156 MDOC_Unfilled,
157 MDOC_Literal,
158 MDOC_File,
159 MDOC_Offset,
160 MDOC_Bullet,
161 MDOC_Dash,
162 MDOC_Hyphen,
163 MDOC_Item,
164 MDOC_Enum,
165 MDOC_Tag,
166 MDOC_Diag,
167 MDOC_Hang,
168 MDOC_Ohang,
169 MDOC_Inset,
170 MDOC_Column,
171 MDOC_Width,
172 MDOC_Compact,
173 MDOC_Std,
174 MDOC_Filled,
175 MDOC_Words,
176 MDOC_Emphasis,
177 MDOC_Symbolic,
178 MDOC_Nested,
179 MDOC_Centred,
180 MDOC_ARG_MAX
181 };
182
183 /*
184 * Type of a syntax node.
185 */
186 enum mdoc_type {
187 MDOC_TEXT,
188 MDOC_ELEM,
189 MDOC_HEAD,
190 MDOC_TAIL,
191 MDOC_BODY,
192 MDOC_BLOCK,
193 MDOC_TBL,
194 MDOC_EQN,
195 MDOC_ROOT
196 };
197
198 /*
199 * Section (named/unnamed) of `Sh'. Note that these appear in the
200 * conventional order imposed by mdoc.7.
201 */
202 enum mdoc_sec {
203 SEC_NONE = 0, /* No section, yet. */
204 SEC_NAME,
205 SEC_LIBRARY,
206 SEC_SYNOPSIS,
207 SEC_DESCRIPTION,
208 SEC_IMPLEMENTATION,
209 SEC_RETURN_VALUES,
210 SEC_ENVIRONMENT,
211 SEC_FILES,
212 SEC_EXIT_STATUS,
213 SEC_EXAMPLES,
214 SEC_DIAGNOSTICS,
215 SEC_COMPATIBILITY,
216 SEC_ERRORS,
217 SEC_SEE_ALSO,
218 SEC_STANDARDS,
219 SEC_HISTORY,
220 SEC_AUTHORS,
221 SEC_CAVEATS,
222 SEC_BUGS,
223 SEC_SECURITY,
224 SEC_CUSTOM, /* User-defined. */
225 SEC__MAX
226 };
227
228 /*
229 * Information from prologue.
230 */
231 struct mdoc_meta {
232 char *msec; /* `Dt' section (1, 3p, etc.) */
233 char *vol; /* `Dt' volume (implied) */
234 char *arch; /* `Dt' arch (i386, etc.) */
235 char *date; /* `Dd' normalised date */
236 char *title; /* `Dt' title (FOO, etc.) */
237 char *os; /* `Os' system (OpenBSD, etc.) */
238 char *name; /* leading `Nm' name */
239 };
240
241 /*
242 * An argument to a macro (multiple values = `-column xxx yyy').
243 */
244 struct mdoc_argv {
245 enum mdocargt arg; /* type of argument */
246 int line;
247 int pos;
248 size_t sz; /* elements in "value" */
249 char **value; /* argument strings */
250 };
251
252 /*
253 * Reference-counted macro arguments. These are refcounted because
254 * blocks have multiple instances of the same arguments spread across
255 * the HEAD, BODY, TAIL, and BLOCK node types.
256 */
257 struct mdoc_arg {
258 size_t argc;
259 struct mdoc_argv *argv;
260 unsigned int refcnt;
261 };
262
263 /*
264 * Indicates that a BODY's formatting has ended, but the scope is still
265 * open. Used for syntax-broken blocks.
266 */
267 enum mdoc_endbody {
268 ENDBODY_NOT = 0,
269 ENDBODY_SPACE, /* is broken: append a space */
270 ENDBODY_NOSPACE /* is broken: don't append a space */
271 };
272
273 /*
274 * Normalised `Bl' list type.
275 */
276 enum mdoc_list {
277 LIST__NONE = 0,
278 LIST_bullet,
279 LIST_column,
280 LIST_dash,
281 LIST_diag,
282 LIST_enum,
283 LIST_hang,
284 LIST_hyphen,
285 LIST_inset,
286 LIST_item,
287 LIST_ohang,
288 LIST_tag,
289 LIST_MAX
290 };
291
292 /*
293 * Normalised `Bd' display type.
294 */
295 enum mdoc_disp {
296 DISP__NONE = 0,
297 DISP_centred,
298 DISP_ragged,
299 DISP_unfilled,
300 DISP_filled,
301 DISP_literal
302 };
303
304 /*
305 * Normalised `An' splitting argument.
306 */
307 enum mdoc_auth {
308 AUTH__NONE = 0,
309 AUTH_split,
310 AUTH_nosplit
311 };
312
313 /*
314 * Normalised `Bf' font type.
315 */
316 enum mdoc_font {
317 FONT__NONE = 0,
318 FONT_Em,
319 FONT_Li,
320 FONT_Sy
321 };
322
323 /*
324 * Normalised arguments for `Bd'.
325 */
326 struct mdoc_bd {
327 const char *offs; /* -offset */
328 enum mdoc_disp type; /* -ragged, etc. */
329 int comp; /* -compact */
330 };
331
332 /*
333 * Normalised arguments for `Bl'.
334 */
335 struct mdoc_bl {
336 const char *width; /* -width */
337 const char *offs; /* -offset */
338 enum mdoc_list type; /* -tag, -enum, etc. */
339 int comp; /* -compact */
340 size_t ncols; /* -column arg count */
341 const char **cols; /* -column val ptr */
342 };
343
344 /*
345 * Normalised arguments for `Bf'.
346 */
347 struct mdoc_bf {
348 enum mdoc_font font; /* font */
349 };
350
351 /*
352 * Normalised arguments for `An'.
353 */
354 struct mdoc_an {
355 enum mdoc_auth auth; /* -split, etc. */
356 };
357
358 struct mdoc_rs {
359 int quote_T; /* whether to quote %T */
360 };
361
362 /*
363 * Consists of normalised node arguments. These should be used instead
364 * of iterating through the mdoc_arg pointers of a node: defaults are
365 * provided, etc.
366 */
367 union mdoc_data {
368 struct mdoc_an An;
369 struct mdoc_bd Bd;
370 struct mdoc_bf Bf;
371 struct mdoc_bl Bl;
372 struct mdoc_rs Rs;
373 };
374
375 /*
376 * Single node in tree-linked AST.
377 */
378 struct mdoc_node {
379 struct mdoc_node *parent; /* parent AST node */
380 struct mdoc_node *child; /* first child AST node */
381 struct mdoc_node *last; /* last child AST node */
382 struct mdoc_node *next; /* sibling AST node */
383 struct mdoc_node *prev; /* prior sibling AST node */
384 int nchild; /* number children */
385 int line; /* parse line */
386 int pos; /* parse column */
387 enum mdoct tok; /* tok or MDOC__MAX if none */
388 int flags;
389 #define MDOC_VALID (1 << 0) /* has been validated */
390 #define MDOC_EOS (1 << 2) /* at sentence boundary */
391 #define MDOC_LINE (1 << 3) /* first macro/text on line */
392 #define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */
393 #define MDOC_ENDED (1 << 5) /* rendering has been ended */
394 enum mdoc_type type; /* AST node type */
395 enum mdoc_sec sec; /* current named section */
396 union mdoc_data *norm; /* normalised args */
397 /* FIXME: these can be union'd to shave a few bytes. */
398 struct mdoc_arg *args; /* BLOCK/ELEM */
399 struct mdoc_node *pending; /* BLOCK */
400 struct mdoc_node *head; /* BLOCK */
401 struct mdoc_node *body; /* BLOCK */
402 struct mdoc_node *tail; /* BLOCK */
403 char *string; /* TEXT */
404 const struct tbl_span *span; /* TBL */
405 const struct eqn *eqn; /* EQN */
406 enum mdoc_endbody end; /* BODY */
407 };
408
409 /*
410 * Names of macros. Index is enum mdoct. Indexing into this returns
411 * the normalised name, e.g., mdoc_macronames[MDOC_Sh] -> "Sh".
412 */
413 extern const char *const *mdoc_macronames;
414
415 /*
416 * Names of macro args. Index is enum mdocargt. Indexing into this
417 * returns the normalised name, e.g., mdoc_argnames[MDOC_File] ->
418 * "file".
419 */
420 extern const char *const *mdoc_argnames;
421
422 __BEGIN_DECLS
423
424 struct mdoc;
425
426 void mdoc_free(struct mdoc *);
427 struct mdoc *mdoc_alloc(struct regset *, void *, mandocmsg);
428 void mdoc_reset(struct mdoc *);
429 int mdoc_parseln(struct mdoc *, int, char *, int);
430 const struct mdoc_node *mdoc_node(const struct mdoc *);
431 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
432 int mdoc_endparse(struct mdoc *);
433 int mdoc_addspan(struct mdoc *,
434 const struct tbl_span *);
435 int mdoc_addeqn(struct mdoc *,
436 const struct eqn *);
437
438 __END_DECLS
439
440 #endif /*!MDOC_H*/