version 1.118, 2011/03/07 01:35:51 |
version 1.139, 2015/04/02 23:48:19 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* 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 above |
* purpose with or without fee is hereby granted, provided that the above |
* copyright notice and this permission notice appear in all copies. |
* copyright notice and this permission notice appear in all copies. |
* |
* |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#ifndef MDOC_H |
|
#define MDOC_H |
|
|
|
/* |
#define MDOC_Ap 0 |
* What follows is a list of ALL possible macros. |
#define MDOC_Dd 1 |
*/ |
#define MDOC_Dt 2 |
enum mdoct { |
#define MDOC_Os 3 |
MDOC_Ap = 0, |
#define MDOC_Sh 4 |
MDOC_Dd, |
#define MDOC_Ss 5 |
MDOC_Dt, |
#define MDOC_Pp 6 |
MDOC_Os, |
#define MDOC_D1 7 |
MDOC_Sh, |
#define MDOC_Dl 8 |
MDOC_Ss, |
#define MDOC_Bd 9 |
MDOC_Pp, |
#define MDOC_Ed 10 |
MDOC_D1, |
#define MDOC_Bl 11 |
MDOC_Dl, |
#define MDOC_El 12 |
MDOC_Bd, |
#define MDOC_It 13 |
MDOC_Ed, |
#define MDOC_Ad 14 |
MDOC_Bl, |
#define MDOC_An 15 |
MDOC_El, |
#define MDOC_Ar 16 |
MDOC_It, |
#define MDOC_Cd 17 |
MDOC_Ad, |
#define MDOC_Cm 18 |
MDOC_An, |
#define MDOC_Dv 19 |
MDOC_Ar, |
#define MDOC_Er 20 |
MDOC_Cd, |
#define MDOC_Ev 21 |
MDOC_Cm, |
#define MDOC_Ex 22 |
MDOC_Dv, |
#define MDOC_Fa 23 |
MDOC_Er, |
#define MDOC_Fd 24 |
MDOC_Ev, |
#define MDOC_Fl 25 |
MDOC_Ex, |
#define MDOC_Fn 26 |
MDOC_Fa, |
#define MDOC_Ft 27 |
MDOC_Fd, |
#define MDOC_Ic 28 |
MDOC_Fl, |
#define MDOC_In 29 |
MDOC_Fn, |
#define MDOC_Li 30 |
MDOC_Ft, |
#define MDOC_Nd 31 |
MDOC_Ic, |
#define MDOC_Nm 32 |
MDOC_In, |
#define MDOC_Op 33 |
MDOC_Li, |
#define MDOC_Ot 34 |
MDOC_Nd, |
#define MDOC_Pa 35 |
MDOC_Nm, |
#define MDOC_Rv 36 |
MDOC_Op, |
#define MDOC_St 37 |
MDOC_Ot, |
#define MDOC_Va 38 |
MDOC_Pa, |
#define MDOC_Vt 39 |
MDOC_Rv, |
#define MDOC_Xr 40 |
MDOC_St, |
#define MDOC__A 41 |
MDOC_Va, |
#define MDOC__B 42 |
MDOC_Vt, |
#define MDOC__D 43 |
MDOC_Xr, |
#define MDOC__I 44 |
MDOC__A, |
#define MDOC__J 45 |
MDOC__B, |
#define MDOC__N 46 |
MDOC__D, |
#define MDOC__O 47 |
MDOC__I, |
#define MDOC__P 48 |
MDOC__J, |
#define MDOC__R 49 |
MDOC__N, |
#define MDOC__T 50 |
MDOC__O, |
#define MDOC__V 51 |
MDOC__P, |
#define MDOC_Ac 52 |
MDOC__R, |
#define MDOC_Ao 53 |
MDOC__T, |
#define MDOC_Aq 54 |
MDOC__V, |
#define MDOC_At 55 |
MDOC_Ac, |
#define MDOC_Bc 56 |
MDOC_Ao, |
#define MDOC_Bf 57 |
MDOC_Aq, |
#define MDOC_Bo 58 |
MDOC_At, |
#define MDOC_Bq 59 |
MDOC_Bc, |
#define MDOC_Bsx 60 |
MDOC_Bf, |
#define MDOC_Bx 61 |
MDOC_Bo, |
#define MDOC_Db 62 |
MDOC_Bq, |
#define MDOC_Dc 63 |
MDOC_Bsx, |
#define MDOC_Do 64 |
MDOC_Bx, |
#define MDOC_Dq 65 |
MDOC_Db, |
#define MDOC_Ec 66 |
MDOC_Dc, |
#define MDOC_Ef 67 |
MDOC_Do, |
#define MDOC_Em 68 |
MDOC_Dq, |
#define MDOC_Eo 69 |
MDOC_Ec, |
#define MDOC_Fx 70 |
MDOC_Ef, |
#define MDOC_Ms 71 |
MDOC_Em, |
#define MDOC_No 72 |
MDOC_Eo, |
#define MDOC_Ns 73 |
MDOC_Fx, |
#define MDOC_Nx 74 |
MDOC_Ms, |
#define MDOC_Ox 75 |
MDOC_No, |
#define MDOC_Pc 76 |
MDOC_Ns, |
#define MDOC_Pf 77 |
MDOC_Nx, |
#define MDOC_Po 78 |
MDOC_Ox, |
#define MDOC_Pq 79 |
MDOC_Pc, |
#define MDOC_Qc 80 |
MDOC_Pf, |
#define MDOC_Ql 81 |
MDOC_Po, |
#define MDOC_Qo 82 |
MDOC_Pq, |
#define MDOC_Qq 83 |
MDOC_Qc, |
#define MDOC_Re 84 |
MDOC_Ql, |
#define MDOC_Rs 85 |
MDOC_Qo, |
#define MDOC_Sc 86 |
MDOC_Qq, |
#define MDOC_So 87 |
MDOC_Re, |
#define MDOC_Sq 88 |
MDOC_Rs, |
#define MDOC_Sm 89 |
MDOC_Sc, |
#define MDOC_Sx 90 |
MDOC_So, |
#define MDOC_Sy 91 |
MDOC_Sq, |
#define MDOC_Tn 92 |
MDOC_Sm, |
#define MDOC_Ux 93 |
MDOC_Sx, |
#define MDOC_Xc 94 |
MDOC_Sy, |
#define MDOC_Xo 95 |
MDOC_Tn, |
#define MDOC_Fo 96 |
MDOC_Ux, |
#define MDOC_Fc 97 |
MDOC_Xc, |
#define MDOC_Oo 98 |
MDOC_Xo, |
#define MDOC_Oc 99 |
MDOC_Fo, |
#define MDOC_Bk 100 |
MDOC_Fc, |
#define MDOC_Ek 101 |
MDOC_Oo, |
#define MDOC_Bt 102 |
MDOC_Oc, |
#define MDOC_Hf 103 |
MDOC_Bk, |
#define MDOC_Fr 104 |
MDOC_Ek, |
#define MDOC_Ud 105 |
MDOC_Bt, |
#define MDOC_Lb 106 |
MDOC_Hf, |
#define MDOC_Lp 107 |
MDOC_Fr, |
#define MDOC_Lk 108 |
MDOC_Ud, |
#define MDOC_Mt 109 |
MDOC_Lb, |
#define MDOC_Brq 110 |
MDOC_Lp, |
#define MDOC_Bro 111 |
MDOC_Lk, |
#define MDOC_Brc 112 |
MDOC_Mt, |
#define MDOC__C 113 |
MDOC_Brq, |
#define MDOC_Es 114 |
MDOC_Bro, |
#define MDOC_En 115 |
MDOC_Brc, |
#define MDOC_Dx 116 |
MDOC__C, |
#define MDOC__Q 117 |
MDOC_Es, |
#define MDOC_br 118 |
MDOC_En, |
#define MDOC_sp 119 |
MDOC_Dx, |
#define MDOC__U 120 |
MDOC__Q, |
#define MDOC_Ta 121 |
MDOC_br, |
#define MDOC_ll 122 |
MDOC_sp, |
#define MDOC_MAX 123 |
MDOC__U, |
|
MDOC_Ta, |
|
MDOC_MAX |
|
}; |
|
|
|
/* |
|
* What follows is a list of ALL possible macro arguments. |
|
*/ |
|
enum mdocargt { |
enum mdocargt { |
MDOC_Split, |
MDOC_Split, /* -split */ |
MDOC_Nosplit, |
MDOC_Nosplit, /* -nospli */ |
MDOC_Ragged, |
MDOC_Ragged, /* -ragged */ |
MDOC_Unfilled, |
MDOC_Unfilled, /* -unfilled */ |
MDOC_Literal, |
MDOC_Literal, /* -literal */ |
MDOC_File, |
MDOC_File, /* -file */ |
MDOC_Offset, |
MDOC_Offset, /* -offset */ |
MDOC_Bullet, |
MDOC_Bullet, /* -bullet */ |
MDOC_Dash, |
MDOC_Dash, /* -dash */ |
MDOC_Hyphen, |
MDOC_Hyphen, /* -hyphen */ |
MDOC_Item, |
MDOC_Item, /* -item */ |
MDOC_Enum, |
MDOC_Enum, /* -enum */ |
MDOC_Tag, |
MDOC_Tag, /* -tag */ |
MDOC_Diag, |
MDOC_Diag, /* -diag */ |
MDOC_Hang, |
MDOC_Hang, /* -hang */ |
MDOC_Ohang, |
MDOC_Ohang, /* -ohang */ |
MDOC_Inset, |
MDOC_Inset, /* -inset */ |
MDOC_Column, |
MDOC_Column, /* -column */ |
MDOC_Width, |
MDOC_Width, /* -width */ |
MDOC_Compact, |
MDOC_Compact, /* -compact */ |
MDOC_Std, |
MDOC_Std, /* -std */ |
MDOC_Filled, |
MDOC_Filled, /* -filled */ |
MDOC_Words, |
MDOC_Words, /* -words */ |
MDOC_Emphasis, |
MDOC_Emphasis, /* -emphasis */ |
MDOC_Symbolic, |
MDOC_Symbolic, /* -symbolic */ |
MDOC_Nested, |
MDOC_Nested, /* -nested */ |
MDOC_Centred, |
MDOC_Centred, /* -centered */ |
MDOC_ARG_MAX |
MDOC_ARG_MAX |
}; |
}; |
|
|
/* |
/* |
* Type of a syntax node. |
* An argument to a macro (multiple values = `-column xxx yyy'). |
*/ |
*/ |
enum mdoc_type { |
|
MDOC_TEXT, |
|
MDOC_ELEM, |
|
MDOC_HEAD, |
|
MDOC_TAIL, |
|
MDOC_BODY, |
|
MDOC_BLOCK, |
|
MDOC_TBL, |
|
MDOC_EQN, |
|
MDOC_ROOT |
|
}; |
|
|
|
/* |
|
* Section (named/unnamed) of `Sh'. Note that these appear in the |
|
* conventional order imposed by mdoc.7. |
|
*/ |
|
enum mdoc_sec { |
|
SEC_NONE = 0, /* No section, yet. */ |
|
SEC_NAME, |
|
SEC_LIBRARY, |
|
SEC_SYNOPSIS, |
|
SEC_DESCRIPTION, |
|
SEC_IMPLEMENTATION, |
|
SEC_RETURN_VALUES, |
|
SEC_ENVIRONMENT, |
|
SEC_FILES, |
|
SEC_EXIT_STATUS, |
|
SEC_EXAMPLES, |
|
SEC_DIAGNOSTICS, |
|
SEC_COMPATIBILITY, |
|
SEC_ERRORS, |
|
SEC_SEE_ALSO, |
|
SEC_STANDARDS, |
|
SEC_HISTORY, |
|
SEC_AUTHORS, |
|
SEC_CAVEATS, |
|
SEC_BUGS, |
|
SEC_SECURITY, |
|
SEC_CUSTOM, /* User-defined. */ |
|
SEC__MAX |
|
}; |
|
|
|
/* |
|
* Information from prologue. |
|
*/ |
|
struct mdoc_meta { |
|
char *msec; /* `Dt' section (1, 3p, etc.) */ |
|
char *vol; /* `Dt' volume (implied) */ |
|
char *arch; /* `Dt' arch (i386, etc.) */ |
|
char *date; /* `Dd' normalised date */ |
|
char *title; /* `Dt' title (FOO, etc.) */ |
|
char *os; /* `Os' system (OpenBSD, etc.) */ |
|
char *name; /* leading `Nm' name */ |
|
}; |
|
|
|
/* |
|
* An argument to a macro (multiple values = `-column xxx yyy'). |
|
*/ |
|
struct mdoc_argv { |
struct mdoc_argv { |
enum mdocargt arg; /* type of argument */ |
enum mdocargt arg; /* type of argument */ |
int line; |
int line; |
int pos; |
int pos; |
size_t sz; /* elements in "value" */ |
size_t sz; /* elements in "value" */ |
Line 254 struct mdoc_argv { |
|
Line 188 struct mdoc_argv { |
|
* blocks have multiple instances of the same arguments spread across |
* blocks have multiple instances of the same arguments spread across |
* the HEAD, BODY, TAIL, and BLOCK node types. |
* the HEAD, BODY, TAIL, and BLOCK node types. |
*/ |
*/ |
struct mdoc_arg { |
struct mdoc_arg { |
size_t argc; |
size_t argc; |
struct mdoc_argv *argv; |
struct mdoc_argv *argv; |
unsigned int refcnt; |
unsigned int refcnt; |
}; |
}; |
|
|
/* |
|
* Indicates that a BODY's formatting has ended, but the scope is still |
|
* open. Used for syntax-broken blocks. |
|
*/ |
|
enum mdoc_endbody { |
|
ENDBODY_NOT = 0, |
|
ENDBODY_SPACE, /* is broken: append a space */ |
|
ENDBODY_NOSPACE /* is broken: don't append a space */ |
|
}; |
|
|
|
/* |
|
* Normalised `Bl' list type. |
|
*/ |
|
enum mdoc_list { |
enum mdoc_list { |
LIST__NONE = 0, |
LIST__NONE = 0, |
LIST_bullet, |
LIST_bullet, /* -bullet */ |
LIST_column, |
LIST_column, /* -column */ |
LIST_dash, |
LIST_dash, /* -dash */ |
LIST_diag, |
LIST_diag, /* -diag */ |
LIST_enum, |
LIST_enum, /* -enum */ |
LIST_hang, |
LIST_hang, /* -hang */ |
LIST_hyphen, |
LIST_hyphen, /* -hyphen */ |
LIST_inset, |
LIST_inset, /* -inset */ |
LIST_item, |
LIST_item, /* -item */ |
LIST_ohang, |
LIST_ohang, /* -ohang */ |
LIST_tag, |
LIST_tag, /* -tag */ |
LIST_MAX |
LIST_MAX |
}; |
}; |
|
|
/* |
|
* Normalised `Bd' display type. |
|
*/ |
|
enum mdoc_disp { |
enum mdoc_disp { |
DISP__NONE = 0, |
DISP__NONE = 0, |
DISP_centred, |
DISP_centered, /* -centered */ |
DISP_ragged, |
DISP_ragged, /* -ragged */ |
DISP_unfilled, |
DISP_unfilled, /* -unfilled */ |
DISP_filled, |
DISP_filled, /* -filled */ |
DISP_literal |
DISP_literal /* -literal */ |
}; |
}; |
|
|
/* |
|
* Normalised `An' splitting argument. |
|
*/ |
|
enum mdoc_auth { |
enum mdoc_auth { |
AUTH__NONE = 0, |
AUTH__NONE = 0, |
AUTH_split, |
AUTH_split, /* -split */ |
AUTH_nosplit |
AUTH_nosplit /* -nosplit */ |
}; |
}; |
|
|
/* |
|
* Normalised `Bf' font type. |
|
*/ |
|
enum mdoc_font { |
enum mdoc_font { |
FONT__NONE = 0, |
FONT__NONE = 0, |
FONT_Em, |
FONT_Em, /* Em, -emphasis */ |
FONT_Li, |
FONT_Li, /* Li, -literal */ |
FONT_Sy |
FONT_Sy /* Sy, -symbolic */ |
}; |
}; |
|
|
/* |
|
* Normalised arguments for `Bd'. |
|
*/ |
|
struct mdoc_bd { |
struct mdoc_bd { |
const char *offs; /* -offset */ |
const char *offs; /* -offset */ |
enum mdoc_disp type; /* -ragged, etc. */ |
enum mdoc_disp type; /* -ragged, etc. */ |
int comp; /* -compact */ |
int comp; /* -compact */ |
}; |
}; |
|
|
/* |
|
* Normalised arguments for `Bl'. |
|
*/ |
|
struct mdoc_bl { |
struct mdoc_bl { |
const char *width; /* -width */ |
const char *width; /* -width */ |
const char *offs; /* -offset */ |
const char *offs; /* -offset */ |
Line 339 struct mdoc_bl { |
|
Line 245 struct mdoc_bl { |
|
int comp; /* -compact */ |
int comp; /* -compact */ |
size_t ncols; /* -column arg count */ |
size_t ncols; /* -column arg count */ |
const char **cols; /* -column val ptr */ |
const char **cols; /* -column val ptr */ |
|
int count; /* -enum counter */ |
}; |
}; |
|
|
/* |
|
* Normalised arguments for `Bf'. |
|
*/ |
|
struct mdoc_bf { |
struct mdoc_bf { |
enum mdoc_font font; /* font */ |
enum mdoc_font font; /* font */ |
}; |
}; |
|
|
/* |
|
* Normalised arguments for `An'. |
|
*/ |
|
struct mdoc_an { |
struct mdoc_an { |
enum mdoc_auth auth; /* -split, etc. */ |
enum mdoc_auth auth; /* -split, etc. */ |
}; |
}; |
Line 365 struct mdoc_rs { |
|
Line 266 struct mdoc_rs { |
|
* provided, etc. |
* provided, etc. |
*/ |
*/ |
union mdoc_data { |
union mdoc_data { |
struct mdoc_an An; |
struct mdoc_an An; |
struct mdoc_bd Bd; |
struct mdoc_bd Bd; |
struct mdoc_bf Bf; |
struct mdoc_bf Bf; |
struct mdoc_bl Bl; |
struct mdoc_bl Bl; |
|
struct roff_node *Es; |
struct mdoc_rs Rs; |
struct mdoc_rs Rs; |
}; |
}; |
|
|
/* |
/* Names of macros. */ |
* Single node in tree-linked AST. |
|
*/ |
|
struct mdoc_node { |
|
struct mdoc_node *parent; /* parent AST node */ |
|
struct mdoc_node *child; /* first child AST node */ |
|
struct mdoc_node *last; /* last child AST node */ |
|
struct mdoc_node *next; /* sibling AST node */ |
|
struct mdoc_node *prev; /* prior sibling AST node */ |
|
int nchild; /* number children */ |
|
int line; /* parse line */ |
|
int pos; /* parse column */ |
|
enum mdoct tok; /* tok or MDOC__MAX if none */ |
|
int flags; |
|
#define MDOC_VALID (1 << 0) /* has been validated */ |
|
#define MDOC_EOS (1 << 2) /* at sentence boundary */ |
|
#define MDOC_LINE (1 << 3) /* first macro/text on line */ |
|
#define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */ |
|
#define MDOC_ENDED (1 << 5) /* rendering has been ended */ |
|
enum mdoc_type type; /* AST node type */ |
|
enum mdoc_sec sec; /* current named section */ |
|
union mdoc_data *norm; /* normalised args */ |
|
/* FIXME: these can be union'd to shave a few bytes. */ |
|
struct mdoc_arg *args; /* BLOCK/ELEM */ |
|
struct mdoc_node *pending; /* BLOCK */ |
|
struct mdoc_node *head; /* BLOCK */ |
|
struct mdoc_node *body; /* BLOCK */ |
|
struct mdoc_node *tail; /* BLOCK */ |
|
char *string; /* TEXT */ |
|
const struct tbl_span *span; /* TBL */ |
|
const struct eqn *eqn; /* EQN */ |
|
enum mdoc_endbody end; /* BODY */ |
|
}; |
|
|
|
/* |
|
* Names of macros. Index is enum mdoct. Indexing into this returns |
|
* the normalised name, e.g., mdoc_macronames[MDOC_Sh] -> "Sh". |
|
*/ |
|
extern const char *const *mdoc_macronames; |
extern const char *const *mdoc_macronames; |
|
|
/* |
/* Names of macro args. Index is enum mdocargt. */ |
* Names of macro args. Index is enum mdocargt. Indexing into this |
|
* returns the normalised name, e.g., mdoc_argnames[MDOC_File] -> |
|
* "file". |
|
*/ |
|
extern const char *const *mdoc_argnames; |
extern const char *const *mdoc_argnames; |
|
|
__BEGIN_DECLS |
__BEGIN_DECLS |
|
|
struct mdoc; |
struct mdoc; |
|
|
void mdoc_free(struct mdoc *); |
const struct roff_node *mdoc_node(const struct mdoc *); |
struct mdoc *mdoc_alloc(struct regset *, void *, mandocmsg); |
const struct roff_meta *mdoc_meta(const struct mdoc *); |
void mdoc_reset(struct mdoc *); |
void mdoc_deroff(char **, const struct roff_node *); |
int mdoc_parseln(struct mdoc *, int, char *, int); |
|
const struct mdoc_node *mdoc_node(const struct mdoc *); |
|
const struct mdoc_meta *mdoc_meta(const struct mdoc *); |
|
int mdoc_endparse(struct mdoc *); |
|
int mdoc_addspan(struct mdoc *, |
|
const struct tbl_span *); |
|
int mdoc_addeqn(struct mdoc *, |
|
const struct eqn *); |
|
|
|
__END_DECLS |
__END_DECLS |
|
|
#endif /*!MDOC_H*/ |
|