]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
1 /* $Id: mdoc.h,v 1.118 2011/03/07 01:35:51 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.
21 * What follows is a list of ALL possible macros.
150 * What follows is a list of ALL possible macro arguments.
184 * Type of a syntax node.
199 * Section (named/unnamed) of `Sh'. Note that these appear in the
200 * conventional order imposed by mdoc.7.
203 SEC_NONE
= 0, /* No section, yet. */
224 SEC_CUSTOM
, /* User-defined. */
229 * Information from prologue.
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 */
242 * An argument to a macro (multiple values = `-column xxx yyy').
245 enum mdocargt arg
; /* type of argument */
248 size_t sz
; /* elements in "value" */
249 char **value
; /* argument strings */
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.
259 struct mdoc_argv
*argv
;
264 * Indicates that a BODY's formatting has ended, but the scope is still
265 * open. Used for syntax-broken blocks.
269 ENDBODY_SPACE
, /* is broken: append a space */
270 ENDBODY_NOSPACE
/* is broken: don't append a space */
274 * Normalised `Bl' list type.
293 * Normalised `Bd' display type.
305 * Normalised `An' splitting argument.
314 * Normalised `Bf' font type.
324 * Normalised arguments for `Bd'.
327 const char *offs
; /* -offset */
328 enum mdoc_disp type
; /* -ragged, etc. */
329 int comp
; /* -compact */
333 * Normalised arguments for `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 */
345 * Normalised arguments for `Bf'.
348 enum mdoc_font font
; /* font */
352 * Normalised arguments for `An'.
355 enum mdoc_auth auth
; /* -split, etc. */
359 int quote_T
; /* whether to quote %T */
363 * Consists of normalised node arguments. These should be used instead
364 * of iterating through the mdoc_arg pointers of a node: defaults are
376 * Single node in tree-linked AST.
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 */
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 */
410 * Names of macros. Index is enum mdoct. Indexing into this returns
411 * the normalised name, e.g., mdoc_macronames[MDOC_Sh] -> "Sh".
413 extern const char *const *mdoc_macronames
;
416 * Names of macro args. Index is enum mdocargt. Indexing into this
417 * returns the normalised name, e.g., mdoc_argnames[MDOC_File] ->
420 extern const char *const *mdoc_argnames
;
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
*,