comparison src/define.h @ 202:2f38c4ce606f

remove readpstlog, switch to plain ascii debug log files
author Carl Byington <carl@five-ten-sg.com>
date Mon, 18 May 2009 15:55:05 -0700
parents 3850a3b11745
children 5f3fa53cb0e1
comparison
equal deleted inserted replaced
201:3850a3b11745 202:2f38c4ce606f
15 #include "libpst.h" 15 #include "libpst.h"
16 #include "timeconv.h" 16 #include "timeconv.h"
17 #include "libstrfunc.h" 17 #include "libstrfunc.h"
18 #include "vbuf.h" 18 #include "vbuf.h"
19 19
20 #define DEBUG_MODE_GEN
21 #define DEBUGPRINT
22 #define DEBUG_MODE_WARN
23 #define DEBUG_MODE_READ
24 #define DEBUG_MODE_EMAIL
25 #define DEBUG_MODE_MAIN
26 #define DEBUG_MODE_INDEX
27 #define DEBUG_MODE_CODE
28 #define DEBUG_MODE_INFO
29 #define DEBUG_MODE_HEXDUMP
30 #define DEBUG_MODE_FUNC
31
32 //number of items to save in memory between writes
33 #define DEBUG_MAX_ITEMS 0
34
35 #define DEBUG_FILE_NO 1
36 #define DEBUG_INDEX_NO 2
37 #define DEBUG_EMAIL_NO 3
38 #define DEBUG_WARN_NO 4
39 #define DEBUG_READ_NO 5
40 #define DEBUG_INFO_NO 6
41 #define DEBUG_MAIN_NO 7
42 #define DEBUG_DECRYPT_NO 8
43 #define DEBUG_FUNCENT_NO 9
44 #define DEBUG_FUNCRET_NO 10
45 #define DEBUG_HEXDUMP_NO 11
46 20
47 #ifdef HAVE_TIME_H 21 #ifdef HAVE_TIME_H
48 #include <time.h> 22 #include <time.h>
49 #endif 23 #endif
50 24
151 #ifdef HAVE_SEMAPHORE_H 125 #ifdef HAVE_SEMAPHORE_H
152 #include <semaphore.h> 126 #include <semaphore.h>
153 #endif 127 #endif
154 128
155 129
156 void pst_debug(const char *fmt, ...); 130 void pst_debug_lock();
157 void pst_debug_hexdumper(FILE* out, char* buf, size_t size, int col, int delta); 131 void pst_debug_unlock();
158 void pst_debug_hexprint(char *data, int size); 132 void pst_debug_init(const char* fname, void* output_mutex);
159 void pst_debug_init(const char *fname); 133 void pst_debug_func(const char* function);
160 void pst_debug_msg_info (int line, const char *file, int type);
161 void pst_debug_msg_text(const char* fmt, ...);
162 void pst_debug_hexdump(char *x, size_t y, int cols, int delta);
163 void pst_debug_func(const char *function);
164 void pst_debug_func_ret(); 134 void pst_debug_func_ret();
135 void pst_debug(int line, const char *file, const char *fmt, ...);
136 void pst_debug_hexdump(int line, const char *file, const char* buf, size_t size, int cols, int delta);
137 void pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta);
165 void pst_debug_close(void); 138 void pst_debug_close(void);
166 void* pst_malloc(size_t size); 139 void* pst_malloc(size_t size);
167 140
168 #define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\ 141 #define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__, __VA_ARGS__)
169 pst_debug_msg_text x;} 142
170 143 #define WARN(x) { \
171 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();} 144 MESSAGEPRINT x; \
145 pst_debug_lock(); \
146 printf x; \
147 fflush(stdout); \
148 pst_debug_unlock(); \
149 }
172 150
173 #define DIE(x) { \ 151 #define DIE(x) { \
174 MESSAGEPRINT(x, 0); \ 152 WARN(x); \
175 printf x; \
176 fflush(stdout); \
177 exit(EXIT_FAILURE); \ 153 exit(EXIT_FAILURE); \
178 } 154 }
179 #define WARN(x) { \ 155
180 MESSAGEPRINT(x, 0); \ 156 #define DEBUG_WARN(x) MESSAGEPRINT x
181 printf x; \ 157 #define DEBUG_INFO(x) MESSAGEPRINT x
182 fflush(stdout); \ 158 #define DEBUG_HEXDUMP(x, s) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, 0x10, 0)
183 } 159 #define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, c, 0)
184 160
185 #ifdef DEBUGPRINT 161
186 #define DEBUG_PRINT(x) pst_debug x;
187 #else
188 #define DEBUG_PRINT(x) {}
189 #endif
190
191 #ifdef DEBUG_MODE_GEN
192 #define DEBUG(x) {DEBUG_PRINT(x);}
193 #else
194 #define DEBUG(x) {}
195 #endif
196
197 #ifdef DEBUG_MODE_INDEX
198 #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
199 #else
200 #define DEBUG_INDEX(x) {}
201 #endif
202
203 #ifdef DEBUG_MODE_EMAIL
204 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
205 #define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
206 pst_debug_hexdump((char*)x, y, 0x10, 0);}
207 #else
208 #define DEBUG_EMAIL(x) {}
209 #define DEBUG_EMAIL_HEXPRINT(x,y) {}
210 #endif
211
212 #ifdef DEBUG_MODE_WARN
213 #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
214 #else
215 #define DEBUG_WARN(x) {}
216 #endif
217
218 #ifdef DEBUG_MODE_READ
219 #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
220 #else
221 #define DEBUG_READ(x) {}
222 #endif
223
224 #ifdef DEBUG_MODE_INFO
225 #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
226 #else
227 #define DEBUG_INFO(x) {}
228 #endif
229
230 #ifdef DEBUG_MODE_MAIN
231 #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
232 #else
233 #define DEBUG_MAIN(x) {}
234 #endif
235
236 #ifdef DEBUG_MODE_CODE
237 #define DEBUG_CODE(x) {x}
238 #else
239 #define DEBUG_CODE(x) {}
240 #endif
241
242 #ifdef DEBUG_MODE_DECRYPT
243 #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
244 #else
245 #define DEBUG_DECRYPT(x) {}
246 #endif
247
248 #ifdef DEBUG_MODE_HEXDUMP
249 #define DEBUG_HEXDUMP(x, s)\
250 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
251 pst_debug_hexdump((char*)x, s, 0x10, 0);}
252 #define DEBUG_HEXDUMPC(x, s, c)\
253 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
254 pst_debug_hexdump((char*)x, s, c, 0);}
255 #else
256 #define DEBUG_HEXDUMP(x, s) {}
257 #define DEBUG_HEXDUMPC(x, s, c) {}
258 #endif
259
260 #define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
261 pst_debug_msg_text x;}
262
263 #ifdef DEBUG_MODE_FUNC
264 # define DEBUG_ENT(x) \ 162 # define DEBUG_ENT(x) \
265 { \ 163 { \
266 pst_debug_func(x); \ 164 pst_debug_func(x); \
267 MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNCENT_NO); \ 165 pst_debug(__LINE__, __FILE__, "Entering function\n"); \
268 } 166 }
269 # define DEBUG_RET() \ 167 # define DEBUG_RET() \
270 { \ 168 { \
271 MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO); \ 169 pst_debug(__LINE__, __FILE__, "Leaving function\n"); \
272 pst_debug_func_ret(); \ 170 pst_debug_func_ret(); \
273 } 171 }
274 #else 172
275 # define DEBUG_ENT(x) {} 173 #define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);}
276 # define DEBUG_RET() {} 174 #define DEBUG_CLOSE() {pst_debug_close();}
277 #endif 175 #define RET_DERROR(res, ret_val, x) if (res) { DIE(x);}
278 176
279 #define DEBUG_INIT(fname) {pst_debug_init(fname);} 177
280 #define DEBUG_CLOSE() {pst_debug_close();}
281 #define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
282
283 #define RET_DERROR(res, ret_val, x)\
284 if (res) { DIE(x);}
285
286 #define RET_ERROR(res, ret_val)\
287 if (res) {return ret_val;}
288
289 #define DEBUG_VERSION 1
290 struct pst_debug_file_rec_m {
291 unsigned short int funcname;
292 unsigned short int filename;
293 unsigned short int text;
294 unsigned short int end;
295 unsigned int line;
296 unsigned int type;
297 };
298
299 struct pst_debug_file_rec_l {
300 unsigned int funcname;
301 unsigned int filename;
302 unsigned int text;
303 unsigned int end;
304 unsigned int line;
305 unsigned int type;
306 };
307 178
308 #if BYTE_ORDER == BIG_ENDIAN 179 #if BYTE_ORDER == BIG_ENDIAN
309 # define LE64_CPU(x) \ 180 # define LE64_CPU(x) \
310 x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \ 181 x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
311 (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \ 182 (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \