Annotation of mandoc/mandoc_msg.c, Revision 1.1
1.1 ! schwarze 1: /* $OpenBSD$ */
! 2: /*
! 3: * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
! 4: * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
! 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: *
! 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
! 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
! 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.
! 17: */
! 18: #include <stdarg.h>
! 19: #include <stdio.h>
! 20: #include <stdlib.h>
! 21:
! 22: #include "mandoc.h"
! 23:
! 24: static const enum mandocerr lowest_type[MANDOCLEVEL_MAX] = {
! 25: MANDOCERR_OK,
! 26: MANDOCERR_OK,
! 27: MANDOCERR_WARNING,
! 28: MANDOCERR_ERROR,
! 29: MANDOCERR_UNSUPP,
! 30: MANDOCERR_MAX,
! 31: MANDOCERR_MAX
! 32: };
! 33:
! 34: static const char *const level_name[MANDOCLEVEL_MAX] = {
! 35: "SUCCESS",
! 36: "STYLE",
! 37: "WARNING",
! 38: "ERROR",
! 39: "UNSUPP",
! 40: "BADARG",
! 41: "SYSERR"
! 42: };
! 43:
! 44: static const char *const type_message[MANDOCERR_MAX] = {
! 45: "ok",
! 46:
! 47: "base system convention",
! 48:
! 49: "Mdocdate found",
! 50: "Mdocdate missing",
! 51: "unknown architecture",
! 52: "operating system explicitly specified",
! 53: "RCS id missing",
! 54: "referenced manual not found",
! 55:
! 56: "generic style suggestion",
! 57:
! 58: "legacy man(7) date format",
! 59: "normalizing date format to",
! 60: "lower case character in document title",
! 61: "duplicate RCS id",
! 62: "possible typo in section name",
! 63: "unterminated quoted argument",
! 64: "useless macro",
! 65: "consider using OS macro",
! 66: "errnos out of order",
! 67: "duplicate errno",
! 68: "trailing delimiter",
! 69: "no blank before trailing delimiter",
! 70: "fill mode already enabled, skipping",
! 71: "fill mode already disabled, skipping",
! 72: "verbatim \"--\", maybe consider using \\(em",
! 73: "function name without markup",
! 74: "whitespace at end of input line",
! 75: "bad comment style",
! 76:
! 77: "generic warning",
! 78:
! 79: /* related to the prologue */
! 80: "missing manual title, using UNTITLED",
! 81: "missing manual title, using \"\"",
! 82: "missing manual section, using \"\"",
! 83: "unknown manual section",
! 84: "missing date, using today's date",
! 85: "cannot parse date, using it verbatim",
! 86: "date in the future, using it anyway",
! 87: "missing Os macro, using \"\"",
! 88: "late prologue macro",
! 89: "prologue macros out of order",
! 90:
! 91: /* related to document structure */
! 92: ".so is fragile, better use ln(1)",
! 93: "no document body",
! 94: "content before first section header",
! 95: "first section is not \"NAME\"",
! 96: "NAME section without Nm before Nd",
! 97: "NAME section without description",
! 98: "description not at the end of NAME",
! 99: "bad NAME section content",
! 100: "missing comma before name",
! 101: "missing description line, using \"\"",
! 102: "description line outside NAME section",
! 103: "sections out of conventional order",
! 104: "duplicate section title",
! 105: "unexpected section",
! 106: "cross reference to self",
! 107: "unusual Xr order",
! 108: "unusual Xr punctuation",
! 109: "AUTHORS section without An macro",
! 110:
! 111: /* related to macros and nesting */
! 112: "obsolete macro",
! 113: "macro neither callable nor escaped",
! 114: "skipping paragraph macro",
! 115: "moving paragraph macro out of list",
! 116: "skipping no-space macro",
! 117: "blocks badly nested",
! 118: "nested displays are not portable",
! 119: "moving content out of list",
! 120: "first macro on line",
! 121: "line scope broken",
! 122: "skipping blank line in line scope",
! 123:
! 124: /* related to missing macro arguments */
! 125: "skipping empty request",
! 126: "conditional request controls empty scope",
! 127: "skipping empty macro",
! 128: "empty block",
! 129: "empty argument, using 0n",
! 130: "missing display type, using -ragged",
! 131: "list type is not the first argument",
! 132: "missing -width in -tag list, using 6n",
! 133: "missing utility name, using \"\"",
! 134: "missing function name, using \"\"",
! 135: "empty head in list item",
! 136: "empty list item",
! 137: "missing argument, using next line",
! 138: "missing font type, using \\fR",
! 139: "unknown font type, using \\fR",
! 140: "nothing follows prefix",
! 141: "empty reference block",
! 142: "missing section argument",
! 143: "missing -std argument, adding it",
! 144: "missing option string, using \"\"",
! 145: "missing resource identifier, using \"\"",
! 146: "missing eqn box, using \"\"",
! 147:
! 148: /* related to bad macro arguments */
! 149: "duplicate argument",
! 150: "skipping duplicate argument",
! 151: "skipping duplicate display type",
! 152: "skipping duplicate list type",
! 153: "skipping -width argument",
! 154: "wrong number of cells",
! 155: "unknown AT&T UNIX version",
! 156: "comma in function argument",
! 157: "parenthesis in function name",
! 158: "unknown library name",
! 159: "invalid content in Rs block",
! 160: "invalid Boolean argument",
! 161: "argument contains two font escapes",
! 162: "unknown font, skipping request",
! 163: "odd number of characters in request",
! 164:
! 165: /* related to plain text */
! 166: "blank line in fill mode, using .sp",
! 167: "tab in filled text",
! 168: "new sentence, new line",
! 169: "invalid escape sequence",
! 170: "undefined string, using \"\"",
! 171:
! 172: /* related to tables */
! 173: "tbl line starts with span",
! 174: "tbl column starts with span",
! 175: "skipping vertical bar in tbl layout",
! 176:
! 177: "generic error",
! 178:
! 179: /* related to tables */
! 180: "non-alphabetic character in tbl options",
! 181: "skipping unknown tbl option",
! 182: "missing tbl option argument",
! 183: "wrong tbl option argument size",
! 184: "empty tbl layout",
! 185: "invalid character in tbl layout",
! 186: "unmatched parenthesis in tbl layout",
! 187: "tbl without any data cells",
! 188: "ignoring data in spanned tbl cell",
! 189: "ignoring extra tbl data cells",
! 190: "data block open at end of tbl",
! 191:
! 192: /* related to document structure and macros */
! 193: NULL,
! 194: "duplicate prologue macro",
! 195: "skipping late title macro",
! 196: "input stack limit exceeded, infinite loop?",
! 197: "skipping bad character",
! 198: "skipping unknown macro",
! 199: "ignoring request outside macro",
! 200: "skipping insecure request",
! 201: "skipping item outside list",
! 202: "skipping column outside column list",
! 203: "skipping end of block that is not open",
! 204: "fewer RS blocks open, skipping",
! 205: "inserting missing end of block",
! 206: "appending missing end of block",
! 207:
! 208: /* related to request and macro arguments */
! 209: "escaped character not allowed in a name",
! 210: "using macro argument outside macro",
! 211: "argument number is not numeric",
! 212: "NOT IMPLEMENTED: Bd -file",
! 213: "skipping display without arguments",
! 214: "missing list type, using -item",
! 215: "argument is not numeric, using 1",
! 216: "argument is not a character",
! 217: "missing manual name, using \"\"",
! 218: "uname(3) system call failed, using UNKNOWN",
! 219: "unknown standard specifier",
! 220: "skipping request without numeric argument",
! 221: "excessive shift",
! 222: "NOT IMPLEMENTED: .so with absolute path or \"..\"",
! 223: ".so request failed",
! 224: "skipping all arguments",
! 225: "skipping excess arguments",
! 226: "divide by zero",
! 227:
! 228: "unsupported feature",
! 229: "input too large",
! 230: "unsupported control character",
! 231: "unsupported roff request",
! 232: "nested .while loops",
! 233: "end of scope with open .while loop",
! 234: "end of .while loop in inner scope",
! 235: "cannot continue this .while loop",
! 236: "eqn delim option in tbl",
! 237: "unsupported tbl layout modifier",
! 238: "ignoring macro in table",
! 239: };
! 240:
! 241: static FILE *fileptr = stderr;
! 242: static const char *filename = NULL;
! 243: static enum mandocerr min_type = MANDOCERR_MAX;
! 244: static enum mandoclevel rc = MANDOCLEVEL_OK;
! 245:
! 246:
! 247: void
! 248: mandoc_msg_setoutfile(FILE *fp)
! 249: {
! 250: fileptr = fp;
! 251: }
! 252:
! 253: const char *
! 254: mandoc_msg_getinfilename(void)
! 255: {
! 256: return filename;
! 257: }
! 258:
! 259: void
! 260: mandoc_msg_setinfilename(const char *fn)
! 261: {
! 262: filename = fn;
! 263: }
! 264:
! 265: enum mandocerr
! 266: mandoc_msg_getmin(void)
! 267: {
! 268: return min_type;
! 269: }
! 270:
! 271: void
! 272: mandoc_msg_setmin(enum mandocerr t)
! 273: {
! 274: min_type = t;
! 275: }
! 276:
! 277: enum mandoclevel
! 278: mandoc_msg_getrc(void)
! 279: {
! 280: return rc;
! 281: }
! 282:
! 283: void
! 284: mandoc_msg_setrc(enum mandoclevel level)
! 285: {
! 286: if (rc < level)
! 287: rc = level;
! 288: }
! 289:
! 290: void
! 291: mandoc_vmsg(enum mandocerr t, void *dummy, int line, int col,
! 292: const char *fmt, ...)
! 293: {
! 294: va_list ap;
! 295: enum mandoclevel level;
! 296:
! 297: if (t < min_type && t != MANDOCERR_FILE)
! 298: return;
! 299:
! 300: level = MANDOCLEVEL_UNSUPP;
! 301: while (t < lowest_type[level])
! 302: level--;
! 303: mandoc_msg_setrc(level);
! 304:
! 305: if (fileptr == NULL)
! 306: return;
! 307:
! 308: fprintf(fileptr, "%s:", getprogname());
! 309: if (filename != NULL)
! 310: fprintf(fileptr, " %s:", filename);
! 311:
! 312: if (line > 0)
! 313: fprintf(fileptr, "%d:%d:", line, col + 1);
! 314:
! 315: fprintf(fileptr, " %s", level_name[level]);
! 316: if (type_message[t] != NULL)
! 317: fprintf(fileptr, ": %s", type_message[t]);
! 318:
! 319: if (fmt != NULL) {
! 320: fprintf(fileptr, ": ");
! 321: va_start(ap, fmt);
! 322: vfprintf(fileptr, fmt, ap);
! 323: va_end(ap);
! 324: }
! 325: fputc('\n', fileptr);
! 326: }
! 327:
! 328: void
! 329: mandoc_msg(enum mandocerr t, void *dummy, int line, int col, const char *msg)
! 330: {
! 331: if (msg == NULL)
! 332: mandoc_vmsg(t, dummy, line, col, NULL);
! 333: else
! 334: mandoc_vmsg(t, dummy, line, col, "%s", msg);
! 335: }
CVSweb