1 /* $Id: mdoc.h,v 1.124 2012/11/16 17:16:55 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.
147 MDOC_Split
, /* -split */
148 MDOC_Nosplit
, /* -nospli */
149 MDOC_Ragged
, /* -ragged */
150 MDOC_Unfilled
, /* -unfilled */
151 MDOC_Literal
, /* -literal */
152 MDOC_File
, /* -file */
153 MDOC_Offset
, /* -offset */
154 MDOC_Bullet
, /* -bullet */
155 MDOC_Dash
, /* -dash */
156 MDOC_Hyphen
, /* -hyphen */
157 MDOC_Item
, /* -item */
158 MDOC_Enum
, /* -enum */
160 MDOC_Diag
, /* -diag */
161 MDOC_Hang
, /* -hang */
162 MDOC_Ohang
, /* -ohang */
163 MDOC_Inset
, /* -inset */
164 MDOC_Column
, /* -column */
165 MDOC_Width
, /* -width */
166 MDOC_Compact
, /* -compact */
168 MDOC_Filled
, /* -filled */
169 MDOC_Words
, /* -words */
170 MDOC_Emphasis
, /* -emphasis */
171 MDOC_Symbolic
, /* -symbolic */
172 MDOC_Nested
, /* -nested */
173 MDOC_Centred
, /* -centered */
190 * Section (named/unnamed) of `Sh'. Note that these appear in the
191 * conventional order imposed by mdoc.7. In the case of SEC_NONE, no
192 * section has been invoked (this shouldn't happen). SEC_CUSTOM refers
198 SEC_LIBRARY
, /* LIBRARY */
199 SEC_SYNOPSIS
, /* SYNOPSIS */
200 SEC_DESCRIPTION
, /* DESCRIPTION */
201 SEC_IMPLEMENTATION
, /* IMPLEMENTATION NOTES */
202 SEC_RETURN_VALUES
, /* RETURN VALUES */
203 SEC_ENVIRONMENT
, /* ENVIRONMENT */
204 SEC_FILES
, /* FILES */
205 SEC_EXIT_STATUS
, /* EXIT STATUS */
206 SEC_EXAMPLES
, /* EXAMPLES */
207 SEC_DIAGNOSTICS
, /* DIAGNOSTICS */
208 SEC_COMPATIBILITY
, /* COMPATIBILITY */
209 SEC_ERRORS
, /* ERRORS */
210 SEC_SEE_ALSO
, /* SEE ALSO */
211 SEC_STANDARDS
, /* STANDARDS */
212 SEC_HISTORY
, /* HISTORY */
213 SEC_AUTHORS
, /* AUTHORS */
214 SEC_CAVEATS
, /* CAVEATS */
216 SEC_SECURITY
, /* SECURITY */
222 char *msec
; /* `Dt' section (1, 3p, etc.) */
223 char *vol
; /* `Dt' volume (implied) */
224 char *arch
; /* `Dt' arch (i386, etc.) */
225 char *date
; /* `Dd' normalised date */
226 char *title
; /* `Dt' title (FOO, etc.) */
227 char *os
; /* `Os' system (OpenBSD, etc.) */
228 char *name
; /* leading `Nm' name */
232 * An argument to a macro (multiple values = `-column xxx yyy').
235 enum mdocargt arg
; /* type of argument */
238 size_t sz
; /* elements in "value" */
239 char **value
; /* argument strings */
243 * Reference-counted macro arguments. These are refcounted because
244 * blocks have multiple instances of the same arguments spread across
245 * the HEAD, BODY, TAIL, and BLOCK node types.
249 struct mdoc_argv
*argv
;
254 * Indicates that a BODY's formatting has ended, but the scope is still
255 * open. Used for syntax-broken blocks.
259 ENDBODY_SPACE
, /* is broken: append a space */
260 ENDBODY_NOSPACE
/* is broken: don't append a space */
265 LIST_bullet
, /* -bullet */
266 LIST_column
, /* -column */
267 LIST_dash
, /* -dash */
268 LIST_diag
, /* -diag */
269 LIST_enum
, /* -enum */
270 LIST_hang
, /* -hang */
271 LIST_hyphen
, /* -hyphen */
272 LIST_inset
, /* -inset */
273 LIST_item
, /* -item */
274 LIST_ohang
, /* -ohang */
281 DISP_centred
, /* -centered */
282 DISP_ragged
, /* -ragged */
283 DISP_unfilled
, /* -unfilled */
284 DISP_filled
, /* -filled */
285 DISP_literal
/* -literal */
290 AUTH_split
, /* -split */
291 AUTH_nosplit
/* -nosplit */
296 FONT_Em
, /* Em, -emphasis */
297 FONT_Li
, /* Li, -literal */
298 FONT_Sy
/* Sy, -symbolic */
302 const char *offs
; /* -offset */
303 enum mdoc_disp type
; /* -ragged, etc. */
304 int comp
; /* -compact */
308 const char *width
; /* -width */
309 const char *offs
; /* -offset */
310 enum mdoc_list type
; /* -tag, -enum, etc. */
311 int comp
; /* -compact */
312 size_t ncols
; /* -column arg count */
313 const char **cols
; /* -column val ptr */
314 int count
; /* -enum counter */
318 enum mdoc_font font
; /* font */
322 enum mdoc_auth auth
; /* -split, etc. */
326 int quote_T
; /* whether to quote %T */
330 * Consists of normalised node arguments. These should be used instead
331 * of iterating through the mdoc_arg pointers of a node: defaults are
343 * Single node in tree-linked AST.
346 struct mdoc_node
*parent
; /* parent AST node */
347 struct mdoc_node
*child
; /* first child AST node */
348 struct mdoc_node
*last
; /* last child AST node */
349 struct mdoc_node
*next
; /* sibling AST node */
350 struct mdoc_node
*prev
; /* prior sibling AST node */
351 int nchild
; /* number children */
352 int line
; /* parse line */
353 int pos
; /* parse column */
354 enum mdoct tok
; /* tok or MDOC__MAX if none */
356 #define MDOC_VALID (1 << 0) /* has been validated */
357 #define MDOC_EOS (1 << 2) /* at sentence boundary */
358 #define MDOC_LINE (1 << 3) /* first macro/text on line */
359 #define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */
360 #define MDOC_ENDED (1 << 5) /* rendering has been ended */
361 #define MDOC_DELIMO (1 << 6)
362 #define MDOC_DELIMC (1 << 7)
363 enum mdoc_type type
; /* AST node type */
364 enum mdoc_sec sec
; /* current named section */
365 union mdoc_data
*norm
; /* normalised args */
366 const void *prev_font
; /* before entering this node */
367 /* FIXME: these can be union'd to shave a few bytes. */
368 struct mdoc_arg
*args
; /* BLOCK/ELEM */
369 struct mdoc_node
*pending
; /* BLOCK */
370 struct mdoc_node
*head
; /* BLOCK */
371 struct mdoc_node
*body
; /* BLOCK */
372 struct mdoc_node
*tail
; /* BLOCK */
373 char *string
; /* TEXT */
374 const struct tbl_span
*span
; /* TBL */
375 const struct eqn
*eqn
; /* EQN */
376 enum mdoc_endbody end
; /* BODY */
379 /* Names of macros. Index is enum mdoct. */
380 extern const char *const *mdoc_macronames
;
382 /* Names of macro args. Index is enum mdocargt. */
383 extern const char *const *mdoc_argnames
;
389 const struct mdoc_node
*mdoc_node(const struct mdoc
*);
390 const struct mdoc_meta
*mdoc_meta(const struct mdoc
*);