/*===================================================================== Error handlers with support for parallel programming. Copyright 1993 (C) David Hinds - All Rights Reserved Source file errors.h Version 1.2, Updated 3/15/93 =====================================================================*/ #ifdef ERRORS_C static char ident_h[] = "@(#) errors.h version 1.2 (3/15/93)"; #endif /* Macros to error check results */ #define check(s) ((s) ? fatal(__FILE__, __LINE__, #s): (void)0) #define checkresult(s) check((s) == -1) #define checknull(s) check((s) == NULL) #define checkio(s, n) \ (((s) != n) ? ioerror(__FILE__, __LINE__, #s) : (void)0) /* Used to protect stderr from collisions */ void init_lock(void (*lock)(), void (*unlock)()); /* Used to specify prefix string for error messages */ void init_err(char *cmd); /* Functions to write to stderr, with locking */ void set_info(char *pre, int_t level); int_t get_info(void); void inform(int_t level, char *fmt, ...); void warning(char *fmt, ...); void error(char *fmt, ...); /* Generate a system error with file name, line number, etc */ void fatal(char *a, int_t b, char *c); /* For formatting errors */ void ioerror(char *a, int_t b, char *c); /*===================================================================== Error-checking wrappers for standard I/O functions =====================================================================*/ #define c_sscanf(a, b) \ ((sscanf b != (a)) ? ioerror(__FILE__, __LINE__, #b) : (void)0) #define c_scanf(a, b) \ while (scanf b != (a)) ioerror(__FILE__, __LINE__, #b) #define c_fscanf(a, b) \ ((fscanf b != (a)) ? ioerror(__FILE__, __LINE__, #b) : (void)0) #define c_fput(a, f) checkio(fwrite(a, sizeof *a, 1, f), 1) #define c_fget(a, f) checkio(fread(a, sizeof *a, 1, f), 1) #define c_fputs(a, f) checkresult(fputs(a, f)) #define c_fgets(a, n, f) checknull(fgets(a, n, f)) #define c_puts(a) checkresult(puts(a)) #define c_gets(a) checknull(gets(a)) #define c_fwrite(a, n, f) checkio(fwrite(a, sizeof *a, n, f), n) #define c_fread(a, n, f) checkio(fread(a, sizeof *a, n, f), n)