[BACK]Return to mandoc_msg.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/mandoc_msg.c, Revision 1.21

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

CVSweb