-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget.c
More file actions
87 lines (68 loc) · 2.03 KB
/
Copy pathget.c
File metadata and controls
87 lines (68 loc) · 2.03 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
76
77
78
79
80
81
82
83
84
85
86
87
#include <config.h>
#include <logging.h>
#include <stdio.h>
int config_get_enum(const struct config_path path, unsigned index, char *buf, size_t size)
{
const struct configtab *tab = path.tab;
const struct config_enum *e;
if (config_enum_find_by_value(tab->enum_type.values, tab->enum_type.value[index], &e)) {
LOG_ERROR("%s%d.%s: unknown value: %#x", path.mod->name, path.index, tab->name, tab->enum_type.value[index]);
return -1;
}
if (snprintf(buf, size, "%s", e->name) >= size) {
return -1;
}
return 0;
}
int config_get(const struct config_path path, unsigned index, char *buf, size_t size)
{
const struct configtab *tab = path.tab;
if (tab->migrated) {
LOG_ERROR("migrated name=%s", tab->name);
return -1;
}
if (index >= configtab_count(tab)) {
LOG_ERROR("invalid index=%u for count=%u", index, configtab_count(tab));
}
LOG_DEBUG("type=%u name=%s index=%u", tab->type, tab->name, index);
switch(tab->type) {
case CONFIG_TYPE_NULL:
break;
case CONFIG_TYPE_UINT16:
if (snprintf(buf, size, "%u", tab->uint16_type.value[index]) >= size) {
return -1;
} else {
break;
}
case CONFIG_TYPE_STRING:
if (snprintf(buf, size, "%s", &tab->string_type.value[index * tab->string_type.size]) >= size) {
return -1;
} else {
break;
}
case CONFIG_TYPE_BOOL:
if (snprintf(buf, size, "%s", tab->bool_type.value[index] ? "true" : "false") >= size) {
return -1;
} else {
break;
}
case CONFIG_TYPE_ENUM:
return config_get_enum(path, index, buf, size);
case CONFIG_TYPE_FILE:
if (snprintf(buf, size, "%s", &tab->file_type.value[index * tab->file_type.size]) >= size) {
return -1;
} else {
break;
}
case CONFIG_TYPE_COLOR:
if (config_color_str(buf, size, tab->color_type.value[index])) {
return -1;
} else {
break;
}
default:
LOG_ERROR("invalid type=%d", tab->type);
return -1;
}
return 0;
}