]> git.cameronkatri.com Git - mandoc.git/blob - mandoc_msg.c
Manually tag the section option.
[mandoc.git] / mandoc_msg.c
1 /* $OpenBSD: mandoc_msg.c,v 1.8 2020/01/19 17:59:01 schwarze Exp $ */
2 /*
3 * Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
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.
17 *
18 * Implementation of warning and error messages for mandoc(1).
19 */
20 #include "config.h"
21
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,
34 MANDOCERR_BADARG,
35 MANDOCERR_SYSERR
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 "referenced manual not found",
59
60 "generic style suggestion",
61
62 "legacy man(7) date format",
63 "normalizing date format to",
64 "lower case character in document title",
65 "duplicate RCS id",
66 "possible typo in section name",
67 "unterminated quoted argument",
68 "useless macro",
69 "consider using OS macro",
70 "errnos out of order",
71 "duplicate errno",
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",
88 "filename/section mismatch",
89 "missing date, using \"\"",
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",
175 "undefined escape, printing literally",
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",
193 "tbl without any data cells",
194 "ignoring data in spanned tbl cell",
195 "ignoring extra tbl data cells",
196 "data block open at end of tbl",
197
198 /* related to document structure and macros */
199 "duplicate prologue macro",
200 "skipping late title macro",
201 "input stack limit exceeded, infinite loop?",
202 "skipping bad character",
203 "skipping unknown macro",
204 "ignoring request outside macro",
205 "skipping insecure request",
206 "skipping item outside list",
207 "skipping column outside column list",
208 "skipping end of block that is not open",
209 "fewer RS blocks open, skipping",
210 "inserting missing end of block",
211 "appending missing end of block",
212
213 /* related to request and macro arguments */
214 "escaped character not allowed in a name",
215 "using macro argument outside macro",
216 "argument number is not numeric",
217 "NOT IMPLEMENTED: Bd -file",
218 "skipping display without arguments",
219 "missing list type, using -item",
220 "argument is not numeric, using 1",
221 "argument is not a character",
222 "missing manual name, using \"\"",
223 "uname(3) system call failed, using UNKNOWN",
224 "unknown standard specifier",
225 "skipping request without numeric argument",
226 "excessive shift",
227 "NOT IMPLEMENTED: .so with absolute path or \"..\"",
228 ".so request failed",
229 "skipping tag containing whitespace",
230 "skipping all arguments",
231 "skipping excess arguments",
232 "divide by zero",
233
234 "unsupported feature",
235 "input too large",
236 "unsupported control character",
237 "unsupported escape sequence",
238 "unsupported roff request",
239 "nested .while loops",
240 "end of scope with open .while loop",
241 "end of .while loop in inner scope",
242 "cannot continue this .while loop",
243 "eqn delim option in tbl",
244 "unsupported tbl layout modifier",
245 "ignoring macro in table",
246
247 /* bad command line arguments */
248 NULL,
249 "bad command line argument",
250 "duplicate command line argument",
251 "option has a superfluous value",
252 "missing option value",
253 "bad option value",
254 "duplicate option value",
255 "no such tag",
256
257 /* system errors */
258 NULL,
259 "dup",
260 "exec",
261 "fdopen",
262 "fflush",
263 "fork",
264 "fstat",
265 "getline",
266 "glob",
267 "gzclose",
268 "gzdopen",
269 "mkstemp",
270 "open",
271 "pledge",
272 "read",
273 "wait",
274 "write",
275 };
276
277 static FILE *fileptr = NULL;
278 static const char *filename = NULL;
279 static enum mandocerr min_type = MANDOCERR_BADARG;
280 static enum mandoclevel rc = MANDOCLEVEL_OK;
281
282
283 void
284 mandoc_msg_setoutfile(FILE *fp)
285 {
286 fileptr = fp;
287 }
288
289 const char *
290 mandoc_msg_getinfilename(void)
291 {
292 return filename;
293 }
294
295 void
296 mandoc_msg_setinfilename(const char *fn)
297 {
298 filename = fn;
299 }
300
301 enum mandocerr
302 mandoc_msg_getmin(void)
303 {
304 return min_type;
305 }
306
307 void
308 mandoc_msg_setmin(enum mandocerr t)
309 {
310 min_type = t;
311 }
312
313 enum mandoclevel
314 mandoc_msg_getrc(void)
315 {
316 return rc;
317 }
318
319 void
320 mandoc_msg_setrc(enum mandoclevel level)
321 {
322 if (rc < level)
323 rc = level;
324 }
325
326 void
327 mandoc_msg(enum mandocerr t, int line, int col, const char *fmt, ...)
328 {
329 va_list ap;
330 enum mandoclevel level;
331
332 if (t < min_type)
333 return;
334
335 level = MANDOCLEVEL_SYSERR;
336 while (t < lowest_type[level])
337 level--;
338 mandoc_msg_setrc(level);
339
340 if (fileptr == NULL)
341 return;
342
343 fprintf(fileptr, "%s:", getprogname());
344 if (filename != NULL)
345 fprintf(fileptr, " %s:", filename);
346
347 if (line > 0)
348 fprintf(fileptr, "%d:%d:", line, col + 1);
349
350 fprintf(fileptr, " %s", level_name[level]);
351 if (type_message[t] != NULL)
352 fprintf(fileptr, ": %s", type_message[t]);
353
354 if (fmt != NULL) {
355 fprintf(fileptr, ": ");
356 va_start(ap, fmt);
357 vfprintf(fileptr, fmt, ap);
358 va_end(ap);
359 }
360 fputc('\n', fileptr);
361 }
362
363 void
364 mandoc_msg_summary(void)
365 {
366 if (fileptr != NULL && rc != MANDOCLEVEL_OK)
367 fprintf(fileptr,
368 "%s: see above the output for %s messages\n",
369 getprogname(), level_name[rc]);
370 }