-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror_handler.cpp
More file actions
48 lines (43 loc) · 1.11 KB
/
Copy patherror_handler.cpp
File metadata and controls
48 lines (43 loc) · 1.11 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
#include "error_handler.h"
#include <assert.h>
#include <string.h>
#define CR "\x1b[0m"
#define RED "\x1b[31m"
#define YELLOW "\x1b[33m"
#define CYAN "\x1b[36m"
#define GREEN "\x1b[32m"
#define BON "\e[1m"
#define BOFF "\e[0m"
char * fname = NULL;
bool errorExists = false;
void error_handler_init(const char * name) {
fname = strdup(name);
}
void error_handler_destroy() {
if (!fname) return;
free(fname);
}
void error(ErrorType et, unsigned int line, const char * format, ...) {
assert(fname != NULL);
va_list argptr;
va_start(argptr, format);
fprintf(stderr, BON "%s:%u:" BOFF, fname, line);
switch(et) {
case(ErrorType::Error):
errorExists = true;
fprintf(stderr, BON RED " Error: " CR BOFF);
break;
case(ErrorType::Warning):
fprintf(stderr, BON YELLOW " Warning: " CR BOFF);
break;
case(ErrorType::FatalError):
errorExists = true;
fprintf(stderr, BON RED " Fatal Error: " CR BOFF);
break;
default:
errorExists = true;
fprintf(stderr, BON CYAN " Unknown Error Type: " CR BOFF);
}
vfprintf(stderr, format, argptr);
va_end(argptr);
}