Mercurial > libpst
diff 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 |
line wrap: on
line diff
--- a/src/define.h Sat May 16 10:32:26 2009 -0700 +++ b/src/define.h Mon May 18 15:55:05 2009 -0700 @@ -17,32 +17,6 @@ #include "libstrfunc.h" #include "vbuf.h" -#define DEBUG_MODE_GEN -#define DEBUGPRINT -#define DEBUG_MODE_WARN -#define DEBUG_MODE_READ -#define DEBUG_MODE_EMAIL -#define DEBUG_MODE_MAIN -#define DEBUG_MODE_INDEX -#define DEBUG_MODE_CODE -#define DEBUG_MODE_INFO -#define DEBUG_MODE_HEXDUMP -#define DEBUG_MODE_FUNC - -//number of items to save in memory between writes -#define DEBUG_MAX_ITEMS 0 - -#define DEBUG_FILE_NO 1 -#define DEBUG_INDEX_NO 2 -#define DEBUG_EMAIL_NO 3 -#define DEBUG_WARN_NO 4 -#define DEBUG_READ_NO 5 -#define DEBUG_INFO_NO 6 -#define DEBUG_MAIN_NO 7 -#define DEBUG_DECRYPT_NO 8 -#define DEBUG_FUNCENT_NO 9 -#define DEBUG_FUNCRET_NO 10 -#define DEBUG_HEXDUMP_NO 11 #ifdef HAVE_TIME_H #include <time.h> @@ -153,157 +127,54 @@ #endif -void pst_debug(const char *fmt, ...); -void pst_debug_hexdumper(FILE* out, char* buf, size_t size, int col, int delta); -void pst_debug_hexprint(char *data, int size); -void pst_debug_init(const char *fname); -void pst_debug_msg_info (int line, const char *file, int type); -void pst_debug_msg_text(const char* fmt, ...); -void pst_debug_hexdump(char *x, size_t y, int cols, int delta); -void pst_debug_func(const char *function); +void pst_debug_lock(); +void pst_debug_unlock(); +void pst_debug_init(const char* fname, void* output_mutex); +void pst_debug_func(const char* function); void pst_debug_func_ret(); +void pst_debug(int line, const char *file, const char *fmt, ...); +void pst_debug_hexdump(int line, const char *file, const char* buf, size_t size, int cols, int delta); +void pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta); void pst_debug_close(void); void* pst_malloc(size_t size); -#define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\ - pst_debug_msg_text x;} - -#define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();} +#define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__, __VA_ARGS__) -#define DIE(x) { \ - MESSAGEPRINT(x, 0); \ - printf x; \ - fflush(stdout); \ - exit(EXIT_FAILURE); \ -} #define WARN(x) { \ - MESSAGEPRINT(x, 0); \ - printf x; \ - fflush(stdout); \ + MESSAGEPRINT x; \ + pst_debug_lock(); \ + printf x; \ + fflush(stdout); \ + pst_debug_unlock(); \ } -#ifdef DEBUGPRINT -#define DEBUG_PRINT(x) pst_debug x; -#else -#define DEBUG_PRINT(x) {} -#endif - -#ifdef DEBUG_MODE_GEN -#define DEBUG(x) {DEBUG_PRINT(x);} -#else -#define DEBUG(x) {} -#endif - -#ifdef DEBUG_MODE_INDEX -#define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO); -#else -#define DEBUG_INDEX(x) {} -#endif - -#ifdef DEBUG_MODE_EMAIL -#define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO); -#define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\ - pst_debug_hexdump((char*)x, y, 0x10, 0);} -#else -#define DEBUG_EMAIL(x) {} -#define DEBUG_EMAIL_HEXPRINT(x,y) {} -#endif - -#ifdef DEBUG_MODE_WARN -#define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO); -#else -#define DEBUG_WARN(x) {} -#endif - -#ifdef DEBUG_MODE_READ -#define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO); -#else -#define DEBUG_READ(x) {} -#endif +#define DIE(x) { \ + WARN(x); \ + exit(EXIT_FAILURE); \ +} -#ifdef DEBUG_MODE_INFO -#define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO); -#else -#define DEBUG_INFO(x) {} -#endif - -#ifdef DEBUG_MODE_MAIN -#define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO); -#else -#define DEBUG_MAIN(x) {} -#endif - -#ifdef DEBUG_MODE_CODE -#define DEBUG_CODE(x) {x} -#else -#define DEBUG_CODE(x) {} -#endif +#define DEBUG_WARN(x) MESSAGEPRINT x +#define DEBUG_INFO(x) MESSAGEPRINT x +#define DEBUG_HEXDUMP(x, s) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, 0x10, 0) +#define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, c, 0) -#ifdef DEBUG_MODE_DECRYPT -#define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO); -#else -#define DEBUG_DECRYPT(x) {} -#endif -#ifdef DEBUG_MODE_HEXDUMP -#define DEBUG_HEXDUMP(x, s)\ - {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\ - pst_debug_hexdump((char*)x, s, 0x10, 0);} -#define DEBUG_HEXDUMPC(x, s, c)\ - {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\ - pst_debug_hexdump((char*)x, s, c, 0);} -#else -#define DEBUG_HEXDUMP(x, s) {} -#define DEBUG_HEXDUMPC(x, s, c) {} -#endif - -#define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\ - pst_debug_msg_text x;} - -#ifdef DEBUG_MODE_FUNC # define DEBUG_ENT(x) \ { \ pst_debug_func(x); \ - MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNCENT_NO); \ + pst_debug(__LINE__, __FILE__, "Entering function\n"); \ } # define DEBUG_RET() \ { \ - MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO); \ + pst_debug(__LINE__, __FILE__, "Leaving function\n"); \ pst_debug_func_ret(); \ } -#else -# define DEBUG_ENT(x) {} -# define DEBUG_RET() {} -#endif - -#define DEBUG_INIT(fname) {pst_debug_init(fname);} -#define DEBUG_CLOSE() {pst_debug_close();} -#define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");} - -#define RET_DERROR(res, ret_val, x)\ - if (res) { DIE(x);} - -#define RET_ERROR(res, ret_val)\ - if (res) {return ret_val;} -#define DEBUG_VERSION 1 -struct pst_debug_file_rec_m { - unsigned short int funcname; - unsigned short int filename; - unsigned short int text; - unsigned short int end; - unsigned int line; - unsigned int type; -}; +#define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);} +#define DEBUG_CLOSE() {pst_debug_close();} +#define RET_DERROR(res, ret_val, x) if (res) { DIE(x);} -struct pst_debug_file_rec_l { - unsigned int funcname; - unsigned int filename; - unsigned int text; - unsigned int end; - unsigned int line; - unsigned int type; -}; + #if BYTE_ORDER == BIG_ENDIAN # define LE64_CPU(x) \