ide_errlog.c
2.71 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* $Revision: 1.2 $
*/
/*
* ide_errlog.c:
*
* Diagnostic error reporting interface function for Host based diagnostics.
*
* FUNCTIONS DEFINED:
*
* errlog ... Selectively prints diagnostic error messages.
*
* Silicon Graphics, Inc. (C) copyright 1989 (all rights reserved).
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <varargs.h>
#include <sys/types.h>
#include <string.h>
#include "diag.h"
extern FILE *logfile;
/*
* errlog(): Error message filter function. Uses the varargs libc feature so
* that we can pass this function a variable number of arguments.
*/
/*VARARGS*/
void
errlog(va_alist)
va_dcl
{
register int errdesc, errstart, errend, errlevel;
register char *fmt;
va_list args;
time_t clock;
char buf[20];
int tm;
char errmsg[256], tmp[256];
static last_errend = 1;
va_start(args);
/*
* The first arg is the error level for this message.
* The second arg is the standard printf format string.
* Any subsequent args must be supplied to satisfy the format requirements.
*/
errdesc = va_arg(args, int);
errlevel = errdesc & 0xf;
errend = !(errdesc & 0x10);
errstart = !(errdesc & 0x20);
/*
* Update the communication structure fields which tell the IDE server
* which test levels generated errors. Only do this if the current
* error level is actually an error message.
*/
if ((errlevel == ERR_SEVERE) || (errlevel == ERR_SIMPLE)) {
if (pGlobalComm->errNums[errIndex] < ideSubTestNum) {
errIndex++;
pGlobalComm->errNums[errIndex] = ideSubTestNum;
}
}
fmt = va_arg(args, char *);
errmsg[0] = '\0';
if (errstart) {
if (!last_errend) strcat(errmsg, "\n");
switch (errlevel) {
case ERR_SEVERE:
case ERR_SIMPLE:
sprintf(errmsg, "%sERROR:\t(%d)\t", errmsg, ideSubTestNum);
break;
case INFO:
sprintf(errmsg, "%sINFO:\t", errmsg);
break;
case DEBUG:
sprintf(errmsg, "%sDEBUG:\t", errmsg);
break;
}
}
vsprintf(tmp, fmt, args); /* print the user's message. */
strcat(errmsg, tmp);
strcat(errmsg, "\n");
if (printmask & errlevel) {
last_errend = errend;
printf("%s", errmsg);
}
fflush(stdout);
if (logmask & errlevel) {
if (errlevel != INFO || getenv("IDE_TIMESTAMP_INFO") && errstart) {
/*
* time stamp the log entries
*/
clock = time(0);
tm = localtime(&clock);
#ifdef __sgi__
ascftime(buf, "%D(%T)", tm);
#else
strftime(buf, sizeof buf, "%D(%T)", tm);
#endif
strcat(errmsg, buf);
strcat(errmsg, "\n");
}
fprintf(logfile, "%s", errmsg);
}
fflush(logfile);
if (exitmask & errlevel)
diagexit();
va_end(args);
}