summaryrefslogtreecommitdiff
path: root/fitz/base_error.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2011-03-06 14:25:41 +0000
committerTor Andersson <tor@ghostscript.com>2011-03-06 14:25:41 +0000
commitb5a4ed89c89dd94b21f4c9936abc2567a1553555 (patch)
tree5ee5dee10dc4f1d67c391bb3895b4d7bef24b197 /fitz/base_error.c
parentade55e530539613b4ccc5184a4746091018a866b (diff)
downloadmupdf-b5a4ed89c89dd94b21f4c9936abc2567a1553555.tar.xz
Inhibit warning message spam by introducing a repeat counter.
Diffstat (limited to 'fitz/base_error.c')
-rw-r--r--fitz/base_error.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/fitz/base_error.c b/fitz/base_error.c
index 5aa8768c..4117bc92 100644
--- a/fitz/base_error.c
+++ b/fitz/base_error.c
@@ -1,19 +1,45 @@
#include "fitz.h"
+enum { LINELEN = 160, LINECOUNT = 25 };
+
+static char warnmessage[LINELEN] = "";
+static int warncount = 0;
+
+void fz_flushwarnings(void)
+{
+ if (warncount > 1)
+ fprintf(stderr, "warning: ... repeated %d times ...\n", warncount);
+ warnmessage[0] = 0;
+ warncount = 0;
+}
+
void fz_warn(char *fmt, ...)
{
va_list ap;
- fprintf(stderr, "warning: ");
+ char buf[LINELEN];
+
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- fprintf(stderr, "\n");
+
+ if (!strcmp(buf, warnmessage))
+ {
+ warncount++;
+ }
+ else
+ {
+ fz_flushwarnings();
+ fprintf(stderr, "warning: %s\n", buf);
+ fz_strlcpy(warnmessage, buf, sizeof warnmessage);
+ warncount = 1;
+ }
}
fz_error
fz_throwimp(const char *file, int line, const char *func, char *fmt, ...)
{
va_list ap;
+ fz_flushwarnings();
fprintf(stderr, "+ %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
@@ -26,6 +52,7 @@ fz_error
fz_rethrowimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
{
va_list ap;
+ fz_flushwarnings();
fprintf(stderr, "| %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
@@ -38,6 +65,7 @@ void
fz_catchimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
{
va_list ap;
+ fz_flushwarnings();
fprintf(stderr, "\\ %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
@@ -49,6 +77,7 @@ fz_error
fz_throwimpx(char *fmt, ...)
{
va_list ap;
+ fz_flushwarnings();
fprintf(stderr, "+ ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
@@ -61,6 +90,7 @@ fz_error
fz_rethrowimpx(fz_error cause, char *fmt, ...)
{
va_list ap;
+ fz_flushwarnings();
fprintf(stderr, "| ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
@@ -73,6 +103,7 @@ void
fz_catchimpx(fz_error cause, char *fmt, ...)
{
va_list ap;
+ fz_flushwarnings();
fprintf(stderr, "\\ ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);