X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Fcommon.h;fp=pctb%2Fcommon.h;h=9afb083e4fc332467daaf04562ee565af8b739b9;hb=52210ae670b22ce2d187bd2dc943fd8ae3f4a8c0;hp=0000000000000000000000000000000000000000;hpb=4d7eb93b7c82da31f928349ac7c6cd551d78ca57;p=ypp-sc-tools.db-test.git diff --git a/pctb/common.h b/pctb/common.h new file mode 100644 index 0000000..9afb083 --- /dev/null +++ b/pctb/common.h @@ -0,0 +1,92 @@ + +#ifndef COMMON_H +#define COMMON_H + +#define _GNU_SOURCE + +#include + +#include + +typedef struct { + int w,h; + char d[]; +} CanonImage; + + +/*----- debugging arrangements, rather contingent -----*/ + +typedef struct { + int x, y; +} Point; + +typedef struct { /* both inclusive */ + Point tl; + Point br; +} Rect; + + + +#define DEBUG_FLAG_LIST \ + DF(findypp) \ + DF(pages) \ + DF(rect) \ + DF(ocr) \ + DF(callout) + +enum { +#define DF(f) dbg__shift_##f, + DEBUG_FLAG_LIST +#undef DF +}; +enum { +#define DF(f) dbg_##f = 1 << dbg__shift_##f, + DEBUG_FLAG_LIST +#undef DF +}; + +unsigned debug_flags; + +#define DEBUGP(f) (!!(debug_flags & dbg_##f)) + +void debug_flush(void); +#define debug stderr + +const char *get_vardir(void); + +#define FMT(f,a) __attribute__((format(printf,f,a))) +#define NORET __attribute__((noreturn)) + +#define DEFINE_VWRAPPERF(decls, funcf, otherattribs) \ + decls void funcf(const char *fmt, ...) FMT(1,2) otherattribs; \ + decls void funcf(const char *fmt, ...) { \ + va_list al; va_start(al,fmt); v##funcf(fmt,al); va_end(al); \ + } + +#define DEBUG_DEFINE_SOME_DEBUGF(fl,funcf) \ + static void v##funcf(const char *fmt, va_list al) { \ + if (DEBUGP(fl)) \ + vfprintf(debug,fmt,al); \ + } \ + DEFINE_VWRAPPERF(static, funcf, ) + +#define DEBUG_DEFINE_DEBUGF(fl) DEBUG_DEFINE_SOME_DEBUGF(fl,debugf) + + +/*---------- error handling ----------*/ + +void vfatal(const char *fmt, va_list) FMT(1,0) NORET; +void fatal(const char *fmt, ...) FMT(1,2) NORET; + +#define sysassert(what) \ + ((what) ? (void)0 : sysassert_fail(__FILE__, __LINE__, #what)) + +void sysassert_fail(const char *file, int line, const char *what) + __attribute__((noreturn)); + + +void *mmalloc(size_t sz); +void *mrealloc(void *p, size_t sz); + + +#endif /*COMMON_H*/