comparison define.h @ 0:6b1b602514db libpst_0_5

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