comparison src/define.h @ 16:c508ee15dfca

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