diff options
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/base_error.c | 37 | ||||
-rw-r--r-- | fitz/fitz.h | 1 |
2 files changed, 35 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); diff --git a/fitz/fitz.h b/fitz/fitz.h index 13e285e6..14372efd 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -113,6 +113,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); typedef int fz_error; void fz_warn(char *fmt, ...) __printflike(1, 2); +void fz_flushwarnings(void); fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5); fz_error fz_rethrowimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6); |