00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef UTIL_H
00011 #define UTIL_H
00012
00013 #if defined(_IBMR2)
00014 #ifndef _POSIX_SOURCE
00015 #define _POSIX_SOURCE
00016 #endif
00017 #ifndef _ALL_SOURCE
00018 #define _ALL_SOURCE
00019 #endif
00020 #ifndef _ANSI_C_SOURCE
00021 #define _ANSI_C_SOURCE
00022 #endif
00023 #endif
00024
00025 #if defined(__STDC__) || defined(sprite) || defined(_IBMR2) || defined(__osf__)
00026 #include <unistd.h>
00027 #endif
00028
00029 #if defined(_IBMR2) && !defined(__STDC__)
00030 #define _BSD
00031 #endif
00032
00033 #include "ansi.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042 #define NIL(type) ((type *) 0)
00043
00044 #ifdef USE_MM
00045
00046
00047
00048
00049
00050
00051 #define ALLOC(type, num) \
00052 ((type *) malloc(sizeof(type) * (num)))
00053 #define REALLOC(type, obj, num) \
00054 (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) : \
00055 ((type *) malloc(sizeof(type) * (num)))
00056 #define FREE(obj) \
00057 ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
00058 #else
00059
00060
00061
00062
00063 #define ALLOC(type, num) \
00064 ((type *) MMalloc((long) sizeof(type) * (long) (num)))
00065 #define REALLOC(type, obj, num) \
00066 ((type *) MMrealloc((char *) (obj), (long) sizeof(type) * (long) (num)))
00067 #define FREE(obj) \
00068 ((obj) ? (free((void *) (obj)), (obj) = 0) : 0)
00069 #endif
00070
00071
00072
00073 #if defined(ultrix) || defined(SABER) || defined(aiws) || defined(__hpux) || defined(__STDC__) || defined(apollo)
00074 #define VOID_HACK void
00075 #else
00076 #define VOID_HACK int
00077 #endif
00078
00079
00080
00081 #include <stdio.h>
00082 #include <ctype.h>
00083
00084
00085
00086 #if !defined(__STDC__) && !defined(sprite) && !defined(_IBMR2) && !defined(__osf__)
00087 extern FILE *popen(), *tmpfile();
00088 extern int pclose();
00089 #ifndef clearerr
00090 extern VOID_HACK clearerr();
00091 #endif
00092 #ifndef rewind
00093 extern VOID_HACK rewind();
00094 #endif
00095 #endif
00096
00097 #ifndef PORT_H
00098 #include <sys/types.h>
00099 #include <signal.h>
00100 #if defined(ultrix)
00101 #if defined(_SIZE_T_)
00102 #define ultrix4
00103 #else
00104 #if defined(SIGLOST)
00105 #define ultrix3
00106 #else
00107 #define ultrix2
00108 #endif
00109 #endif
00110 #endif
00111 #endif
00112
00113
00114 #if defined(__STDC__) || defined(sprite) || defined(_IBMR2) || defined(__osf__) || defined(sunos4) || defined(__hpux)
00115 #include <stdlib.h>
00116 #if defined(__hpux)
00117 #include <errno.h>
00118 #endif
00119 #else
00120 extern VOID_HACK abort(), free(), exit(), perror();
00121 extern char *getenv();
00122 #ifdef ultrix4
00123 extern void *malloc(), *realloc(), *calloc();
00124 #else
00125 extern char *malloc(), *realloc(), *calloc();
00126 #endif
00127 #if defined(aiws)
00128 extern int sprintf();
00129 #else
00130 #ifndef _IBMR2
00131 extern char *sprintf();
00132 #endif
00133 #endif
00134 extern int system();
00135 extern double atof();
00136 #endif
00137
00138 #ifndef PORT_H
00139 #if defined(ultrix3) || defined(sunos4) || defined(_IBMR2) || defined(__STDC__)
00140 #define SIGNAL_FN void
00141 #else
00142
00143 #define SIGNAL_FN int
00144 #endif
00145 #endif
00146
00147
00148 #if defined(__STDC__) || defined(sprite)
00149 #include <string.h>
00150 #else
00151 #if defined(ultrix4) || defined(__hpux)
00152 #include <strings.h>
00153 #else
00154 #if defined(_IBMR2) || defined(__osf__)
00155 #include<string.h>
00156 #include<strings.h>
00157 #else
00158
00159
00160 #ifndef PORT_H
00161 extern char *strcpy(), *strncpy(), *strcat(), *strncat(), *strerror();
00162 extern char *strpbrk(), *strtok(), *strchr(), *strrchr(), *strstr();
00163 extern int strcoll(), strxfrm(), strncmp(), strlen(), strspn(), strcspn();
00164 extern char *memmove(), *memccpy(), *memchr(), *memcpy(), *memset();
00165 extern int memcmp(), strcmp();
00166 #endif
00167 #endif
00168 #endif
00169 #endif
00170
00171
00172 #if defined(__hpux)
00173 #define random() lrand48()
00174 #define srandom(a) srand48(a)
00175 #define bzero(a,b) memset(a, 0, b)
00176 #else
00177 #if !defined(__osf__) && !defined(linux)
00178
00179 extern VOID_HACK srandom();
00180 extern long random();
00181 #endif
00182 #endif
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 # ifdef NDEBUG
00211 # define assert(ex) {ex;}
00212 # else
00213 # define assert(ex) {\
00214 if (! (ex)) {\
00215 (void) fprintf(stderr,\
00216 "Assertion failed: file %s, line %d\n\"%s\"\n",\
00217 __FILE__, __LINE__, "ex");\
00218 (void) fflush(stdout);\
00219 abort();\
00220 }\
00221 }
00222 # endif
00223
00224
00225 #define fail(why) {\
00226 (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
00227 __FILE__, __LINE__, why);\
00228 (void) fflush(stdout);\
00229 abort();\
00230 }
00231
00232
00233 #ifdef lint
00234 #undef putc
00235 #undef ALLOC
00236 #undef REALLOC
00237 #define ALLOC(type, num) (((type *) 0) + (num))
00238 #define REALLOC(type, obj, num) ((obj) + (num))
00239 #endif
00240
00241
00242
00243
00244
00245
00246
00247
00248 #ifndef ABS
00249 #define ABS(a) ((a) < 0 ? -(a) : (a))
00250 #endif
00251 #ifndef MAX
00252 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00253 #endif
00254 #ifndef MIN
00255 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00256 #endif
00257
00258
00259 #ifndef USE_MM
00260 EXTERN void MMout_of_memory ARGS((long));
00261 EXTERN char *MMalloc ARGS((long));
00262 EXTERN char *MMrealloc ARGS((char *, long));
00263 EXTERN void MMfree ARGS((char *));
00264 #endif
00265
00266 EXTERN void util_print_cpu_stats ARGS((FILE *));
00267 EXTERN long util_cpu_time ARGS((void));
00268 EXTERN void util_getopt_reset ARGS((void));
00269 EXTERN int util_getopt ARGS((int, char **, char *));
00270 EXTERN char *util_path_search ARGS((char *));
00271 EXTERN char *util_file_search ARGS((char *, char *, char *));
00272 EXTERN int util_pipefork ARGS((char **, FILE **, FILE **, int *));
00273 EXTERN char *util_print_time ARGS((long));
00274 EXTERN int util_save_image ARGS((char *, char *));
00275 EXTERN char *util_strsav ARGS((char *));
00276 EXTERN int util_do_nothing ARGS((void));
00277 EXTERN char *util_tilde_expand ARGS((char *));
00278 EXTERN char *util_tempnam ARGS((char *, char *));
00279 EXTERN FILE *util_tmpfile ARGS((void));
00280 EXTERN long getSoftDataLimit();
00281
00282 #define ptime() util_cpu_time()
00283 #define print_time(t) util_print_time(t)
00284
00285
00286 extern int util_optind;
00287 extern char *util_optarg;
00288
00289 #include <math.h>
00290 #ifndef HUGE_VAL
00291 #ifndef HUGE
00292 #define HUGE 8.9884656743115790e+307
00293 #endif
00294 #define HUGE_VAL HUGE
00295 #endif
00296 #ifndef MAXINT
00297 #define MAXINT (1 << 30)
00298 #endif
00299
00300 #include <varargs.h>
00301 #endif