]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc.h
1 /* $Id: mdoc.h,v 1.113 2010/12/26 14:44:13 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010 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.
197 * Section (named/unnamed) of `Sh'. Note that these appear in the
198 * conventional order imposed by mdoc.7.
201 SEC_NONE
= 0, /* No section, yet. */
222 SEC_CUSTOM
, /* User-defined. */
227 * Information from prologue.
230 char *msec
; /* `Dt' section (1, 3p, etc.) */
231 char *vol
; /* `Dt' volume (implied) */
232 char *arch
; /* `Dt' arch (i386, etc.) */
233 time_t date
; /* `Dd' normalised date */
234 char *title
; /* `Dt' title (FOO, etc.) */
235 char *os
; /* `Os' system (OpenBSD, etc.) */
236 char *name
; /* leading `Nm' name */
240 * An argument to a macro (multiple values = `-column xxx yyy').
243 enum mdocargt arg
; /* type of argument */
246 size_t sz
; /* elements in "value" */
247 char **value
; /* argument strings */
251 * Reference-counted macro arguments. These are refcounted because
252 * blocks have multiple instances of the same arguments spread across
253 * the HEAD, BODY, TAIL, and BLOCK node types.
257 struct mdoc_argv
*argv
;
262 * Indicates that a BODY's formatting has ended, but the scope is still
263 * open. Used for syntax-broken blocks.
267 ENDBODY_SPACE
, /* is broken: append a space */
268 ENDBODY_NOSPACE
/* is broken: don't append a space */
272 * Normalised `Bl' list type.
291 * Normalised `Bd' display type.
303 * Normalised `An' splitting argument.
312 * Normalised `Bf' font type.
322 * Normalised arguments for `Bd'.
325 const char *offs
; /* -offset */
326 enum mdoc_disp type
; /* -ragged, etc. */
327 int comp
; /* -compact */
331 * Normalised arguments for `Bl'.
334 const char *width
; /* -width */
335 const char *offs
; /* -offset */
336 enum mdoc_list type
; /* -tag, -enum, etc. */
337 int comp
; /* -compact */
338 size_t ncols
; /* -column arg count */
339 const char **cols
; /* -column val ptr */
343 * Normalised arguments for `Bf'.
346 enum mdoc_font font
; /* font */
350 * Normalised arguments for `An'.
353 enum mdoc_auth auth
; /* -split, etc. */
357 struct mdoc_node
*child_J
; /* pointer to %J */
361 * Consists of normalised node arguments. These should be used instead
362 * of iterating through the mdoc_arg pointers of a node: defaults are
374 * Single node in tree-linked AST.
377 struct mdoc_node
*parent
; /* parent AST node */
378 struct mdoc_node
*child
; /* first child AST node */
379 struct mdoc_node
*last
; /* last child AST node */
380 struct mdoc_node
*next
; /* sibling AST node */
381 struct mdoc_node
*prev
; /* prior sibling AST node */
382 int nchild
; /* number children */
383 int line
; /* parse line */
384 int pos
; /* parse column */
385 enum mdoct tok
; /* tok or MDOC__MAX if none */
387 #define MDOC_VALID (1 << 0) /* has been validated */
388 #define MDOC_EOS (1 << 2) /* at sentence boundary */
389 #define MDOC_LINE (1 << 3) /* first macro/text on line */
390 #define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */
391 #define MDOC_ENDED (1 << 5) /* rendering has been ended */
392 enum mdoc_type type
; /* AST node type */
393 enum mdoc_sec sec
; /* current named section */
394 union mdoc_data
*norm
; /* normalised args */
395 /* FIXME: these can be union'd to shave a few bytes. */
396 struct mdoc_arg
*args
; /* BLOCK/ELEM */
397 struct mdoc_node
*pending
; /* BLOCK */
398 struct mdoc_node
*head
; /* BLOCK */
399 struct mdoc_node
*body
; /* BLOCK */
400 struct mdoc_node
*tail
; /* BLOCK */
401 char *string
; /* TEXT */
402 enum mdoc_endbody end
; /* BODY */
406 * Names of macros. Index is enum mdoct. Indexing into this returns
407 * the normalised name, e.g., mdoc_macronames[MDOC_Sh] -> "Sh".
409 extern const char *const *mdoc_macronames
;
412 * Names of macro args. Index is enum mdocargt. Indexing into this
413 * returns the normalised name, e.g., mdoc_argnames[MDOC_File] ->
416 extern const char *const *mdoc_argnames
;
422 void mdoc_free(struct mdoc
*);
423 struct mdoc
*mdoc_alloc(struct regset
*, void *, mandocmsg
);
424 void mdoc_reset(struct mdoc
*);
425 int mdoc_parseln(struct mdoc
*, int, char *, int);
426 const struct mdoc_node
*mdoc_node(const struct mdoc
*);
427 const struct mdoc_meta
*mdoc_meta(const struct mdoc
*);
428 int mdoc_endparse(struct mdoc
*);