aboutsummaryrefslogtreecommitdiff
path: root/ic-reals-6.3/base/error.c
blob: 07de0e3222635ec288dd6f1c5d712c460b20c508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 <stdio.h>
#include "real.h"
#include "real-impl.h"
#include <stdarg.h>
#include <string.h>
#include <errno.h>

/*
 * 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);
}