/**CHeaderFile***************************************************************** FileName [ util.h ] PackageName [ util ] Synopsis [ Low-level utilities ] Description [ ] Author [Adnan Aziz] Copyright [Copyright (c) 2005 Adnan Aziz] ******************************************************************************/ #ifndef _UTIL #define _UTIL #include #include #include #include #include #include #include #include "array.h" #ifdef NM_DEBUG #define util_assert( x ) \ if ( !x ) { \ fail("util_assert fails!\n"); } #else #define util_assert( x ) #endif #define fail(why) {\ (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\ __FILE__, __LINE__, why);\ (void) fflush(stdout);\ abort();\ } /* * A neater way to define zero pointers * * Usage: * int * fred; * fred = NIL(int); */ #define NIL(type) ((type *) 0) /* * Left over from SIS and Octtools: */ # define ALLOC(type, num) \ ((type *) MMalloc((long) sizeof(type) * (long) (num))) # define REALLOC(type, obj, num) \ ((type *) MMrealloc((char *) (obj), (long) sizeof(type) * (long) (num))) # define FREE(obj) \ free( obj ) // old decls abound #ifndef EXTERN # define EXTERN extern #endif #ifndef ABS # define ABS(a) ((a) < 0 ? -(a) : (a)) #endif #ifndef MAX # define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif #ifndef HUGE_VAL # ifndef HUGE # define HUGE 8.9884656743115790e+307 # endif # define HUGE_VAL HUGE #endif #ifndef MAXINT # define MAXINT (1 << 30) #endif #define TRUE 1 #define FALSE 0 extern void MMout_of_memory (long); extern char * MMalloc (long); extern char * MMrealloc (char *, long); extern void MMfree (char *); extern void util_getopt_reset (void); extern int util_getopt (int, char **, char *); extern char * util_optarg; /**Enum************************************************************************ Synopsis [Types of modes in which to open files.] Description [Types of modes in which to open files.] ******************************************************************************/ typedef enum { Util_FileOverWrite_c, Util_FileAppend_c } Util_FileOpenMode_t; // random number generation code inline float util_unit_rand(); inline int util_rand_int(); // error reporting code extern void error_init (void); extern void error_append (char *); extern char *error_string (void); extern void error_cleanup (void); #endif /* _UTIL */