From 97c9056b6af80e8b6703031a0ae45fe6dc0e2766 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 10 Nov 2017 14:12:48 +0100 Subject: Remove fz_android_fprintf. Use android logging for throw/warn like we do with OutputDebugString on windows. --- source/fitz/error.c | 92 +++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 73 deletions(-) (limited to 'source') diff --git a/source/fitz/error.c b/source/fitz/error.c index 0f371bc6..fe1045dd 100644 --- a/source/fitz/error.c +++ b/source/fitz/error.c @@ -13,6 +13,11 @@ #endif #endif +#ifdef __ANDROID__ +#define USE_ANDROID_LOG +#include +#endif + /* Warning context */ void fz_var_imp(void *var) @@ -40,6 +45,9 @@ void fz_vwarn(fz_context *ctx, const char *fmt, va_list ap) OutputDebugStringA(buf); OutputDebugStringA("\n"); #endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_WARN, "libmupdf", "%s", buf); +#endif if (!strcmp(buf, ctx->warn->message)) { @@ -102,11 +110,14 @@ FZ_NORETURN static void throw(fz_context *ctx) } else { - fprintf(stderr, "uncaught exception: %s\n", ctx->error->message); + fprintf(stderr, "uncaught error: %s\n", ctx->error->message); #ifdef USE_OUTPUT_DEBUG_STRING - OutputDebugStringA("uncaught exception: "); + OutputDebugStringA("uncaught error: "); OutputDebugStringA(ctx->error->message); OutputDebugStringA("\n"); +#endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_ERROR, "libmupdf", "(uncaught) %s", ctx->error->message); #endif exit(EXIT_FAILURE); } @@ -131,6 +142,9 @@ static int fz_fake_throw(fz_context *ctx, int code, const char *fmt, ...) OutputDebugStringA("error: "); OutputDebugStringA(ctx->error->message); OutputDebugStringA("\n"); +#endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_ERROR, "libmupdf", "%s", ctx->error->message); #endif } @@ -181,6 +195,9 @@ FZ_NORETURN void fz_vthrow(fz_context *ctx, int code, const char *fmt, va_list a OutputDebugStringA("error: "); OutputDebugStringA(ctx->error->message); OutputDebugStringA("\n"); +#endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_ERROR, "libmupdf", "%s", ctx->error->message); #endif } @@ -207,74 +224,3 @@ void fz_rethrow_if(fz_context *ctx, int err) if (ctx->error->errcode == err) fz_rethrow(ctx); } - -/* Android specific code to take fprintf to LOG */ - -#ifdef __ANDROID__ -#include -#include - -#define LOG_TAG "libmupdf" - -static char android_log_buffer[4096]; -static int android_log_fill = 0; - -static char android_log_buffer2[4096]; - -int fz_android_fprintf(void *file, const char *fmt, ...) -{ - va_list args; - char *p, *q; - - /* Just in case someone has some magic fprintf redirection code working */ - va_start(args, fmt); - vfprintf(file, fmt, args); - va_end(args); - - if (file != stdout && file != stderr) - return 0; - - va_start(args, fmt); - vsnprintf(android_log_buffer2, sizeof(android_log_buffer2)-1, fmt, args); - va_end(args); - - /* Ensure we are always null terminated */ - android_log_buffer2[sizeof(android_log_buffer2)-1] = 0; - - p = android_log_buffer2; - q = p; - do - { - /* Find the end of the string, or the next \n */ - while (*p && *p != '\n') - p++; - - /* We need to output from q to p. Limit ourselves to what - * will fit in the existing buffer. */ - if (p - q >= sizeof(android_log_buffer)-1 - android_log_fill) - p = q + sizeof(android_log_buffer)-1 - android_log_fill; - - memcpy(&android_log_buffer[android_log_fill], q, p-q); - android_log_fill += p-q; - if (*p == '\n') - { - android_log_buffer[android_log_fill] = 0; - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", android_log_buffer); - usleep(1); /* Hack to avoid the logcat buffer losing data */ - android_log_fill = 0; - p++; /* Skip over the \n */ - } - else if (android_log_fill >= sizeof(android_log_buffer)-1) - { - android_log_buffer[sizeof(android_log_buffer2)-1] = 0; - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", android_log_buffer); - usleep(1); /* Hack to avoid the logcat buffer losing data */ - android_log_fill = 0; - } - q = p; - } - while (*p); - - return 0; -} -#endif -- cgit v1.2.3