1*95c635efSGarrett D'Amore /* $Id: mandoc.h,v 1.99 2012/02/16 20:51:31 joerg Exp $ */ 2*95c635efSGarrett D'Amore /* 3*95c635efSGarrett D'Amore * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*95c635efSGarrett D'Amore * 5*95c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 6*95c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 7*95c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 8*95c635efSGarrett D'Amore * 9*95c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*95c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*95c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*95c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*95c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*95c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*95c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*95c635efSGarrett D'Amore */ 17*95c635efSGarrett D'Amore #ifndef MANDOC_H 18*95c635efSGarrett D'Amore #define MANDOC_H 19*95c635efSGarrett D'Amore 20*95c635efSGarrett D'Amore #define ASCII_NBRSP 31 /* non-breaking space */ 21*95c635efSGarrett D'Amore #define ASCII_HYPH 30 /* breakable hyphen */ 22*95c635efSGarrett D'Amore 23*95c635efSGarrett D'Amore /* 24*95c635efSGarrett D'Amore * Status level. This refers to both internal status (i.e., whilst 25*95c635efSGarrett D'Amore * running, when warnings/errors are reported) and an indicator of a 26*95c635efSGarrett D'Amore * threshold of when to halt (when said internal state exceeds the 27*95c635efSGarrett D'Amore * threshold). 28*95c635efSGarrett D'Amore */ 29*95c635efSGarrett D'Amore enum mandoclevel { 30*95c635efSGarrett D'Amore MANDOCLEVEL_OK = 0, 31*95c635efSGarrett D'Amore MANDOCLEVEL_RESERVED, 32*95c635efSGarrett D'Amore MANDOCLEVEL_WARNING, /* warnings: syntax, whitespace, etc. */ 33*95c635efSGarrett D'Amore MANDOCLEVEL_ERROR, /* input has been thrown away */ 34*95c635efSGarrett D'Amore MANDOCLEVEL_FATAL, /* input is borked */ 35*95c635efSGarrett D'Amore MANDOCLEVEL_BADARG, /* bad argument in invocation */ 36*95c635efSGarrett D'Amore MANDOCLEVEL_SYSERR, /* system error */ 37*95c635efSGarrett D'Amore MANDOCLEVEL_MAX 38*95c635efSGarrett D'Amore }; 39*95c635efSGarrett D'Amore 40*95c635efSGarrett D'Amore /* 41*95c635efSGarrett D'Amore * All possible things that can go wrong within a parse, be it libroff, 42*95c635efSGarrett D'Amore * libmdoc, or libman. 43*95c635efSGarrett D'Amore */ 44*95c635efSGarrett D'Amore enum mandocerr { 45*95c635efSGarrett D'Amore MANDOCERR_OK, 46*95c635efSGarrett D'Amore 47*95c635efSGarrett D'Amore MANDOCERR_WARNING, /* ===== start of warnings ===== */ 48*95c635efSGarrett D'Amore 49*95c635efSGarrett D'Amore /* related to the prologue */ 50*95c635efSGarrett D'Amore MANDOCERR_NOTITLE, /* no title in document */ 51*95c635efSGarrett D'Amore MANDOCERR_UPPERCASE, /* document title should be all caps */ 52*95c635efSGarrett D'Amore MANDOCERR_BADMSEC, /* unknown manual section */ 53*95c635efSGarrett D'Amore MANDOCERR_NODATE, /* date missing, using today's date */ 54*95c635efSGarrett D'Amore MANDOCERR_BADDATE, /* cannot parse date, using it verbatim */ 55*95c635efSGarrett D'Amore MANDOCERR_PROLOGOOO, /* prologue macros out of order */ 56*95c635efSGarrett D'Amore MANDOCERR_PROLOGREP, /* duplicate prologue macro */ 57*95c635efSGarrett D'Amore MANDOCERR_BADPROLOG, /* macro not allowed in prologue */ 58*95c635efSGarrett D'Amore MANDOCERR_BADBODY, /* macro not allowed in body */ 59*95c635efSGarrett D'Amore 60*95c635efSGarrett D'Amore /* related to document structure */ 61*95c635efSGarrett D'Amore MANDOCERR_SO, /* .so is fragile, better use ln(1) */ 62*95c635efSGarrett D'Amore MANDOCERR_NAMESECFIRST, /* NAME section must come first */ 63*95c635efSGarrett D'Amore MANDOCERR_BADNAMESEC, /* bad NAME section contents */ 64*95c635efSGarrett D'Amore MANDOCERR_NONAME, /* manual name not yet set */ 65*95c635efSGarrett D'Amore MANDOCERR_SECOOO, /* sections out of conventional order */ 66*95c635efSGarrett D'Amore MANDOCERR_SECREP, /* duplicate section name */ 67*95c635efSGarrett D'Amore MANDOCERR_SECMSEC, /* section not in conventional manual section */ 68*95c635efSGarrett D'Amore 69*95c635efSGarrett D'Amore /* related to macros and nesting */ 70*95c635efSGarrett D'Amore MANDOCERR_MACROOBS, /* skipping obsolete macro */ 71*95c635efSGarrett D'Amore MANDOCERR_IGNPAR, /* skipping paragraph macro */ 72*95c635efSGarrett D'Amore MANDOCERR_IGNNS, /* skipping no-space macro */ 73*95c635efSGarrett D'Amore MANDOCERR_SCOPENEST, /* blocks badly nested */ 74*95c635efSGarrett D'Amore MANDOCERR_CHILD, /* child violates parent syntax */ 75*95c635efSGarrett D'Amore MANDOCERR_NESTEDDISP, /* nested displays are not portable */ 76*95c635efSGarrett D'Amore MANDOCERR_SCOPEREP, /* already in literal mode */ 77*95c635efSGarrett D'Amore MANDOCERR_LINESCOPE, /* line scope broken */ 78*95c635efSGarrett D'Amore 79*95c635efSGarrett D'Amore /* related to missing macro arguments */ 80*95c635efSGarrett D'Amore MANDOCERR_MACROEMPTY, /* skipping empty macro */ 81*95c635efSGarrett D'Amore MANDOCERR_ARGCWARN, /* argument count wrong */ 82*95c635efSGarrett D'Amore MANDOCERR_DISPTYPE, /* missing display type */ 83*95c635efSGarrett D'Amore MANDOCERR_LISTFIRST, /* list type must come first */ 84*95c635efSGarrett D'Amore MANDOCERR_NOWIDTHARG, /* tag lists require a width argument */ 85*95c635efSGarrett D'Amore MANDOCERR_FONTTYPE, /* missing font type */ 86*95c635efSGarrett D'Amore MANDOCERR_WNOSCOPE, /* skipping end of block that is not open */ 87*95c635efSGarrett D'Amore 88*95c635efSGarrett D'Amore /* related to bad macro arguments */ 89*95c635efSGarrett D'Amore MANDOCERR_IGNARGV, /* skipping argument */ 90*95c635efSGarrett D'Amore MANDOCERR_ARGVREP, /* duplicate argument */ 91*95c635efSGarrett D'Amore MANDOCERR_DISPREP, /* duplicate display type */ 92*95c635efSGarrett D'Amore MANDOCERR_LISTREP, /* duplicate list type */ 93*95c635efSGarrett D'Amore MANDOCERR_BADATT, /* unknown AT&T UNIX version */ 94*95c635efSGarrett D'Amore MANDOCERR_BADBOOL, /* bad Boolean value */ 95*95c635efSGarrett D'Amore MANDOCERR_BADFONT, /* unknown font */ 96*95c635efSGarrett D'Amore MANDOCERR_BADSTANDARD, /* unknown standard specifier */ 97*95c635efSGarrett D'Amore MANDOCERR_BADWIDTH, /* bad width argument */ 98*95c635efSGarrett D'Amore 99*95c635efSGarrett D'Amore /* related to plain text */ 100*95c635efSGarrett D'Amore MANDOCERR_NOBLANKLN, /* blank line in non-literal context */ 101*95c635efSGarrett D'Amore MANDOCERR_BADTAB, /* tab in non-literal context */ 102*95c635efSGarrett D'Amore MANDOCERR_EOLNSPACE, /* end of line whitespace */ 103*95c635efSGarrett D'Amore MANDOCERR_BADCOMMENT, /* bad comment style */ 104*95c635efSGarrett D'Amore MANDOCERR_BADESCAPE, /* unknown escape sequence */ 105*95c635efSGarrett D'Amore MANDOCERR_BADQUOTE, /* unterminated quoted string */ 106*95c635efSGarrett D'Amore 107*95c635efSGarrett D'Amore /* related to equations */ 108*95c635efSGarrett D'Amore MANDOCERR_EQNQUOTE, /* unexpected literal in equation */ 109*95c635efSGarrett D'Amore 110*95c635efSGarrett D'Amore MANDOCERR_ERROR, /* ===== start of errors ===== */ 111*95c635efSGarrett D'Amore 112*95c635efSGarrett D'Amore /* related to equations */ 113*95c635efSGarrett D'Amore MANDOCERR_EQNNSCOPE, /* unexpected equation scope closure*/ 114*95c635efSGarrett D'Amore MANDOCERR_EQNSCOPE, /* equation scope open on exit */ 115*95c635efSGarrett D'Amore MANDOCERR_EQNBADSCOPE, /* overlapping equation scopes */ 116*95c635efSGarrett D'Amore MANDOCERR_EQNEOF, /* unexpected end of equation */ 117*95c635efSGarrett D'Amore MANDOCERR_EQNSYNT, /* equation syntax error */ 118*95c635efSGarrett D'Amore 119*95c635efSGarrett D'Amore /* related to tables */ 120*95c635efSGarrett D'Amore MANDOCERR_TBL, /* bad table syntax */ 121*95c635efSGarrett D'Amore MANDOCERR_TBLOPT, /* bad table option */ 122*95c635efSGarrett D'Amore MANDOCERR_TBLLAYOUT, /* bad table layout */ 123*95c635efSGarrett D'Amore MANDOCERR_TBLNOLAYOUT, /* no table layout cells specified */ 124*95c635efSGarrett D'Amore MANDOCERR_TBLNODATA, /* no table data cells specified */ 125*95c635efSGarrett D'Amore MANDOCERR_TBLIGNDATA, /* ignore data in cell */ 126*95c635efSGarrett D'Amore MANDOCERR_TBLBLOCK, /* data block still open */ 127*95c635efSGarrett D'Amore MANDOCERR_TBLEXTRADAT, /* ignoring extra data cells */ 128*95c635efSGarrett D'Amore 129*95c635efSGarrett D'Amore MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */ 130*95c635efSGarrett D'Amore MANDOCERR_BADCHAR, /* skipping bad character */ 131*95c635efSGarrett D'Amore MANDOCERR_NAMESC, /* escaped character not allowed in a name */ 132*95c635efSGarrett D'Amore MANDOCERR_NOTEXT, /* skipping text before the first section header */ 133*95c635efSGarrett D'Amore MANDOCERR_MACRO, /* skipping unknown macro */ 134*95c635efSGarrett D'Amore MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */ 135*95c635efSGarrett D'Amore MANDOCERR_ARGCOUNT, /* argument count wrong */ 136*95c635efSGarrett D'Amore MANDOCERR_NOSCOPE, /* skipping end of block that is not open */ 137*95c635efSGarrett D'Amore MANDOCERR_SCOPEBROKEN, /* missing end of block */ 138*95c635efSGarrett D'Amore MANDOCERR_SCOPEEXIT, /* scope open on exit */ 139*95c635efSGarrett D'Amore MANDOCERR_UNAME, /* uname(3) system call failed */ 140*95c635efSGarrett D'Amore /* FIXME: merge following with MANDOCERR_ARGCOUNT */ 141*95c635efSGarrett D'Amore MANDOCERR_NOARGS, /* macro requires line argument(s) */ 142*95c635efSGarrett D'Amore MANDOCERR_NOBODY, /* macro requires body argument(s) */ 143*95c635efSGarrett D'Amore MANDOCERR_NOARGV, /* macro requires argument(s) */ 144*95c635efSGarrett D'Amore MANDOCERR_LISTTYPE, /* missing list type */ 145*95c635efSGarrett D'Amore MANDOCERR_ARGSLOST, /* line argument(s) will be lost */ 146*95c635efSGarrett D'Amore MANDOCERR_BODYLOST, /* body argument(s) will be lost */ 147*95c635efSGarrett D'Amore 148*95c635efSGarrett D'Amore MANDOCERR_FATAL, /* ===== start of fatal errors ===== */ 149*95c635efSGarrett D'Amore 150*95c635efSGarrett D'Amore MANDOCERR_NOTMANUAL, /* manual isn't really a manual */ 151*95c635efSGarrett D'Amore MANDOCERR_COLUMNS, /* column syntax is inconsistent */ 152*95c635efSGarrett D'Amore MANDOCERR_BADDISP, /* NOT IMPLEMENTED: .Bd -file */ 153*95c635efSGarrett D'Amore MANDOCERR_SYNTARGVCOUNT, /* argument count wrong, violates syntax */ 154*95c635efSGarrett D'Amore MANDOCERR_SYNTCHILD, /* child violates parent syntax */ 155*95c635efSGarrett D'Amore MANDOCERR_SYNTARGCOUNT, /* argument count wrong, violates syntax */ 156*95c635efSGarrett D'Amore MANDOCERR_SOPATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */ 157*95c635efSGarrett D'Amore MANDOCERR_NODOCBODY, /* no document body */ 158*95c635efSGarrett D'Amore MANDOCERR_NODOCPROLOG, /* no document prologue */ 159*95c635efSGarrett D'Amore MANDOCERR_MEM, /* static buffer exhausted */ 160*95c635efSGarrett D'Amore MANDOCERR_MAX 161*95c635efSGarrett D'Amore }; 162*95c635efSGarrett D'Amore 163*95c635efSGarrett D'Amore struct tbl { 164*95c635efSGarrett D'Amore char tab; /* cell-separator */ 165*95c635efSGarrett D'Amore char decimal; /* decimal point */ 166*95c635efSGarrett D'Amore int linesize; 167*95c635efSGarrett D'Amore int opts; 168*95c635efSGarrett D'Amore #define TBL_OPT_CENTRE (1 << 0) 169*95c635efSGarrett D'Amore #define TBL_OPT_EXPAND (1 << 1) 170*95c635efSGarrett D'Amore #define TBL_OPT_BOX (1 << 2) 171*95c635efSGarrett D'Amore #define TBL_OPT_DBOX (1 << 3) 172*95c635efSGarrett D'Amore #define TBL_OPT_ALLBOX (1 << 4) 173*95c635efSGarrett D'Amore #define TBL_OPT_NOKEEP (1 << 5) 174*95c635efSGarrett D'Amore #define TBL_OPT_NOSPACE (1 << 6) 175*95c635efSGarrett D'Amore int cols; /* number of columns */ 176*95c635efSGarrett D'Amore }; 177*95c635efSGarrett D'Amore 178*95c635efSGarrett D'Amore enum tbl_headt { 179*95c635efSGarrett D'Amore TBL_HEAD_DATA, /* plug in data from tbl_dat */ 180*95c635efSGarrett D'Amore TBL_HEAD_VERT, /* vertical spacer */ 181*95c635efSGarrett D'Amore TBL_HEAD_DVERT /* double-vertical spacer */ 182*95c635efSGarrett D'Amore }; 183*95c635efSGarrett D'Amore 184*95c635efSGarrett D'Amore /* 185*95c635efSGarrett D'Amore * The head of a table specifies all of its columns. When formatting a 186*95c635efSGarrett D'Amore * tbl_span, iterate over these and plug in data from the tbl_span when 187*95c635efSGarrett D'Amore * appropriate, using tbl_cell as a guide to placement. 188*95c635efSGarrett D'Amore */ 189*95c635efSGarrett D'Amore struct tbl_head { 190*95c635efSGarrett D'Amore enum tbl_headt pos; 191*95c635efSGarrett D'Amore int ident; /* 0 <= unique id < cols */ 192*95c635efSGarrett D'Amore struct tbl_head *next; 193*95c635efSGarrett D'Amore struct tbl_head *prev; 194*95c635efSGarrett D'Amore }; 195*95c635efSGarrett D'Amore 196*95c635efSGarrett D'Amore enum tbl_cellt { 197*95c635efSGarrett D'Amore TBL_CELL_CENTRE, /* c, C */ 198*95c635efSGarrett D'Amore TBL_CELL_RIGHT, /* r, R */ 199*95c635efSGarrett D'Amore TBL_CELL_LEFT, /* l, L */ 200*95c635efSGarrett D'Amore TBL_CELL_NUMBER, /* n, N */ 201*95c635efSGarrett D'Amore TBL_CELL_SPAN, /* s, S */ 202*95c635efSGarrett D'Amore TBL_CELL_LONG, /* a, A */ 203*95c635efSGarrett D'Amore TBL_CELL_DOWN, /* ^ */ 204*95c635efSGarrett D'Amore TBL_CELL_HORIZ, /* _, - */ 205*95c635efSGarrett D'Amore TBL_CELL_DHORIZ, /* = */ 206*95c635efSGarrett D'Amore TBL_CELL_VERT, /* | */ 207*95c635efSGarrett D'Amore TBL_CELL_DVERT, /* || */ 208*95c635efSGarrett D'Amore TBL_CELL_MAX 209*95c635efSGarrett D'Amore }; 210*95c635efSGarrett D'Amore 211*95c635efSGarrett D'Amore /* 212*95c635efSGarrett D'Amore * A cell in a layout row. 213*95c635efSGarrett D'Amore */ 214*95c635efSGarrett D'Amore struct tbl_cell { 215*95c635efSGarrett D'Amore struct tbl_cell *next; 216*95c635efSGarrett D'Amore enum tbl_cellt pos; 217*95c635efSGarrett D'Amore size_t spacing; 218*95c635efSGarrett D'Amore int flags; 219*95c635efSGarrett D'Amore #define TBL_CELL_TALIGN (1 << 0) /* t, T */ 220*95c635efSGarrett D'Amore #define TBL_CELL_BALIGN (1 << 1) /* d, D */ 221*95c635efSGarrett D'Amore #define TBL_CELL_BOLD (1 << 2) /* fB, B, b */ 222*95c635efSGarrett D'Amore #define TBL_CELL_ITALIC (1 << 3) /* fI, I, i */ 223*95c635efSGarrett D'Amore #define TBL_CELL_EQUAL (1 << 4) /* e, E */ 224*95c635efSGarrett D'Amore #define TBL_CELL_UP (1 << 5) /* u, U */ 225*95c635efSGarrett D'Amore #define TBL_CELL_WIGN (1 << 6) /* z, Z */ 226*95c635efSGarrett D'Amore struct tbl_head *head; 227*95c635efSGarrett D'Amore }; 228*95c635efSGarrett D'Amore 229*95c635efSGarrett D'Amore /* 230*95c635efSGarrett D'Amore * A layout row. 231*95c635efSGarrett D'Amore */ 232*95c635efSGarrett D'Amore struct tbl_row { 233*95c635efSGarrett D'Amore struct tbl_row *next; 234*95c635efSGarrett D'Amore struct tbl_cell *first; 235*95c635efSGarrett D'Amore struct tbl_cell *last; 236*95c635efSGarrett D'Amore }; 237*95c635efSGarrett D'Amore 238*95c635efSGarrett D'Amore enum tbl_datt { 239*95c635efSGarrett D'Amore TBL_DATA_NONE, /* has no data */ 240*95c635efSGarrett D'Amore TBL_DATA_DATA, /* consists of data/string */ 241*95c635efSGarrett D'Amore TBL_DATA_HORIZ, /* horizontal line */ 242*95c635efSGarrett D'Amore TBL_DATA_DHORIZ, /* double-horizontal line */ 243*95c635efSGarrett D'Amore TBL_DATA_NHORIZ, /* squeezed horizontal line */ 244*95c635efSGarrett D'Amore TBL_DATA_NDHORIZ /* squeezed double-horizontal line */ 245*95c635efSGarrett D'Amore }; 246*95c635efSGarrett D'Amore 247*95c635efSGarrett D'Amore /* 248*95c635efSGarrett D'Amore * A cell within a row of data. The "string" field contains the actual 249*95c635efSGarrett D'Amore * string value that's in the cell. The rest is layout. 250*95c635efSGarrett D'Amore */ 251*95c635efSGarrett D'Amore struct tbl_dat { 252*95c635efSGarrett D'Amore struct tbl_cell *layout; /* layout cell */ 253*95c635efSGarrett D'Amore int spans; /* how many spans follow */ 254*95c635efSGarrett D'Amore struct tbl_dat *next; 255*95c635efSGarrett D'Amore char *string; /* data (NULL if not TBL_DATA_DATA) */ 256*95c635efSGarrett D'Amore enum tbl_datt pos; 257*95c635efSGarrett D'Amore }; 258*95c635efSGarrett D'Amore 259*95c635efSGarrett D'Amore enum tbl_spant { 260*95c635efSGarrett D'Amore TBL_SPAN_DATA, /* span consists of data */ 261*95c635efSGarrett D'Amore TBL_SPAN_HORIZ, /* span is horizontal line */ 262*95c635efSGarrett D'Amore TBL_SPAN_DHORIZ /* span is double horizontal line */ 263*95c635efSGarrett D'Amore }; 264*95c635efSGarrett D'Amore 265*95c635efSGarrett D'Amore /* 266*95c635efSGarrett D'Amore * A row of data in a table. 267*95c635efSGarrett D'Amore */ 268*95c635efSGarrett D'Amore struct tbl_span { 269*95c635efSGarrett D'Amore struct tbl *tbl; 270*95c635efSGarrett D'Amore struct tbl_head *head; 271*95c635efSGarrett D'Amore struct tbl_row *layout; /* layout row */ 272*95c635efSGarrett D'Amore struct tbl_dat *first; 273*95c635efSGarrett D'Amore struct tbl_dat *last; 274*95c635efSGarrett D'Amore int line; /* parse line */ 275*95c635efSGarrett D'Amore int flags; 276*95c635efSGarrett D'Amore #define TBL_SPAN_FIRST (1 << 0) 277*95c635efSGarrett D'Amore #define TBL_SPAN_LAST (1 << 1) 278*95c635efSGarrett D'Amore enum tbl_spant pos; 279*95c635efSGarrett D'Amore struct tbl_span *next; 280*95c635efSGarrett D'Amore }; 281*95c635efSGarrett D'Amore 282*95c635efSGarrett D'Amore enum eqn_boxt { 283*95c635efSGarrett D'Amore EQN_ROOT, /* root of parse tree */ 284*95c635efSGarrett D'Amore EQN_TEXT, /* text (number, variable, whatever) */ 285*95c635efSGarrett D'Amore EQN_SUBEXPR, /* nested `eqn' subexpression */ 286*95c635efSGarrett D'Amore EQN_LIST, /* subexpressions list */ 287*95c635efSGarrett D'Amore EQN_MATRIX /* matrix subexpression */ 288*95c635efSGarrett D'Amore }; 289*95c635efSGarrett D'Amore 290*95c635efSGarrett D'Amore enum eqn_markt { 291*95c635efSGarrett D'Amore EQNMARK_NONE = 0, 292*95c635efSGarrett D'Amore EQNMARK_DOT, 293*95c635efSGarrett D'Amore EQNMARK_DOTDOT, 294*95c635efSGarrett D'Amore EQNMARK_HAT, 295*95c635efSGarrett D'Amore EQNMARK_TILDE, 296*95c635efSGarrett D'Amore EQNMARK_VEC, 297*95c635efSGarrett D'Amore EQNMARK_DYAD, 298*95c635efSGarrett D'Amore EQNMARK_BAR, 299*95c635efSGarrett D'Amore EQNMARK_UNDER, 300*95c635efSGarrett D'Amore EQNMARK__MAX 301*95c635efSGarrett D'Amore }; 302*95c635efSGarrett D'Amore 303*95c635efSGarrett D'Amore enum eqn_fontt { 304*95c635efSGarrett D'Amore EQNFONT_NONE = 0, 305*95c635efSGarrett D'Amore EQNFONT_ROMAN, 306*95c635efSGarrett D'Amore EQNFONT_BOLD, 307*95c635efSGarrett D'Amore EQNFONT_FAT, 308*95c635efSGarrett D'Amore EQNFONT_ITALIC, 309*95c635efSGarrett D'Amore EQNFONT__MAX 310*95c635efSGarrett D'Amore }; 311*95c635efSGarrett D'Amore 312*95c635efSGarrett D'Amore enum eqn_post { 313*95c635efSGarrett D'Amore EQNPOS_NONE = 0, 314*95c635efSGarrett D'Amore EQNPOS_OVER, 315*95c635efSGarrett D'Amore EQNPOS_SUP, 316*95c635efSGarrett D'Amore EQNPOS_SUB, 317*95c635efSGarrett D'Amore EQNPOS_TO, 318*95c635efSGarrett D'Amore EQNPOS_FROM, 319*95c635efSGarrett D'Amore EQNPOS__MAX 320*95c635efSGarrett D'Amore }; 321*95c635efSGarrett D'Amore 322*95c635efSGarrett D'Amore enum eqn_pilet { 323*95c635efSGarrett D'Amore EQNPILE_NONE = 0, 324*95c635efSGarrett D'Amore EQNPILE_PILE, 325*95c635efSGarrett D'Amore EQNPILE_CPILE, 326*95c635efSGarrett D'Amore EQNPILE_RPILE, 327*95c635efSGarrett D'Amore EQNPILE_LPILE, 328*95c635efSGarrett D'Amore EQNPILE_COL, 329*95c635efSGarrett D'Amore EQNPILE_CCOL, 330*95c635efSGarrett D'Amore EQNPILE_RCOL, 331*95c635efSGarrett D'Amore EQNPILE_LCOL, 332*95c635efSGarrett D'Amore EQNPILE__MAX 333*95c635efSGarrett D'Amore }; 334*95c635efSGarrett D'Amore 335*95c635efSGarrett D'Amore /* 336*95c635efSGarrett D'Amore * A "box" is a parsed mathematical expression as defined by the eqn.7 337*95c635efSGarrett D'Amore * grammar. 338*95c635efSGarrett D'Amore */ 339*95c635efSGarrett D'Amore struct eqn_box { 340*95c635efSGarrett D'Amore int size; /* font size of expression */ 341*95c635efSGarrett D'Amore #define EQN_DEFSIZE INT_MIN 342*95c635efSGarrett D'Amore enum eqn_boxt type; /* type of node */ 343*95c635efSGarrett D'Amore struct eqn_box *first; /* first child node */ 344*95c635efSGarrett D'Amore struct eqn_box *last; /* last child node */ 345*95c635efSGarrett D'Amore struct eqn_box *next; /* node sibling */ 346*95c635efSGarrett D'Amore struct eqn_box *parent; /* node sibling */ 347*95c635efSGarrett D'Amore char *text; /* text (or NULL) */ 348*95c635efSGarrett D'Amore char *left; 349*95c635efSGarrett D'Amore char *right; 350*95c635efSGarrett D'Amore enum eqn_post pos; /* position of next box */ 351*95c635efSGarrett D'Amore enum eqn_markt mark; /* a mark about the box */ 352*95c635efSGarrett D'Amore enum eqn_fontt font; /* font of box */ 353*95c635efSGarrett D'Amore enum eqn_pilet pile; /* equation piling */ 354*95c635efSGarrett D'Amore }; 355*95c635efSGarrett D'Amore 356*95c635efSGarrett D'Amore /* 357*95c635efSGarrett D'Amore * An equation consists of a tree of expressions starting at a given 358*95c635efSGarrett D'Amore * line and position. 359*95c635efSGarrett D'Amore */ 360*95c635efSGarrett D'Amore struct eqn { 361*95c635efSGarrett D'Amore char *name; /* identifier (or NULL) */ 362*95c635efSGarrett D'Amore struct eqn_box *root; /* root mathematical expression */ 363*95c635efSGarrett D'Amore int ln; /* invocation line */ 364*95c635efSGarrett D'Amore int pos; /* invocation position */ 365*95c635efSGarrett D'Amore }; 366*95c635efSGarrett D'Amore 367*95c635efSGarrett D'Amore /* 368*95c635efSGarrett D'Amore * The type of parse sequence. This value is usually passed via the 369*95c635efSGarrett D'Amore * mandoc(1) command line of -man and -mdoc. It's almost exclusively 370*95c635efSGarrett D'Amore * -mandoc but the others have been retained for compatibility. 371*95c635efSGarrett D'Amore */ 372*95c635efSGarrett D'Amore enum mparset { 373*95c635efSGarrett D'Amore MPARSE_AUTO, /* magically determine the document type */ 374*95c635efSGarrett D'Amore MPARSE_MDOC, /* assume -mdoc */ 375*95c635efSGarrett D'Amore MPARSE_MAN /* assume -man */ 376*95c635efSGarrett D'Amore }; 377*95c635efSGarrett D'Amore 378*95c635efSGarrett D'Amore enum mandoc_esc { 379*95c635efSGarrett D'Amore ESCAPE_ERROR = 0, /* bail! unparsable escape */ 380*95c635efSGarrett D'Amore ESCAPE_IGNORE, /* escape to be ignored */ 381*95c635efSGarrett D'Amore ESCAPE_SPECIAL, /* a regular special character */ 382*95c635efSGarrett D'Amore ESCAPE_FONT, /* a generic font mode */ 383*95c635efSGarrett D'Amore ESCAPE_FONTBOLD, /* bold font mode */ 384*95c635efSGarrett D'Amore ESCAPE_FONTITALIC, /* italic font mode */ 385*95c635efSGarrett D'Amore ESCAPE_FONTROMAN, /* roman font mode */ 386*95c635efSGarrett D'Amore ESCAPE_FONTPREV, /* previous font mode */ 387*95c635efSGarrett D'Amore ESCAPE_NUMBERED, /* a numbered glyph */ 388*95c635efSGarrett D'Amore ESCAPE_UNICODE, /* a unicode codepoint */ 389*95c635efSGarrett D'Amore ESCAPE_NOSPACE /* suppress space if the last on a line */ 390*95c635efSGarrett D'Amore }; 391*95c635efSGarrett D'Amore 392*95c635efSGarrett D'Amore typedef void (*mandocmsg)(enum mandocerr, enum mandoclevel, 393*95c635efSGarrett D'Amore const char *, int, int, const char *); 394*95c635efSGarrett D'Amore 395*95c635efSGarrett D'Amore struct mparse; 396*95c635efSGarrett D'Amore struct mchars; 397*95c635efSGarrett D'Amore struct mdoc; 398*95c635efSGarrett D'Amore struct man; 399*95c635efSGarrett D'Amore 400*95c635efSGarrett D'Amore __BEGIN_DECLS 401*95c635efSGarrett D'Amore 402*95c635efSGarrett D'Amore void *mandoc_calloc(size_t, size_t); 403*95c635efSGarrett D'Amore enum mandoc_esc mandoc_escape(const char **, const char **, int *); 404*95c635efSGarrett D'Amore void *mandoc_malloc(size_t); 405*95c635efSGarrett D'Amore void *mandoc_realloc(void *, size_t); 406*95c635efSGarrett D'Amore char *mandoc_strdup(const char *); 407*95c635efSGarrett D'Amore char *mandoc_strndup(const char *, size_t); 408*95c635efSGarrett D'Amore struct mchars *mchars_alloc(void); 409*95c635efSGarrett D'Amore void mchars_free(struct mchars *); 410*95c635efSGarrett D'Amore char mchars_num2char(const char *, size_t); 411*95c635efSGarrett D'Amore int mchars_num2uc(const char *, size_t); 412*95c635efSGarrett D'Amore int mchars_spec2cp(const struct mchars *, 413*95c635efSGarrett D'Amore const char *, size_t); 414*95c635efSGarrett D'Amore const char *mchars_spec2str(const struct mchars *, 415*95c635efSGarrett D'Amore const char *, size_t, size_t *); 416*95c635efSGarrett D'Amore struct mparse *mparse_alloc(enum mparset, 417*95c635efSGarrett D'Amore enum mandoclevel, mandocmsg, void *); 418*95c635efSGarrett D'Amore void mparse_free(struct mparse *); 419*95c635efSGarrett D'Amore void mparse_keep(struct mparse *); 420*95c635efSGarrett D'Amore enum mandoclevel mparse_readfd(struct mparse *, int, const char *); 421*95c635efSGarrett D'Amore enum mandoclevel mparse_readmem(struct mparse *, const void *, size_t, 422*95c635efSGarrett D'Amore const char *); 423*95c635efSGarrett D'Amore void mparse_reset(struct mparse *); 424*95c635efSGarrett D'Amore void mparse_result(struct mparse *, 425*95c635efSGarrett D'Amore struct mdoc **, struct man **); 426*95c635efSGarrett D'Amore const char *mparse_getkeep(const struct mparse *); 427*95c635efSGarrett D'Amore const char *mparse_strerror(enum mandocerr); 428*95c635efSGarrett D'Amore const char *mparse_strlevel(enum mandoclevel); 429*95c635efSGarrett D'Amore 430*95c635efSGarrett D'Amore __END_DECLS 431*95c635efSGarrett D'Amore 432*95c635efSGarrett D'Amore #endif /*!MANDOC_H*/ 433