1 /* $Id: mdoc.h,v 1.131 2014/07/29 13:58:18 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
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.
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.
148 MDOC_Split, /* -split */
149 MDOC_Nosplit, /* -nospli */
150 MDOC_Ragged, /* -ragged */
151 MDOC_Unfilled, /* -unfilled */
152 MDOC_Literal, /* -literal */
153 MDOC_File, /* -file */
154 MDOC_Offset, /* -offset */
155 MDOC_Bullet, /* -bullet */
156 MDOC_Dash, /* -dash */
157 MDOC_Hyphen, /* -hyphen */
158 MDOC_Item, /* -item */
159 MDOC_Enum, /* -enum */
161 MDOC_Diag, /* -diag */
162 MDOC_Hang, /* -hang */
163 MDOC_Ohang, /* -ohang */
164 MDOC_Inset, /* -inset */
165 MDOC_Column, /* -column */
166 MDOC_Width, /* -width */
167 MDOC_Compact, /* -compact */
169 MDOC_Filled, /* -filled */
170 MDOC_Words, /* -words */
171 MDOC_Emphasis, /* -emphasis */
172 MDOC_Symbolic, /* -symbolic */
173 MDOC_Nested, /* -nested */
174 MDOC_Centred, /* -centered */
191 * Section (named/unnamed) of `Sh'. Note that these appear in the
192 * conventional order imposed by mdoc.7. In the case of SEC_NONE, no
193 * section has been invoked (this shouldn't happen). SEC_CUSTOM refers
199 SEC_LIBRARY, /* LIBRARY */
200 SEC_SYNOPSIS, /* SYNOPSIS */
201 SEC_DESCRIPTION, /* DESCRIPTION */
202 SEC_CONTEXT, /* CONTEXT */
203 SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */
204 SEC_RETURN_VALUES, /* RETURN VALUES */
205 SEC_ENVIRONMENT, /* ENVIRONMENT */
206 SEC_FILES, /* FILES */
207 SEC_EXIT_STATUS, /* EXIT STATUS */
208 SEC_EXAMPLES, /* EXAMPLES */
209 SEC_DIAGNOSTICS, /* DIAGNOSTICS */
210 SEC_COMPATIBILITY, /* COMPATIBILITY */
211 SEC_ERRORS, /* ERRORS */
212 SEC_SEE_ALSO, /* SEE ALSO */
213 SEC_STANDARDS, /* STANDARDS */
214 SEC_HISTORY, /* HISTORY */
215 SEC_AUTHORS, /* AUTHORS */
216 SEC_CAVEATS, /* CAVEATS */
218 SEC_SECURITY, /* SECURITY */
224 char *msec; /* `Dt' section (1, 3p, etc.) */
225 char *vol; /* `Dt' volume (implied) */
226 char *arch; /* `Dt' arch (i386, etc.) */
227 char *date; /* `Dd' normalised date */
228 char *title; /* `Dt' title (FOO, etc.) */
229 char *os; /* `Os' system (OpenBSD, etc.) */
230 char *name; /* leading `Nm' name */
234 * An argument to a macro (multiple values = `-column xxx yyy').
237 enum mdocargt arg; /* type of argument */
240 size_t sz; /* elements in "value" */
241 char **value; /* argument strings */
245 * Reference-counted macro arguments. These are refcounted because
246 * blocks have multiple instances of the same arguments spread across
247 * the HEAD, BODY, TAIL, and BLOCK node types.
251 struct mdoc_argv *argv;
256 * Indicates that a BODY's formatting has ended, but the scope is still
257 * open. Used for syntax-broken blocks.
261 ENDBODY_SPACE, /* is broken: append a space */
262 ENDBODY_NOSPACE /* is broken: don't append a space */
267 LIST_bullet, /* -bullet */
268 LIST_column, /* -column */
269 LIST_dash, /* -dash */
270 LIST_diag, /* -diag */
271 LIST_enum, /* -enum */
272 LIST_hang, /* -hang */
273 LIST_hyphen, /* -hyphen */
274 LIST_inset, /* -inset */
275 LIST_item, /* -item */
276 LIST_ohang, /* -ohang */
283 DISP_centered, /* -centered */
284 DISP_ragged, /* -ragged */
285 DISP_unfilled, /* -unfilled */
286 DISP_filled, /* -filled */
287 DISP_literal /* -literal */
292 AUTH_split, /* -split */
293 AUTH_nosplit /* -nosplit */
298 FONT_Em, /* Em, -emphasis */
299 FONT_Li, /* Li, -literal */
300 FONT_Sy /* Sy, -symbolic */
304 const char *offs; /* -offset */
305 enum mdoc_disp type; /* -ragged, etc. */
306 int comp; /* -compact */
310 const char *width; /* -width */
311 const char *offs; /* -offset */
312 enum mdoc_list type; /* -tag, -enum, etc. */
313 int comp; /* -compact */
314 size_t ncols; /* -column arg count */
315 const char **cols; /* -column val ptr */
316 int count; /* -enum counter */
320 enum mdoc_font font; /* font */
324 enum mdoc_auth auth; /* -split, etc. */
328 int quote_T; /* whether to quote %T */
332 * Consists of normalised node arguments. These should be used instead
333 * of iterating through the mdoc_arg pointers of a node: defaults are
341 struct mdoc_node *Es;
346 * Single node in tree-linked AST.
349 struct mdoc_node *parent; /* parent AST node */
350 struct mdoc_node *child; /* first child AST node */
351 struct mdoc_node *last; /* last child AST node */
352 struct mdoc_node *next; /* sibling AST node */
353 struct mdoc_node *prev; /* prior sibling AST node */
354 int nchild; /* number children */
355 int line; /* parse line */
356 int pos; /* parse column */
357 int lastline; /* the node ends on this line */
358 enum mdoct tok; /* tok or MDOC__MAX if none */
360 #define MDOC_VALID (1 << 0) /* has been validated */
361 #define MDOC_EOS (1 << 2) /* at sentence boundary */
362 #define MDOC_LINE (1 << 3) /* first macro/text on line */
363 #define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */
364 #define MDOC_ENDED (1 << 5) /* rendering has been ended */
365 #define MDOC_DELIMO (1 << 6)
366 #define MDOC_DELIMC (1 << 7)
367 enum mdoc_type type; /* AST node type */
368 enum mdoc_sec sec; /* current named section */
369 union mdoc_data *norm; /* normalised args */
370 const void *prev_font; /* before entering this node */
371 /* FIXME: these can be union'd to shave a few bytes. */
372 struct mdoc_arg *args; /* BLOCK/ELEM */
373 struct mdoc_node *pending; /* BLOCK */
374 struct mdoc_node *head; /* BLOCK */
375 struct mdoc_node *body; /* BLOCK */
376 struct mdoc_node *tail; /* BLOCK */
377 char *string; /* TEXT */
378 const struct tbl_span *span; /* TBL */
379 const struct eqn *eqn; /* EQN */
380 enum mdoc_endbody end; /* BODY */
383 /* Names of macros. Index is enum mdoct. */
384 extern const char *const *mdoc_macronames;
386 /* Names of macro args. Index is enum mdocargt. */
387 extern const char *const *mdoc_argnames;
393 const struct mdoc_node *mdoc_node(const struct mdoc *);
394 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
395 void mdoc_deroff(char **, const struct mdoc_node *);