home *** CD-ROM | disk | FTP | other *** search
- /*
- % ERRORS . C
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- This software is copyright (C) by the Lawrence Berkeley Laboratory.
- Permission is granted to reproduce this software for non-commercial
- purposes provided that this notice is left intact.
-
- It is acknowledged that the U.S. Government has rights to this software
- under Contract DE-AC03-765F00098 between the U.S. Department of Energy
- and the University of California.
-
- This software is provided as a professional and academic contribution
- for joint exchange. Thus, it is experimental, and is provided ``as is'',
- with no warranties of any kind whatsoever, no support, no promise of
- updates, or printed documentation. By using this software, you
- acknowledge that the Lawrence Berkeley Laboratory and Regents of the
- University of California shall have no liability with respect to the
- infringement of other copyrights by any part of this software.
-
- For further information about this notice, contact William Johnston,
- Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- (wejohnston@lbl.gov)
-
- For further information about this software, contact:
- Jin Guojun
- Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- g_jin@lbl.gov
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Error handler -- for all machines.
- %
- % AUTHOR: Jin Guojun - LBL 10/1/90
- */
-
- #include <errno.h>
- #include "header.def"
- #include "imagedef.h"
-
- extern int sys_nerr;
- extern char *sys_errlist[];
-
- char *Mversion, *io_test_msg[] = {"stdin", "stdout", "stderr", "aux", "?"};
-
- #ifndef HIPS2_HF
- char *Progname;
- int hipserrlev, hipserrprt;
- #endif
-
- #define HaveMVersion Mversion ? Mversion : "NoVer"
- #define Error_Body(virtual) \
- message("%s [%s] : ", Progname, HaveMVersion); \
- vfprintf(stderr, (char*)vfmt, virtual); \
- error_mesg();
- #define HowFatal() if (fatal > 0) exit(fatal); return ~fatal;
-
- void
- error_mesg()
- {
- if (errno>0 && errno<sys_nerr)
- message("; Error<%d> %s", errno, sys_errlist[errno]);
- mesg("\n"); fflush(stderr);
- }
-
- #if !defined TC_Need
-
- #include <varargs.h>
-
- #ifdef SHOW_WARNINGS
- VType /* system error function for va_list handling machines. */
- #endif
-
- #ifndef NO_V_LIST
- #ifdef MIPS
- syserr(char* vfmt, ...)
- #else
- syserr(vfmt, va_alist)
- va_list va_alist;
- #endif
- {
- va_list ap;
-
- va_start(ap);
- Error_Body(ap);
- exit(errno);
- }
-
- #ifdef MIPS
- prgmerr(bool fatal, char* vfmt, ...)
- #else
- prgmerr(fatal, vfmt, va_alist)
- va_list va_alist;
- #endif
- {
- va_list ap;
-
- va_start(ap);
- Error_Body(ap);
- HowFatal();
- }
-
- #else /* some stupid C compiler, can't handle virtual lists easier */
-
- syserr(s, a1, a2, a3, a4, a5, a6)
- char *s;
- {
- message("%s [%s] : ", Progname, HaveMVersion);
- message(s, a1, a2, a3, a4, a5, a6);
- error_mesg();
- exit(errno);
- }
-
- prgmerr(fatal, fmt, a1, a2, a3, a4)
- char *fmt;
- {
- message("%s [%s] : ", Progname, HaveMVersion);
- message(fmt, a1, a2, a3, a4);
- error_mesg();
- HowFatal();
- }
- #endif V_LIST
-
- #else FOR TURBO_C
- #include <stdarg.h>
-
- syserr(char* vfmt, ...)
- {
- Error_Body(...);
- exit(errno);
- }
-
- prgmerr(bool fatal, char* vfmt, ...)
- {
- message("%s [%s] : %s : ", Progname, HaveMVersion, strerror(errno));
- vfprintf(stderr, vfmt, ...);
- HowFatal();
- }
-
- #endif TC_Need
-