version 1.29, 2009/02/20 07:43:15 |
version 1.136, 2015/02/12 12:24:33 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
|
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the |
* purpose with or without fee is hereby granted, provided that the above |
* above copyright notice and this permission notice appear in all |
* copyright notice and this permission notice appear in all copies. |
* copies. |
|
* |
* |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* PERFORMANCE OF THIS SOFTWARE. |
|
*/ |
*/ |
#ifndef MDOC_H |
|
#define MDOC_H |
|
|
|
/* What follows is a list of ALL possible macros. */ |
enum mdoct { |
|
MDOC_Ap = 0, |
#define MDOC___ 0 |
MDOC_Dd, |
#define MDOC_Dd 1 |
MDOC_Dt, |
#define MDOC_Dt 2 |
MDOC_Os, |
#define MDOC_Os 3 |
MDOC_Sh, |
#define MDOC_Sh 4 |
MDOC_Ss, |
#define MDOC_Ss 5 |
MDOC_Pp, |
#define MDOC_Pp 6 |
MDOC_D1, |
#define MDOC_D1 7 |
MDOC_Dl, |
#define MDOC_Dl 8 |
MDOC_Bd, |
#define MDOC_Bd 9 |
MDOC_Ed, |
#define MDOC_Ed 10 |
MDOC_Bl, |
#define MDOC_Bl 11 |
MDOC_El, |
#define MDOC_El 12 |
MDOC_It, |
#define MDOC_It 13 |
MDOC_Ad, |
#define MDOC_Ad 14 |
MDOC_An, |
#define MDOC_An 15 |
MDOC_Ar, |
#define MDOC_Ar 16 |
MDOC_Cd, |
#define MDOC_Cd 17 |
MDOC_Cm, |
#define MDOC_Cm 18 |
MDOC_Dv, |
#define MDOC_Dv 19 |
MDOC_Er, |
#define MDOC_Er 20 |
MDOC_Ev, |
#define MDOC_Ev 21 |
MDOC_Ex, |
#define MDOC_Ex 22 |
MDOC_Fa, |
#define MDOC_Fa 23 |
MDOC_Fd, |
#define MDOC_Fd 24 |
MDOC_Fl, |
#define MDOC_Fl 25 |
MDOC_Fn, |
#define MDOC_Fn 26 |
MDOC_Ft, |
#define MDOC_Ft 27 |
MDOC_Ic, |
#define MDOC_Ic 28 |
MDOC_In, |
#define MDOC_In 29 |
MDOC_Li, |
#define MDOC_Li 30 |
MDOC_Nd, |
#define MDOC_Nd 31 |
MDOC_Nm, |
#define MDOC_Nm 32 |
MDOC_Op, |
#define MDOC_Op 33 |
MDOC_Ot, |
#define MDOC_Ot 34 |
MDOC_Pa, |
#define MDOC_Pa 35 |
MDOC_Rv, |
#define MDOC_Rv 36 |
MDOC_St, |
#define MDOC_St 37 |
MDOC_Va, |
#define MDOC_Va 38 |
MDOC_Vt, |
#define MDOC_Vt 39 |
MDOC_Xr, |
#define MDOC_Xr 40 |
MDOC__A, |
#define MDOC__A 41 |
MDOC__B, |
#define MDOC__B 42 |
MDOC__D, |
#define MDOC__D 43 |
MDOC__I, |
#define MDOC__I 44 |
MDOC__J, |
#define MDOC__J 45 |
MDOC__N, |
#define MDOC__N 46 |
MDOC__O, |
#define MDOC__O 47 |
MDOC__P, |
#define MDOC__P 48 |
MDOC__R, |
#define MDOC__R 49 |
MDOC__T, |
#define MDOC__T 50 |
MDOC__V, |
#define MDOC__V 51 |
MDOC_Ac, |
#define MDOC_Ac 52 |
MDOC_Ao, |
#define MDOC_Ao 53 |
MDOC_Aq, |
#define MDOC_Aq 54 |
MDOC_At, |
#define MDOC_At 55 |
MDOC_Bc, |
#define MDOC_Bc 56 |
MDOC_Bf, |
#define MDOC_Bf 57 |
MDOC_Bo, |
#define MDOC_Bo 58 |
MDOC_Bq, |
#define MDOC_Bq 59 |
MDOC_Bsx, |
#define MDOC_Bsx 60 |
MDOC_Bx, |
#define MDOC_Bx 61 |
MDOC_Db, |
#define MDOC_Db 62 |
MDOC_Dc, |
#define MDOC_Dc 63 |
MDOC_Do, |
#define MDOC_Do 64 |
MDOC_Dq, |
#define MDOC_Dq 65 |
MDOC_Ec, |
#define MDOC_Ec 66 |
MDOC_Ef, |
#define MDOC_Ef 67 |
MDOC_Em, |
#define MDOC_Em 68 |
MDOC_Eo, |
#define MDOC_Eo 69 |
MDOC_Fx, |
#define MDOC_Fx 70 |
MDOC_Ms, |
#define MDOC_Ms 71 |
MDOC_No, |
#define MDOC_No 72 |
MDOC_Ns, |
#define MDOC_Ns 73 |
MDOC_Nx, |
#define MDOC_Nx 74 |
MDOC_Ox, |
#define MDOC_Ox 75 |
MDOC_Pc, |
#define MDOC_Pc 76 |
MDOC_Pf, |
#define MDOC_Pf 77 |
MDOC_Po, |
#define MDOC_Po 78 |
MDOC_Pq, |
#define MDOC_Pq 79 |
MDOC_Qc, |
#define MDOC_Qc 80 |
MDOC_Ql, |
#define MDOC_Ql 81 |
MDOC_Qo, |
#define MDOC_Qo 82 |
MDOC_Qq, |
#define MDOC_Qq 83 |
MDOC_Re, |
#define MDOC_Re 84 |
MDOC_Rs, |
#define MDOC_Rs 85 |
MDOC_Sc, |
#define MDOC_Sc 86 |
MDOC_So, |
#define MDOC_So 87 |
MDOC_Sq, |
#define MDOC_Sq 88 |
MDOC_Sm, |
#define MDOC_Sm 89 |
MDOC_Sx, |
#define MDOC_Sx 90 |
MDOC_Sy, |
#define MDOC_Sy 91 |
MDOC_Tn, |
#define MDOC_Tn 92 |
MDOC_Ux, |
#define MDOC_Ux 93 |
MDOC_Xc, |
#define MDOC_Xc 94 |
MDOC_Xo, |
#define MDOC_Xo 95 |
MDOC_Fo, |
#define MDOC_Fo 96 |
MDOC_Fc, |
#define MDOC_Fc 97 |
MDOC_Oo, |
#define MDOC_Oo 98 |
MDOC_Oc, |
#define MDOC_Oc 99 |
MDOC_Bk, |
#define MDOC_Bk 100 |
MDOC_Ek, |
#define MDOC_Ek 101 |
MDOC_Bt, |
#define MDOC_Bt 102 |
MDOC_Hf, |
#define MDOC_Hf 103 |
MDOC_Fr, |
#define MDOC_Fr 104 |
MDOC_Ud, |
#define MDOC_Ud 105 |
MDOC_Lb, |
#define MDOC_MAX 106 |
MDOC_Lp, |
|
MDOC_Lk, |
/* What follows is a list of ALL possible macro arguments. */ |
MDOC_Mt, |
|
MDOC_Brq, |
#define MDOC_Split 0 |
MDOC_Bro, |
#define MDOC_Nosplit 1 |
MDOC_Brc, |
#define MDOC_Ragged 2 |
MDOC__C, |
#define MDOC_Unfilled 3 |
MDOC_Es, |
#define MDOC_Literal 4 |
MDOC_En, |
#define MDOC_File 5 |
MDOC_Dx, |
#define MDOC_Offset 6 |
MDOC__Q, |
#define MDOC_Bullet 7 |
MDOC_br, |
#define MDOC_Dash 8 |
MDOC_sp, |
#define MDOC_Hyphen 9 |
MDOC__U, |
#define MDOC_Item 10 |
MDOC_Ta, |
#define MDOC_Enum 11 |
MDOC_ll, |
#define MDOC_Tag 12 |
MDOC_MAX |
#define MDOC_Diag 13 |
|
#define MDOC_Hang 14 |
|
#define MDOC_Ohang 15 |
|
#define MDOC_Inset 16 |
|
#define MDOC_Column 17 |
|
#define MDOC_Width 18 |
|
#define MDOC_Compact 19 |
|
#define MDOC_Std 20 |
|
#define MDOC_p1003_1_88 21 |
|
#define MDOC_p1003_1_90 22 |
|
#define MDOC_p1003_1_96 23 |
|
#define MDOC_p1003_1_2001 24 |
|
#define MDOC_p1003_1_2004 25 |
|
#define MDOC_p1003_1 26 |
|
#define MDOC_p1003_1b 27 |
|
#define MDOC_p1003_1b_93 28 |
|
#define MDOC_p1003_1c_95 29 |
|
#define MDOC_p1003_1g_2000 30 |
|
#define MDOC_p1003_2_92 31 |
|
#define MDOC_p1387_2_95 32 |
|
#define MDOC_p1003_2 33 |
|
#define MDOC_p1387_2 34 |
|
#define MDOC_isoC_90 35 |
|
#define MDOC_isoC_amd1 36 |
|
#define MDOC_isoC_tcor1 37 |
|
#define MDOC_isoC_tcor2 38 |
|
#define MDOC_isoC_99 39 |
|
#define MDOC_ansiC 40 |
|
#define MDOC_ansiC_89 41 |
|
#define MDOC_ansiC_99 42 |
|
#define MDOC_ieee754 43 |
|
#define MDOC_iso8802_3 44 |
|
#define MDOC_xpg3 45 |
|
#define MDOC_xpg4 46 |
|
#define MDOC_xpg4_2 47 |
|
#define MDOC_xpg4_3 48 |
|
#define MDOC_xbd5 49 |
|
#define MDOC_xcu5 50 |
|
#define MDOC_xsh5 51 |
|
#define MDOC_xns5 52 |
|
#define MDOC_xns5_2d2_0 53 |
|
#define MDOC_xcurses4_2 54 |
|
#define MDOC_susv2 55 |
|
#define MDOC_susv3 56 |
|
#define MDOC_svid4 57 |
|
#define MDOC_Filled 58 |
|
#define MDOC_Words 59 |
|
#define MDOC_Emphasis 60 |
|
#define MDOC_Symbolic 61 |
|
#define MDOC_ARG_MAX 62 |
|
|
|
/* Warnings are either syntax or groff-compatibility. */ |
|
enum mdoc_warn { |
|
WARN_SYNTAX, |
|
WARN_COMPAT |
|
}; |
}; |
|
|
/* Possible values for the `At' macro. */ |
enum mdocargt { |
enum mdoc_att { |
MDOC_Split, /* -split */ |
ATT_DEFAULT = 0, |
MDOC_Nosplit, /* -nospli */ |
ATT_v1, |
MDOC_Ragged, /* -ragged */ |
ATT_v2, |
MDOC_Unfilled, /* -unfilled */ |
ATT_v3, |
MDOC_Literal, /* -literal */ |
ATT_v4, |
MDOC_File, /* -file */ |
ATT_v5, |
MDOC_Offset, /* -offset */ |
ATT_v6, |
MDOC_Bullet, /* -bullet */ |
ATT_v7, |
MDOC_Dash, /* -dash */ |
ATT_32v, |
MDOC_Hyphen, /* -hyphen */ |
ATT_V1, |
MDOC_Item, /* -item */ |
ATT_V2, |
MDOC_Enum, /* -enum */ |
ATT_V3, |
MDOC_Tag, /* -tag */ |
ATT_V4 |
MDOC_Diag, /* -diag */ |
|
MDOC_Hang, /* -hang */ |
|
MDOC_Ohang, /* -ohang */ |
|
MDOC_Inset, /* -inset */ |
|
MDOC_Column, /* -column */ |
|
MDOC_Width, /* -width */ |
|
MDOC_Compact, /* -compact */ |
|
MDOC_Std, /* -std */ |
|
MDOC_Filled, /* -filled */ |
|
MDOC_Words, /* -words */ |
|
MDOC_Emphasis, /* -emphasis */ |
|
MDOC_Symbolic, /* -symbolic */ |
|
MDOC_Nested, /* -nested */ |
|
MDOC_Centred, /* -centered */ |
|
MDOC_ARG_MAX |
}; |
}; |
|
|
/* An argument to a macro (multiple values = `It -column'). */ |
|
struct mdoc_arg { |
|
int arg; |
|
int line; |
|
int pos; |
|
size_t sz; |
|
char **value; |
|
}; |
|
|
|
/* Type of a syntax node. */ |
|
enum mdoc_type { |
enum mdoc_type { |
MDOC_TEXT, |
MDOC_TEXT, |
MDOC_ELEM, |
MDOC_ELEM, |
Line 235 enum mdoc_type { |
|
Line 181 enum mdoc_type { |
|
MDOC_TAIL, |
MDOC_TAIL, |
MDOC_BODY, |
MDOC_BODY, |
MDOC_BLOCK, |
MDOC_BLOCK, |
|
MDOC_TBL, |
|
MDOC_EQN, |
MDOC_ROOT |
MDOC_ROOT |
}; |
}; |
|
|
/* Manual section. */ |
/* |
enum mdoc_msec { |
* Section (named/unnamed) of `Sh'. Note that these appear in the |
MSEC_DEFAULT = 0, |
* conventional order imposed by mdoc.7. In the case of SEC_NONE, no |
MSEC_1, |
* section has been invoked (this shouldn't happen). SEC_CUSTOM refers |
MSEC_2, |
* to other sections. |
MSEC_3, |
*/ |
MSEC_3f, |
enum mdoc_sec { |
MSEC_3p, |
SEC_NONE = 0, |
MSEC_4, |
SEC_NAME, /* NAME */ |
MSEC_5, |
SEC_LIBRARY, /* LIBRARY */ |
MSEC_6, |
SEC_SYNOPSIS, /* SYNOPSIS */ |
MSEC_7, |
SEC_DESCRIPTION, /* DESCRIPTION */ |
MSEC_8, |
SEC_CONTEXT, /* CONTEXT */ |
MSEC_9, |
SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */ |
MSEC_X11, |
SEC_RETURN_VALUES, /* RETURN VALUES */ |
MSEC_X11R6, |
SEC_ENVIRONMENT, /* ENVIRONMENT */ |
MSEC_local, |
SEC_FILES, /* FILES */ |
MSEC_n, |
SEC_EXIT_STATUS, /* EXIT STATUS */ |
MSEC_unass, |
SEC_EXAMPLES, /* EXAMPLES */ |
MSEC_draft, |
SEC_DIAGNOSTICS, /* DIAGNOSTICS */ |
MSEC_paper |
SEC_COMPATIBILITY, /* COMPATIBILITY */ |
|
SEC_ERRORS, /* ERRORS */ |
|
SEC_SEE_ALSO, /* SEE ALSO */ |
|
SEC_STANDARDS, /* STANDARDS */ |
|
SEC_HISTORY, /* HISTORY */ |
|
SEC_AUTHORS, /* AUTHORS */ |
|
SEC_CAVEATS, /* CAVEATS */ |
|
SEC_BUGS, /* BUGS */ |
|
SEC_SECURITY, /* SECURITY */ |
|
SEC_CUSTOM, |
|
SEC__MAX |
}; |
}; |
|
|
/* Section (named/unnamed) of `Ss'. */ |
struct mdoc_meta { |
enum mdoc_sec { |
char *msec; /* `Dt' section (1, 3p, etc.) */ |
SEC_PROLOGUE = 0, |
char *vol; /* `Dt' volume (implied) */ |
SEC_BODY, |
char *arch; /* `Dt' arch (i386, etc.) */ |
SEC_NAME, |
char *date; /* `Dd' normalised date */ |
SEC_SYNOPSIS, |
char *title; /* `Dt' title (FOO, etc.) */ |
SEC_DESCRIPTION, |
char *os; /* `Os' system (OpenBSD, etc.) */ |
SEC_RETURN_VALUES, |
char *name; /* leading `Nm' name */ |
SEC_ENVIRONMENT, |
|
SEC_FILES, |
|
SEC_EXAMPLES, |
|
SEC_DIAGNOSTICS, |
|
SEC_ERRORS, |
|
SEC_SEE_ALSO, |
|
SEC_STANDARDS, |
|
SEC_HISTORY, |
|
SEC_AUTHORS, |
|
SEC_CAVEATS, |
|
SEC_BUGS, |
|
SEC_CUSTOM |
|
}; |
}; |
|
|
/* Volume of `Dt'. */ |
/* |
enum mdoc_vol { |
* An argument to a macro (multiple values = `-column xxx yyy'). |
VOL_DEFAULT = 0, |
*/ |
VOL_AMD, |
struct mdoc_argv { |
VOL_IND, |
enum mdocargt arg; /* type of argument */ |
VOL_KM, |
int line; |
VOL_LOCAL, |
int pos; |
VOL_PRM, |
size_t sz; /* elements in "value" */ |
VOL_PS1, |
char **value; /* argument strings */ |
VOL_SMM, |
|
VOL_URM, |
|
VOL_USD |
|
}; |
}; |
|
|
/* Architecture of `Dt'. */ |
/* |
enum mdoc_arch { |
* Reference-counted macro arguments. These are refcounted because |
ARCH_DEFAULT = 0, |
* blocks have multiple instances of the same arguments spread across |
ARCH_alpha, |
* the HEAD, BODY, TAIL, and BLOCK node types. |
ARCH_amd64, |
*/ |
ARCH_amiga, |
struct mdoc_arg { |
ARCH_arc, |
size_t argc; |
ARCH_arm, |
struct mdoc_argv *argv; |
ARCH_armish, |
unsigned int refcnt; |
ARCH_aviion, |
|
ARCH_hp300, |
|
ARCH_hppa, |
|
ARCH_hppa64, |
|
ARCH_i386, |
|
ARCH_landisk, |
|
ARCH_luna88k, |
|
ARCH_mac68k, |
|
ARCH_macppc, |
|
ARCH_mvme68k, |
|
ARCH_mvme88k, |
|
ARCH_mvmeppc, |
|
ARCH_pmax, |
|
ARCH_sgi, |
|
ARCH_socppc, |
|
ARCH_sparc, |
|
ARCH_sparc64, |
|
ARCH_sun3, |
|
ARCH_vax, |
|
ARCH_zaurus |
|
}; |
}; |
|
|
/* Information from prologue. */ |
/* |
struct mdoc_meta { |
* Indicates that a BODY's formatting has ended, but the scope is still |
enum mdoc_msec msec; |
* open. Used for syntax-broken blocks. |
enum mdoc_vol vol; |
*/ |
enum mdoc_arch arch; |
enum mdoc_endbody { |
time_t date; |
ENDBODY_NOT = 0, |
char *title; |
ENDBODY_SPACE, /* is broken: append a space */ |
char *os; |
ENDBODY_NOSPACE /* is broken: don't append a space */ |
char *name; |
|
}; |
}; |
|
|
/* Text-only node. */ |
enum mdoc_list { |
struct mdoc_text { |
LIST__NONE = 0, |
char *string; |
LIST_bullet, /* -bullet */ |
|
LIST_column, /* -column */ |
|
LIST_dash, /* -dash */ |
|
LIST_diag, /* -diag */ |
|
LIST_enum, /* -enum */ |
|
LIST_hang, /* -hang */ |
|
LIST_hyphen, /* -hyphen */ |
|
LIST_inset, /* -inset */ |
|
LIST_item, /* -item */ |
|
LIST_ohang, /* -ohang */ |
|
LIST_tag, /* -tag */ |
|
LIST_MAX |
}; |
}; |
|
|
/* Block (scoped) node. */ |
enum mdoc_disp { |
struct mdoc_block { |
DISP__NONE = 0, |
size_t argc; |
DISP_centered, /* -centered */ |
struct mdoc_arg *argv; |
DISP_ragged, /* -ragged */ |
struct mdoc_node *head; |
DISP_unfilled, /* -unfilled */ |
struct mdoc_node *body; |
DISP_filled, /* -filled */ |
struct mdoc_node *tail; |
DISP_literal /* -literal */ |
}; |
}; |
|
|
/* In-line element node. */ |
enum mdoc_auth { |
struct mdoc_elem { |
AUTH__NONE = 0, |
size_t sz; |
AUTH_split, /* -split */ |
char **args; |
AUTH_nosplit /* -nosplit */ |
size_t argc; |
|
struct mdoc_arg *argv; |
|
}; |
}; |
|
|
/* Typed nodes of an AST node. */ |
enum mdoc_font { |
|
FONT__NONE = 0, |
|
FONT_Em, /* Em, -emphasis */ |
|
FONT_Li, /* Li, -literal */ |
|
FONT_Sy /* Sy, -symbolic */ |
|
}; |
|
|
|
struct mdoc_bd { |
|
const char *offs; /* -offset */ |
|
enum mdoc_disp type; /* -ragged, etc. */ |
|
int comp; /* -compact */ |
|
}; |
|
|
|
struct mdoc_bl { |
|
const char *width; /* -width */ |
|
const char *offs; /* -offset */ |
|
enum mdoc_list type; /* -tag, -enum, etc. */ |
|
int comp; /* -compact */ |
|
size_t ncols; /* -column arg count */ |
|
const char **cols; /* -column val ptr */ |
|
int count; /* -enum counter */ |
|
}; |
|
|
|
struct mdoc_bf { |
|
enum mdoc_font font; /* font */ |
|
}; |
|
|
|
struct mdoc_an { |
|
enum mdoc_auth auth; /* -split, etc. */ |
|
}; |
|
|
|
struct mdoc_rs { |
|
int quote_T; /* whether to quote %T */ |
|
}; |
|
|
|
/* |
|
* Consists of normalised node arguments. These should be used instead |
|
* of iterating through the mdoc_arg pointers of a node: defaults are |
|
* provided, etc. |
|
*/ |
union mdoc_data { |
union mdoc_data { |
struct mdoc_text text; |
struct mdoc_an An; |
struct mdoc_elem elem; |
struct mdoc_bd Bd; |
struct mdoc_block block; |
struct mdoc_bf Bf; |
|
struct mdoc_bl Bl; |
|
struct mdoc_node *Es; |
|
struct mdoc_rs Rs; |
}; |
}; |
|
|
/* Node in AST. */ |
/* |
|
* Single node in tree-linked AST. |
|
*/ |
struct mdoc_node { |
struct mdoc_node { |
struct mdoc_node *parent; |
struct mdoc_node *parent; /* parent AST node */ |
struct mdoc_node *child; |
struct mdoc_node *child; /* first child AST node */ |
struct mdoc_node *next; |
struct mdoc_node *last; /* last child AST node */ |
struct mdoc_node *prev; |
struct mdoc_node *next; /* sibling AST node */ |
int line; |
struct mdoc_node *prev; /* prior sibling AST node */ |
int pos; |
int nchild; /* number children */ |
int tok; |
int line; /* parse line */ |
|
int pos; /* parse column */ |
|
enum mdoct tok; /* tok or MDOC__MAX if none */ |
int flags; |
int flags; |
#define MDOC_VALID (1 << 0) |
#define MDOC_VALID (1 << 0) /* has been validated */ |
#define MDOC_ACTED (1 << 1) |
#define MDOC_ENDED (1 << 1) /* gone past body end mark */ |
enum mdoc_type type; |
#define MDOC_EOS (1 << 2) /* at sentence boundary */ |
union mdoc_data data; |
#define MDOC_LINE (1 << 3) /* first macro/text on line */ |
/* FIXME: have an enum mdoc_sec. */ |
#define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */ |
|
#define MDOC_BROKEN (1 << 5) /* must validate parent when ending */ |
|
#define MDOC_DELIMO (1 << 6) |
|
#define MDOC_DELIMC (1 << 7) |
|
enum mdoc_type type; /* AST node type */ |
|
enum mdoc_sec sec; /* current named section */ |
|
union mdoc_data *norm; /* normalised args */ |
|
int prev_font; /* before entering this node */ |
|
/* FIXME: these can be union'd to shave a few bytes. */ |
|
struct mdoc_arg *args; /* BLOCK/ELEM */ |
|
struct mdoc_node *head; /* BLOCK */ |
|
struct mdoc_node *body; /* BLOCK/ENDBODY */ |
|
struct mdoc_node *tail; /* BLOCK */ |
|
char *string; /* TEXT */ |
|
const struct tbl_span *span; /* TBL */ |
|
const struct eqn *eqn; /* EQN */ |
|
enum mdoc_endbody end; /* BODY */ |
}; |
}; |
|
|
/* Call-backs for parse messages. */ |
/* Names of macros. Index is enum mdoct. */ |
struct mdoc_cb { |
|
void (*mdoc_msg)(void *, int, int, const char *); |
|
int (*mdoc_err)(void *, int, int, const char *); |
|
int (*mdoc_warn)(void *, int, int, |
|
enum mdoc_warn, const char *); |
|
}; |
|
|
|
/* Global table of macro names (`Bd', `Ed', etc.). */ |
|
extern const char *const *mdoc_macronames; |
extern const char *const *mdoc_macronames; |
|
|
/* Global table of argument names (`column', `tag', etc.). */ |
/* Names of macro args. Index is enum mdocargt. */ |
extern const char *const *mdoc_argnames; |
extern const char *const *mdoc_argnames; |
|
|
__BEGIN_DECLS |
__BEGIN_DECLS |
|
|
struct mdoc; |
struct mdoc; |
|
|
/* Free memory allocated with mdoc_alloc. */ |
const struct mdoc_node *mdoc_node(const struct mdoc *); |
void mdoc_free(struct mdoc *); |
const struct mdoc_meta *mdoc_meta(const struct mdoc *); |
|
void mdoc_deroff(char **, const struct mdoc_node *); |
|
|
/* Allocate a new parser instance. */ |
|
struct mdoc *mdoc_alloc(void *data, const struct mdoc_cb *); |
|
|
|
/* Parse a single line in a stream (boolean retval). */ |
|
int mdoc_parseln(struct mdoc *, int, char *buf); |
|
|
|
/* Get result first node (after mdoc_endparse!). */ |
|
const struct mdoc_node *mdoc_node(struct mdoc *); |
|
|
|
/* Get result meta-information (after mdoc_endparse!). */ |
|
const struct mdoc_meta *mdoc_meta(struct mdoc *); |
|
|
|
/* Signal end of parse sequence (boolean retval). */ |
|
int mdoc_endparse(struct mdoc *); |
|
|
|
__END_DECLS |
__END_DECLS |
|
|
#endif /*!MDOC_H*/ |
|