-
Notifications
You must be signed in to change notification settings - Fork 17
/
error.c
63 lines (48 loc) · 1.91 KB
/
error.c
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
/* ------- file: -------------------------- Error.c -----------------
Version: rh2.0
Author: Han Uitenbroek (huitenbroek@nso.edu)
Last modified: Tue Dec 23 14:47:16 2008 --
-------------------------- ----------RH-- */
/* --- Print warning, or print error string and exit when error level
is above preset treshold -- -------------- */
#include <stdlib.h>
#include <errno.h>
#include "rh.h"
#include "error.h"
#include "inputs.h"
/* --- Function prototypes -- -------------- */
/* --- Global variables -- -------------- */
extern CommandLine commandline;
/* ------- begin -------------------------- Error.c ----------------- */
void Error(enum errorlevel level, const char *routineName,
const char *messageStr)
{
char errorStr[MAX_MESSAGE_LENGTH];
enum errorlevel defaultLevel = ERROR_LEVEL_1;
switch (level) {
case MESSAGE:
if (!commandline.quiet)
fprintf(commandline.logfile, "%s", (messageStr) ? messageStr : "");
return;
case WARNING:
fprintf(commandline.logfile, "\n-WARNING in routine %s\n %s\n",
routineName, (messageStr) ? messageStr : " (Undocumented)\n");
return;
default:
if (level < defaultLevel) {
fprintf(commandline.logfile, "\a\n-ERROR in routine %s\n %s \n %s\n",
routineName,(messageStr) ? messageStr : " (Undocumented)\n",
"Trying to continue.....");
return;
} else {
sprintf(errorStr, "\a\n\n-FATAL_ERROR in routine %s\n %s \n %s\n",
routineName,(messageStr) ? messageStr : " (Undocumented)\n",
"Exiting.....");
fprintf(commandline.logfile, "%s", errorStr);
if (commandline.logfile != stderr) fprintf(stderr, "%s", errorStr);
if (errno) perror(routineName);
exit(level);
}
}
}
/* ------- end ---------------------------- Error.c ----------------- */