-
Notifications
You must be signed in to change notification settings - Fork 1
/
flags.c
56 lines (44 loc) · 1.13 KB
/
flags.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
#include "flags.h"
int DEBUG = 0;
int INFO = 1;
int STATS = 1;
int STEP = 0;
int TAIL = 1;
int LIB = 1;
/* flag manipulation */
// inelegant
void switch_flag(char* flag_command) {
if (DEBUG) printf("%s\n", "switching flag...");
if (streq(flag_command, DEBUG_COMMAND))
toggle_val(&DEBUG);
else if (streq(flag_command, INFO_COMMAND))
toggle_val(&INFO);
else if (streq(flag_command, STATS_COMMAND))
toggle_val(&STATS);
else if (streq(flag_command, TAIL_COMMAND))
toggle_val(&TAIL);
else if (streq(flag_command, STEP_COMMAND))
toggle_val(&STEP);
else if (streq(flag_command, REPL_COMMAND))
repl_switch();
else if (streq(flag_command, DEMO_COMMAND))
demo_switch();
}
void toggle_LIB(void) { toggle_val(&LIB); }
void toggle_val(int* flag) {
if (DEBUG) printf("toggle_val: %d\n", *flag);
*flag = 1 - *flag;
// self-referential debugging statement?
if (DEBUG) printf("toggled! %d\n", *flag);
return;
}
void repl_switch(void) {
INFO = 0;
STATS = 0;
STEP = 0;
}
void demo_switch(void) {
INFO = 1;
STATS = 1;
STEP = 1;
}