xref: /titanic_51/usr/src/cmd/mandoc/mandoc.h (revision 260e9a87725c090ba5835b1f9f0b62fa2f96036f)
1*260e9a87SYuri Pankov /*	$Id: mandoc.h,v 1.201 2015/02/23 13:31:04 schwarze Exp $ */
295c635efSGarrett D'Amore /*
3*260e9a87SYuri Pankov  * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4*260e9a87SYuri Pankov  * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
595c635efSGarrett D'Amore  *
695c635efSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
795c635efSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
895c635efSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
995c635efSGarrett D'Amore  *
1095c635efSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1195c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1295c635efSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1395c635efSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1495c635efSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1595c635efSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1695c635efSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1795c635efSGarrett D'Amore  */
1895c635efSGarrett D'Amore 
1995c635efSGarrett D'Amore #define ASCII_NBRSP	 31  /* non-breaking space */
2095c635efSGarrett D'Amore #define	ASCII_HYPH	 30  /* breakable hyphen */
21*260e9a87SYuri Pankov #define	ASCII_BREAK	 29  /* breakable zero-width space */
2295c635efSGarrett D'Amore 
2395c635efSGarrett D'Amore /*
2495c635efSGarrett D'Amore  * Status level.  This refers to both internal status (i.e., whilst
2595c635efSGarrett D'Amore  * running, when warnings/errors are reported) and an indicator of a
2695c635efSGarrett D'Amore  * threshold of when to halt (when said internal state exceeds the
2795c635efSGarrett D'Amore  * threshold).
2895c635efSGarrett D'Amore  */
2995c635efSGarrett D'Amore enum	mandoclevel {
3095c635efSGarrett D'Amore 	MANDOCLEVEL_OK = 0,
3195c635efSGarrett D'Amore 	MANDOCLEVEL_RESERVED,
3295c635efSGarrett D'Amore 	MANDOCLEVEL_WARNING, /* warnings: syntax, whitespace, etc. */
3395c635efSGarrett D'Amore 	MANDOCLEVEL_ERROR, /* input has been thrown away */
34*260e9a87SYuri Pankov 	MANDOCLEVEL_UNSUPP, /* input needs unimplemented features */
3595c635efSGarrett D'Amore 	MANDOCLEVEL_BADARG, /* bad argument in invocation */
3695c635efSGarrett D'Amore 	MANDOCLEVEL_SYSERR, /* system error */
3795c635efSGarrett D'Amore 	MANDOCLEVEL_MAX
3895c635efSGarrett D'Amore };
3995c635efSGarrett D'Amore 
4095c635efSGarrett D'Amore /*
4195c635efSGarrett D'Amore  * All possible things that can go wrong within a parse, be it libroff,
4295c635efSGarrett D'Amore  * libmdoc, or libman.
4395c635efSGarrett D'Amore  */
4495c635efSGarrett D'Amore enum	mandocerr {
4595c635efSGarrett D'Amore 	MANDOCERR_OK,
4695c635efSGarrett D'Amore 
4795c635efSGarrett D'Amore 	MANDOCERR_WARNING, /* ===== start of warnings ===== */
4895c635efSGarrett D'Amore 
4995c635efSGarrett D'Amore 	/* related to the prologue */
50*260e9a87SYuri Pankov 	MANDOCERR_DT_NOTITLE, /* missing manual title, using UNTITLED: line */
51*260e9a87SYuri Pankov 	MANDOCERR_TH_NOTITLE, /* missing manual title, using "": [macro] */
52*260e9a87SYuri Pankov 	MANDOCERR_TITLE_CASE, /* lower case character in document title */
53*260e9a87SYuri Pankov 	MANDOCERR_MSEC_MISSING, /* missing manual section, using "": macro */
54*260e9a87SYuri Pankov 	MANDOCERR_MSEC_BAD, /* unknown manual section: Dt ... section */
55*260e9a87SYuri Pankov 	MANDOCERR_DATE_MISSING, /* missing date, using today's date */
56*260e9a87SYuri Pankov 	MANDOCERR_DATE_BAD, /* cannot parse date, using it verbatim: date */
57*260e9a87SYuri Pankov 	MANDOCERR_OS_MISSING, /* missing Os macro, using "" */
58*260e9a87SYuri Pankov 	MANDOCERR_PROLOG_REP, /* duplicate prologue macro: macro */
59*260e9a87SYuri Pankov 	MANDOCERR_PROLOG_LATE, /* late prologue macro: macro */
60*260e9a87SYuri Pankov 	MANDOCERR_DT_LATE, /* skipping late title macro: Dt args */
61*260e9a87SYuri Pankov 	MANDOCERR_PROLOG_ORDER, /* prologue macros out of order: macros */
6295c635efSGarrett D'Amore 
6395c635efSGarrett D'Amore 	/* related to document structure */
64*260e9a87SYuri Pankov 	MANDOCERR_SO, /* .so is fragile, better use ln(1): so path */
65*260e9a87SYuri Pankov 	MANDOCERR_DOC_EMPTY, /* no document body */
66*260e9a87SYuri Pankov 	MANDOCERR_SEC_BEFORE, /* content before first section header: macro */
67*260e9a87SYuri Pankov 	MANDOCERR_NAMESEC_FIRST, /* first section is not NAME: Sh title */
68*260e9a87SYuri Pankov 	MANDOCERR_NAMESEC_NONM, /* NAME section without name */
69*260e9a87SYuri Pankov 	MANDOCERR_NAMESEC_NOND, /* NAME section without description */
70*260e9a87SYuri Pankov 	MANDOCERR_NAMESEC_ND, /* description not at the end of NAME */
71*260e9a87SYuri Pankov 	MANDOCERR_NAMESEC_BAD, /* bad NAME section content: macro */
72*260e9a87SYuri Pankov 	MANDOCERR_ND_EMPTY, /* missing description line, using "" */
73*260e9a87SYuri Pankov 	MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */
74*260e9a87SYuri Pankov 	MANDOCERR_SEC_REP, /* duplicate section title: Sh title */
75*260e9a87SYuri Pankov 	MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */
76*260e9a87SYuri Pankov 	MANDOCERR_XR_ORDER, /* unusual Xr order: ... after ... */
77*260e9a87SYuri Pankov 	MANDOCERR_XR_PUNCT, /* unusual Xr punctuation: ... after ... */
78*260e9a87SYuri Pankov 	MANDOCERR_AN_MISSING, /* AUTHORS section without An macro */
7995c635efSGarrett D'Amore 
8095c635efSGarrett D'Amore 	/* related to macros and nesting */
81*260e9a87SYuri Pankov 	MANDOCERR_MACRO_OBS, /* obsolete macro: macro */
82*260e9a87SYuri Pankov 	MANDOCERR_MACRO_CALL, /* macro neither callable nor escaped: macro */
83*260e9a87SYuri Pankov 	MANDOCERR_PAR_SKIP, /* skipping paragraph macro: macro ... */
84*260e9a87SYuri Pankov 	MANDOCERR_PAR_MOVE, /* moving paragraph macro out of list: macro */
85*260e9a87SYuri Pankov 	MANDOCERR_NS_SKIP, /* skipping no-space macro */
86*260e9a87SYuri Pankov 	MANDOCERR_BLK_NEST, /* blocks badly nested: macro ... */
87*260e9a87SYuri Pankov 	MANDOCERR_BD_NEST, /* nested displays are not portable: macro ... */
88*260e9a87SYuri Pankov 	MANDOCERR_BL_MOVE, /* moving content out of list: macro */
89*260e9a87SYuri Pankov 	MANDOCERR_VT_CHILD, /* .Vt block has child macro: macro */
90*260e9a87SYuri Pankov 	MANDOCERR_FI_SKIP, /* fill mode already enabled, skipping: fi */
91*260e9a87SYuri Pankov 	MANDOCERR_NF_SKIP, /* fill mode already disabled, skipping: nf */
92*260e9a87SYuri Pankov 	MANDOCERR_BLK_LINE, /* line scope broken: macro breaks macro */
9395c635efSGarrett D'Amore 
94*260e9a87SYuri Pankov 	/* related to missing arguments */
95*260e9a87SYuri Pankov 	MANDOCERR_REQ_EMPTY, /* skipping empty request: request */
96*260e9a87SYuri Pankov 	MANDOCERR_COND_EMPTY, /* conditional request controls empty scope */
97*260e9a87SYuri Pankov 	MANDOCERR_MACRO_EMPTY, /* skipping empty macro: macro */
98*260e9a87SYuri Pankov 	MANDOCERR_BLK_EMPTY, /* empty block: macro */
99*260e9a87SYuri Pankov 	MANDOCERR_ARG_EMPTY, /* empty argument, using 0n: macro arg */
100*260e9a87SYuri Pankov 	MANDOCERR_BD_NOTYPE, /* missing display type, using -ragged: Bd */
101*260e9a87SYuri Pankov 	MANDOCERR_BL_LATETYPE, /* list type is not the first argument: Bl arg */
102*260e9a87SYuri Pankov 	MANDOCERR_BL_NOWIDTH, /* missing -width in -tag list, using 8n */
103*260e9a87SYuri Pankov 	MANDOCERR_EX_NONAME, /* missing utility name, using "": Ex */
104*260e9a87SYuri Pankov 	MANDOCERR_FO_NOHEAD, /* missing function name, using "": Fo */
105*260e9a87SYuri Pankov 	MANDOCERR_IT_NOHEAD, /* empty head in list item: Bl -type It */
106*260e9a87SYuri Pankov 	MANDOCERR_IT_NOBODY, /* empty list item: Bl -type It */
107*260e9a87SYuri Pankov 	MANDOCERR_BF_NOFONT, /* missing font type, using \fR: Bf */
108*260e9a87SYuri Pankov 	MANDOCERR_BF_BADFONT, /* unknown font type, using \fR: Bf font */
109*260e9a87SYuri Pankov 	MANDOCERR_PF_SKIP, /* nothing follows prefix: Pf arg */
110*260e9a87SYuri Pankov 	MANDOCERR_RS_EMPTY, /* empty reference block: Rs */
111*260e9a87SYuri Pankov 	MANDOCERR_ARG_STD, /* missing -std argument, adding it: macro */
112*260e9a87SYuri Pankov 	MANDOCERR_OP_EMPTY, /* missing option string, using "": OP */
113*260e9a87SYuri Pankov 	MANDOCERR_UR_NOHEAD, /* missing resource identifier, using "": UR */
114*260e9a87SYuri Pankov 	MANDOCERR_EQN_NOBOX, /* missing eqn box, using "": op */
11595c635efSGarrett D'Amore 
116*260e9a87SYuri Pankov 	/* related to bad arguments */
117*260e9a87SYuri Pankov 	MANDOCERR_ARG_QUOTE, /* unterminated quoted argument */
118*260e9a87SYuri Pankov 	MANDOCERR_ARG_REP, /* duplicate argument: macro arg */
119*260e9a87SYuri Pankov 	MANDOCERR_AN_REP, /* skipping duplicate argument: An -arg */
120*260e9a87SYuri Pankov 	MANDOCERR_BD_REP, /* skipping duplicate display type: Bd -type */
121*260e9a87SYuri Pankov 	MANDOCERR_BL_REP, /* skipping duplicate list type: Bl -type */
122*260e9a87SYuri Pankov 	MANDOCERR_BL_SKIPW, /* skipping -width argument: Bl -type */
123*260e9a87SYuri Pankov 	MANDOCERR_BL_COL, /* wrong number of cells */
124*260e9a87SYuri Pankov 	MANDOCERR_AT_BAD, /* unknown AT&T UNIX version: At version */
125*260e9a87SYuri Pankov 	MANDOCERR_FA_COMMA, /* comma in function argument: arg */
126*260e9a87SYuri Pankov 	MANDOCERR_FN_PAREN, /* parenthesis in function name: arg */
127*260e9a87SYuri Pankov 	MANDOCERR_RS_BAD, /* invalid content in Rs block: macro */
128*260e9a87SYuri Pankov 	MANDOCERR_SM_BAD, /* invalid Boolean argument: macro arg */
129*260e9a87SYuri Pankov 	MANDOCERR_FT_BAD, /* unknown font, skipping request: ft font */
130*260e9a87SYuri Pankov 	MANDOCERR_TR_ODD, /* odd number of characters in request: tr char */
13195c635efSGarrett D'Amore 
13295c635efSGarrett D'Amore 	/* related to plain text */
133*260e9a87SYuri Pankov 	MANDOCERR_FI_BLANK, /* blank line in fill mode, using .sp */
134*260e9a87SYuri Pankov 	MANDOCERR_FI_TAB, /* tab in filled text */
135*260e9a87SYuri Pankov 	MANDOCERR_SPACE_EOL, /* whitespace at end of input line */
136*260e9a87SYuri Pankov 	MANDOCERR_COMMENT_BAD, /* bad comment style */
137*260e9a87SYuri Pankov 	MANDOCERR_ESC_BAD, /* invalid escape sequence: esc */
138*260e9a87SYuri Pankov 	MANDOCERR_STR_UNDEF, /* undefined string, using "": name */
13995c635efSGarrett D'Amore 
140*260e9a87SYuri Pankov 	/* related to tables */
141*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_SPAN, /* tbl line starts with span */
142*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_DOWN, /* tbl column starts with span */
143*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_VERT, /* skipping vertical bar in tbl layout */
14495c635efSGarrett D'Amore 
14595c635efSGarrett D'Amore 	MANDOCERR_ERROR, /* ===== start of errors ===== */
14695c635efSGarrett D'Amore 
14795c635efSGarrett D'Amore 	/* related to tables */
148*260e9a87SYuri Pankov 	MANDOCERR_TBLOPT_ALPHA, /* non-alphabetic character in tbl options */
149*260e9a87SYuri Pankov 	MANDOCERR_TBLOPT_BAD, /* skipping unknown tbl option: option */
150*260e9a87SYuri Pankov 	MANDOCERR_TBLOPT_NOARG, /* missing tbl option argument: option */
151*260e9a87SYuri Pankov 	MANDOCERR_TBLOPT_ARGSZ, /* wrong tbl option argument size: option */
152*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_NONE, /* empty tbl layout */
153*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_CHAR, /* invalid character in tbl layout: char */
154*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_PAR, /* unmatched parenthesis in tbl layout */
155*260e9a87SYuri Pankov 	MANDOCERR_TBLDATA_NONE, /* tbl without any data cells */
156*260e9a87SYuri Pankov 	MANDOCERR_TBLDATA_SPAN, /* ignoring data in spanned tbl cell: data */
157*260e9a87SYuri Pankov 	MANDOCERR_TBLDATA_EXTRA, /* ignoring extra tbl data cells: data */
158*260e9a87SYuri Pankov 	MANDOCERR_TBLDATA_BLK, /* data block open at end of tbl: macro */
15995c635efSGarrett D'Amore 
160*260e9a87SYuri Pankov 	/* related to document structure and macros */
161*260e9a87SYuri Pankov 	MANDOCERR_FILE, /* cannot open file */
16295c635efSGarrett D'Amore 	MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
163*260e9a87SYuri Pankov 	MANDOCERR_CHAR_BAD, /* skipping bad character: number */
164*260e9a87SYuri Pankov 	MANDOCERR_MACRO, /* skipping unknown macro: macro */
165*260e9a87SYuri Pankov 	MANDOCERR_REQ_INSEC, /* skipping insecure request: request */
166*260e9a87SYuri Pankov 	MANDOCERR_IT_STRAY, /* skipping item outside list: It ... */
167*260e9a87SYuri Pankov 	MANDOCERR_TA_STRAY, /* skipping column outside column list: Ta */
168*260e9a87SYuri Pankov 	MANDOCERR_BLK_NOTOPEN, /* skipping end of block that is not open */
169*260e9a87SYuri Pankov 	MANDOCERR_RE_NOTOPEN, /* fewer RS blocks open, skipping: RE arg */
170*260e9a87SYuri Pankov 	MANDOCERR_BLK_BROKEN, /* inserting missing end of block: macro ... */
171*260e9a87SYuri Pankov 	MANDOCERR_BLK_NOEND, /* appending missing end of block: macro */
17295c635efSGarrett D'Amore 
173*260e9a87SYuri Pankov 	/* related to request and macro arguments */
174*260e9a87SYuri Pankov 	MANDOCERR_NAMESC, /* escaped character not allowed in a name: name */
175*260e9a87SYuri Pankov 	MANDOCERR_BD_FILE, /* NOT IMPLEMENTED: Bd -file */
176*260e9a87SYuri Pankov 	MANDOCERR_BL_NOTYPE, /* missing list type, using -item: Bl */
177*260e9a87SYuri Pankov 	MANDOCERR_NM_NONAME, /* missing manual name, using "": Nm */
178*260e9a87SYuri Pankov 	MANDOCERR_OS_UNAME, /* uname(3) system call failed, using UNKNOWN */
179*260e9a87SYuri Pankov 	MANDOCERR_ST_BAD, /* unknown standard specifier: St standard */
180*260e9a87SYuri Pankov 	MANDOCERR_IT_NONUM, /* skipping request without numeric argument */
181*260e9a87SYuri Pankov 	MANDOCERR_SO_PATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */
182*260e9a87SYuri Pankov 	MANDOCERR_SO_FAIL, /* .so request failed */
183*260e9a87SYuri Pankov 	MANDOCERR_ARG_SKIP, /* skipping all arguments: macro args */
184*260e9a87SYuri Pankov 	MANDOCERR_ARG_EXCESS, /* skipping excess arguments: macro ... args */
185*260e9a87SYuri Pankov 	MANDOCERR_DIVZERO, /* divide by zero */
18695c635efSGarrett D'Amore 
187*260e9a87SYuri Pankov 	MANDOCERR_UNSUPP, /* ===== start of unsupported features ===== */
188*260e9a87SYuri Pankov 
189*260e9a87SYuri Pankov 	MANDOCERR_TOOLARGE, /* input too large */
190*260e9a87SYuri Pankov 	MANDOCERR_CHAR_UNSUPP, /* unsupported control character: number */
191*260e9a87SYuri Pankov 	MANDOCERR_REQ_UNSUPP, /* unsupported roff request: request */
192*260e9a87SYuri Pankov 	MANDOCERR_TBLOPT_EQN, /* eqn delim option in tbl: arg */
193*260e9a87SYuri Pankov 	MANDOCERR_TBLLAYOUT_MOD, /* unsupported tbl layout modifier: m */
194*260e9a87SYuri Pankov 	MANDOCERR_TBLMACRO, /* ignoring macro in table: macro */
195*260e9a87SYuri Pankov 
19695c635efSGarrett D'Amore 	MANDOCERR_MAX
19795c635efSGarrett D'Amore };
19895c635efSGarrett D'Amore 
199698f87a4SGarrett D'Amore struct	tbl_opts {
20095c635efSGarrett D'Amore 	char		  tab; /* cell-separator */
20195c635efSGarrett D'Amore 	char		  decimal; /* decimal point */
20295c635efSGarrett D'Amore 	int		  opts;
20395c635efSGarrett D'Amore #define	TBL_OPT_CENTRE	 (1 << 0)
20495c635efSGarrett D'Amore #define	TBL_OPT_EXPAND	 (1 << 1)
20595c635efSGarrett D'Amore #define	TBL_OPT_BOX	 (1 << 2)
20695c635efSGarrett D'Amore #define	TBL_OPT_DBOX	 (1 << 3)
20795c635efSGarrett D'Amore #define	TBL_OPT_ALLBOX	 (1 << 4)
20895c635efSGarrett D'Amore #define	TBL_OPT_NOKEEP	 (1 << 5)
20995c635efSGarrett D'Amore #define	TBL_OPT_NOSPACE	 (1 << 6)
210*260e9a87SYuri Pankov #define	TBL_OPT_NOWARN	 (1 << 7)
21195c635efSGarrett D'Amore 	int		  cols; /* number of columns */
212*260e9a87SYuri Pankov 	int		  lvert; /* width of left vertical line */
213*260e9a87SYuri Pankov 	int		  rvert; /* width of right vertical line */
21495c635efSGarrett D'Amore };
21595c635efSGarrett D'Amore 
21695c635efSGarrett D'Amore enum	tbl_cellt {
21795c635efSGarrett D'Amore 	TBL_CELL_CENTRE, /* c, C */
21895c635efSGarrett D'Amore 	TBL_CELL_RIGHT, /* r, R */
21995c635efSGarrett D'Amore 	TBL_CELL_LEFT, /* l, L */
22095c635efSGarrett D'Amore 	TBL_CELL_NUMBER, /* n, N */
22195c635efSGarrett D'Amore 	TBL_CELL_SPAN, /* s, S */
22295c635efSGarrett D'Amore 	TBL_CELL_LONG, /* a, A */
22395c635efSGarrett D'Amore 	TBL_CELL_DOWN, /* ^ */
22495c635efSGarrett D'Amore 	TBL_CELL_HORIZ, /* _, - */
22595c635efSGarrett D'Amore 	TBL_CELL_DHORIZ, /* = */
22695c635efSGarrett D'Amore 	TBL_CELL_MAX
22795c635efSGarrett D'Amore };
22895c635efSGarrett D'Amore 
22995c635efSGarrett D'Amore /*
23095c635efSGarrett D'Amore  * A cell in a layout row.
23195c635efSGarrett D'Amore  */
23295c635efSGarrett D'Amore struct	tbl_cell {
23395c635efSGarrett D'Amore 	struct tbl_cell	 *next;
234*260e9a87SYuri Pankov 	int		  vert; /* width of subsequent vertical line */
23595c635efSGarrett D'Amore 	enum tbl_cellt	  pos;
23695c635efSGarrett D'Amore 	size_t		  spacing;
237*260e9a87SYuri Pankov 	int		  col; /* column number, starting from 0 */
23895c635efSGarrett D'Amore 	int		  flags;
23995c635efSGarrett D'Amore #define	TBL_CELL_TALIGN	 (1 << 0) /* t, T */
24095c635efSGarrett D'Amore #define	TBL_CELL_BALIGN	 (1 << 1) /* d, D */
24195c635efSGarrett D'Amore #define	TBL_CELL_BOLD	 (1 << 2) /* fB, B, b */
24295c635efSGarrett D'Amore #define	TBL_CELL_ITALIC	 (1 << 3) /* fI, I, i */
24395c635efSGarrett D'Amore #define	TBL_CELL_EQUAL	 (1 << 4) /* e, E */
24495c635efSGarrett D'Amore #define	TBL_CELL_UP	 (1 << 5) /* u, U */
24595c635efSGarrett D'Amore #define	TBL_CELL_WIGN	 (1 << 6) /* z, Z */
246*260e9a87SYuri Pankov #define	TBL_CELL_WMAX	 (1 << 7) /* x, X */
24795c635efSGarrett D'Amore };
24895c635efSGarrett D'Amore 
24995c635efSGarrett D'Amore /*
25095c635efSGarrett D'Amore  * A layout row.
25195c635efSGarrett D'Amore  */
25295c635efSGarrett D'Amore struct	tbl_row {
25395c635efSGarrett D'Amore 	struct tbl_row	 *next;
25495c635efSGarrett D'Amore 	struct tbl_cell	 *first;
25595c635efSGarrett D'Amore 	struct tbl_cell	 *last;
256*260e9a87SYuri Pankov 	int		  vert; /* width of left vertical line */
25795c635efSGarrett D'Amore };
25895c635efSGarrett D'Amore 
25995c635efSGarrett D'Amore enum	tbl_datt {
26095c635efSGarrett D'Amore 	TBL_DATA_NONE, /* has no data */
26195c635efSGarrett D'Amore 	TBL_DATA_DATA, /* consists of data/string */
26295c635efSGarrett D'Amore 	TBL_DATA_HORIZ, /* horizontal line */
26395c635efSGarrett D'Amore 	TBL_DATA_DHORIZ, /* double-horizontal line */
26495c635efSGarrett D'Amore 	TBL_DATA_NHORIZ, /* squeezed horizontal line */
26595c635efSGarrett D'Amore 	TBL_DATA_NDHORIZ /* squeezed double-horizontal line */
26695c635efSGarrett D'Amore };
26795c635efSGarrett D'Amore 
26895c635efSGarrett D'Amore /*
26995c635efSGarrett D'Amore  * A cell within a row of data.  The "string" field contains the actual
27095c635efSGarrett D'Amore  * string value that's in the cell.  The rest is layout.
27195c635efSGarrett D'Amore  */
27295c635efSGarrett D'Amore struct	tbl_dat {
27395c635efSGarrett D'Amore 	struct tbl_cell	 *layout; /* layout cell */
27495c635efSGarrett D'Amore 	int		  spans; /* how many spans follow */
27595c635efSGarrett D'Amore 	struct tbl_dat	 *next;
27695c635efSGarrett D'Amore 	char		 *string; /* data (NULL if not TBL_DATA_DATA) */
27795c635efSGarrett D'Amore 	enum tbl_datt	  pos;
27895c635efSGarrett D'Amore };
27995c635efSGarrett D'Amore 
28095c635efSGarrett D'Amore enum	tbl_spant {
28195c635efSGarrett D'Amore 	TBL_SPAN_DATA, /* span consists of data */
28295c635efSGarrett D'Amore 	TBL_SPAN_HORIZ, /* span is horizontal line */
28395c635efSGarrett D'Amore 	TBL_SPAN_DHORIZ /* span is double horizontal line */
28495c635efSGarrett D'Amore };
28595c635efSGarrett D'Amore 
28695c635efSGarrett D'Amore /*
28795c635efSGarrett D'Amore  * A row of data in a table.
28895c635efSGarrett D'Amore  */
28995c635efSGarrett D'Amore struct	tbl_span {
290698f87a4SGarrett D'Amore 	struct tbl_opts	 *opts;
29195c635efSGarrett D'Amore 	struct tbl_row	 *layout; /* layout row */
29295c635efSGarrett D'Amore 	struct tbl_dat	 *first;
29395c635efSGarrett D'Amore 	struct tbl_dat	 *last;
294*260e9a87SYuri Pankov 	struct tbl_span	 *prev;
29595c635efSGarrett D'Amore 	struct tbl_span	 *next;
296*260e9a87SYuri Pankov 	int		  line; /* parse line */
297*260e9a87SYuri Pankov 	enum tbl_spant	  pos;
29895c635efSGarrett D'Amore };
29995c635efSGarrett D'Amore 
30095c635efSGarrett D'Amore enum	eqn_boxt {
30195c635efSGarrett D'Amore 	EQN_ROOT, /* root of parse tree */
30295c635efSGarrett D'Amore 	EQN_TEXT, /* text (number, variable, whatever) */
30395c635efSGarrett D'Amore 	EQN_SUBEXPR, /* nested `eqn' subexpression */
304*260e9a87SYuri Pankov 	EQN_LIST, /* list (braces, etc.) */
305*260e9a87SYuri Pankov 	EQN_LISTONE, /* singleton list */
306*260e9a87SYuri Pankov 	EQN_PILE, /* vertical pile */
307*260e9a87SYuri Pankov 	EQN_MATRIX /* pile of piles */
30895c635efSGarrett D'Amore };
30995c635efSGarrett D'Amore 
31095c635efSGarrett D'Amore enum	eqn_fontt {
31195c635efSGarrett D'Amore 	EQNFONT_NONE = 0,
31295c635efSGarrett D'Amore 	EQNFONT_ROMAN,
31395c635efSGarrett D'Amore 	EQNFONT_BOLD,
31495c635efSGarrett D'Amore 	EQNFONT_FAT,
31595c635efSGarrett D'Amore 	EQNFONT_ITALIC,
31695c635efSGarrett D'Amore 	EQNFONT__MAX
31795c635efSGarrett D'Amore };
31895c635efSGarrett D'Amore 
31995c635efSGarrett D'Amore enum	eqn_post {
32095c635efSGarrett D'Amore 	EQNPOS_NONE = 0,
32195c635efSGarrett D'Amore 	EQNPOS_SUP,
322*260e9a87SYuri Pankov 	EQNPOS_SUBSUP,
32395c635efSGarrett D'Amore 	EQNPOS_SUB,
32495c635efSGarrett D'Amore 	EQNPOS_TO,
32595c635efSGarrett D'Amore 	EQNPOS_FROM,
326*260e9a87SYuri Pankov 	EQNPOS_FROMTO,
327*260e9a87SYuri Pankov 	EQNPOS_OVER,
328*260e9a87SYuri Pankov 	EQNPOS_SQRT,
32995c635efSGarrett D'Amore 	EQNPOS__MAX
33095c635efSGarrett D'Amore };
33195c635efSGarrett D'Amore 
33295c635efSGarrett D'Amore enum	eqn_pilet {
33395c635efSGarrett D'Amore 	EQNPILE_NONE = 0,
33495c635efSGarrett D'Amore 	EQNPILE_PILE,
33595c635efSGarrett D'Amore 	EQNPILE_CPILE,
33695c635efSGarrett D'Amore 	EQNPILE_RPILE,
33795c635efSGarrett D'Amore 	EQNPILE_LPILE,
33895c635efSGarrett D'Amore 	EQNPILE_COL,
33995c635efSGarrett D'Amore 	EQNPILE_CCOL,
34095c635efSGarrett D'Amore 	EQNPILE_RCOL,
34195c635efSGarrett D'Amore 	EQNPILE_LCOL,
34295c635efSGarrett D'Amore 	EQNPILE__MAX
34395c635efSGarrett D'Amore };
34495c635efSGarrett D'Amore 
34595c635efSGarrett D'Amore  /*
34695c635efSGarrett D'Amore  * A "box" is a parsed mathematical expression as defined by the eqn.7
34795c635efSGarrett D'Amore  * grammar.
34895c635efSGarrett D'Amore  */
34995c635efSGarrett D'Amore struct	eqn_box {
35095c635efSGarrett D'Amore 	int		  size; /* font size of expression */
35195c635efSGarrett D'Amore #define	EQN_DEFSIZE	  INT_MIN
35295c635efSGarrett D'Amore 	enum eqn_boxt	  type; /* type of node */
35395c635efSGarrett D'Amore 	struct eqn_box	 *first; /* first child node */
35495c635efSGarrett D'Amore 	struct eqn_box	 *last; /* last child node */
35595c635efSGarrett D'Amore 	struct eqn_box	 *next; /* node sibling */
356*260e9a87SYuri Pankov 	struct eqn_box	 *prev; /* node sibling */
35795c635efSGarrett D'Amore 	struct eqn_box	 *parent; /* node sibling */
35895c635efSGarrett D'Amore 	char		 *text; /* text (or NULL) */
359*260e9a87SYuri Pankov 	char		 *left; /* fence left-hand */
360*260e9a87SYuri Pankov 	char		 *right; /* fence right-hand */
361*260e9a87SYuri Pankov 	char		 *top; /* expression over-symbol */
362*260e9a87SYuri Pankov 	char		 *bottom; /* expression under-symbol */
363*260e9a87SYuri Pankov 	size_t		  args; /* arguments in parent */
364*260e9a87SYuri Pankov 	size_t		  expectargs; /* max arguments in parent */
36595c635efSGarrett D'Amore 	enum eqn_post	  pos; /* position of next box */
36695c635efSGarrett D'Amore 	enum eqn_fontt	  font; /* font of box */
36795c635efSGarrett D'Amore 	enum eqn_pilet	  pile; /* equation piling */
36895c635efSGarrett D'Amore };
36995c635efSGarrett D'Amore 
37095c635efSGarrett D'Amore /*
37195c635efSGarrett D'Amore  * An equation consists of a tree of expressions starting at a given
37295c635efSGarrett D'Amore  * line and position.
37395c635efSGarrett D'Amore  */
37495c635efSGarrett D'Amore struct	eqn {
37595c635efSGarrett D'Amore 	char		 *name; /* identifier (or NULL) */
37695c635efSGarrett D'Amore 	struct eqn_box	 *root; /* root mathematical expression */
37795c635efSGarrett D'Amore 	int		  ln; /* invocation line */
37895c635efSGarrett D'Amore 	int		  pos; /* invocation position */
37995c635efSGarrett D'Amore };
38095c635efSGarrett D'Amore 
38195c635efSGarrett D'Amore /*
382*260e9a87SYuri Pankov  * Parse options.
38395c635efSGarrett D'Amore  */
384*260e9a87SYuri Pankov #define	MPARSE_MDOC	1  /* assume -mdoc */
385*260e9a87SYuri Pankov #define	MPARSE_MAN	2  /* assume -man */
386*260e9a87SYuri Pankov #define	MPARSE_SO	4  /* honour .so requests */
387*260e9a87SYuri Pankov #define	MPARSE_QUICK	8  /* abort the parse early */
388*260e9a87SYuri Pankov #define	MPARSE_UTF8	16 /* accept UTF-8 input */
389*260e9a87SYuri Pankov #define	MPARSE_LATIN1	32 /* accept ISO-LATIN-1 input */
39095c635efSGarrett D'Amore 
39195c635efSGarrett D'Amore enum	mandoc_esc {
39295c635efSGarrett D'Amore 	ESCAPE_ERROR = 0, /* bail! unparsable escape */
39395c635efSGarrett D'Amore 	ESCAPE_IGNORE, /* escape to be ignored */
39495c635efSGarrett D'Amore 	ESCAPE_SPECIAL, /* a regular special character */
39595c635efSGarrett D'Amore 	ESCAPE_FONT, /* a generic font mode */
39695c635efSGarrett D'Amore 	ESCAPE_FONTBOLD, /* bold font mode */
39795c635efSGarrett D'Amore 	ESCAPE_FONTITALIC, /* italic font mode */
398698f87a4SGarrett D'Amore 	ESCAPE_FONTBI, /* bold italic font mode */
39995c635efSGarrett D'Amore 	ESCAPE_FONTROMAN, /* roman font mode */
40095c635efSGarrett D'Amore 	ESCAPE_FONTPREV, /* previous font mode */
40195c635efSGarrett D'Amore 	ESCAPE_NUMBERED, /* a numbered glyph */
40295c635efSGarrett D'Amore 	ESCAPE_UNICODE, /* a unicode codepoint */
403698f87a4SGarrett D'Amore 	ESCAPE_NOSPACE, /* suppress space if the last on a line */
404*260e9a87SYuri Pankov 	ESCAPE_SKIPCHAR, /* skip the next character */
405*260e9a87SYuri Pankov 	ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */
40695c635efSGarrett D'Amore };
40795c635efSGarrett D'Amore 
40895c635efSGarrett D'Amore typedef	void	(*mandocmsg)(enum mandocerr, enum mandoclevel,
40995c635efSGarrett D'Amore 			const char *, int, int, const char *);
41095c635efSGarrett D'Amore 
411*260e9a87SYuri Pankov __BEGIN_DECLS
412*260e9a87SYuri Pankov 
41395c635efSGarrett D'Amore struct	mparse;
41495c635efSGarrett D'Amore struct	mchars;
41595c635efSGarrett D'Amore struct	mdoc;
41695c635efSGarrett D'Amore struct	man;
41795c635efSGarrett D'Amore 
41895c635efSGarrett D'Amore enum mandoc_esc	  mandoc_escape(const char **, const char **, int *);
41995c635efSGarrett D'Amore struct mchars	 *mchars_alloc(void);
42095c635efSGarrett D'Amore void		  mchars_free(struct mchars *);
421*260e9a87SYuri Pankov int		  mchars_num2char(const char *, size_t);
422*260e9a87SYuri Pankov const char	 *mchars_uc2str(int);
42395c635efSGarrett D'Amore int		  mchars_num2uc(const char *, size_t);
42495c635efSGarrett D'Amore int		  mchars_spec2cp(const struct mchars *,
42595c635efSGarrett D'Amore 			const char *, size_t);
42695c635efSGarrett D'Amore const char	 *mchars_spec2str(const struct mchars *,
42795c635efSGarrett D'Amore 			const char *, size_t, size_t *);
428*260e9a87SYuri Pankov struct mparse	 *mparse_alloc(int, enum mandoclevel, mandocmsg,
429*260e9a87SYuri Pankov 			const struct mchars *, const char *);
43095c635efSGarrett D'Amore void		  mparse_free(struct mparse *);
43195c635efSGarrett D'Amore void		  mparse_keep(struct mparse *);
432*260e9a87SYuri Pankov enum mandoclevel  mparse_open(struct mparse *, int *, const char *);
43395c635efSGarrett D'Amore enum mandoclevel  mparse_readfd(struct mparse *, int, const char *);
434*260e9a87SYuri Pankov enum mandoclevel  mparse_readmem(struct mparse *, void *, size_t,
43595c635efSGarrett D'Amore 			const char *);
43695c635efSGarrett D'Amore void		  mparse_reset(struct mparse *);
43795c635efSGarrett D'Amore void		  mparse_result(struct mparse *,
438*260e9a87SYuri Pankov 			struct mdoc **, struct man **, char **);
43995c635efSGarrett D'Amore const char	 *mparse_getkeep(const struct mparse *);
44095c635efSGarrett D'Amore const char	 *mparse_strerror(enum mandocerr);
44195c635efSGarrett D'Amore const char	 *mparse_strlevel(enum mandoclevel);
442*260e9a87SYuri Pankov enum mandoclevel  mparse_wait(struct mparse *);
44395c635efSGarrett D'Amore 
44495c635efSGarrett D'Amore __END_DECLS
445