1 /** @file sanei_debug.h
2 * Support for printing debug messages.
4 * Use the functions of this header file to print debug or warning messages.
12 /** @name Public macros
13 * These macros can be used in backends and other SANE-related
16 * Before including sanei_debug.h, the following macros must be set:
18 * - BACKEND_NAME - The name of your backend without double-quotes (must be set in any case)
19 * - STUBS - If this is defined, no macros will be included. Used in
20 * backends consisting of more than one .c file.
21 * - DEBUG_DECLARE_ONLY - Generates prototypes instead of functions. Used in
22 * backends consisting of more than one .c file.
23 * - DEBUG_NOT_STATIC - Doesn't generate static functions. Used in header files if
24 * they are include in more than one .c file.
30 * Initialize sanei_debug.
32 * Call this function before you use any DBG function.
35 /** @def DBG(level, fmt, ...)
36 * Print a message at debug level `level' or higher using a printf-like
37 * function. Example: DBG(1, "sane_open: opening fd \%d\\n", fd).
39 * @param level debug level
40 * @param fmt format (see man 3 printf for details)
41 * @param ... additional arguments
45 * Compile code only if debugging is enabled.
47 * Expands to x if debug support is enabled at compile-time. If NDEBUG is
48 * defined at compile-time this macro expands to nothing.
50 * @param x code to expand when debugging is enabled
55 * Current debug level.
57 * You can only read this "variable".
61 * Expands to sane_BACKEND_NAME_name.
63 * Example: ENTRY(init) in mustek.c will expand to sane_mustek_init.
68 /** @name Internal macros and functions
69 * Do not use in your own code.
74 * Do not use in backends directly.
76 * Internal wrapper for printing function.
79 /** @fn extern void sanei_init_debug (const char * backend, int * debug_level_var);
80 * Do not use in backends directly.
82 * Actual init function.
85 /** @fn extern void sanei_debug_msg (int level, int max_level, const char *be, const char *fmt, va_list ap);
86 * Do not use in backends directly.
88 * Actual printing function.
92 /** @hideinitializer*/
93 #define ENTRY(name) PASTE(PASTE(PASTE(sane_,BACKEND_NAME),_),name)
97 extern void sanei_debug_ndebug (int level, const char *msg, ...);
99 # define DBG_LEVEL (0)
101 # define DBG sanei_debug_ndebug
106 /** @hideinitializer*/
107 # define DBG_LEVEL PASTE(sanei_debug_,BACKEND_NAME)
109 # if defined(BACKEND_NAME) && !defined(STUBS)
110 # ifdef DEBUG_DECLARE_ONLY
111 extern int DBG_LEVEL;
112 # else /* !DEBUG_DECLARE_ONLY */
114 # endif /* DEBUG_DECLARE_ONLY */
115 # endif /* BACKEND_NAME && !STUBS */
117 /** @hideinitializer*/
118 # define DBG_INIT() \
119 sanei_init_debug (STRINGIFY(BACKEND_NAME), &DBG_LEVEL)
121 /** @hideinitializer*/
122 # define DBG_LOCAL PASTE(DBG_LEVEL,_call)
127 # ifdef DEBUG_DECLARE_ONLY
129 extern void DBG_LOCAL (int level, const char *msg, ...)
131 __attribute__ ((format (printf, 2, 3)))
135 # else /* !DEBUG_DECLARE_ONLY */
139 extern void sanei_debug_msg
140 (int level, int max_level, const char *be, const char *fmt, va_list ap);
143 # ifndef DEBUG_NOT_STATIC
145 # endif /* !DEBUG_NOT_STATIC */
146 void DBG_LOCAL (int level, const char *msg, ...) __attribute__ ((format (printf, 2, 3)));
147 #endif /* __GNUC__ */
149 # ifndef DEBUG_NOT_STATIC
151 # endif /* !DEBUG_NOT_STATIC */
153 DBG_LOCAL (int level, const char *msg, ...)
158 sanei_debug_msg (level, DBG_LEVEL, STRINGIFY(BACKEND_NAME), msg, ap);
162 # endif /* DEBUG_DECLARE_ONLY */
166 /** @hideinitializer*/
167 # define DBG DBG_LOCAL
169 extern void sanei_init_debug (const char * backend, int * debug_level_var);
171 /** @hideinitializer*/
176 #endif /* _SANEI_DEBUG_H */