00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef TRACE_H
00021 #define TRACE_H
00022
00023 #include <common/ac/stddef.h>
00024
00025 #include <common/main.h>
00026
00027 struct string_ty;
00028
00035 #ifdef DEBUG
00036 #define trace_pretest_ \
00037 ( \
00038 ( \
00039 trace_pretest_result \
00040 ? \
00041 trace_pretest_result \
00042 : \
00043 trace_pretest(__FILE__, &trace_pretest_result) \
00044 ) \
00045 & \
00046 1 \
00047 )
00048 #define trace_where_ trace_where(__FILE__, __LINE__)
00049 #define trace(x) (void)(trace_pretest_ && (trace_where_, trace_printf x, 0))
00050 #define trace_if() (trace_pretest_ && (trace_where_, 1))
00051 #else
00052 #define trace(x)
00053 #define trace_if() 0
00054 #endif
00055
00056
00057
00058
00059
00060
00061
00062
00063 #ifdef DEBUG
00064 static int trace_pretest_result;
00065 #endif
00066
00067 int trace_pretest(const char *file, int *result);
00068 void trace_where(const char *file, int line);
00069 void trace_printf(const char *, ...) ATTR_PRINTF(1, 2);
00070 const char * trace_args();
00071 void trace_enable(const char *);
00072 void trace_indent_reset(void);
00073
00074
00075 #if defined(__STDC__) || defined(__stdc__)
00076 #define trace_stringize(x) #x
00077 #else
00078 #define trace_stringize(x) "x"
00079 #endif
00080
00081 void trace_bool_real(const char *name, const bool &value);
00082 void trace_char_real(const char *, const char *);
00083 void trace_char_unsigned_real(const char *, const unsigned char *);
00084 void trace_int_real(const char *, const int *);
00085 void trace_int_unsigned_real(const char *, const unsigned *);
00086 void trace_long_real(const char *, const long *);
00087 void trace_long_unsigned_real(const char *, const unsigned long *);
00088 void trace_pointer_real(const char *, const void *);
00089 void trace_short_real(const char *, const short *);
00090 void trace_short_unsigned_real(const char *, const unsigned short *);
00091 void trace_string_real(const char *, const string_ty *);
00092 void trace_string_real(const char *, const char *);
00093 void trace_time_real(const char *, long);
00094 void trace_double_real(const char *, const double &);
00095
00096 #ifdef DEBUG
00097
00098 #define trace_bool(x) \
00099 (void) \
00100 ( \
00101 trace_pretest_ \
00102 && \
00103 ( \
00104 trace_where_, \
00105 trace_bool_real(trace_stringize(x), (x)), \
00106 0 \
00107 ) \
00108 )
00109
00110 #define trace_char(x) \
00111 (void) \
00112 ( \
00113 trace_pretest_ \
00114 && \
00115 ( \
00116 trace_where_, \
00117 trace_char_real(trace_stringize(x), &(x)), \
00118 0 \
00119 ) \
00120 )
00121
00122 #define trace_char_unsigned(x) \
00123 (void) \
00124 ( \
00125 trace_pretest_ \
00126 && \
00127 ( \
00128 trace_where_, \
00129 trace_char_unsigned_real(trace_stringize(x), &(x)), \
00130 0 \
00131 ) \
00132 )
00133
00134 #define trace_int(x) \
00135 (void) \
00136 ( \
00137 trace_pretest_ \
00138 && \
00139 ( \
00140 trace_where_, \
00141 trace_int_real(trace_stringize(x), &(x)), \
00142 0 \
00143 ) \
00144 )
00145
00146 #define trace_int_unsigned(x) \
00147 (void) \
00148 ( \
00149 trace_pretest_ \
00150 && \
00151 ( \
00152 trace_where_, \
00153 trace_int_unsigned_real(trace_stringize(x), &(x)), \
00154 0 \
00155 ) \
00156 )
00157
00158 #define trace_long(x) \
00159 (void) \
00160 ( \
00161 trace_pretest_ \
00162 && \
00163 ( \
00164 trace_where_, \
00165 trace_long_real(trace_stringize(x), &(x)), \
00166 0 \
00167 ) \
00168 )
00169
00170 #define trace_long_unsigned(x) \
00171 (void) \
00172 ( \
00173 trace_pretest_ \
00174 && \
00175 ( \
00176 trace_where_, \
00177 trace_long_unsigned_real(trace_stringize(x), &(x)), \
00178 0 \
00179 ) \
00180 )
00181
00182 #define trace_pointer(x) \
00183 (void) \
00184 ( \
00185 trace_pretest_ \
00186 && \
00187 ( \
00188 trace_where_, \
00189 trace_pointer_real(trace_stringize(x), &(x)), \
00190 0 \
00191 ) \
00192 )
00193
00194 #define trace_short(x) \
00195 (void) \
00196 ( \
00197 trace_pretest_ \
00198 && \
00199 ( \
00200 trace_where_, \
00201 trace_short_real(trace_stringize(x), &(x)), \
00202 0 \
00203 ) \
00204 )
00205
00206 #define trace_short_unsigned(x) \
00207 (void) \
00208 ( \
00209 trace_pretest_ \
00210 && \
00211 ( \
00212 trace_where_, \
00213 trace_short_unsigned_real(trace_stringize(x), &(x)), \
00214 0 \
00215 ) \
00216 )
00217
00218 #define trace_string(x) \
00219 (void) \
00220 ( \
00221 trace_pretest_ \
00222 && \
00223 ( \
00224 trace_where_, \
00225 trace_string_real(trace_stringize(x), (x)), \
00226 0 \
00227 ) \
00228 )
00229
00230 #define trace_nstring(x) \
00231 (void) \
00232 ( \
00233 trace_pretest_ \
00234 && \
00235 ( \
00236 trace_where_, \
00237 trace_string_real(trace_stringize(x), (x).c_str()), \
00238 0 \
00239 ) \
00240 )
00241
00242 #define trace_time(x) \
00243 (void) \
00244 ( \
00245 trace_pretest_ \
00246 && \
00247 ( \
00248 trace_where_, \
00249 trace_time_real(trace_stringize(x), (long)(x)), \
00250 0 \
00251 ) \
00252 )
00253
00254 #define trace_double(x) \
00255 (void) \
00256 ( \
00257 trace_pretest_ \
00258 && \
00259 ( \
00260 trace_where_, \
00261 trace_time_real(trace_stringize(x), (x)), \
00262 0 \
00263 ) \
00264 )
00265
00266 #else
00267
00268 #define trace_bool(x)
00269 #define trace_char(x)
00270 #define trace_char_unsigned(x)
00271 #define trace_int(x)
00272 #define trace_int_unsigned(x)
00273 #define trace_long(x)
00274 #define trace_long_unsigned(x)
00275 #define trace_pointer(x)
00276 #define trace_short(x)
00277 #define trace_short_unsigned(x)
00278 #define trace_string(x)
00279 #define trace_nstring(x)
00280 #define trace_time(x)
00281 #define trace_double(x)
00282
00283 #endif
00284
00289 const char *unctrl(int);
00290
00292 #endif // TRACE_H