=================================================================== RCS file: /cvs/mandoc/mandoc_msg.c,v retrieving revision 1.1 retrieving revision 1.12 diff -u -p -r1.1 -r1.12 --- mandoc/mandoc_msg.c 2018/12/14 01:18:26 1.1 +++ mandoc/mandoc_msg.c 2020/09/01 18:25:27 1.12 @@ -1,7 +1,7 @@ -/* $OpenBSD: mandoc_msg.c,v 1.1 2018/12/14 01:18:26 schwarze Exp $ */ +/* $OpenBSD: mandoc_msg.c,v 1.12 2020/09/01 18:25:27 schwarze Exp $ */ /* + * Copyright (c) 2014-2020 Ingo Schwarze * Copyright (c) 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,7 +14,11 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Implementation of warning and error messages for mandoc(1). */ +#include "config.h" + #include #include #include @@ -27,8 +31,8 @@ static const enum mandocerr lowest_type[MANDOCLEVEL_MA MANDOCERR_WARNING, MANDOCERR_ERROR, MANDOCERR_UNSUPP, - MANDOCERR_MAX, - MANDOCERR_MAX + MANDOCERR_BADARG, + MANDOCERR_SYSERR }; static const char *const level_name[MANDOCLEVEL_MAX] = { @@ -81,7 +85,8 @@ static const char *const type_message[MANDOCERR_MAX] = "missing manual title, using \"\"", "missing manual section, using \"\"", "unknown manual section", - "missing date, using today's date", + "filename/section mismatch", + "missing date, using \"\"", "cannot parse date, using it verbatim", "date in the future, using it anyway", "missing Os macro, using \"\"", @@ -167,6 +172,7 @@ static const char *const type_message[MANDOCERR_MAX] = "tab in filled text", "new sentence, new line", "invalid escape sequence", + "undefined escape, printing literally", "undefined string, using \"\"", /* related to tables */ @@ -184,13 +190,13 @@ static const char *const type_message[MANDOCERR_MAX] = "empty tbl layout", "invalid character in tbl layout", "unmatched parenthesis in tbl layout", + "ignoring excessive spacing in tbl layout", "tbl without any data cells", "ignoring data in spanned tbl cell", "ignoring extra tbl data cells", "data block open at end of tbl", /* related to document structure and macros */ - NULL, "duplicate prologue macro", "skipping late title macro", "input stack limit exceeded, infinite loop?", @@ -221,6 +227,7 @@ static const char *const type_message[MANDOCERR_MAX] = "excessive shift", "NOT IMPLEMENTED: .so with absolute path or \"..\"", ".so request failed", + "skipping tag containing whitespace", "skipping all arguments", "skipping excess arguments", "divide by zero", @@ -228,6 +235,7 @@ static const char *const type_message[MANDOCERR_MAX] = "unsupported feature", "input too large", "unsupported control character", + "unsupported escape sequence", "unsupported roff request", "nested .while loops", "end of scope with open .while loop", @@ -236,11 +244,40 @@ static const char *const type_message[MANDOCERR_MAX] = "eqn delim option in tbl", "unsupported tbl layout modifier", "ignoring macro in table", + + /* bad command line arguments */ + NULL, + "bad command line argument", + "duplicate command line argument", + "option has a superfluous value", + "missing option value", + "bad option value", + "duplicate option value", + "no such tag", + + /* system errors */ + NULL, + "dup", + "exec", + "fdopen", + "fflush", + "fork", + "fstat", + "getline", + "glob", + "gzclose", + "gzdopen", + "mkstemp", + "open", + "pledge", + "read", + "wait", + "write", }; -static FILE *fileptr = stderr; +static FILE *fileptr = NULL; static const char *filename = NULL; -static enum mandocerr min_type = MANDOCERR_MAX; +static enum mandocerr min_type = MANDOCERR_BADARG; static enum mandoclevel rc = MANDOCLEVEL_OK; @@ -288,16 +325,15 @@ mandoc_msg_setrc(enum mandoclevel level) } void -mandoc_vmsg(enum mandocerr t, void *dummy, int line, int col, - const char *fmt, ...) +mandoc_msg(enum mandocerr t, int line, int col, const char *fmt, ...) { va_list ap; enum mandoclevel level; - if (t < min_type && t != MANDOCERR_FILE) + if (t < min_type) return; - level = MANDOCLEVEL_UNSUPP; + level = MANDOCLEVEL_SYSERR; while (t < lowest_type[level]) level--; mandoc_msg_setrc(level); @@ -326,10 +362,10 @@ mandoc_vmsg(enum mandocerr t, void *dummy, int line, i } void -mandoc_msg(enum mandocerr t, void *dummy, int line, int col, const char *msg) +mandoc_msg_summary(void) { - if (msg == NULL) - mandoc_vmsg(t, dummy, line, col, NULL); - else - mandoc_vmsg(t, dummy, line, col, "%s", msg); + if (fileptr != NULL && rc != MANDOCLEVEL_OK) + fprintf(fileptr, + "%s: see above the output for %s messages\n", + getprogname(), level_name[rc]); }