-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdebug.c
64 lines (52 loc) · 1.1 KB
/
debug.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
/*
* A debugging helper library.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "debug.h"
unsigned int debug = 0;
struct debug_def {
int debug_val;
char *debug_def;
};
/*
* This list is auto-generated and included at compile time.
* To add things, edit debug.h
*/
static
struct debug_def debugs[] = {
#include "debug-text.h"
{ 0, NULL } /* End of list marker */
};
int set_debug(char *arg)
{
int i;
if (!arg || arg[0] == '\0') {
return -1;
}
if (arg[0] == '?' || !strcmp(arg, "list")) {
fprintf(stderr,
"Debug values and definitions\n"
"----------------------------\n");
for (i = 0; debugs[i].debug_def != NULL; i++) {
fprintf(stderr, "%5d %s\n", debugs[i].debug_val,
debugs[i].debug_def);
}
return -1;
}
if (isdigit(arg[0])) {
debug |= atoi(arg);
}
return 0;
}
#ifdef _TEST_DEBUG_
int main() {
if (set_debug("?") != -1) {
fprintf(stderr, "set_debug(\"?\") returned wrong result code\n");
}
exit(0);
}
#endif
/* Packet debugging utilities */