Annotation of mandoc/mandoc.h, Revision 1.260
1.260 ! schwarze 1: /* $Id: mandoc.h,v 1.259 2018/12/14 01:18:25 schwarze Exp $ */
1.1 kristaps 2: /*
1.160 schwarze 3: * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.258 schwarze 4: * Copyright (c) 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
1.1 kristaps 5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
1.202 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.1 kristaps 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.202 schwarze 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.1 kristaps 13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.258 schwarze 17: *
18: * Error handling, escape sequence, and character utilities.
1.1 kristaps 19: */
1.7 kristaps 20:
21: #define ASCII_NBRSP 31 /* non-breaking space */
22: #define ASCII_HYPH 30 /* breakable hyphen */
1.115 schwarze 23: #define ASCII_BREAK 29 /* breakable zero-width space */
1.7 kristaps 24:
1.22 kristaps 25: /*
26: * Status level. This refers to both internal status (i.e., whilst
27: * running, when warnings/errors are reported) and an indicator of a
28: * threshold of when to halt (when said internal state exceeds the
29: * threshold).
30: */
1.18 schwarze 31: enum mandoclevel {
32: MANDOCLEVEL_OK = 0,
1.216 schwarze 33: MANDOCLEVEL_STYLE, /* style suggestions */
1.22 kristaps 34: MANDOCLEVEL_WARNING, /* warnings: syntax, whitespace, etc. */
35: MANDOCLEVEL_ERROR, /* input has been thrown away */
1.183 schwarze 36: MANDOCLEVEL_UNSUPP, /* input needs unimplemented features */
1.22 kristaps 37: MANDOCLEVEL_BADARG, /* bad argument in invocation */
38: MANDOCLEVEL_SYSERR, /* system error */
1.18 schwarze 39: MANDOCLEVEL_MAX
40: };
41:
1.22 kristaps 42: /*
43: * All possible things that can go wrong within a parse, be it libroff,
44: * libmdoc, or libman.
45: */
1.1 kristaps 46: enum mandocerr {
47: MANDOCERR_OK,
1.216 schwarze 48:
1.233 schwarze 49: MANDOCERR_BASE, /* ===== start of base system conventions ===== */
1.217 schwarze 50:
1.229 schwarze 51: MANDOCERR_MDOCDATE, /* Mdocdate found: Dd ... */
52: MANDOCERR_MDOCDATE_MISSING, /* Mdocdate missing: Dd ... */
1.235 schwarze 53: MANDOCERR_ARCH_BAD, /* unknown architecture: Dt ... arch */
1.234 schwarze 54: MANDOCERR_OS_ARG, /* operating system explicitly specified: Os ... */
1.233 schwarze 55: MANDOCERR_RCS_MISSING, /* RCS id missing */
1.238 schwarze 56: MANDOCERR_XR_BAD, /* referenced manual not found: Xr name sec */
1.233 schwarze 57:
58: MANDOCERR_STYLE, /* ===== start of style suggestions ===== */
59:
1.229 schwarze 60: MANDOCERR_DATE_LEGACY, /* legacy man(7) date format: Dd ... */
1.248 schwarze 61: MANDOCERR_DATE_NORM, /* normalizing date format to: ... */
1.243 schwarze 62: MANDOCERR_TITLE_CASE, /* lower case character in document title */
1.232 schwarze 63: MANDOCERR_RCS_REP, /* duplicate RCS id: ... */
1.246 schwarze 64: MANDOCERR_SEC_TYPO, /* possible typo in section name: Sh ... */
1.243 schwarze 65: MANDOCERR_ARG_QUOTE, /* unterminated quoted argument */
1.217 schwarze 66: MANDOCERR_MACRO_USELESS, /* useless macro: macro */
1.218 schwarze 67: MANDOCERR_BX, /* consider using OS macro: macro */
1.224 schwarze 68: MANDOCERR_ER_ORDER, /* errnos out of order: Er ... */
69: MANDOCERR_ER_REP, /* duplicate errno: Er ... */
1.241 schwarze 70: MANDOCERR_DELIM, /* trailing delimiter: macro ... */
71: MANDOCERR_DELIM_NB, /* no blank before trailing delimiter: macro ... */
1.243 schwarze 72: MANDOCERR_FI_SKIP, /* fill mode already enabled, skipping: fi */
73: MANDOCERR_NF_SKIP, /* fill mode already disabled, skipping: nf */
1.247 schwarze 74: MANDOCERR_DASHDASH, /* verbatim "--", maybe consider using \(em */
1.228 schwarze 75: MANDOCERR_FUNC, /* function name without markup: name() */
1.243 schwarze 76: MANDOCERR_SPACE_EOL, /* whitespace at end of input line */
77: MANDOCERR_COMMENT_BAD, /* bad comment style */
1.13 schwarze 78:
1.21 kristaps 79: MANDOCERR_WARNING, /* ===== start of warnings ===== */
1.32 kristaps 80:
81: /* related to the prologue */
1.152 schwarze 82: MANDOCERR_DT_NOTITLE, /* missing manual title, using UNTITLED: line */
83: MANDOCERR_TH_NOTITLE, /* missing manual title, using "": [macro] */
84: MANDOCERR_MSEC_MISSING, /* missing manual section, using "": macro */
1.151 schwarze 85: MANDOCERR_MSEC_BAD, /* unknown manual section: Dt ... section */
1.125 schwarze 86: MANDOCERR_DATE_MISSING, /* missing date, using today's date */
87: MANDOCERR_DATE_BAD, /* cannot parse date, using it verbatim: date */
1.240 schwarze 88: MANDOCERR_DATE_FUTURE, /* date in the future, using it anyway: date */
1.152 schwarze 89: MANDOCERR_OS_MISSING, /* missing Os macro, using "" */
90: MANDOCERR_PROLOG_LATE, /* late prologue macro: macro */
91: MANDOCERR_PROLOG_ORDER, /* prologue macros out of order: macros */
1.32 kristaps 92:
93: /* related to document structure */
1.151 schwarze 94: MANDOCERR_SO, /* .so is fragile, better use ln(1): so path */
1.122 schwarze 95: MANDOCERR_DOC_EMPTY, /* no document body */
1.125 schwarze 96: MANDOCERR_SEC_BEFORE, /* content before first section header: macro */
1.151 schwarze 97: MANDOCERR_NAMESEC_FIRST, /* first section is not NAME: Sh title */
1.212 schwarze 98: MANDOCERR_NAMESEC_NONM, /* NAME section without Nm before Nd */
1.201 schwarze 99: MANDOCERR_NAMESEC_NOND, /* NAME section without description */
100: MANDOCERR_NAMESEC_ND, /* description not at the end of NAME */
101: MANDOCERR_NAMESEC_BAD, /* bad NAME section content: macro */
1.212 schwarze 102: MANDOCERR_NAMESEC_PUNCT, /* missing comma before name: Nm name */
1.195 schwarze 103: MANDOCERR_ND_EMPTY, /* missing description line, using "" */
1.215 schwarze 104: MANDOCERR_ND_LATE, /* description line outside NAME section */
1.151 schwarze 105: MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */
106: MANDOCERR_SEC_REP, /* duplicate section title: Sh title */
107: MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */
1.239 schwarze 108: MANDOCERR_XR_SELF, /* cross reference to self: Xr name sec */
1.155 schwarze 109: MANDOCERR_XR_ORDER, /* unusual Xr order: ... after ... */
110: MANDOCERR_XR_PUNCT, /* unusual Xr punctuation: ... after ... */
1.154 schwarze 111: MANDOCERR_AN_MISSING, /* AUTHORS section without An macro */
1.32 kristaps 112:
113: /* related to macros and nesting */
1.126 schwarze 114: MANDOCERR_MACRO_OBS, /* obsolete macro: macro */
1.172 schwarze 115: MANDOCERR_MACRO_CALL, /* macro neither callable nor escaped: macro */
1.127 schwarze 116: MANDOCERR_PAR_SKIP, /* skipping paragraph macro: macro ... */
117: MANDOCERR_PAR_MOVE, /* moving paragraph macro out of list: macro */
1.128 schwarze 118: MANDOCERR_NS_SKIP, /* skipping no-space macro */
1.141 schwarze 119: MANDOCERR_BLK_NEST, /* blocks badly nested: macro ... */
1.128 schwarze 120: MANDOCERR_BD_NEST, /* nested displays are not portable: macro ... */
1.129 schwarze 121: MANDOCERR_BL_MOVE, /* moving content out of list: macro */
1.237 schwarze 122: MANDOCERR_TA_LINE, /* first macro on line: Ta */
1.141 schwarze 123: MANDOCERR_BLK_LINE, /* line scope broken: macro breaks macro */
1.222 schwarze 124: MANDOCERR_BLK_BLANK, /* skipping blank line in line scope */
1.32 kristaps 125:
1.131 schwarze 126: /* related to missing arguments */
127: MANDOCERR_REQ_EMPTY, /* skipping empty request: request */
128: MANDOCERR_COND_EMPTY, /* conditional request controls empty scope */
1.130 schwarze 129: MANDOCERR_MACRO_EMPTY, /* skipping empty macro: macro */
1.198 schwarze 130: MANDOCERR_BLK_EMPTY, /* empty block: macro */
1.135 schwarze 131: MANDOCERR_ARG_EMPTY, /* empty argument, using 0n: macro arg */
1.151 schwarze 132: MANDOCERR_BD_NOTYPE, /* missing display type, using -ragged: Bd */
133: MANDOCERR_BL_LATETYPE, /* list type is not the first argument: Bl arg */
1.210 schwarze 134: MANDOCERR_BL_NOWIDTH, /* missing -width in -tag list, using 6n */
1.151 schwarze 135: MANDOCERR_EX_NONAME, /* missing utility name, using "": Ex */
1.197 schwarze 136: MANDOCERR_FO_NOHEAD, /* missing function name, using "": Fo */
1.151 schwarze 137: MANDOCERR_IT_NOHEAD, /* empty head in list item: Bl -type It */
138: MANDOCERR_IT_NOBODY, /* empty list item: Bl -type It */
1.237 schwarze 139: MANDOCERR_IT_NOARG, /* missing argument, using next line: Bl -c It */
1.151 schwarze 140: MANDOCERR_BF_NOFONT, /* missing font type, using \fR: Bf */
141: MANDOCERR_BF_BADFONT, /* unknown font type, using \fR: Bf font */
1.173 schwarze 142: MANDOCERR_PF_SKIP, /* nothing follows prefix: Pf arg */
1.196 schwarze 143: MANDOCERR_RS_EMPTY, /* empty reference block: Rs */
1.211 schwarze 144: MANDOCERR_XR_NOSEC, /* missing section argument: Xr arg */
1.133 schwarze 145: MANDOCERR_ARG_STD, /* missing -std argument, adding it: macro */
1.199 schwarze 146: MANDOCERR_OP_EMPTY, /* missing option string, using "": OP */
147: MANDOCERR_UR_NOHEAD, /* missing resource identifier, using "": UR */
1.162 schwarze 148: MANDOCERR_EQN_NOBOX, /* missing eqn box, using "": op */
1.13 schwarze 149:
1.137 schwarze 150: /* related to bad arguments */
1.135 schwarze 151: MANDOCERR_ARG_REP, /* duplicate argument: macro arg */
1.149 schwarze 152: MANDOCERR_AN_REP, /* skipping duplicate argument: An -arg */
1.151 schwarze 153: MANDOCERR_BD_REP, /* skipping duplicate display type: Bd -type */
154: MANDOCERR_BL_REP, /* skipping duplicate list type: Bl -type */
1.149 schwarze 155: MANDOCERR_BL_SKIPW, /* skipping -width argument: Bl -type */
1.200 schwarze 156: MANDOCERR_BL_COL, /* wrong number of cells */
1.151 schwarze 157: MANDOCERR_AT_BAD, /* unknown AT&T UNIX version: At version */
1.156 schwarze 158: MANDOCERR_FA_COMMA, /* comma in function argument: arg */
1.161 schwarze 159: MANDOCERR_FN_PAREN, /* parenthesis in function name: arg */
1.225 schwarze 160: MANDOCERR_LB_BAD, /* unknown library name: Lb ... */
1.140 schwarze 161: MANDOCERR_RS_BAD, /* invalid content in Rs block: macro */
1.136 schwarze 162: MANDOCERR_SM_BAD, /* invalid Boolean argument: macro arg */
1.253 schwarze 163: MANDOCERR_CHAR_FONT, /* argument contains two font escapes */
1.151 schwarze 164: MANDOCERR_FT_BAD, /* unknown font, skipping request: ft font */
1.200 schwarze 165: MANDOCERR_TR_ODD, /* odd number of characters in request: tr char */
1.32 kristaps 166:
167: /* related to plain text */
1.137 schwarze 168: MANDOCERR_FI_BLANK, /* blank line in fill mode, using .sp */
169: MANDOCERR_FI_TAB, /* tab in filled text */
1.214 schwarze 170: MANDOCERR_EOS, /* new sentence, new line */
1.137 schwarze 171: MANDOCERR_ESC_BAD, /* invalid escape sequence: esc */
172: MANDOCERR_STR_UNDEF, /* undefined string, using "": name */
1.79 kristaps 173:
1.189 schwarze 174: /* related to tables */
175: MANDOCERR_TBLLAYOUT_SPAN, /* tbl line starts with span */
176: MANDOCERR_TBLLAYOUT_DOWN, /* tbl column starts with span */
177: MANDOCERR_TBLLAYOUT_VERT, /* skipping vertical bar in tbl layout */
178:
1.32 kristaps 179: MANDOCERR_ERROR, /* ===== start of errors ===== */
180:
1.42 kristaps 181: /* related to tables */
1.187 schwarze 182: MANDOCERR_TBLOPT_ALPHA, /* non-alphabetic character in tbl options */
183: MANDOCERR_TBLOPT_BAD, /* skipping unknown tbl option: option */
1.191 schwarze 184: MANDOCERR_TBLOPT_NOARG, /* missing tbl option argument: option */
185: MANDOCERR_TBLOPT_ARGSZ, /* wrong tbl option argument size: option */
1.189 schwarze 186: MANDOCERR_TBLLAYOUT_NONE, /* empty tbl layout */
187: MANDOCERR_TBLLAYOUT_CHAR, /* invalid character in tbl layout: char */
188: MANDOCERR_TBLLAYOUT_PAR, /* unmatched parenthesis in tbl layout */
1.191 schwarze 189: MANDOCERR_TBLDATA_NONE, /* tbl without any data cells */
190: MANDOCERR_TBLDATA_SPAN, /* ignoring data in spanned tbl cell: data */
191: MANDOCERR_TBLDATA_EXTRA, /* ignoring extra tbl data cells: data */
192: MANDOCERR_TBLDATA_BLK, /* data block open at end of tbl: macro */
1.42 kristaps 193:
1.141 schwarze 194: /* related to document structure and macros */
1.179 schwarze 195: MANDOCERR_FILE, /* cannot open file */
1.243 schwarze 196: MANDOCERR_PROLOG_REP, /* duplicate prologue macro: macro */
197: MANDOCERR_DT_LATE, /* skipping late title macro: Dt args */
1.33 schwarze 198: MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
1.185 schwarze 199: MANDOCERR_CHAR_BAD, /* skipping bad character: number */
1.151 schwarze 200: MANDOCERR_MACRO, /* skipping unknown macro: macro */
1.250 schwarze 201: MANDOCERR_REQ_NOMAC, /* skipping request outside macro: ... */
1.183 schwarze 202: MANDOCERR_REQ_INSEC, /* skipping insecure request: request */
1.151 schwarze 203: MANDOCERR_IT_STRAY, /* skipping item outside list: It ... */
204: MANDOCERR_TA_STRAY, /* skipping column outside column list: Ta */
1.141 schwarze 205: MANDOCERR_BLK_NOTOPEN, /* skipping end of block that is not open */
1.186 schwarze 206: MANDOCERR_RE_NOTOPEN, /* fewer RS blocks open, skipping: RE arg */
1.141 schwarze 207: MANDOCERR_BLK_BROKEN, /* inserting missing end of block: macro ... */
208: MANDOCERR_BLK_NOEND, /* appending missing end of block: macro */
209:
210: /* related to request and macro arguments */
1.151 schwarze 211: MANDOCERR_NAMESC, /* escaped character not allowed in a name: name */
1.250 schwarze 212: MANDOCERR_ARG_UNDEF, /* using macro argument outside macro */
213: MANDOCERR_ARG_NONUM, /* argument number is not numeric */
1.170 schwarze 214: MANDOCERR_BD_FILE, /* NOT IMPLEMENTED: Bd -file */
1.207 schwarze 215: MANDOCERR_BD_NOARG, /* skipping display without arguments: Bd */
1.151 schwarze 216: MANDOCERR_BL_NOTYPE, /* missing list type, using -item: Bl */
1.223 schwarze 217: MANDOCERR_CE_NONUM, /* argument is not numeric, using 1: ce ... */
1.253 schwarze 218: MANDOCERR_CHAR_ARG, /* argument is not a character: char ... */
1.151 schwarze 219: MANDOCERR_NM_NONAME, /* missing manual name, using "": Nm */
1.144 schwarze 220: MANDOCERR_OS_UNAME, /* uname(3) system call failed, using UNKNOWN */
1.151 schwarze 221: MANDOCERR_ST_BAD, /* unknown standard specifier: St standard */
1.144 schwarze 222: MANDOCERR_IT_NONUM, /* skipping request without numeric argument */
1.250 schwarze 223: MANDOCERR_SHIFT, /* excessive shift: ..., but max is ... */
1.180 schwarze 224: MANDOCERR_SO_PATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */
1.181 schwarze 225: MANDOCERR_SO_FAIL, /* .so request failed */
1.134 schwarze 226: MANDOCERR_ARG_SKIP, /* skipping all arguments: macro args */
227: MANDOCERR_ARG_EXCESS, /* skipping excess arguments: macro ... args */
1.164 kristaps 228: MANDOCERR_DIVZERO, /* divide by zero */
1.183 schwarze 229:
230: MANDOCERR_UNSUPP, /* ===== start of unsupported features ===== */
231:
232: MANDOCERR_TOOLARGE, /* input too large */
1.185 schwarze 233: MANDOCERR_CHAR_UNSUPP, /* unsupported control character: number */
1.183 schwarze 234: MANDOCERR_REQ_UNSUPP, /* unsupported roff request: request */
1.252 schwarze 235: MANDOCERR_WHILE_NEST, /* nested .while loops */
236: MANDOCERR_WHILE_OUTOF, /* end of scope with open .while loop */
237: MANDOCERR_WHILE_INTO, /* end of .while loop in inner scope */
238: MANDOCERR_WHILE_FAIL, /* cannot continue this .while loop */
1.191 schwarze 239: MANDOCERR_TBLOPT_EQN, /* eqn delim option in tbl: arg */
1.189 schwarze 240: MANDOCERR_TBLLAYOUT_MOD, /* unsupported tbl layout modifier: m */
1.183 schwarze 241: MANDOCERR_TBLMACRO, /* ignoring macro in table: macro */
1.113 schwarze 242:
1.1 kristaps 243: MANDOCERR_MAX
1.16 kristaps 244: };
1.22 kristaps 245:
1.70 kristaps 246: enum mandoc_esc {
247: ESCAPE_ERROR = 0, /* bail! unparsable escape */
248: ESCAPE_IGNORE, /* escape to be ignored */
249: ESCAPE_SPECIAL, /* a regular special character */
250: ESCAPE_FONT, /* a generic font mode */
251: ESCAPE_FONTBOLD, /* bold font mode */
252: ESCAPE_FONTITALIC, /* italic font mode */
1.109 schwarze 253: ESCAPE_FONTBI, /* bold italic font mode */
1.70 kristaps 254: ESCAPE_FONTROMAN, /* roman font mode */
1.254 schwarze 255: ESCAPE_FONTCW, /* constant width font mode */
1.70 kristaps 256: ESCAPE_FONTPREV, /* previous font mode */
257: ESCAPE_NUMBERED, /* a numbered glyph */
1.75 kristaps 258: ESCAPE_UNICODE, /* a unicode codepoint */
1.249 schwarze 259: ESCAPE_DEVICE, /* print the output device name */
1.230 schwarze 260: ESCAPE_BREAK, /* break the output line */
1.102 schwarze 261: ESCAPE_NOSPACE, /* suppress space if the last on a line */
1.220 schwarze 262: ESCAPE_HORIZ, /* horizontal movement */
1.221 schwarze 263: ESCAPE_HLINE, /* horizontal line drawing */
1.184 schwarze 264: ESCAPE_SKIPCHAR, /* skip the next character */
265: ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */
1.70 kristaps 266: };
267:
1.176 schwarze 268:
1.112 schwarze 269: enum mandoc_esc mandoc_escape(const char **, const char **, int *);
1.259 schwarze 270: void mandoc_msg_setoutfile(FILE *);
271: const char *mandoc_msg_getinfilename(void);
272: void mandoc_msg_setinfilename(const char *);
273: enum mandocerr mandoc_msg_getmin(void);
274: void mandoc_msg_setmin(enum mandocerr);
275: enum mandoclevel mandoc_msg_getrc(void);
276: void mandoc_msg_setrc(enum mandoclevel);
1.260 ! schwarze 277: void mandoc_msg(enum mandocerr, int, int, const char *, ...)
! 278: __attribute__((__format__ (__printf__, 4, 5)));
1.206 schwarze 279: void mchars_alloc(void);
280: void mchars_free(void);
1.168 schwarze 281: int mchars_num2char(const char *, size_t);
1.166 schwarze 282: const char *mchars_uc2str(int);
1.76 kristaps 283: int mchars_num2uc(const char *, size_t);
1.206 schwarze 284: int mchars_spec2cp(const char *, size_t);
285: const char *mchars_spec2str(const char *, size_t, size_t *);
CVSweb