picox  0.1
xdebug.h
[詳解]
1 
14 /*
15  * License: MIT license
16  * Copyright (c) <2015> <MaskedW [maskedw00@gmail.com]>
17  *
18  * Permission is hereby granted, free of charge, to any person
19  * obtaining a copy of this software and associated documentation
20  * files (the "Software"), to deal in the Software without
21  * restriction, including without limitation the rights to use, copy,
22  * modify, merge, publish, distribute, sublicense, and/or sell copies
23  * of the Software, and to permit persons to whom the Software is
24  * furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be
27  * included in all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36  * SOFTWARE.
37  */
38 
39 #ifndef picox_core_detail_xdebug_h_
40 #define picox_core_detail_xdebug_h_
41 
42 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
63 typedef void(*XAssertionFailedFunc)(const char* expr, const char* msg, const char* func, const char* file, int line);
64 
65 
72 
73 
79 
80 
91 
92 
110 #define X_LOG_LEVEL_ERR (1) /* error */
111 #define X_LOG_LEVEL_WARN (2) /* warning */
112 #define X_LOG_LEVEL_NOTI (3) /* notice */
113 #define X_LOG_LEVEL_INFO (4) /* infomation */
114 #define X_LOG_LEVEL_VERB (5) /* verbose */
115 #define X_LOG_LEVEL X_CONF_LOG_LEVEL
116 
117 
129 #define X_ANSI_COLOR_BLACK "\x1b[1;30m"
130 #define X_ANSI_COLOR_RED "\x1b[1;31m"
131 #define X_ANSI_COLOR_GREEN "\x1b[1;32m"
132 #define X_ANSI_COLOR_YELLOW "\x1b[1;33m"
133 #define X_ANSI_COLOR_BLUE "\x1b[1;34m"
134 #define X_ANSI_COLOR_MAGENTA "\x1b[1;35m"
135 #define X_ANSI_COLOR_CYAN "\x1b[1;36m"
136 #define X_ANSI_COLOR_WHITE "\x1b[1;37m"
137 #define X_ANSI_COLOR_RESET "\x1b[0m"
138 
139 
140 #if X_CONF_USE_ANSI_COLOR_LOG != 0
141  #define X_COLOR_BLACK X_ANSI_COLOR_BLACK
142  #define X_COLOR_RED X_ANSI_COLOR_RED
143  #define X_COLOR_GREEN X_ANSI_COLOR_GREEN
144  #define X_COLOR_YELLOW X_ANSI_COLOR_YELLOW
145  #define X_COLOR_BLUE X_ANSI_COLOR_BLUE
146  #define X_COLOR_MAGENTA X_ANSI_COLOR_MAGENTA
147  #define X_COLOR_CYAN X_ANSI_COLOR_CYAN
148  #define X_COLOR_WHITE X_ANSI_COLOR_WHITE
149  #define X_COLOR_RESET X_ANSI_COLOR_RESET
150 #else
151  #define X_COLOR_BLACK
152  #define X_COLOR_RED
153  #define X_COLOR_GREEN
154  #define X_COLOR_YELLOW
155  #define X_COLOR_BLUE
156  #define X_COLOR_MAGENTA
157  #define X_COLOR_CYAN
158  #define X_COLOR_WHITE
159  #define X_COLOR_RESET
160 #endif
161 
162 
181 #if (X_CONF_USE_DYNAMIC_LOG_SUPPRESS != 0) || (X_LOG_LEVEL >= X_LOG_LEVEL_VERB)
182  #define X_LOG_VERB(args) x_verb_printlog args
183  #define X_LOG_HEXDUMP_VERB(args) x_verb_hexdump args
184 #else
185  #define X_LOG_VERB(args) (void)0
186  #define X_LOG_HEXDUMP_VERB(args) (void)0
187 #endif
188 
189 
190 #if (X_CONF_USE_DYNAMIC_LOG_SUPPRESS != 0) || (X_LOG_LEVEL >= X_LOG_LEVEL_INFO)
191  #define X_LOG_INFO(args) x_info_printlog args
192  #define X_LOG_HEXDUMP_INFO(args) x_info_hexdump args
193 #else
194  #define X_LOG_INFO(args) (void)0
195  #define X_LOG_HEXDUMP_INFO(args) (void)0
196 #endif
197 
198 
199 #if (X_CONF_USE_DYNAMIC_LOG_SUPPRESS != 0) || (X_LOG_LEVEL >= X_LOG_LEVEL_NOTI)
200  #define X_LOG_NOTI(args) x_noti_printlog args
201  #define X_LOG_HEXDUMP_NOTI(args) x_noti_hexdump args
202 #else
203  #define X_LOG_NOTI(args) (void)0
204  #define X_LOG_HEXDUMP_NOTI(args) (void)0
205 #endif
206 
207 
208 #if (X_CONF_USE_DYNAMIC_LOG_SUPPRESS != 0) || (X_LOG_LEVEL >= X_LOG_LEVEL_WARN)
209  #define X_LOG_WARN(args) x_warn_printlog args
210  #define X_LOG_HEXDUMP_WARN(args) x_warn_hexdump args
211 #else
212  #define X_LOG_WARN(args) (void)0
213  #define X_LOG_HEXDUMP_WARN(args) (void)0
214 #endif
215 
216 
217 #if (X_CONF_USE_DYNAMIC_LOG_SUPPRESS != 0) || (X_LOG_LEVEL >= X_LOG_LEVEL_ERR)
218  #define X_LOG_ERR(args) x_err_printlog args
219  #define X_LOG_HEXDUMP_ERR(args) x_err_hexdump args
220 #else
221  #define X_LOG_ERR(args) (void)0
222  #define X_LOG_HEXDUMP_ERR(args) (void)0
223 #endif
224 
225 
238 #define X_DEFAULT_ASSERT(expr) X_DEFAULT_ASSERT_MSG(expr, NULL)
239 
243 #define X_DEFAULT_ASSERT_MSG(expr, msg) ((expr) ? (void)0 : x_assertion_failed(#expr, msg, X_FUNC, __FILE__, __LINE__))
244 
245 
246 #if (X_CONF_NDEBUG == 0)
247  #define X_ASSERT(expr) X_DEFAULT_ASSERT(expr)
248  #define X_ASSERT_MSG(expr, msg) X_DEFAULT_ASSERT_MSG(expr, msg)
249 #else
250  #define X_ASSERT(expr) (void)0
251  #define X_ASSERT_MSG(expr, msg) (void)0
252 #endif
253 
254 
258 #if X_CONF_USE_ASSERT_SELF != 0
259  #define X_ASSERT_SELF(expr) X_ASSERT(expr)
260 #else
261  #define X_ASSERT_SELF(expr) (void)0
262 #endif
263 
264 
268 #if X_CONF_USE_ASSERT_ARG != 0
269  #define X_ASSERT_ARG(expr) X_ASSERT(expr)
270 #else
271  #define X_ASSERT_ARG(expr) (void)0
272 #endif
273 
274 
278 #if X_CONF_USE_ASSERT_NULL != 0
279  #define X_ASSERT_NULL(expr) X_ASSERT(expr)
280 #else
281  #define X_ASSERT_NULL(expr) (void)0
282 #endif
283 
284 
288 #if X_CONF_USE_ASSERT_TAG
289  #define X_ASSERT_TAG(expr) X_ASSERT(expr)
290 #else
291  #define X_ASSERT_TAG(expr) (void)0
292 #endif
293 
294 
298 #if X_CONF_USE_ASSERT_ENUM
299  #define X_ASSERT_ENUM(expr) X_ASSERT(expr)
300 #else
301  #define X_ASSERT_ENUM(expr) (void)0
302 #endif
303 
304 
308 #if X_CONF_USE_DETECT_MALLOC_NULL != 0
309  #define X_ASSERT_MALLOC_NULL(expr) X_ASSERT(expr)
310 #else
311  #define X_ASSERT_MALLOC_NULL(expr) (void)0
312 #endif
313 
314 
318 #define X_ABORT(msg) X_ASSERT_MSG(0, msg)
319 
320 
324 #define X_ABORT_DEFAULT default: X_ABORT("Runtime error"); break
325 
326 
330 #define X_EXIT(return_code) X_ABORT("exit:" #return_code)
331 
332 
341 #define X_VERB_COLOR ""
342 #define X_INFO_COLOR X_COLOR_GREEN
343 #define X_NOTI_COLOR X_COLOR_MAGENTA
344 #define X_WARN_COLOR X_COLOR_YELLOW
345 #define X_ERR_COLOR X_COLOR_RED
346 #define X_VERB_HEADER X_VERB_COLOR X_CONF_VERB_HEADER X_COLOR_RESET
347 #define X_INFO_HEADER X_INFO_COLOR X_CONF_INFO_HEADER X_COLOR_RESET
348 #define X_NOTI_HEADER X_NOTI_COLOR X_CONF_NOTI_HEADER X_COLOR_RESET
349 #define X_WARN_HEADER X_WARN_COLOR X_CONF_WARN_HEADER X_COLOR_RESET
350 #define X_ERR_HEADER X_ERR_COLOR X_CONF_ERR_HEADER X_COLOR_RESET
351 
352 
357 int x_set_log_level(int level);
358 void x_hexdump(const void* src, size_t len, size_t cols);
359 
360 
368 void x_verb_printlog(const char* tag, const char* fmt, ...);
369 void x_info_printlog(const char* tag, const char* fmt, ...);
370 void x_noti_printlog(const char* tag, const char* fmt, ...);
371 void x_warn_printlog(const char* tag, const char* fmt, ...);
372 void x_err_printlog(const char* tag, const char* fmt, ...);
373 void x_verb_hexdump(const char* tag, const void* src, size_t len, size_t cols, const char* fmt, ...);
374 void x_info_hexdump(const char* tag, const void* src, size_t len, size_t cols, const char* fmt, ...);
375 void x_noti_hexdump(const char* tag, const void* src, size_t len, size_t cols, const char* fmt, ...);
376 void x_warn_hexdump(const char* tag, const void* src, size_t len, size_t cols, const char* fmt, ...);
377 void x_err_hexdump(const char* tag, const void* src, size_t len, size_t cols, const char* fmt, ...);
378 
379 
384 #ifdef __cplusplus
385 }
386 #endif
387 
388 
394 #endif // picox_core_detail_xdebug_h_
XAssertionFailedFunc x_post_assertion_failed
x_assertion_failedの呼び出し後に呼びされる関数のポインタです
Definition: xdebug.c:65
void(* XAssertionFailedFunc)(const char *expr, const char *msg, const char *func, const char *file, int line)
アサーションに失敗した時に呼び出される関数のポインタ型です
Definition: xdebug.h:63
XAssertionFailedFunc x_assertion_failed
アサーション失敗時に呼びされる関数のポインタです
Definition: xdebug.c:66
XAssertionFailedFunc x_pre_assertion_failed
x_assertion_failedの呼び出し前に呼びされる関数のポインタです
Definition: xdebug.c:64