From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o5UHedD2027742 for ; Wed, 30 Jun 2010 13:40:40 -0400 (EDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1OU1H1-0006dO-Ft; Wed, 30 Jun 2010 19:40:37 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.71) (envelope-from ) id 1OU1H1-0006vQ-Ej for tech@mdocml.bsd.lv; Wed, 30 Jun 2010 19:40:35 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1OU1H1-00014Q-Do for tech@mdocml.bsd.lv; Wed, 30 Jun 2010 19:40:35 +0200 Received: from schwarze by usta.de with local (Exim 4.71) (envelope-from ) id 1OU1H1-0006Sp-Ct for tech@mdocml.bsd.lv; Wed, 30 Jun 2010 19:40:35 +0200 Date: Wed, 30 Jun 2010 19:40:35 +0200 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: [PATCH] show error level on stderr Message-ID: <20100630174035.GJ24358@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Hi, while looking into nesting woes, i wished to be able to distinguish warnings, errors and fatal errors without looking at mandoc.h and main.c. So i decided to add FATAL: and ERROR: to the error messages on stdout, leaving warnings alone. While writing the patch, i noticed that nomenclature is inconsistent: with_error refers to MANDOCERR_FATAL. Besides, we decided in Elmenhorst to return an error code when encountering an error; in fact, the code still exits non-zero even when only a warning is encountered. Thus, the following patch * renames with_error to with_fatal * tracks with_error instead of with_warning * uses these two to determine the exit code * adds ERROR: and FATAL: to messages * sorts the code in mmsg() to make it easier on the eye OK? Yours, Ingo Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.39 diff -u -p -r1.39 main.c --- main.c 29 Jun 2010 15:49:52 -0000 1.39 +++ main.c 30 Jun 2010 17:37:01 -0000 @@ -171,8 +171,8 @@ static void version(void) __attribute static int woptions(int *, char *); static const char *progname; -static int with_error; -static int with_warning; +static int with_fatal; +static int with_error; int main(int argc, char *argv[]) @@ -235,7 +235,7 @@ main(int argc, char *argv[]) while (*argv) { ffile(*argv, &curp); - if (with_error && !(curp.fflags & FL_IGN_ERRORS)) + if (with_fatal && !(curp.fflags & FL_IGN_ERRORS)) break; ++argv; } @@ -249,7 +249,7 @@ main(int argc, char *argv[]) if (curp.roff) roff_free(curp.roff); - return((with_warning || with_error) ? + return((with_fatal || with_error) ? EXIT_FAILURE : EXIT_SUCCESS); } @@ -327,7 +327,7 @@ ffile(const char *file, struct curparse curp->file = file; if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) { perror(curp->file); - with_error = 1; + with_fatal = 1; return; } @@ -368,7 +368,7 @@ read_whole_file(struct curparse *curp, s if (-1 == fstat(curp->fd, &st)) { perror(curp->file); - with_error = 1; + with_fatal = 1; return(0); } @@ -383,7 +383,7 @@ read_whole_file(struct curparse *curp, s if (st.st_size >= (1U << 31)) { fprintf(stderr, "%s: input too large\n", curp->file); - with_error = 1; + with_fatal = 1; return(0); } *with_mmap = 1; @@ -427,7 +427,7 @@ read_whole_file(struct curparse *curp, s free(fb->buf); fb->buf = NULL; - with_error = 1; + with_fatal = 1; return(0); } @@ -643,7 +643,7 @@ fdesc(struct curparse *curp) return; bailout: - with_error = 1; + with_fatal = 1; goto cleanup; } @@ -828,30 +828,37 @@ static int mmsg(enum mandocerr t, void *arg, int ln, int col, const char *msg) { struct curparse *cp; + const char *level; + int rc; cp = (struct curparse *)arg; + level = NULL; + rc = 1; - if (t <= MANDOCERR_ERROR) { - if ( ! (cp->wflags & WARN_WALL)) + if (t > MANDOCERR_ERROR) { + with_fatal = 1; + level = "FATAL"; + rc = 0; + } else { + if ( ! (WARN_WALL & cp->wflags)) return(1); - with_warning = 1; - } else - with_error = 1; - - fprintf(stderr, "%s:%d:%d: %s", cp->file, - ln, col + 1, mandocerrs[t]); + if (t > MANDOCERR_WARNING) { + with_error = 1; + level = "ERROR"; + } + if (WARN_WERR & cp->wflags) { + with_fatal = 1; + rc = 0; + } + } + fprintf(stderr, "%s:%d:%d:", cp->file, ln, col + 1); + if (level) + fprintf(stderr, " %s:", level); + fprintf(stderr, " %s", mandocerrs[t]); if (msg) fprintf(stderr, ": %s", msg); - fputc('\n', stderr); - /* This is superfluous, but whatever. */ - if (t > MANDOCERR_ERROR) - return(0); - if (cp->wflags & WARN_WERR) { - with_error = 1; - return(0); - } - return(1); + return(rc); } -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv