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