Repository navigation
Expand file tree
/
Copy pathdebug.h
More file actions
75 lines (65 loc) · 2.12 KB
/
Copy pathdebug.h
File metadata and controls
75 lines (65 loc) · 2.12 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
#ifndef DEBUG_H
#define DEBUG_H
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
extern bool debug_mode;
static inline void debug_printf(const char* fmt, ...)
{
const char* always_suppress[] = {
"[DEBUG] Initializing language pack: ", "[DEBUG] Cleaning up language pack: ",
"[DEBUG] Parsing file with language pack: "};
const char* non_debug_suppress[] = {"Successfully extracted",
"Codemap option enabled",
"Generating codemap",
"Generating codemap with",
"Pattern ",
"Loaded ",
"Recursively scanning",
"Searching for ",
"Matched pattern",
"Processing ",
"Success: Parsed",
"Codemap generation complete",
"Successfully built codemap",
"Codemap generated successfully"};
for (size_t i = 0; i < sizeof(always_suppress) / sizeof(always_suppress[0]); i++)
{
if (strstr(fmt, always_suppress[i]) != NULL)
{
return;
}
}
if (!debug_mode)
{
for (size_t i = 0; i < sizeof(non_debug_suppress) / sizeof(non_debug_suppress[0]); i++)
{
if (strstr(fmt, non_debug_suppress[i]) != NULL)
{
return;
}
}
}
va_list ap;
va_start(ap, fmt);
if (debug_mode)
{
fprintf(stderr, "[DEBUG] ");
vfprintf(stderr, fmt, ap);
if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] != '\n')
{
fputc('\n', stderr);
}
}
else
{
vfprintf(stderr, fmt, ap);
if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] != '\n')
{
fputc('\n', stderr);
}
}
va_end(ap);
}
#endif /* DEBUG_H */