summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-11 21:05:03 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-11 21:08:10 (GMT)
commit31e61ae51b50efbf23c836ae47a556b6eedb2555 (patch)
treee635bbed84e25700f5460e69d4898fd73e374609 /misc
parent275f91f0728393365de8cb37881656d137844688 (diff)
downloadeeshow-31e61ae51b50efbf23c836ae47a556b6eedb2555.zip
eeshow-31e61ae51b50efbf23c836ae47a556b6eedb2555.tar.gz
eeshow-31e61ae51b50efbf23c836ae47a556b6eedb2555.tar.bz2
misc/diag.c (diag_defer_*): defer/suppress reporting of errors
This lets us avoid confusing "No such file or directory" complaints when processing a search path.
Diffstat (limited to 'misc')
-rw-r--r--misc/diag.c39
-rw-r--r--misc/diag.h11
2 files changed, 48 insertions, 2 deletions
diff --git a/misc/diag.c b/misc/diag.c
index 7ab7908..ef429dd 100644
--- a/misc/diag.c
+++ b/misc/diag.c
@@ -19,11 +19,15 @@
#include <git2.h>
+#include "misc/util.h"
#include "misc/diag.h"
unsigned verbose = 0;
+static int deferring = 0;
+static char *deferred = NULL;
+
/* ----- Specialized diagnostic functions ---------------------------------- */
@@ -56,6 +60,33 @@ void perror_git(const char *s)
}
+/* ----- Deferred errors --------------------------------------------------- */
+
+
+void diag_defer_begin(void)
+{
+ deferring++;
+}
+
+
+static void diag_defer_finish(bool report)
+{
+ if (deferred && report)
+ fprintf(stderr, "%s\n", deferred);
+ free(deferred);
+ deferred = NULL;
+}
+
+
+void diag_defer_end(bool report)
+{
+ if (!deferring--)
+ BUG("deferring == 0");
+ if (!deferring)
+ diag_defer_finish(report);
+}
+
+
/* ----- General diagnostic functions -------------------------------------- */
@@ -63,6 +94,7 @@ void fatal(const char *fmt, ...)
{
va_list ap;
+ diag_defer_finish(1);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
@@ -75,10 +107,13 @@ void error(const char *fmt, ...)
{
va_list ap;
+ if (deferred)
+ free(deferred);
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ alloc_vprintf(&deferred, fmt, ap);
va_end(ap);
- fprintf(stderr, "\n");
+ if (!deferring)
+ diag_defer_finish(1);
}
diff --git a/misc/diag.h b/misc/diag.h
index 501249f..8e296c2 100644
--- a/misc/diag.h
+++ b/misc/diag.h
@@ -13,6 +13,9 @@
#ifndef MISC_DIAG_H
#define MISC_DIAG_H
+#include <stdbool.h>
+
+
/*
* 0: no progress indications
* 1: reasonable progress indications
@@ -33,6 +36,13 @@ extern unsigned verbose;
fatal("BUG " __FILE__ ":" STRINGIFY_EXPAND(__LINE__) ": " __VA_ARGS__)
+/* ----- Deferred errors --------------------------------------------------- */
+
+
+void diag_defer_begin(void);
+void diag_defer_end(bool report);
+
+
/* ----- Specialized diagnostic functions ---------------------------------- */
@@ -44,6 +54,7 @@ void diag_perror(const char *s);
void __attribute__((noreturn)) pfatal_git(const char *s);
void perror_git(const char *s);
+
/* ----- General diagnostic functions -------------------------------------- */