Papageno
An Advanced Pattern Matching Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
ppg_debug.h
Go to the documentation of this file.
1 /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef PPG_DEBUG_H
18 #define PPG_DEBUG_H
19 
22 #include "ppg_settings.h"
23 #include "ppg_context.h"
24 
25 #include <stdlib.h>
26 #include <stdbool.h>
27 
28 #ifdef PPG_BUILDING_FOR_QMK
29 # ifndef USER_PRINT
30 # define USER_PRINT
31 # endif
32 # include "debug.h"
33 #endif
34 
35 #if PPG_HAVE_LOGGING
36 
37 # include <stdio.h>
38 
39 // Define the preprocessor macro PPG_PRINT_SELF_ENABLED
40 // to enable verbose class output of token classes
41 
42 #ifdef PPG_BUILDING_FOR_QMK
43 # define PPG_LOG(...) \
44  if(ppg_logging_get_enabled()) { \
45  uprintf(__VA_ARGS__); \
46  }
47 
48 #else
49 // # include <stdio.h>
50 # define PPG_LOG(...) \
51  if(ppg_logging_get_enabled()) { \
52  printf(__VA_ARGS__); \
53  }
54 
55 #endif
56 
59 bool ppg_logging_set_enabled(bool state);
60 
63 bool ppg_logging_get_enabled(void);
64 
70 #define PPG_LOGGING_SET_ENABLED(STATE) \
71  ppg_logging_set_enabled(STATE);
72 #else
73 
79 #define PPG_LOGGING_SET_ENABLED(STATE)
80 
81 #endif //PPG_HAVE_LOGGING
82 
83 
84 #ifdef PPG_BUILDING_FOR_QMK
85 
87 # define PPG_ERROR(...) uprintf("*** Error: " __VA_ARGS__);
88 
89 #else
90 
91 # include <stdio.h>
94 # define PPG_ERROR(...) printf("*** Error: " __VA_ARGS__);
95 #endif
96 
97 #if PPG_HAVE_ASSERTIONS
98 
101 #define PPG_ASSERT(...) \
102  if(!(__VA_ARGS__)) { \
103  PPG_ERROR("%s: %d: Assertion failed: %s\n", __FILE__, __LINE__, #__VA_ARGS__) \
104  abort(); \
105  }
106 #else
107 
109 #define PPG_ASSERT(...)
110 #endif // PPG_HAVE_ASSERTIONS
111 
112 #ifndef PPG_LOG
113 
115 #define PPG_LOG(...)
116 #define PPG_LOG_NOOP
117 #endif
118 
119 #define PPG_UNUSED(X) (void)(X)
120 
121 #endif