tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: [PATCH] show error level on stderr
Date: Wed, 30 Jun 2010 19:40:35 +0200	[thread overview]
Message-ID: <20100630174035.GJ24358@iris.usta.de> (raw)

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

             reply	other threads:[~2010-06-30 17:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-30 17:40 Ingo Schwarze [this message]
2010-06-30 18:48 ` Ingo Schwarze
2010-06-30 19:59   ` Kristaps Dzonsons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100630174035.GJ24358@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).