00001 #ifndef UTIL_H
00002 #define UTIL_H
00003
00004
00005 #ifndef EXTERN
00006 # ifdef __cplusplus
00007 # define EXTERN extern "C"
00008 # else
00009 # define EXTERN extern
00010 # endif
00011 #endif
00012 #ifndef ARGS
00013 # if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
00014 # define ARGS(protos) protos
00015 # else
00016 # define ARGS(protos) ()
00017 # endif
00018 #endif
00019 #ifndef NULLARGS
00020 # if defined(__STDC__) || defined(__cplusplus)
00021 # define NULLARGS (void)
00022 # else
00023 # define NULLARGS ()
00024 # endif
00025 #endif
00026 #ifndef const
00027 # if !defined(__STDC__) && !defined(__cplusplus)
00028 # define const
00029 # endif
00030 #endif
00031
00032
00033 #if defined(__GNUC__)
00034 # define UTIL_INLINE __inline__
00035 # if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
00036 # define UTIL_UNUSED __attribute__ ((unused))
00037 # else
00038 # define UTIL_UNUSED
00039 # endif
00040 #else
00041 # define UTIL_INLINE
00042 # define UTIL_UNUSED
00043 #endif
00044
00045 #ifndef SIZEOF_VOID_P
00046 #define SIZEOF_VOID_P 4
00047 #endif
00048 #ifndef SIZEOF_INT
00049 #define SIZEOF_INT 4
00050 #endif
00051 #ifndef SIZEOF_LONG
00052 #define SIZEOF_LONG 4
00053 #endif
00054
00055 #if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
00056 typedef long util_ptrint;
00057 #else
00058 typedef int util_ptrint;
00059 #endif
00060
00061
00062
00063
00064 #define strsav util_strsav
00065
00066 #ifndef _MSC_VER
00067 #include <unistd.h>
00068 extern char *optarg;
00069 extern int optind, opterr;
00070 #endif
00071
00072 #include "scv/scv_config.h"
00073
00074 #if !defined(__linux__) && !defined(_MSC_VER)
00075 #if defined(__STDC__) || defined(__cplusplus)
00076 EXTERN void exit ARGS((int));
00077 #endif
00078 #endif
00079
00080 #define NIL(type) ((type *) 0)
00081
00082 #if defined(USE_MM) || defined(MNEMOSYNE)
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #ifdef MNEMOSYNE
00094 #include "mnemosyne.h"
00095 #define ALLOC(type, num) \
00096 ((num) ? ((type *) malloc(sizeof(type) * (num))) : \
00097 ((type *) malloc(sizeof(long))))
00098 #else
00099 #define ALLOC(type, num) \
00100 ((type *) malloc(sizeof(type) * (num)))
00101 #endif
00102 #define REALLOC(type, obj, num) \
00103 (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) : \
00104 ((type *) malloc(sizeof(type) * (num)))
00105 #define FREE(obj) \
00106 ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
00107 #else
00108
00109
00110
00111
00112 #define ALLOC(type, num) \
00113 ((type *) MMalloc((long) sizeof(type) * (long) (num)))
00114 #define REALLOC(type, obj, num) \
00115 ((type *) MMrealloc((char *) (obj), (long) sizeof(type) * (long) (num)))
00116 #define FREE(obj) \
00117 ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
00118 #endif
00119
00120
00121
00122 #if defined(ultrix) || defined(SABER) || defined(aiws) || defined(hpux) || defined(apollo) || defined(__osf__) || defined(__SVR4) || defined(__GNUC__)
00123 #define VOID_OR_INT void
00124 #define VOID_OR_CHAR void
00125 #else
00126 #define VOID_OR_INT int
00127 #define VOID_OR_CHAR char
00128 #endif
00129
00130
00131
00132 #include <stdio.h>
00133 #include <ctype.h>
00134
00135
00136
00137 #if !defined(__STDC__) && !defined(__cplusplus) && !defined(_MSC_VER)
00138 extern FILE *popen(), *tmpfile();
00139 extern int pclose();
00140 #ifndef clearerr
00141 extern VOID_OR_INT clearerr();
00142 #endif
00143 #if !defined(rewind) && !defined(_IBMR2)
00144 extern VOID_OR_INT rewind();
00145 #endif
00146 #endif
00147
00148
00149
00150 #if (defined(__STDC__) || defined(__cplusplus) || defined(ultrix)) && !defined(MNEMOSYNE) || defined(__SVR4)
00151 # include <stdlib.h>
00152 EXTERN void free ARGS((void *));
00153 #else
00154 # ifndef _IBMR2
00155 extern VOID_OR_INT abort(), exit();
00156 # endif
00157 # if !defined(__STDC__) && !defined(_IBMR2) && !defined(_MSC_VER)
00158 extern VOID_OR_INT perror();
00159 # ifdef __osf__
00160 extern int sprintf();
00161 # else
00162 # ifndef _IBMR2
00163 extern char *sprintf();
00164 # endif
00165 # endif
00166 # endif
00167 # if !defined(MNEMOSYNE) && !defined(_IBMR2)
00168 EXTERN VOID_OR_INT free ARGS((void *));
00169 extern VOID_OR_CHAR *malloc(), *realloc();
00170 # endif
00171 extern char *getenv();
00172 extern int system();
00173 extern double atof();
00174 #endif
00175
00176
00177
00178 #if defined(__STDC__) || defined(__cplusplus) || defined(_IBMR2) || defined(ultrix) || defined(_MSC_VER)
00179 #include <string.h>
00180 #else
00181
00182 extern char *strcpy(), *strncpy(), *strcat(), *strncat(), *strerror();
00183 extern char *strpbrk(), *strtok(), *strchr(), *strrchr(), *strstr();
00184 extern int strcoll(), strxfrm(), strncmp(), strlen(), strspn(), strcspn();
00185 extern char *memmove(), *memccpy(), *memchr(), *memcpy(), *memset();
00186 extern int memcmp(), strcmp();
00187 #endif
00188
00189 #ifdef _MSC_VER
00190 #include <search.h>
00191 #endif
00192
00193 #if defined(__STDC__) || defined(_MSC_VER)
00194 #include <assert.h>
00195 #else
00196 #ifndef _HPUX_SOURCE
00197 #ifndef NDEBUG
00198 #define assert(ex) {\
00199 if (! (ex)) {\
00200 (void) fprintf(stderr,\
00201 "Assertion failed: file %s, line %d\n\"%s\"\n",\
00202 __FILE__, __LINE__, "ex");\
00203 (void) fflush(stdout);\
00204 abort();\
00205 }\
00206 }
00207 #else
00208 #define assert(ex) ;
00209 #endif
00210 #endif
00211 #endif
00212
00213
00214 #define fail(why) {\
00215 (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
00216 __FILE__, __LINE__, why);\
00217 (void) fflush(stdout);\
00218 abort();\
00219 }
00220
00221
00222 #ifdef lint
00223 #undef putc
00224 #undef ALLOC
00225 #undef REALLOC
00226 #define ALLOC(type, num) (((type *) 0) + (num))
00227 #define REALLOC(type, obj, num) ((obj) + (num))
00228 #endif
00229
00230
00231
00232 #define ABS(a) ((a) < 0 ? -(a) : (a))
00233
00234 #ifndef _HPUX_SOURCE
00235 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00236 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00237 #endif
00238
00239
00240 #ifndef USE_MM
00241 EXTERN char *MMalloc ARGS((long));
00242 EXTERN void MMout_of_memory ARGS((long));
00243 EXTERN void (*MMoutOfMemory) ARGS((long));
00244 EXTERN char *MMrealloc ARGS((char *, long));
00245 #endif
00246
00247 EXTERN long util_cpu_time ARGS((void));
00248 EXTERN int util_getopt ARGS((int, char **, char *));
00249 EXTERN void util_getopt_reset ARGS((void));
00250 EXTERN char *util_path_search ARGS((char *));
00251 EXTERN char *util_file_search ARGS((char *, char *, char *));
00252 EXTERN int util_pipefork ARGS((char **, FILE **, FILE **, int *));
00253 EXTERN void util_print_cpu_stats ARGS((FILE *));
00254 EXTERN char *util_print_time ARGS((unsigned long));
00255 EXTERN int util_save_image ARGS((char *, char *));
00256 EXTERN char *util_strsav ARGS((char *));
00257 EXTERN char *util_tilde_expand ARGS((char *));
00258 EXTERN void util_restart ARGS((char *, char *, int));
00259
00260
00261
00262 EXTERN int util_optind;
00263 EXTERN char *util_optarg;
00264
00265 EXTERN long getSoftDataLimit ARGS((void));
00266
00267 #endif