From 11da511c784eca003deb90c23570f0873954e0de Mon Sep 17 00:00:00 2001 From: Duncan Wilkie Date: Sat, 18 Nov 2023 06:11:09 -0600 Subject: Initial commit. --- ic-reals-6.3/base/error.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ic-reals-6.3/base/error.c (limited to 'ic-reals-6.3/base/error.c') diff --git a/ic-reals-6.3/base/error.c b/ic-reals-6.3/base/error.c new file mode 100644 index 0000000..07de0e3 --- /dev/null +++ b/ic-reals-6.3/base/error.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2000, Imperial College + * + * This file is part of the Imperial College Exact Real Arithmetic Library. + * See the copyright notice included in the distribution for conditions + * of use. + */ + +#include +#include "real.h" +#include "real-impl.h" +#include +#include +#include + +/* + * An application may choose to set this to a string giving the name + * of the program, typically argv[0]. + */ +char *MyName = NULL; + +/* + * Prints an error message + * Error(fatal, error_type, proc, fmt, arg1, arg2, ....) + * + * fatal = FATAL then we exit after printing a message + * error_type = E_SYS then perror or E_INT + * proc - a pointer to a string containing the name of the calling procedure + * fmt - format string for printf + * arg1... + */ +void +Error(int fatal, int error_type, char *proc, char *fmt, ...) +{ + va_list ap; + + if (MyName != NULL) + fprintf(stderr, "%s: ", MyName); + + if (fatal == FATAL) + fprintf(stderr, "fatal error: %s: ", proc); + else + fprintf(stderr, "%s: ", proc); + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + switch (error_type) { + case E_INT : + fprintf(stderr, "\n"); + break; + + case E_SYS : + perror(strerror(errno)); + break; + + default : + fprintf(stderr, "\n%s: %s: unknown error type: %d\n", + MyName, proc, error_type); + break; + } + + if (fatal == FATAL) + exit(1); +} -- cgit v1.2.3