-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopdb.c
177 lines (146 loc) · 3.47 KB
/
opdb.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* MSPDebug - debugging tool for MSP430 MCUs
* Copyright (C) 2009, 2010 Daniel Beer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
#include "opdb.h"
#include "util.h"
const static struct opdb_key keys[] = {
{
.name = "color",
.type = OPDB_TYPE_BOOLEAN,
.help = "Colorize debugging output.\n",
.defval = {
.boolean = 0
}
},
{
.name = "gdb_loop",
.type = OPDB_TYPE_BOOLEAN,
.help =
"Automatically restart the GDB server after disconnection. If this\n"
"option is set, then the GDB server keeps running until an error occurs,\n"
"or the user interrupts with Ctrl+C.\n",
.defval = {
.boolean = 0
}
},
{
.name = "quiet",
.type = OPDB_TYPE_BOOLEAN,
.help = "Supress debugging output.\n",
.defval = {
.boolean = 0
}
},
{
.name = "iradix",
.type = OPDB_TYPE_NUMERIC,
.help = "Default input radix.\n",
.defval = {
.numeric = 10
}
},
{
.name = "fet_block_size",
.type = OPDB_TYPE_NUMERIC,
.help =
"Size of buffer used for memory transfers to and from the FET device.\n"
"Increasing this value will result in faster transfers, but may cause\n"
"problems with some chips.\n",
.defval = {
.numeric = 64
}
}
};
static union opdb_value values[ARRAY_LEN(keys)];
static int opdb_find(const char *name)
{
int i;
for (i = 0; i < ARRAY_LEN(keys); i++) {
const struct opdb_key *key = &keys[i];
if (!strcasecmp(key->name, name))
return i;
}
return -1;
}
void opdb_reset(void)
{
int i;
for (i = 0; i < ARRAY_LEN(keys); i++) {
const struct opdb_key *key = &keys[i];
union opdb_value *value = &values[i];
memcpy(value, &key->defval, sizeof(*value));
}
}
int opdb_enum(opdb_enum_func_t func, void *user_data)
{
int i;
for (i = 0; i < ARRAY_LEN(keys); i++) {
const struct opdb_key *key = &keys[i];
const union opdb_value *value = &values[i];
if (func(user_data, key, value) < 0)
return -1;
}
return 0;
}
int opdb_get(const char *name, struct opdb_key *key,
union opdb_value *value)
{
int i;
i = opdb_find(name);
if (i < 0)
return -1;
if (key)
memcpy(key, &keys[i], sizeof(*key));
if (value)
memcpy(value, &values[i], sizeof(*value));
return 0;
}
int opdb_set(const char *name, const union opdb_value *value)
{
int i;
union opdb_value *v;
i = opdb_find(name);
if (i < 0)
return -1;
v = &values[i];
memcpy(v, value, sizeof(values[i]));
if (keys[i].type == OPDB_TYPE_STRING)
v->string[sizeof(v->string) - 1] = 0;
return 0;
}
const char *opdb_get_string(const char *name)
{
int idx = opdb_find(name);
if (idx < 0)
return "";
return values[idx].string;
}
int opdb_get_boolean(const char *name)
{
int idx = opdb_find(name);
if (idx < 0)
return 0;
return values[idx].boolean;
}
address_t opdb_get_numeric(const char *name)
{
int idx = opdb_find(name);
if (idx < 0)
return 0;
return values[idx].numeric;
}