summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2009-08-21 17:51:15 +0200
committerTor Andersson <tor@ghostscript.com>2009-08-21 17:51:15 +0200
commita5928bde6a1a757a3d1a3680d542629611656ab5 (patch)
tree15f1071e7664b64d229fdc26ab922cb9b86a0453 /fitz
parentfd2ea36e0848223b58c09c292a551b696a955585 (diff)
downloadmupdf-a5928bde6a1a757a3d1a3680d542629611656ab5.tar.xz
Save error messages in a static buffer so that the windows viewer can show them in a dialog box.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_error.c58
-rw-r--r--fitz/fitz_base.h14
2 files changed, 53 insertions, 19 deletions
diff --git a/fitz/base_error.c b/fitz/base_error.c
index 44df2b59..c446bce9 100644
--- a/fitz/base_error.c
+++ b/fitz/base_error.c
@@ -1,5 +1,36 @@
#include "fitz_base.h"
+char fz_errorbuf[100*20] = {0};
+static int fz_errorlen = 0;
+static int fz_errorclear = 1;
+
+static void
+fz_printerror(int type, const char *file, int line, const char *func, char *msg)
+{
+ char buf[100];
+ int len;
+
+ snprintf(buf, sizeof buf, "%c %s:%d: %s(): %s", type, file, line, func, msg);
+ len = strlen(buf);
+
+ fputs(buf, stderr);
+
+ if (fz_errorclear)
+ {
+ fz_errorclear = 0;
+ fz_errorlen = 0;
+ memset(fz_errorbuf, 0, sizeof fz_errorbuf);
+ }
+
+ if (fz_errorlen + len + 2 < sizeof fz_errorbuf)
+ {
+ memcpy(fz_errorbuf + fz_errorlen, buf, len);
+ fz_errorlen += len;
+ fz_errorbuf[fz_errorlen++] = '\n';
+ fz_errorbuf[fz_errorlen] = 0;
+ }
+}
+
void fz_warn(char *fmt, ...)
{
va_list ap;
@@ -10,36 +41,37 @@ void fz_warn(char *fmt, ...)
fprintf(stderr, "\n");
}
-fz_error fz_throwimp(const char *func, const char *file, int line, char *fmt, ...)
+fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...)
{
+ char buf[100];
va_list ap;
- fprintf(stderr, "+ %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- fprintf(stderr, "\n");
- return ((fz_error)-1);
+ fz_printerror('+', file, line, func, buf);
+ return -1;
}
-fz_error fz_rethrowimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...)
+fz_error fz_rethrowimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...)
{
+ char buf[100];
va_list ap;
- fprintf(stderr, "| %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- fprintf(stderr, "\n");
+ fz_printerror('|', file, line, func, buf);
return cause;
}
-fz_error fz_catchimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...)
+fz_error fz_catchimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...)
{
+ char buf[100];
va_list ap;
- fprintf(stderr, "\\ %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- fprintf(stderr, "\n");
+ fz_printerror('\\', file, line, func, buf);
+ fz_errorclear = 1;
return cause;
}
diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h
index 9c89c4fa..6983d0e5 100644
--- a/fitz/fitz_base.h
+++ b/fitz/fitz_base.h
@@ -168,15 +168,17 @@ int fullrune(char *str, int n);
typedef int fz_error;
-#define fz_throw(...) fz_throwimp(__func__, __FILE__, __LINE__, __VA_ARGS__)
-#define fz_rethrow(cause, ...) fz_rethrowimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__)
-#define fz_catch(cause, ...) fz_catchimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__)
+extern char fz_errorbuf[];
+
+#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __func__, __VA_ARGS__)
+#define fz_rethrow(cause, ...) fz_rethrowimp(cause, __FILE__, __LINE__, __func__, __VA_ARGS__)
+#define fz_catch(cause, ...) fz_catchimp(cause, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define fz_okay ((fz_error)0)
void fz_warn(char *fmt, ...) __printflike(1,2);
-fz_error fz_throwimp(const char *func, const char *file, int line, char *fmt, ...) __printflike(4, 5);
-fz_error fz_rethrowimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6);
-fz_error fz_catchimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6);
+fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5);
+fz_error fz_rethrowimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...) __printflike(5, 6);
+fz_error fz_catchimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...) __printflike(5, 6);
void *fz_malloc(int n);
void *fz_realloc(void *p, int n);