Mercurial > libpst
annotate src/define.h @ 33:12cac756bc05 stable-0-5-5
enable -d option, but if not specified, don't generate a debug file
author | carl |
---|---|
date | Tue, 10 Jul 2007 20:23:55 -0700 |
parents | b88ceb81dba2 |
children | 07177825c91b |
rev | line source |
---|---|
16 | 1 /*** |
2 * define.h | |
3 * Part of the LibPST project | |
4 * Written by David Smith | |
5 * dave.s@earthcorp.com | |
6 */ | |
7 | |
31 | 8 #ifdef HAVE_CONFIG_H |
9 #include "config.h" | |
10 #endif | |
16 | 11 |
12 #ifndef DEFINEH_H | |
13 #define DEFINEH_H | |
14 | |
33
12cac756bc05
enable -d option, but if not specified, don't generate a debug file
carl
parents:
31
diff
changeset
|
15 // #ifdef DEBUG_ALL |
16 | 16 #define DEBUG_MODE_GEN |
17 #define DEBUGPRINT | |
18 #define DEBUG_MODE_WARN | |
19 #define DEBUG_MODE_READ | |
20 #define DEBUG_MODE_EMAIL | |
21 #define DEBUG_MODE_MAIN | |
22 #define DEBUG_MODE_INDEX | |
23 #define DEBUG_MODE_CODE | |
24 #define DEBUG_MODE_INFO | |
25 #define DEBUG_MODE_HEXDUMP | |
26 #define DEBUG_MODE_FUNC | |
33
12cac756bc05
enable -d option, but if not specified, don't generate a debug file
carl
parents:
31
diff
changeset
|
27 // #endif |
16 | 28 |
29 //number of items to save in memory between writes | |
30 #define DEBUG_MAX_ITEMS 0 | |
31 | |
32 #define DEBUG_FILE_NO 1 | |
33 #define DEBUG_INDEX_NO 2 | |
34 #define DEBUG_EMAIL_NO 3 | |
35 #define DEBUG_WARN_NO 4 | |
36 #define DEBUG_READ_NO 5 | |
37 #define DEBUG_INFO_NO 6 | |
38 #define DEBUG_MAIN_NO 7 | |
39 #define DEBUG_DECRYPT_NO 8 | |
40 #define DEBUG_FUNC_NO 10 | |
41 #define DEBUG_HEXDUMP_NO 11 | |
42 | |
43 //variable number of arguments to this macro. will expand them into | |
44 // ## args, then exit with status of 1 | |
45 #include <stdio.h> | |
46 #include <stdlib.h> | |
47 #include <stdarg.h> | |
48 | |
49 #ifdef __LINUX__ | |
50 #include <netinet/in.h> | |
51 #include <unistd.h> | |
52 #endif | |
53 | |
54 | |
55 void _pst_debug(char *fmt, ...); | |
56 void _pst_debug_hexdump(FILE* out, unsigned char* buf, size_t size, int col); | |
57 void _pst_debug_hexprint(char *data, int size); | |
58 | |
59 void _debug_init(char *fname); | |
60 void _debug_msg_info (int line, char *file, int type); | |
61 void _debug_msg_text(char* fmt, ...); | |
31 | 62 void _debug_hexdump(unsigned char *x, int y, int cols); |
16 | 63 void _debug_func(char *function); |
64 void _debug_func_ret(); | |
65 void _debug_close(void); | |
66 void _debug_write(); | |
67 | |
68 void * xmalloc(size_t size); | |
69 | |
70 #define MESSAGEPRINT(x,y) {_debug_msg_info(__LINE__,__FILE__,y);\ | |
71 _debug_msg_text x;} | |
72 | |
73 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();} | |
74 | |
75 #define DIE(x) {\ | |
76 MESSAGEPRINT(x, 0);\ | |
77 printf x;\ | |
78 exit(EXIT_FAILURE);\ | |
79 } | |
80 #define WARN(x) {\ | |
81 MESSAGEPRINT(x, 0);\ | |
82 printf x;\ | |
83 } | |
84 | |
85 #ifdef DEBUGPRINT | |
86 #define DEBUG_PRINT(x) _pst_debug x; | |
87 #else | |
88 #define DEBUG_PRINT(x) {} | |
89 #endif | |
90 | |
91 #ifdef DEBUG_MODE_GEN | |
92 #define DEBUG(x) {DEBUG_PRINT(x);} | |
93 #else | |
94 #define DEBUG(x) {} | |
95 #endif | |
96 | |
97 #ifdef DEBUG_MODE_INDEX | |
98 #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO); | |
99 #else | |
100 #define DEBUG_INDEX(x) {} | |
101 #endif | |
102 | |
103 #ifdef DEBUG_MODE_EMAIL | |
104 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO); | |
105 #define DEBUG_EMAIL_HEXPRINT(x,y) {_debug_msg_info(__LINE__, __FILE__, 11);\ | |
106 _debug_hexdump(x, y, 0x10);} | |
107 #else | |
108 #define DEBUG_EMAIL(x) {} | |
109 #define DEBUG_EMAIL_HEXPRINT(x,y) {} | |
110 #endif | |
111 | |
112 #ifdef DEBUG_MODE_WARN | |
113 #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO); | |
114 #else | |
115 #define DEBUG_WARN(x) {} | |
116 #endif | |
117 | |
118 #ifdef DEBUG_MODE_READ | |
119 #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO); | |
120 #else | |
121 #define DEBUG_READ(x) {} | |
122 #endif | |
123 | |
124 #ifdef DEBUG_MODE_INFO | |
125 #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO); | |
126 #else | |
127 #define DEBUG_INFO(x) {} | |
128 #endif | |
129 | |
130 #ifdef DEBUG_MODE_MAIN | |
131 #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO); | |
132 #else | |
133 #define DEBUG_MAIN(x) {} | |
134 #endif | |
135 | |
136 #ifdef DEBUG_MODE_CODE | |
137 #define DEBUG_CODE(x) {x} | |
138 #else | |
139 #define DEBUG_CODE(x) {} | |
140 #endif | |
141 | |
142 #ifdef DEBUG_MODE_DECRYPT | |
143 #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO); | |
144 #else | |
145 #define DEBUG_DECRYPT(x) {} | |
146 #endif | |
147 | |
148 #ifdef DEBUG_MODE_HEXDUMP | |
149 #define DEBUG_HEXDUMP(x, s)\ | |
150 {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\ | |
151 _debug_hexdump(x, s, 0x10);} | |
152 #define DEBUG_HEXDUMPC(x, s, c)\ | |
153 {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\ | |
154 _debug_hexdump(x, s, c);} | |
155 #else | |
156 #define DEBUG_HEXDUMP(x, s) {} | |
157 #define DEBUG_HEXDUMPC(x, s, c) {} | |
158 #endif | |
159 | |
160 #define DEBUG_FILE(x) {_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\ | |
161 _debug_msg_text x;} | |
162 | |
163 #ifdef DEBUG_MODE_FUNC | |
164 # define DEBUG_ENT(x) \ | |
165 {MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNC_NO);\ | |
166 _debug_func(x);} | |
167 # define DEBUG_RET() {MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNC_NO);\ | |
168 _debug_func_ret();} | |
169 #else | |
170 # define DEBUG_ENT(x) {} | |
171 # define DEBUG_RET() {} | |
172 #endif | |
173 | |
174 #define DEBUG_INIT(fname) {_debug_init(fname);} | |
175 #define DEBUG_CLOSE() {_debug_close();} | |
176 #define DEBUG_REGISTER_CLOSE() {if(atexit(_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");} | |
177 | |
178 #define RET_DERROR(res, ret_val, x)\ | |
179 if (res) { DIE(x);} | |
180 | |
181 #define RET_ERROR(res, ret_val)\ | |
182 if (res) {return ret_val;} | |
183 | |
184 #define DEBUG_VERSION 1 | |
185 struct _debug_file_rec_m { | |
186 unsigned short int funcname; | |
187 unsigned short int filename; | |
188 unsigned short int text; | |
189 unsigned short int end; | |
190 unsigned int line; | |
191 unsigned int type; | |
192 }; | |
193 | |
194 struct _debug_file_rec_l { | |
195 unsigned int funcname; | |
196 unsigned int filename; | |
197 unsigned int text; | |
198 unsigned int end; | |
199 unsigned int line; | |
200 unsigned int type; | |
201 }; | |
202 | |
203 #endif //DEFINEH_H |