diff options
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/base_error.c | 99 | ||||
-rw-r--r-- | fitz/fitz_base.h | 173 | ||||
-rw-r--r-- | fitz/fitz_draw.h | 2 | ||||
-rw-r--r-- | fitz/util_gettimeofday.c | 4 |
4 files changed, 139 insertions, 139 deletions
diff --git a/fitz/base_error.c b/fitz/base_error.c index 3045d912..5aa8768c 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -1,86 +1,81 @@ #include "fitz.h" -char fz_errorbuf[150*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) +void fz_warn(char *fmt, ...) { - char buf[150]; - int len; - char *s; - - s = strrchr(file, '\\'); - if (s) - file = s + 1; - - fprintf(stderr, "%c %s:%d: %s(): %s\n", type, file, line, func, msg); - - snprintf(buf, sizeof buf, "%s:%d: %s(): %s", file, line, func, msg); - buf[sizeof(buf)-1] = 0; - len = strlen(buf); + va_list ap; + fprintf(stderr, "warning: "); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); +} - if (fz_errorclear) - { - fz_errorclear = 0; - fz_errorlen = 0; - memset(fz_errorbuf, 0, sizeof fz_errorbuf); - } +fz_error +fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) +{ + va_list ap; + fprintf(stderr, "+ %s:%d: %s(): ", file, line, func); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + return -1; +} - 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; - } +fz_error +fz_rethrowimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) +{ + va_list ap; + fprintf(stderr, "| %s:%d: %s(): ", file, line, func); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + return cause; } -void fz_warn(char *fmt, ...) +void +fz_catchimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) { va_list ap; - fprintf(stderr, "warning: "); + fprintf(stderr, "\\ %s:%d: %s(): ", file, line, func); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); } -fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) +fz_error +fz_throwimpx(char *fmt, ...) { - char buf[150]; va_list ap; + fprintf(stderr, "+ "); va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); - buf[sizeof(buf)-1] = 0; - fz_printerror('+', file, line, func, buf); + fprintf(stderr, "\n"); return -1; } -fz_error fz_rethrowimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...) +fz_error +fz_rethrowimpx(fz_error cause, char *fmt, ...) { - char buf[150]; va_list ap; + fprintf(stderr, "| "); va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); - buf[sizeof(buf)-1] = 0; - fz_printerror('|', file, line, func, buf); + fprintf(stderr, "\n"); return cause; } -fz_error fz_catchimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...) +void +fz_catchimpx(fz_error cause, char *fmt, ...) { - char buf[150]; va_list ap; + fprintf(stderr, "\\ "); va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); - buf[sizeof(buf)-1] = 0; - fz_printerror('\\', file, line, func, buf); - fz_errorclear = 1; - return cause; + fprintf(stderr, "\n"); } - diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h index 9563b0c9..2f810709 100644 --- a/fitz/fitz_base.h +++ b/fitz/fitz_base.h @@ -1,39 +1,31 @@ -/* - * Include the basic standard libc headers. - */ - #ifndef _FITZ_BASE_H_ #define _FITZ_BASE_H_ +/* + * Include the standard libc headers. + */ + #include <stdio.h> #include <stdlib.h> #include <stddef.h> -#include <string.h> -#include <assert.h> #include <stdarg.h> - -#include <limits.h> /* INT_MIN, MAX ... */ -#include <float.h> /* DBL_EPSILON */ +#include <string.h> #include <math.h> +#include <assert.h> #include <errno.h> +#include <float.h> /* FLT_EPSILON */ #include <fcntl.h> /* O_RDONLY & co */ -/* Stupid macros that don't exist everywhere */ - -#ifndef O_BINARY -#define O_BINARY 0 -#endif +#define nil ((void*)0) -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#define nelem(x) (sizeof(x)/sizeof((x)[0])) -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 -#endif +/* + * Some differences in libc can be smoothed over + */ -#ifdef _MSC_VER /* stupid stone-age compiler */ +#ifdef _MSC_VER /* Microsoft Visual C */ #pragma warning( disable: 4244 ) /* conversion from X to Y, possible loss of data */ #pragma warning( disable: 4996 ) /* The POSIX name for this item is deprecated */ @@ -41,38 +33,66 @@ #include <io.h> -extern int gettimeofday(struct timeval *tv, struct timezone *tz); - -#define inline __inline - -#define __func__ __FUNCTION__ +int gettimeofday(struct timeval *tv, struct timezone *tz); #define snprintf _snprintf #define hypotf _hypotf #define strtoll _strtoi64 -#if _MSC_VER < 1500 -#define vsnprintf _vsnprintf -#endif - -#else /* unix or close enough */ +#else /* Unix or close enough */ #include <unistd.h> +#define O_BINARY 0 + #endif -#ifndef _C99 -#ifdef __GNUC__ -#define restrict __restrict -#else -#define restrict +#ifndef M_PI +#define M_PI 3.14159265358979323846 #endif + +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 #endif +/* + * Variadic macros, inline and restrict keywords + */ + +#if __STDC_VERSION__ == 199901L /* C99 */ + +#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __func__, __VA_ARGS__) +#define fz_rethrow(cause, ...) fz_rethrowimp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__) +#define fz_catch(cause, ...) fz_catchimp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__) + +#elif _MSC_VER >= 1500 /* MSVC 9 or newer */ + +#define inline __inline +#define restrict __restrict +#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) +#define fz_rethrow(cause, ...) fz_rethrowimp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__) +#define fz_catch(cause, ...) fz_catchimp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__) + +#elif __GNUC__ >= 3 /* GCC 3 or newer */ + +#define inline __inline +#define restrict __restrict +#define fz_throw(fmt...) fz_throwimp(__FILE__, __LINE__, __FUNCTION__, fmt) +#define fz_rethrow(cause, fmt...) fz_rethrowimp(__FILE__, __LINE__, __FUNCTION__, cause, fmt) +#define fz_catch(cause, fmt...) fz_catchimp(__FILE__, __LINE__, __FUNCTION__, cause, fmt) + +#else /* Unknown or ancient */ + +#define inline +#define restrict +#define fz_throw fz_throwimpx +#define fz_rethrow fz_rethrowimpx +#define fz_catch fz_catchimpx + #endif /* - * Base Fitz runtime. + * GCC can do type checking of printf strings */ #ifndef __printflike @@ -84,76 +104,57 @@ extern int gettimeofday(struct timeval *tv, struct timezone *tz); #endif #endif -#ifndef nil -#define nil ((void*)0) -#endif +/* + * Error handling + */ -#ifndef offsetof -#define offsetof(s, m) (unsigned long)(&(((s*)0)->m)) -#endif +typedef int fz_error; -#ifndef nelem -#define nelem(x) (sizeof(x)/sizeof((x)[0])) -#endif +void fz_warn(char *fmt, ...) __printflike(1, 2); -#ifndef ABS -#define ABS(x) ( (x) < 0 ? -(x) : (x) ) -#endif +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); +void fz_catchimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6); -#ifndef MAX -#define MAX(a,b) ( (a) > (b) ? (a) : (b) ) -#endif +fz_error fz_throwimpx(char *fmt, ...) __printflike(1, 2); +fz_error fz_rethrowimpx(fz_error cause, char *fmt, ...) __printflike(2, 3); +void fz_catchimpx(fz_error cause, char *fmt, ...) __printflike(2, 3); -#ifndef MIN -#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) -#endif +#define fz_okay ((fz_error)0) -#ifndef CLAMP +/* + * Basic runtime and utility functions + */ + +#define ABS(x) ( (x) < 0 ? -(x) : (x) ) +#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) +#define MAX(a,b) ( (a) > (b) ? (a) : (b) ) #define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) ) -#endif + +/* memory allocation */ +void *fz_malloc(int n); +void *fz_realloc(void *p, int n); +void fz_free(void *p); +char *fz_strdup(char *s); /* runtime (hah!) test for endian-ness */ int fz_isbigendian(void); +/* safe string functions */ +char *fz_strsep(char **stringp, const char *delim); +int fz_strlcpy(char *dst, const char *src, int n); +int fz_strlcat(char *dst, const char *src, int n); + /* utf-8 encoding and decoding */ int chartorune(int *rune, char *str); int runetochar(char *str, int *rune); int runelen(int c); -/* useful string functions */ -extern char *fz_strsep(char **stringp, const char *delim); -extern int fz_strlcpy(char *dst, const char *src, int n); -extern int fz_strlcat(char *dst, const char *src, int n); - /* getopt */ extern int fz_getopt(int nargc, char * const * nargv, const char *ostr); extern int fz_optind; extern char *fz_optarg; -/* memory allocation */ -void *fz_malloc(int n); -void *fz_realloc(void *p, int n); -void fz_free(void *p); -char *fz_strdup(char *s); - -/* - * Error handling. - */ - -typedef int fz_error; - -extern char fz_errorbuf[]; - -void fz_warn(char *fmt, ...) __printflike(1,2); -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); - -#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) - /* * Generic hash-table with fixed-length keys. */ diff --git a/fitz/fitz_draw.h b/fitz/fitz_draw.h index 0f08249e..a2f65579 100644 --- a/fitz/fitz_draw.h +++ b/fitz/fitz_draw.h @@ -34,7 +34,7 @@ typedef enum fz_blendkind_e FZ_BHUE, FZ_BSATURATION, FZ_BCOLOR, - FZ_BLUMINOSITY + FZ_BLUMINOSITY, } fz_blendkind; /* diff --git a/fitz/util_gettimeofday.c b/fitz/util_gettimeofday.c index ee89d445..425c6440 100644 --- a/fitz/util_gettimeofday.c +++ b/fitz/util_gettimeofday.c @@ -33,4 +33,8 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) return 0; } +#else + +void fz_gettimeofday_dummy() { } + #endif |