-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathst_debug.c
More file actions
65 lines (60 loc) · 1.86 KB
/
st_debug.c
File metadata and controls
65 lines (60 loc) · 1.86 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
// Copyright 2024 Guillaume Stordeur <guillaume.stordeur@gmail.com>
// Copyright 2024 Matt Skalecki <ikcelaks@gmail.com>
// Copyright 2024 QKekos <q.kekos.q@gmail.com>
// SPDX-License-Identifier: Apache-2.0
#include <stdbool.h>
#include <string.h>
#include "st_debug.h"
static long st_debug_bits = 0;
#define FLAG_BIT(flag) (1 << (flag - 1))
//////////////////////////////////////////////////////////////////////
static const char *st_debug_flag_names[] = {
[ST_DBG_GENERAL] = "general",
[ST_DBG_SEQ_MATCH] = "sequence_match",
[ST_DBG_RULE_SEARCH] = "rule_search",
[ST_DBG_CURSOR] = "cursor",
[ST_DBG_BACKSPACE] = "backspace",
0
};
//////////////////////////////////////////////////////////////////////
const char **st_debug_get_flag_names(void)
{
return st_debug_flag_names;
}
//////////////////////////////////////////////////////////////////////
void st_debug_set_flag_str(const char *flag)
{
if (!strcmp(flag, "all")) {
st_debug_set_all_flags();
return;
}
for (int i = 1; st_debug_flag_names[i]; ++i) {
if (!strcmp(flag, st_debug_flag_names[i])) {
st_debug_set_flag(i);
return;
}
}
if (!strcmp(flag, "off")) {
st_debug_clear_all_flags();
}
}
//////////////////////////////////////////////////////////////////////
void st_debug_set_flag(st_debug_flag_t flag)
{
st_debug_bits |= FLAG_BIT(flag);
}
//////////////////////////////////////////////////////////////////////
void st_debug_set_all_flags(void)
{
st_debug_bits = 0xFFFFFFFF;
}
//////////////////////////////////////////////////////////////////////
void st_debug_clear_all_flags(void)
{
st_debug_bits = 0;
}
//////////////////////////////////////////////////////////////////////
bool st_debug_test_flag(st_debug_flag_t flag)
{
return (st_debug_bits & FLAG_BIT(flag)) ? true : false;
}