/* J. Stolfi's miscellaneous general-purpose definitions */ /* Last edited on 2002-04-27 13:14:05 by stolfi */ #ifndef JS_H #define JS_H #include #include #include typedef void * MemP; /* Pointer to memory area */ typedef int MemSize; /* Size in bytes of memory area */ void error (char *msg); /* Prints string $*msg$ to $stderr$ and stops. */ void *programerror (char *msg, char *file, unsigned int line, char* proc); /* Prints string $file:line: (*proc) *msg$ to $stderr$ and stops. The return type is `void *' only for the sake of notnull below. */ #define assert(test, msg) \ { if (!(test)) programerror((msg), __FILE__, __LINE__, __FUNCTION__); } /* If test is false, prints $*msg$ and stops. It is declared as a mscro, rather than as a procedure, in order to avoid evaluating $msg$ when $test$ is true. */ #define notnull(p, msg) \ (p != NULL ? p : (void*)programerror((msg), __FILE__, __LINE__, __FUNCTION__)) char *txtcat (char *a, char *b); /* Returns a new string that is the concatenation of $*a$ and $*b$. */ char *today(void); /* Returns today's date in the format "yy-mm-dd hh:mm:ss" */ double now(void); /* Returns the current user time in microseconds. */ FILE *open_write(char *name); FILE *open_read(char *name); /* Opens file for output or input, bombs in case of failure. */ char *read_line(FILE *f); /* Reads the next line from file f, until '\n', NUL, or EOF. Returns it as a NUL-terminated string, without the final '\n'. Replaces TABs by single spaces. Allocates space for it with malloc(). Returns NULL iff the file is already at EOF. */ #if (defined(SunOS4) || defined(SunOS5)) extern long random(void); extern int srandom(unsigned seed); #endif float frandom(void); double drandom(void); /* Returns a uniform random number in [0.0 __ 1.0). */ #endif