xref: /titanic_44/usr/src/cmd/mandoc/mandoc.h (revision 698f87a48e2e945bfe5493ce168e0d0ae1cedd5c)
1*698f87a4SGarrett D'Amore /*	$Id: mandoc.h,v 1.112 2013/12/30 18:30:32 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*698f87a4SGarrett D'Amore  * Copyright (c) 2012, 2013 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 #ifndef MANDOC_H
1995c635efSGarrett D'Amore #define MANDOC_H
2095c635efSGarrett D'Amore 
2195c635efSGarrett D'Amore #define ASCII_NBRSP	 31  /* non-breaking space */
2295c635efSGarrett D'Amore #define	ASCII_HYPH	 30  /* breakable hyphen */
2395c635efSGarrett D'Amore 
2495c635efSGarrett D'Amore /*
2595c635efSGarrett D'Amore  * Status level.  This refers to both internal status (i.e., whilst
2695c635efSGarrett D'Amore  * running, when warnings/errors are reported) and an indicator of a
2795c635efSGarrett D'Amore  * threshold of when to halt (when said internal state exceeds the
2895c635efSGarrett D'Amore  * threshold).
2995c635efSGarrett D'Amore  */
3095c635efSGarrett D'Amore enum	mandoclevel {
3195c635efSGarrett D'Amore 	MANDOCLEVEL_OK = 0,
3295c635efSGarrett D'Amore 	MANDOCLEVEL_RESERVED,
3395c635efSGarrett D'Amore 	MANDOCLEVEL_WARNING, /* warnings: syntax, whitespace, etc. */
3495c635efSGarrett D'Amore 	MANDOCLEVEL_ERROR, /* input has been thrown away */
3595c635efSGarrett D'Amore 	MANDOCLEVEL_FATAL, /* input is borked */
3695c635efSGarrett D'Amore 	MANDOCLEVEL_BADARG, /* bad argument in invocation */
3795c635efSGarrett D'Amore 	MANDOCLEVEL_SYSERR, /* system error */
3895c635efSGarrett D'Amore 	MANDOCLEVEL_MAX
3995c635efSGarrett D'Amore };
4095c635efSGarrett D'Amore 
4195c635efSGarrett D'Amore /*
4295c635efSGarrett D'Amore  * All possible things that can go wrong within a parse, be it libroff,
4395c635efSGarrett D'Amore  * libmdoc, or libman.
4495c635efSGarrett D'Amore  */
4595c635efSGarrett D'Amore enum	mandocerr {
4695c635efSGarrett D'Amore 	MANDOCERR_OK,
4795c635efSGarrett D'Amore 
4895c635efSGarrett D'Amore 	MANDOCERR_WARNING, /* ===== start of warnings ===== */
4995c635efSGarrett D'Amore 
5095c635efSGarrett D'Amore 	/* related to the prologue */
5195c635efSGarrett D'Amore 	MANDOCERR_NOTITLE, /* no title in document */
5295c635efSGarrett D'Amore 	MANDOCERR_UPPERCASE, /* document title should be all caps */
5395c635efSGarrett D'Amore 	MANDOCERR_BADMSEC, /* unknown manual section */
54*698f87a4SGarrett D'Amore 	MANDOCERR_BADVOLARCH, /* unknown manual volume or arch */
5595c635efSGarrett D'Amore 	MANDOCERR_NODATE, /* date missing, using today's date */
5695c635efSGarrett D'Amore 	MANDOCERR_BADDATE, /* cannot parse date, using it verbatim */
5795c635efSGarrett D'Amore 	MANDOCERR_PROLOGOOO, /* prologue macros out of order */
5895c635efSGarrett D'Amore 	MANDOCERR_PROLOGREP, /* duplicate prologue macro */
5995c635efSGarrett D'Amore 	MANDOCERR_BADPROLOG, /* macro not allowed in prologue */
6095c635efSGarrett D'Amore 	MANDOCERR_BADBODY, /* macro not allowed in body */
6195c635efSGarrett D'Amore 
6295c635efSGarrett D'Amore 	/* related to document structure */
6395c635efSGarrett D'Amore 	MANDOCERR_SO, /* .so is fragile, better use ln(1) */
6495c635efSGarrett D'Amore 	MANDOCERR_NAMESECFIRST, /* NAME section must come first */
6595c635efSGarrett D'Amore 	MANDOCERR_BADNAMESEC, /* bad NAME section contents */
6695c635efSGarrett D'Amore 	MANDOCERR_SECOOO, /* sections out of conventional order */
6795c635efSGarrett D'Amore 	MANDOCERR_SECREP, /* duplicate section name */
68*698f87a4SGarrett D'Amore 	MANDOCERR_SECMSEC, /* section header suited to sections ... */
6995c635efSGarrett D'Amore 
7095c635efSGarrett D'Amore 	/* related to macros and nesting */
7195c635efSGarrett D'Amore 	MANDOCERR_MACROOBS, /* skipping obsolete macro */
7295c635efSGarrett D'Amore 	MANDOCERR_IGNPAR, /* skipping paragraph macro */
73*698f87a4SGarrett D'Amore 	MANDOCERR_MOVEPAR, /* moving paragraph macro out of list */
7495c635efSGarrett D'Amore 	MANDOCERR_IGNNS, /* skipping no-space macro */
7595c635efSGarrett D'Amore 	MANDOCERR_SCOPENEST, /* blocks badly nested */
7695c635efSGarrett D'Amore 	MANDOCERR_CHILD, /* child violates parent syntax */
7795c635efSGarrett D'Amore 	MANDOCERR_NESTEDDISP, /* nested displays are not portable */
7895c635efSGarrett D'Amore 	MANDOCERR_SCOPEREP, /* already in literal mode */
7995c635efSGarrett D'Amore 	MANDOCERR_LINESCOPE, /* line scope broken */
8095c635efSGarrett D'Amore 
8195c635efSGarrett D'Amore 	/* related to missing macro arguments */
8295c635efSGarrett D'Amore 	MANDOCERR_MACROEMPTY, /* skipping empty macro */
8395c635efSGarrett D'Amore 	MANDOCERR_ARGCWARN, /* argument count wrong */
8495c635efSGarrett D'Amore 	MANDOCERR_DISPTYPE, /* missing display type */
8595c635efSGarrett D'Amore 	MANDOCERR_LISTFIRST, /* list type must come first */
8695c635efSGarrett D'Amore 	MANDOCERR_NOWIDTHARG, /* tag lists require a width argument */
8795c635efSGarrett D'Amore 	MANDOCERR_FONTTYPE, /* missing font type */
8895c635efSGarrett D'Amore 	MANDOCERR_WNOSCOPE, /* skipping end of block that is not open */
8995c635efSGarrett D'Amore 
9095c635efSGarrett D'Amore 	/* related to bad macro arguments */
9195c635efSGarrett D'Amore 	MANDOCERR_IGNARGV, /* skipping argument */
9295c635efSGarrett D'Amore 	MANDOCERR_ARGVREP, /* duplicate argument */
9395c635efSGarrett D'Amore 	MANDOCERR_DISPREP, /* duplicate display type */
9495c635efSGarrett D'Amore 	MANDOCERR_LISTREP, /* duplicate list type */
9595c635efSGarrett D'Amore 	MANDOCERR_BADATT, /* unknown AT&T UNIX version */
9695c635efSGarrett D'Amore 	MANDOCERR_BADBOOL, /* bad Boolean value */
9795c635efSGarrett D'Amore 	MANDOCERR_BADFONT, /* unknown font */
9895c635efSGarrett D'Amore 	MANDOCERR_BADSTANDARD, /* unknown standard specifier */
9995c635efSGarrett D'Amore 	MANDOCERR_BADWIDTH, /* bad width argument */
10095c635efSGarrett D'Amore 
10195c635efSGarrett D'Amore 	/* related to plain text */
10295c635efSGarrett D'Amore 	MANDOCERR_NOBLANKLN, /* blank line in non-literal context */
10395c635efSGarrett D'Amore 	MANDOCERR_BADTAB, /* tab in non-literal context */
10495c635efSGarrett D'Amore 	MANDOCERR_EOLNSPACE, /* end of line whitespace */
10595c635efSGarrett D'Amore 	MANDOCERR_BADCOMMENT, /* bad comment style */
10695c635efSGarrett D'Amore 	MANDOCERR_BADESCAPE, /* unknown escape sequence */
10795c635efSGarrett D'Amore 	MANDOCERR_BADQUOTE, /* unterminated quoted string */
10895c635efSGarrett D'Amore 
10995c635efSGarrett D'Amore 	/* related to equations */
11095c635efSGarrett D'Amore 	MANDOCERR_EQNQUOTE, /* unexpected literal in equation */
11195c635efSGarrett D'Amore 
11295c635efSGarrett D'Amore 	MANDOCERR_ERROR, /* ===== start of errors ===== */
11395c635efSGarrett D'Amore 
11495c635efSGarrett D'Amore 	/* related to equations */
11595c635efSGarrett D'Amore 	MANDOCERR_EQNNSCOPE, /* unexpected equation scope closure*/
11695c635efSGarrett D'Amore 	MANDOCERR_EQNSCOPE, /* equation scope open on exit */
11795c635efSGarrett D'Amore 	MANDOCERR_EQNBADSCOPE, /* overlapping equation scopes */
11895c635efSGarrett D'Amore 	MANDOCERR_EQNEOF, /* unexpected end of equation */
11995c635efSGarrett D'Amore 	MANDOCERR_EQNSYNT, /* equation syntax error */
12095c635efSGarrett D'Amore 
12195c635efSGarrett D'Amore 	/* related to tables */
12295c635efSGarrett D'Amore 	MANDOCERR_TBL, /* bad table syntax */
12395c635efSGarrett D'Amore 	MANDOCERR_TBLOPT, /* bad table option */
12495c635efSGarrett D'Amore 	MANDOCERR_TBLLAYOUT, /* bad table layout */
12595c635efSGarrett D'Amore 	MANDOCERR_TBLNOLAYOUT, /* no table layout cells specified */
12695c635efSGarrett D'Amore 	MANDOCERR_TBLNODATA, /* no table data cells specified */
12795c635efSGarrett D'Amore 	MANDOCERR_TBLIGNDATA, /* ignore data in cell */
12895c635efSGarrett D'Amore 	MANDOCERR_TBLBLOCK, /* data block still open */
12995c635efSGarrett D'Amore 	MANDOCERR_TBLEXTRADAT, /* ignoring extra data cells */
13095c635efSGarrett D'Amore 
13195c635efSGarrett D'Amore 	MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
13295c635efSGarrett D'Amore 	MANDOCERR_BADCHAR, /* skipping bad character */
13395c635efSGarrett D'Amore 	MANDOCERR_NAMESC, /* escaped character not allowed in a name */
134*698f87a4SGarrett D'Amore 	MANDOCERR_NONAME, /* manual name not yet set */
13595c635efSGarrett D'Amore 	MANDOCERR_NOTEXT, /* skipping text before the first section header */
13695c635efSGarrett D'Amore 	MANDOCERR_MACRO, /* skipping unknown macro */
13795c635efSGarrett D'Amore 	MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */
13895c635efSGarrett D'Amore 	MANDOCERR_ARGCOUNT, /* argument count wrong */
139*698f87a4SGarrett D'Amore 	MANDOCERR_STRAYTA, /* skipping column outside column list */
14095c635efSGarrett D'Amore 	MANDOCERR_NOSCOPE, /* skipping end of block that is not open */
14195c635efSGarrett D'Amore 	MANDOCERR_SCOPEBROKEN, /* missing end of block */
14295c635efSGarrett D'Amore 	MANDOCERR_SCOPEEXIT, /* scope open on exit */
14395c635efSGarrett D'Amore 	MANDOCERR_UNAME, /* uname(3) system call failed */
14495c635efSGarrett D'Amore 	/* FIXME: merge following with MANDOCERR_ARGCOUNT */
14595c635efSGarrett D'Amore 	MANDOCERR_NOARGS, /* macro requires line argument(s) */
14695c635efSGarrett D'Amore 	MANDOCERR_NOBODY, /* macro requires body argument(s) */
14795c635efSGarrett D'Amore 	MANDOCERR_NOARGV, /* macro requires argument(s) */
148*698f87a4SGarrett D'Amore 	MANDOCERR_NUMERIC, /* request requires a numeric argument */
14995c635efSGarrett D'Amore 	MANDOCERR_LISTTYPE, /* missing list type */
15095c635efSGarrett D'Amore 	MANDOCERR_ARGSLOST, /* line argument(s) will be lost */
15195c635efSGarrett D'Amore 	MANDOCERR_BODYLOST, /* body argument(s) will be lost */
15295c635efSGarrett D'Amore 
15395c635efSGarrett D'Amore 	MANDOCERR_FATAL, /* ===== start of fatal errors ===== */
15495c635efSGarrett D'Amore 
15595c635efSGarrett D'Amore 	MANDOCERR_NOTMANUAL, /* manual isn't really a manual */
15695c635efSGarrett D'Amore 	MANDOCERR_COLUMNS, /* column syntax is inconsistent */
15795c635efSGarrett D'Amore 	MANDOCERR_BADDISP, /* NOT IMPLEMENTED: .Bd -file */
15895c635efSGarrett D'Amore 	MANDOCERR_SYNTARGVCOUNT, /* argument count wrong, violates syntax */
15995c635efSGarrett D'Amore 	MANDOCERR_SYNTCHILD, /* child violates parent syntax */
16095c635efSGarrett D'Amore 	MANDOCERR_SYNTARGCOUNT, /* argument count wrong, violates syntax */
16195c635efSGarrett D'Amore 	MANDOCERR_SOPATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */
16295c635efSGarrett D'Amore 	MANDOCERR_NODOCBODY, /* no document body */
16395c635efSGarrett D'Amore 	MANDOCERR_NODOCPROLOG, /* no document prologue */
16495c635efSGarrett D'Amore 	MANDOCERR_MEM, /* static buffer exhausted */
16595c635efSGarrett D'Amore 	MANDOCERR_MAX
16695c635efSGarrett D'Amore };
16795c635efSGarrett D'Amore 
168*698f87a4SGarrett D'Amore struct	tbl_opts {
16995c635efSGarrett D'Amore 	char		  tab; /* cell-separator */
17095c635efSGarrett D'Amore 	char		  decimal; /* decimal point */
17195c635efSGarrett D'Amore 	int		  linesize;
17295c635efSGarrett D'Amore 	int		  opts;
17395c635efSGarrett D'Amore #define	TBL_OPT_CENTRE	 (1 << 0)
17495c635efSGarrett D'Amore #define	TBL_OPT_EXPAND	 (1 << 1)
17595c635efSGarrett D'Amore #define	TBL_OPT_BOX	 (1 << 2)
17695c635efSGarrett D'Amore #define	TBL_OPT_DBOX	 (1 << 3)
17795c635efSGarrett D'Amore #define	TBL_OPT_ALLBOX	 (1 << 4)
17895c635efSGarrett D'Amore #define	TBL_OPT_NOKEEP	 (1 << 5)
17995c635efSGarrett D'Amore #define	TBL_OPT_NOSPACE	 (1 << 6)
18095c635efSGarrett D'Amore 	int		  cols; /* number of columns */
18195c635efSGarrett D'Amore };
18295c635efSGarrett D'Amore 
18395c635efSGarrett D'Amore /*
18495c635efSGarrett D'Amore  * The head of a table specifies all of its columns.  When formatting a
18595c635efSGarrett D'Amore  * tbl_span, iterate over these and plug in data from the tbl_span when
18695c635efSGarrett D'Amore  * appropriate, using tbl_cell as a guide to placement.
18795c635efSGarrett D'Amore  */
18895c635efSGarrett D'Amore struct	tbl_head {
18995c635efSGarrett D'Amore 	int		  ident; /* 0 <= unique id < cols */
190*698f87a4SGarrett D'Amore 	int		  vert; /* width of preceding vertical line */
19195c635efSGarrett D'Amore 	struct tbl_head	 *next;
19295c635efSGarrett D'Amore 	struct tbl_head	 *prev;
19395c635efSGarrett D'Amore };
19495c635efSGarrett D'Amore 
19595c635efSGarrett D'Amore enum	tbl_cellt {
19695c635efSGarrett D'Amore 	TBL_CELL_CENTRE, /* c, C */
19795c635efSGarrett D'Amore 	TBL_CELL_RIGHT, /* r, R */
19895c635efSGarrett D'Amore 	TBL_CELL_LEFT, /* l, L */
19995c635efSGarrett D'Amore 	TBL_CELL_NUMBER, /* n, N */
20095c635efSGarrett D'Amore 	TBL_CELL_SPAN, /* s, S */
20195c635efSGarrett D'Amore 	TBL_CELL_LONG, /* a, A */
20295c635efSGarrett D'Amore 	TBL_CELL_DOWN, /* ^ */
20395c635efSGarrett D'Amore 	TBL_CELL_HORIZ, /* _, - */
20495c635efSGarrett D'Amore 	TBL_CELL_DHORIZ, /* = */
20595c635efSGarrett D'Amore 	TBL_CELL_MAX
20695c635efSGarrett D'Amore };
20795c635efSGarrett D'Amore 
20895c635efSGarrett D'Amore /*
20995c635efSGarrett D'Amore  * A cell in a layout row.
21095c635efSGarrett D'Amore  */
21195c635efSGarrett D'Amore struct	tbl_cell {
21295c635efSGarrett D'Amore 	struct tbl_cell	 *next;
213*698f87a4SGarrett D'Amore 	int		  vert; /* width of preceding vertical line */
21495c635efSGarrett D'Amore 	enum tbl_cellt	  pos;
21595c635efSGarrett D'Amore 	size_t		  spacing;
21695c635efSGarrett D'Amore 	int		  flags;
21795c635efSGarrett D'Amore #define	TBL_CELL_TALIGN	 (1 << 0) /* t, T */
21895c635efSGarrett D'Amore #define	TBL_CELL_BALIGN	 (1 << 1) /* d, D */
21995c635efSGarrett D'Amore #define	TBL_CELL_BOLD	 (1 << 2) /* fB, B, b */
22095c635efSGarrett D'Amore #define	TBL_CELL_ITALIC	 (1 << 3) /* fI, I, i */
22195c635efSGarrett D'Amore #define	TBL_CELL_EQUAL	 (1 << 4) /* e, E */
22295c635efSGarrett D'Amore #define	TBL_CELL_UP	 (1 << 5) /* u, U */
22395c635efSGarrett D'Amore #define	TBL_CELL_WIGN	 (1 << 6) /* z, Z */
22495c635efSGarrett D'Amore 	struct tbl_head	 *head;
22595c635efSGarrett D'Amore };
22695c635efSGarrett D'Amore 
22795c635efSGarrett D'Amore /*
22895c635efSGarrett D'Amore  * A layout row.
22995c635efSGarrett D'Amore  */
23095c635efSGarrett D'Amore struct	tbl_row {
23195c635efSGarrett D'Amore 	struct tbl_row	 *next;
23295c635efSGarrett D'Amore 	struct tbl_cell	 *first;
23395c635efSGarrett D'Amore 	struct tbl_cell	 *last;
23495c635efSGarrett D'Amore };
23595c635efSGarrett D'Amore 
23695c635efSGarrett D'Amore enum	tbl_datt {
23795c635efSGarrett D'Amore 	TBL_DATA_NONE, /* has no data */
23895c635efSGarrett D'Amore 	TBL_DATA_DATA, /* consists of data/string */
23995c635efSGarrett D'Amore 	TBL_DATA_HORIZ, /* horizontal line */
24095c635efSGarrett D'Amore 	TBL_DATA_DHORIZ, /* double-horizontal line */
24195c635efSGarrett D'Amore 	TBL_DATA_NHORIZ, /* squeezed horizontal line */
24295c635efSGarrett D'Amore 	TBL_DATA_NDHORIZ /* squeezed double-horizontal line */
24395c635efSGarrett D'Amore };
24495c635efSGarrett D'Amore 
24595c635efSGarrett D'Amore /*
24695c635efSGarrett D'Amore  * A cell within a row of data.  The "string" field contains the actual
24795c635efSGarrett D'Amore  * string value that's in the cell.  The rest is layout.
24895c635efSGarrett D'Amore  */
24995c635efSGarrett D'Amore struct	tbl_dat {
25095c635efSGarrett D'Amore 	struct tbl_cell	 *layout; /* layout cell */
25195c635efSGarrett D'Amore 	int		  spans; /* how many spans follow */
25295c635efSGarrett D'Amore 	struct tbl_dat	 *next;
25395c635efSGarrett D'Amore 	char		 *string; /* data (NULL if not TBL_DATA_DATA) */
25495c635efSGarrett D'Amore 	enum tbl_datt	  pos;
25595c635efSGarrett D'Amore };
25695c635efSGarrett D'Amore 
25795c635efSGarrett D'Amore enum	tbl_spant {
25895c635efSGarrett D'Amore 	TBL_SPAN_DATA, /* span consists of data */
25995c635efSGarrett D'Amore 	TBL_SPAN_HORIZ, /* span is horizontal line */
26095c635efSGarrett D'Amore 	TBL_SPAN_DHORIZ /* span is double horizontal line */
26195c635efSGarrett D'Amore };
26295c635efSGarrett D'Amore 
26395c635efSGarrett D'Amore /*
26495c635efSGarrett D'Amore  * A row of data in a table.
26595c635efSGarrett D'Amore  */
26695c635efSGarrett D'Amore struct	tbl_span {
267*698f87a4SGarrett D'Amore 	struct tbl_opts	 *opts;
26895c635efSGarrett D'Amore 	struct tbl_head	 *head;
26995c635efSGarrett D'Amore 	struct tbl_row	 *layout; /* layout row */
27095c635efSGarrett D'Amore 	struct tbl_dat	 *first;
27195c635efSGarrett D'Amore 	struct tbl_dat	 *last;
27295c635efSGarrett D'Amore 	int		  line; /* parse line */
27395c635efSGarrett D'Amore 	int		  flags;
27495c635efSGarrett D'Amore #define	TBL_SPAN_FIRST	 (1 << 0)
27595c635efSGarrett D'Amore #define	TBL_SPAN_LAST	 (1 << 1)
27695c635efSGarrett D'Amore 	enum tbl_spant	  pos;
27795c635efSGarrett D'Amore 	struct tbl_span	 *next;
27895c635efSGarrett D'Amore };
27995c635efSGarrett D'Amore 
28095c635efSGarrett D'Amore enum	eqn_boxt {
28195c635efSGarrett D'Amore 	EQN_ROOT, /* root of parse tree */
28295c635efSGarrett D'Amore 	EQN_TEXT, /* text (number, variable, whatever) */
28395c635efSGarrett D'Amore 	EQN_SUBEXPR, /* nested `eqn' subexpression */
28495c635efSGarrett D'Amore 	EQN_LIST, /* subexpressions list */
28595c635efSGarrett D'Amore 	EQN_MATRIX /* matrix subexpression */
28695c635efSGarrett D'Amore };
28795c635efSGarrett D'Amore 
28895c635efSGarrett D'Amore enum	eqn_markt {
28995c635efSGarrett D'Amore 	EQNMARK_NONE = 0,
29095c635efSGarrett D'Amore 	EQNMARK_DOT,
29195c635efSGarrett D'Amore 	EQNMARK_DOTDOT,
29295c635efSGarrett D'Amore 	EQNMARK_HAT,
29395c635efSGarrett D'Amore 	EQNMARK_TILDE,
29495c635efSGarrett D'Amore 	EQNMARK_VEC,
29595c635efSGarrett D'Amore 	EQNMARK_DYAD,
29695c635efSGarrett D'Amore 	EQNMARK_BAR,
29795c635efSGarrett D'Amore 	EQNMARK_UNDER,
29895c635efSGarrett D'Amore 	EQNMARK__MAX
29995c635efSGarrett D'Amore };
30095c635efSGarrett D'Amore 
30195c635efSGarrett D'Amore enum	eqn_fontt {
30295c635efSGarrett D'Amore 	EQNFONT_NONE = 0,
30395c635efSGarrett D'Amore 	EQNFONT_ROMAN,
30495c635efSGarrett D'Amore 	EQNFONT_BOLD,
30595c635efSGarrett D'Amore 	EQNFONT_FAT,
30695c635efSGarrett D'Amore 	EQNFONT_ITALIC,
30795c635efSGarrett D'Amore 	EQNFONT__MAX
30895c635efSGarrett D'Amore };
30995c635efSGarrett D'Amore 
31095c635efSGarrett D'Amore enum	eqn_post {
31195c635efSGarrett D'Amore 	EQNPOS_NONE = 0,
31295c635efSGarrett D'Amore 	EQNPOS_OVER,
31395c635efSGarrett D'Amore 	EQNPOS_SUP,
31495c635efSGarrett D'Amore 	EQNPOS_SUB,
31595c635efSGarrett D'Amore 	EQNPOS_TO,
31695c635efSGarrett D'Amore 	EQNPOS_FROM,
31795c635efSGarrett D'Amore 	EQNPOS__MAX
31895c635efSGarrett D'Amore };
31995c635efSGarrett D'Amore 
32095c635efSGarrett D'Amore enum	eqn_pilet {
32195c635efSGarrett D'Amore 	EQNPILE_NONE = 0,
32295c635efSGarrett D'Amore 	EQNPILE_PILE,
32395c635efSGarrett D'Amore 	EQNPILE_CPILE,
32495c635efSGarrett D'Amore 	EQNPILE_RPILE,
32595c635efSGarrett D'Amore 	EQNPILE_LPILE,
32695c635efSGarrett D'Amore 	EQNPILE_COL,
32795c635efSGarrett D'Amore 	EQNPILE_CCOL,
32895c635efSGarrett D'Amore 	EQNPILE_RCOL,
32995c635efSGarrett D'Amore 	EQNPILE_LCOL,
33095c635efSGarrett D'Amore 	EQNPILE__MAX
33195c635efSGarrett D'Amore };
33295c635efSGarrett D'Amore 
33395c635efSGarrett D'Amore  /*
33495c635efSGarrett D'Amore  * A "box" is a parsed mathematical expression as defined by the eqn.7
33595c635efSGarrett D'Amore  * grammar.
33695c635efSGarrett D'Amore  */
33795c635efSGarrett D'Amore struct	eqn_box {
33895c635efSGarrett D'Amore 	int		  size; /* font size of expression */
33995c635efSGarrett D'Amore #define	EQN_DEFSIZE	  INT_MIN
34095c635efSGarrett D'Amore 	enum eqn_boxt	  type; /* type of node */
34195c635efSGarrett D'Amore 	struct eqn_box	 *first; /* first child node */
34295c635efSGarrett D'Amore 	struct eqn_box	 *last; /* last child node */
34395c635efSGarrett D'Amore 	struct eqn_box	 *next; /* node sibling */
34495c635efSGarrett D'Amore 	struct eqn_box	 *parent; /* node sibling */
34595c635efSGarrett D'Amore 	char		 *text; /* text (or NULL) */
34695c635efSGarrett D'Amore 	char		 *left;
34795c635efSGarrett D'Amore 	char		 *right;
34895c635efSGarrett D'Amore 	enum eqn_post	  pos; /* position of next box */
34995c635efSGarrett D'Amore 	enum eqn_markt	  mark; /* a mark about the box */
35095c635efSGarrett D'Amore 	enum eqn_fontt	  font; /* font of box */
35195c635efSGarrett D'Amore 	enum eqn_pilet	  pile; /* equation piling */
35295c635efSGarrett D'Amore };
35395c635efSGarrett D'Amore 
35495c635efSGarrett D'Amore /*
35595c635efSGarrett D'Amore  * An equation consists of a tree of expressions starting at a given
35695c635efSGarrett D'Amore  * line and position.
35795c635efSGarrett D'Amore  */
35895c635efSGarrett D'Amore struct	eqn {
35995c635efSGarrett D'Amore 	char		 *name; /* identifier (or NULL) */
36095c635efSGarrett D'Amore 	struct eqn_box	 *root; /* root mathematical expression */
36195c635efSGarrett D'Amore 	int		  ln; /* invocation line */
36295c635efSGarrett D'Amore 	int		  pos; /* invocation position */
36395c635efSGarrett D'Amore };
36495c635efSGarrett D'Amore 
36595c635efSGarrett D'Amore /*
36695c635efSGarrett D'Amore  * The type of parse sequence.  This value is usually passed via the
36795c635efSGarrett D'Amore  * mandoc(1) command line of -man and -mdoc.  It's almost exclusively
36895c635efSGarrett D'Amore  * -mandoc but the others have been retained for compatibility.
36995c635efSGarrett D'Amore  */
37095c635efSGarrett D'Amore enum	mparset {
37195c635efSGarrett D'Amore 	MPARSE_AUTO, /* magically determine the document type */
37295c635efSGarrett D'Amore 	MPARSE_MDOC, /* assume -mdoc */
37395c635efSGarrett D'Amore 	MPARSE_MAN /* assume -man */
37495c635efSGarrett D'Amore };
37595c635efSGarrett D'Amore 
37695c635efSGarrett D'Amore enum	mandoc_esc {
37795c635efSGarrett D'Amore 	ESCAPE_ERROR = 0, /* bail! unparsable escape */
37895c635efSGarrett D'Amore 	ESCAPE_IGNORE, /* escape to be ignored */
37995c635efSGarrett D'Amore 	ESCAPE_SPECIAL, /* a regular special character */
38095c635efSGarrett D'Amore 	ESCAPE_FONT, /* a generic font mode */
38195c635efSGarrett D'Amore 	ESCAPE_FONTBOLD, /* bold font mode */
38295c635efSGarrett D'Amore 	ESCAPE_FONTITALIC, /* italic font mode */
383*698f87a4SGarrett D'Amore 	ESCAPE_FONTBI, /* bold italic font mode */
38495c635efSGarrett D'Amore 	ESCAPE_FONTROMAN, /* roman font mode */
38595c635efSGarrett D'Amore 	ESCAPE_FONTPREV, /* previous font mode */
38695c635efSGarrett D'Amore 	ESCAPE_NUMBERED, /* a numbered glyph */
38795c635efSGarrett D'Amore 	ESCAPE_UNICODE, /* a unicode codepoint */
388*698f87a4SGarrett D'Amore 	ESCAPE_NOSPACE, /* suppress space if the last on a line */
389*698f87a4SGarrett D'Amore 	ESCAPE_SKIPCHAR /* skip the next character */
39095c635efSGarrett D'Amore };
39195c635efSGarrett D'Amore 
39295c635efSGarrett D'Amore typedef	void	(*mandocmsg)(enum mandocerr, enum mandoclevel,
39395c635efSGarrett D'Amore 			const char *, int, int, const char *);
39495c635efSGarrett D'Amore 
39595c635efSGarrett D'Amore struct	mparse;
39695c635efSGarrett D'Amore struct	mchars;
39795c635efSGarrett D'Amore struct	mdoc;
39895c635efSGarrett D'Amore struct	man;
39995c635efSGarrett D'Amore 
40095c635efSGarrett D'Amore __BEGIN_DECLS
40195c635efSGarrett D'Amore 
40295c635efSGarrett D'Amore void		 *mandoc_calloc(size_t, size_t);
40395c635efSGarrett D'Amore enum mandoc_esc	  mandoc_escape(const char **, const char **, int *);
40495c635efSGarrett D'Amore void		 *mandoc_malloc(size_t);
40595c635efSGarrett D'Amore void		 *mandoc_realloc(void *, size_t);
40695c635efSGarrett D'Amore char		 *mandoc_strdup(const char *);
40795c635efSGarrett D'Amore char		 *mandoc_strndup(const char *, size_t);
40895c635efSGarrett D'Amore struct mchars	 *mchars_alloc(void);
40995c635efSGarrett D'Amore void		  mchars_free(struct mchars *);
41095c635efSGarrett D'Amore char	 	  mchars_num2char(const char *, size_t);
41195c635efSGarrett D'Amore int		  mchars_num2uc(const char *, size_t);
41295c635efSGarrett D'Amore int		  mchars_spec2cp(const struct mchars *,
41395c635efSGarrett D'Amore 			const char *, size_t);
41495c635efSGarrett D'Amore const char	 *mchars_spec2str(const struct mchars *,
41595c635efSGarrett D'Amore 			const char *, size_t, size_t *);
416*698f87a4SGarrett D'Amore struct mparse	 *mparse_alloc(enum mparset, enum mandoclevel,
417*698f87a4SGarrett D'Amore 			mandocmsg, void *, char *);
41895c635efSGarrett D'Amore void		  mparse_free(struct mparse *);
41995c635efSGarrett D'Amore void		  mparse_keep(struct mparse *);
42095c635efSGarrett D'Amore enum mandoclevel  mparse_readfd(struct mparse *, int, const char *);
42195c635efSGarrett D'Amore enum mandoclevel  mparse_readmem(struct mparse *, const void *, size_t,
42295c635efSGarrett D'Amore 			const char *);
42395c635efSGarrett D'Amore void		  mparse_reset(struct mparse *);
42495c635efSGarrett D'Amore void		  mparse_result(struct mparse *,
42595c635efSGarrett D'Amore 			struct mdoc **, struct man **);
42695c635efSGarrett D'Amore const char	 *mparse_getkeep(const struct mparse *);
42795c635efSGarrett D'Amore const char	 *mparse_strerror(enum mandocerr);
42895c635efSGarrett D'Amore const char	 *mparse_strlevel(enum mandoclevel);
42995c635efSGarrett D'Amore 
43095c635efSGarrett D'Amore __END_DECLS
43195c635efSGarrett D'Amore 
43295c635efSGarrett D'Amore #endif /*!MANDOC_H*/
433