1

Committer:
floatlei
Date:
Sat Oct 08 02:35:14 2016 +0000
Revision:
0:7e14d7c443f1
11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
floatlei 0:7e14d7c443f1 1 /* Copyright (c) 2012 mbed.org, MIT License
floatlei 0:7e14d7c443f1 2 *
floatlei 0:7e14d7c443f1 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
floatlei 0:7e14d7c443f1 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
floatlei 0:7e14d7c443f1 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
floatlei 0:7e14d7c443f1 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
floatlei 0:7e14d7c443f1 7 * furnished to do so, subject to the following conditions:
floatlei 0:7e14d7c443f1 8 *
floatlei 0:7e14d7c443f1 9 * The above copyright notice and this permission notice shall be included in all copies or
floatlei 0:7e14d7c443f1 10 * substantial portions of the Software.
floatlei 0:7e14d7c443f1 11 *
floatlei 0:7e14d7c443f1 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
floatlei 0:7e14d7c443f1 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
floatlei 0:7e14d7c443f1 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
floatlei 0:7e14d7c443f1 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
floatlei 0:7e14d7c443f1 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
floatlei 0:7e14d7c443f1 17 */
floatlei 0:7e14d7c443f1 18
floatlei 0:7e14d7c443f1 19 #ifndef DEBUG_H
floatlei 0:7e14d7c443f1 20 #define DEBUG_H
floatlei 0:7e14d7c443f1 21
floatlei 0:7e14d7c443f1 22 /** @file debug.h */
floatlei 0:7e14d7c443f1 23
floatlei 0:7e14d7c443f1 24 #ifndef NDEBUG
floatlei 0:7e14d7c443f1 25
floatlei 0:7e14d7c443f1 26 #include <stdarg.h>
floatlei 0:7e14d7c443f1 27 #include <stdio.h>
floatlei 0:7e14d7c443f1 28
floatlei 0:7e14d7c443f1 29 /** Output a debug message
floatlei 0:7e14d7c443f1 30 *
floatlei 0:7e14d7c443f1 31 * @param format printf-style format string, followed by variables
floatlei 0:7e14d7c443f1 32 */
floatlei 0:7e14d7c443f1 33 static inline void debug(const char *format, ...) {
floatlei 0:7e14d7c443f1 34 va_list args;
floatlei 0:7e14d7c443f1 35 va_start(args, format);
floatlei 0:7e14d7c443f1 36 vfprintf(stderr, format, args);
floatlei 0:7e14d7c443f1 37 va_end(args);
floatlei 0:7e14d7c443f1 38 }
floatlei 0:7e14d7c443f1 39
floatlei 0:7e14d7c443f1 40 /** Conditionally output a debug message
floatlei 0:7e14d7c443f1 41 *
floatlei 0:7e14d7c443f1 42 * @param condition output only if condition is true
floatlei 0:7e14d7c443f1 43 * @param format printf-style format string, followed by variables
floatlei 0:7e14d7c443f1 44 */
floatlei 0:7e14d7c443f1 45 static inline void debug_if(bool condition, const char *format, ...) {
floatlei 0:7e14d7c443f1 46 if(condition) {
floatlei 0:7e14d7c443f1 47 va_list args;
floatlei 0:7e14d7c443f1 48 va_start(args, format);
floatlei 0:7e14d7c443f1 49 vfprintf(stderr, format, args);
floatlei 0:7e14d7c443f1 50 va_end(args);
floatlei 0:7e14d7c443f1 51 }
floatlei 0:7e14d7c443f1 52 }
floatlei 0:7e14d7c443f1 53
floatlei 0:7e14d7c443f1 54 #else
floatlei 0:7e14d7c443f1 55
floatlei 0:7e14d7c443f1 56 static inline void debug(const char *format, ...) {}
floatlei 0:7e14d7c443f1 57 static inline void debug(bool condition, const char *format, ...) {}
floatlei 0:7e14d7c443f1 58
floatlei 0:7e14d7c443f1 59 #endif
floatlei 0:7e14d7c443f1 60
floatlei 0:7e14d7c443f1 61 #endif