00001
00002
00003
00004
00005
00006
00007
00013 #ifndef Z_UTILS_H
00014 #define Z_UTILS_H
00015
00016 #include <config.h>
00017 #include <sys/time.h>
00018 #include <stdio.h>
00019
00020
00022 extern int GTCDEBUGLEVEL;
00023
00025 double gtc_time();
00026
00028 void gtc_time_convert (double t,
00029 struct timeval *tv);
00030
00032 void gtc_stream_int (unsigned char *destination, int foo);
00034 int degtc_stream_int (unsigned char *destination);
00035
00037 typedef float gtcReal;
00038
00040 #define gtc_max(a,b) ((a)>(b)?(a):(b))
00041
00042 #define gtc_min(a,b) ((a)<(b)?(a):(b))
00043
00044
00045 #ifdef WITH_DMALLOC
00046 #define gtc_must_malloc malloc
00047 #define gtc_strdup strdup
00048 #else
00049
00050 void *_gtc_must_malloc(int size, char *file, char *function, int line);
00051 #define gtc_must_malloc(x) _gtc_must_malloc(x,__FILE__,__PRETTY_FUNCTION__, __LINE__)
00052
00053 char *gtc_strdup (char *s);
00054 #endif
00055 void *gtc_memdup(void *buffer, int size);
00056
00057 #define gtc_free(x) _gtc_free(x,__FILE__,__PRETTY_FUNCTION__, __LINE__)
00058 void _gtc_free(void *x, char *file, char *function, int line);
00059
00060
00061
00062
00063
00065 extern const char *LEGAL;
00066
00067 extern const char *gtcBuildTime;
00068 extern const char *gtcVersion;
00069
00104 void gtc_init_tokens(void);
00106 char *gtc_get_token(char *id);
00118 int gtc_tokenize(char *s, char *tok, int n, int maxsize);
00120 int gtc_count_tokens(char *s);
00121
00133 FILE *gtc_fopen(char *filename, char *mode);
00141 FILE *gtc_open(char *filename, char *mode);
00142
00144 extern char *(*gtcTokens)[2];
00146 extern int gtcNumTokens;
00147
00148 int gtc_internal_error_prefix(char *file, char *function, int line,
00149 char *prefix);
00150 int gtc_internal_error(const char *format, ...);
00151 int gtc_debug_msg(const char *format, ...);
00152
00162 #define GTCERROR gtc_internal_error_prefix(__FILE__,__PRETTY_FUNCTION__, \
00163 __LINE__, "ERROR") && gtc_internal_error
00164
00172 #define GTCWARN gtc_internal_error_prefix(__FILE__,__PRETTY_FUNCTION__, \
00173 __LINE__, "WARNING") && gtc_debug_msg
00174
00175 #ifdef GTCSILENT
00176 #define GTCDEBUG 0 && gtc_debug_msg
00177 #define GTCPRINT 0 && gtc_debug_msg
00178 #define GTCINFO 0 && gtc_info_msg
00179 #else
00180
00189 #define GTCDEBUG GTCDEBUGLEVEL && gtc_internal_error_prefix(__FILE__, \
00190 __PRETTY_FUNCTION__, __LINE__, "DEBUG") && gtc_debug_msg
00191 #define GTCPRINT printf
00192
00194 #define GTCINFO gtc_internal_error_prefix(__FILE__,__PRETTY_FUNCTION__, \
00195 __LINE__, "INFO") && gtc_info_msg
00196 #endif
00197
00198 int gtc_assert(char *file, char *f, int line,char *assertion);
00199
00200 #define GTC_ASSERT_REFCOUNT(x) ((x)->refcount>0||gtc_assert(__FILE__,__PRETTY_FUNCTION__,__LINE__,"refcount of " #x ">0"))
00201
00203 #define GTCASSERT(x) ((x)||gtc_assert(__FILE__,__PRETTY_FUNCTION__,__LINE__,"(" #x ")"))
00204 #define GTC_INCREF(x) (x)->refcount++
00205 #define GTC_DECREF(x,destructor) GTC_ASSERT_REFCOUNT(x)&&((--(x)->refcount)||destructor(x))
00206
00208
00217 void gtc_init(void);
00218
00219 #endif