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