00001
00037 #ifndef _UTIL
00038 #define _UTIL
00039
00040 #include <stdio.h>
00041 #include <ctype.h>
00042 #include <math.h>
00043
00044 #if HAVE_UNISTD_H
00045 # include <unistd.h>
00046 #endif
00047
00048 #if HAVE_SYS_TYPES_H
00049 # include <sys/types.h>
00050 #endif
00051
00052 #if HAVE_VARARGS_H
00053 # include <varargs.h>
00054 #endif
00055
00056 #if STDC_HEADERS
00057 # include <stdlib.h>
00058 # include <string.h>
00059 #else
00060 # ifdef HAVE_STRCHR
00061 char * strchr(const char *, int);
00062 int strcmp(const char *, const char *);
00063 # else
00064 # define strchr index
00065 # endif
00066 # ifdef HAVE_GETENV
00067 char * getenv(const char *);
00068 # endif
00069 #endif
00070
00071 #if HAVE_ERRNO_H
00072 # include <errno.h>
00073 #endif
00074
00075
00076
00077
00078
00079 #if HAVE_ASSERT_H
00080 # include <assert.h>
00081 #else
00082 # ifdef NDEBUG
00083 # define assert(ex) ;
00084 # else
00085 # define assert(ex) {\
00086 if (! (ex)) {\
00087 (void) fprintf(stderr,\
00088 "Assertion failed: file %s, line %d\n\"%s\"\n",\
00089 __FILE__, __LINE__, "ex");\
00090 (void) fflush(stdout);\
00091 abort();\
00092 }\
00093 }
00094 # endif
00095 #endif
00096
00097 #define fail(why) {\
00098 (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
00099 __FILE__, __LINE__, why);\
00100 (void) fflush(stdout);\
00101 abort();\
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111 #ifndef ARGS
00112 # ifdef __STDC__
00113 # define ARGS(args) args
00114 # else
00115 # define ARGS(args) ()
00116 # endif
00117 #endif
00118
00119 #ifndef NULLARGS
00120 # ifdef __STDC__
00121 # define NULLARGS (void)
00122 # else
00123 # define NULLARGS ()
00124 # endif
00125 #endif
00126
00127
00128
00129
00130
00131 #ifdef __cplusplus
00132 # define EXTERN extern "C"
00133 #else
00134 # define EXTERN extern
00135 #endif
00136
00137
00138
00139
00140 #if defined (__GNUC__)
00141 #if (__GNUC__ >2 || __GNUC_MINOR__ >=7) && !defined(UNUSED)
00142 #define UNUSED __attribute__ ((unused))
00143 #else
00144 #define UNUSED
00145 #endif
00146 #else
00147 #define UNUSED
00148 #endif
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 #define NIL(type) ((type *) 0)
00159
00160
00161
00162 #ifdef USE_MM
00163
00164
00165
00166
00167
00168
00169 # define ALLOC(type, num) \
00170 ((type *) malloc(sizeof(type) * (num)))
00171 # define REALLOC(type, obj, num) \
00172 (obj) ? ((type *) realloc((void *) obj, sizeof(type) * (num))) : \
00173 ((type *) malloc(sizeof(type) * (num)))
00174 # define FREE(obj) \
00175 ((obj) ? (free((void *) (obj)), (obj) = 0) : 0)
00176 #else
00177
00178
00179
00180 # define ALLOC(type, num) \
00181 ((type *) MMalloc(sizeof(type) * (unsigned long) (num)))
00182 # define REALLOC(type, obj, num) \
00183 ((type *) MMrealloc((void *) (obj), sizeof(type) * (unsigned long) (num)))
00184 # define FREE(obj) \
00185 ((obj) ? (free((void *) (obj)), (obj) = 0) : 0)
00186 #endif
00187
00188 #ifndef TRUE
00189 # define TRUE 1
00190 #endif
00191
00192 #ifndef FALSE
00193 # define FALSE 0
00194 #endif
00195
00196 #ifndef ABS
00197 # define ABS(a) ((a) < 0 ? -(a) : (a))
00198 #endif
00199
00200 #ifndef MAX
00201 # define MAX(a,b) ((a) > (b) ? (a) : (b))
00202 #endif
00203
00204 #ifndef MIN
00205 # define MIN(a,b) ((a) < (b) ? (a) : (b))
00206 #endif
00207
00208 #define ptime() util_cpu_time()
00209 #define print_time(t) util_print_time(t)
00210
00211 #ifndef HUGE_VAL
00212 # ifndef HUGE
00213 # define HUGE 8.9884656743115790e+307
00214 # endif
00215 # define HUGE_VAL HUGE
00216 #endif
00217
00218 #ifndef MAXINT
00219 # define MAXINT (1 << 30)
00220 #endif
00221
00222 EXTERN void util_print_cpu_stats ARGS((FILE *));
00223 EXTERN long util_cpu_time ARGS((void));
00224 EXTERN long util_cpu_ctime ARGS((void));
00225 EXTERN void util_getopt_reset ARGS((void));
00226 EXTERN int util_getopt ARGS((int, char * const *, char const *));
00227 EXTERN int util_check_file ARGS((char const *, char const *));
00228 EXTERN char *util_path_search ARGS((char const *));
00229 EXTERN char *util_file_search ARGS((char const *, char *, char const *));
00230 EXTERN char *util_print_time ARGS((long));
00231 EXTERN int util_save_image ARGS((char const *, char const *));
00232 EXTERN char *util_strsav ARGS((char const *));
00233 EXTERN char *util_inttostr ARGS((int));
00234 EXTERN char *util_strcat3 ARGS((char const *, char const *, char const *));
00235 EXTERN char *util_strcat4 ARGS((char const *, char const *, char const *, char const *));
00236 EXTERN int util_do_nothing ARGS((void));
00237 EXTERN char *util_tilde_expand ARGS((char const *));
00238 EXTERN char *util_tempnam ARGS((char const *, char const *));
00239 EXTERN FILE *util_tmpfile ARGS((void));
00240 EXTERN void util_srandom ARGS((long));
00241 EXTERN long util_random ARGS((void));
00242 EXTERN unsigned long getSoftDataLimit ARGS((void));
00243 EXTERN void MMout_of_memory ARGS((unsigned long));
00244 EXTERN void *MMalloc ARGS((unsigned long));
00245 EXTERN void *MMrealloc ARGS((void *, unsigned long));
00246 EXTERN void MMfree ARGS((void *));
00247
00248
00249
00250
00251
00252 extern int util_optind;
00253 extern char *util_optarg;
00254
00257
00258
00259
00260
00263 #endif