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
|
#include "cmdline.h"
static char *CLGetErrorString(SInt16 errid, char *buffer) {
getindstring(buffer, 12000, errid);
strcat(buffer, "\n");
return buffer;
}
static void CLMessageReporter(int flags, SInt16 errid, va_list va) {
static char stmsg[256];
static char stbuf[256];
char *ptr;
CLGetErrorString(errid, stmsg);
ptr = mvprintf(stbuf, sizeof(stbuf), stmsg, va);
CLStyledMessageDispatch(
NULL,
NULL,
0,
(flags == messagetypeError) ? CLStyledMessageDispatch_Type3 : (flags == messagetypeWarning) ? CLStyledMessageDispatch_Type2 : CLStyledMessageDispatch_Type5,
"%",
ptr);
if (ptr != stbuf)
free(ptr);
}
void CLReportError(SInt16 errid, ...) {
va_list va;
va_start(va, errid);
CLMessageReporter(messagetypeError, errid, va);
va_end(va);
}
void CLReportWarning(SInt16 errid, ...) {
va_list va;
va_start(va, errid);
CLMessageReporter(messagetypeWarning, errid, va);
va_end(va);
}
void CLReport(SInt16 errid, ...) {
va_list va;
va_start(va, errid);
CLMessageReporter(messagetypeInfo, errid, va);
va_end(va);
}
void CLReportOSError(SInt16 errid, int err, ...) {
char *txt;
const char *oserr;
char mybuf[256];
char myerr[256];
va_list va;
va_start(va, err);
txt = mvprintf(mybuf, sizeof(mybuf), CLGetErrorString(errid, myerr), va);
va_end(va);
oserr = OS_GetErrText(err);
CLReportError(CLStr99, txt, oserr, err);
if (txt != mybuf)
free(txt);
}
void CLReportCError(SInt16 errid, int err_no, ...) {
char *txt;
const char *serr;
char mybuf[256];
char myerr[256];
va_list va;
va_start(va, err_no);
txt = mvprintf(mybuf, sizeof(mybuf), CLGetErrorString(errid, myerr), va);
va_end(va);
serr = strerror(err_no);
CLReportError(CLStr100, txt, serr, err_no);
if (txt != mybuf)
free(txt);
}
void CLInternalError(const char *file, int line, const char *format, ...) {
char mybuf[256];
char *txt;
va_list va;
va_start(va, format);
txt = mvprintf(mybuf, sizeof(mybuf), format, va);
va_end(va);
CLPrintErr("INTERNAL ERROR [%s:%d]:\n%s\n", file, line, txt);
if (txt != mybuf)
free(txt);
}
void CLFatalError(const char *format, ...) {
char mybuf[256];
char *txt;
va_list va;
va_start(va, format);
txt = mvprintf(mybuf, sizeof(mybuf), format, va);
va_end(va);
CLPrintErr("FATAL ERROR:\n%s\n", txt);
if (txt != mybuf)
free(txt);
exit(-123);
}
|