chiark / gitweb /
factor out DEBUG_DEFINE_DEBUGF
[ypp-sc-tools.main.git] / pctb / ocr.h
index 60234a8e91e6028ea8f028a912f0a53d8eafbc7d..93b158b6a4ee220d0d15466310adb5295d79371e 100644 (file)
@@ -7,10 +7,6 @@
 #define OCR_H
 
 
-// #define DEBUG_RECTANGLES
-// #define DEBUG_OCR
-
-
 #define _GNU_SOURCE
 
 #include <string.h>
@@ -58,6 +54,26 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType, int w, Pixcol cols[]);
 
 /*----- debugging arrangements, rather contingent -----*/
 
+#define DEBUG_FLAG_LIST                                \
+   DF(ocr)                                     \
+   DF(rect)                                    \
+   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 eassert assert
@@ -65,4 +81,13 @@ void debug_flush(void);
 
 const char *get_vardir(void);
 
+#define DEBUG_DEFINE_DEBUGF(f)                                         \
+  static void vdebugf(const char *fmt, va_list al) {                   \
+    if (DEBUGP(f))                                                     \
+      vfprintf(debug,fmt,al);                                          \
+  }                                                                    \
+  static void debugf(const char *fmt, ...) {                           \
+    va_list al;  va_start(al,fmt);  vdebugf(fmt,al);  va_end(al);      \
+  }
+
 #endif /*OCR_H*/