root / qemu-option.c @ 419fb20a
History | View | Annotate | Download (24.2 kB)
1 | d3f24367 | Kevin Wolf | /*
|
---|---|---|---|
2 | d3f24367 | Kevin Wolf | * Commandline option parsing functions
|
3 | d3f24367 | Kevin Wolf | *
|
4 | d3f24367 | Kevin Wolf | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | d3f24367 | Kevin Wolf | * Copyright (c) 2009 Kevin Wolf <kwolf@redhat.com>
|
6 | d3f24367 | Kevin Wolf | *
|
7 | d3f24367 | Kevin Wolf | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | d3f24367 | Kevin Wolf | * of this software and associated documentation files (the "Software"), to deal
|
9 | d3f24367 | Kevin Wolf | * in the Software without restriction, including without limitation the rights
|
10 | d3f24367 | Kevin Wolf | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | d3f24367 | Kevin Wolf | * copies of the Software, and to permit persons to whom the Software is
|
12 | d3f24367 | Kevin Wolf | * furnished to do so, subject to the following conditions:
|
13 | d3f24367 | Kevin Wolf | *
|
14 | d3f24367 | Kevin Wolf | * The above copyright notice and this permission notice shall be included in
|
15 | d3f24367 | Kevin Wolf | * all copies or substantial portions of the Software.
|
16 | d3f24367 | Kevin Wolf | *
|
17 | d3f24367 | Kevin Wolf | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | d3f24367 | Kevin Wolf | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | d3f24367 | Kevin Wolf | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | d3f24367 | Kevin Wolf | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | d3f24367 | Kevin Wolf | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | d3f24367 | Kevin Wolf | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | d3f24367 | Kevin Wolf | * THE SOFTWARE.
|
24 | d3f24367 | Kevin Wolf | */
|
25 | d3f24367 | Kevin Wolf | |
26 | d3f24367 | Kevin Wolf | #include <stdio.h> |
27 | d3f24367 | Kevin Wolf | #include <string.h> |
28 | d3f24367 | Kevin Wolf | |
29 | d3f24367 | Kevin Wolf | #include "qemu-common.h" |
30 | 827b0813 | Markus Armbruster | #include "qemu-error.h" |
31 | 01e7f188 | Markus Armbruster | #include "qemu-objects.h" |
32 | d3f24367 | Kevin Wolf | #include "qemu-option.h" |
33 | 975b63a4 | Markus Armbruster | #include "qerror.h" |
34 | d3f24367 | Kevin Wolf | |
35 | d3f24367 | Kevin Wolf | /*
|
36 | d3f24367 | Kevin Wolf | * Extracts the name of an option from the parameter string (p points at the
|
37 | d3f24367 | Kevin Wolf | * first byte of the option name)
|
38 | d3f24367 | Kevin Wolf | *
|
39 | d3f24367 | Kevin Wolf | * The option name is delimited by delim (usually , or =) or the string end
|
40 | d3f24367 | Kevin Wolf | * and is copied into buf. If the option name is longer than buf_size, it is
|
41 | d3f24367 | Kevin Wolf | * truncated. buf is always zero terminated.
|
42 | d3f24367 | Kevin Wolf | *
|
43 | d3f24367 | Kevin Wolf | * The return value is the position of the delimiter/zero byte after the option
|
44 | d3f24367 | Kevin Wolf | * name in p.
|
45 | d3f24367 | Kevin Wolf | */
|
46 | d3f24367 | Kevin Wolf | const char *get_opt_name(char *buf, int buf_size, const char *p, char delim) |
47 | d3f24367 | Kevin Wolf | { |
48 | d3f24367 | Kevin Wolf | char *q;
|
49 | d3f24367 | Kevin Wolf | |
50 | d3f24367 | Kevin Wolf | q = buf; |
51 | d3f24367 | Kevin Wolf | while (*p != '\0' && *p != delim) { |
52 | d3f24367 | Kevin Wolf | if (q && (q - buf) < buf_size - 1) |
53 | d3f24367 | Kevin Wolf | *q++ = *p; |
54 | d3f24367 | Kevin Wolf | p++; |
55 | d3f24367 | Kevin Wolf | } |
56 | d3f24367 | Kevin Wolf | if (q)
|
57 | d3f24367 | Kevin Wolf | *q = '\0';
|
58 | d3f24367 | Kevin Wolf | |
59 | d3f24367 | Kevin Wolf | return p;
|
60 | d3f24367 | Kevin Wolf | } |
61 | d3f24367 | Kevin Wolf | |
62 | d3f24367 | Kevin Wolf | /*
|
63 | d3f24367 | Kevin Wolf | * Extracts the value of an option from the parameter string p (p points at the
|
64 | d3f24367 | Kevin Wolf | * first byte of the option value)
|
65 | d3f24367 | Kevin Wolf | *
|
66 | d3f24367 | Kevin Wolf | * This function is comparable to get_opt_name with the difference that the
|
67 | d3f24367 | Kevin Wolf | * delimiter is fixed to be comma which starts a new option. To specify an
|
68 | d3f24367 | Kevin Wolf | * option value that contains commas, double each comma.
|
69 | d3f24367 | Kevin Wolf | */
|
70 | d3f24367 | Kevin Wolf | const char *get_opt_value(char *buf, int buf_size, const char *p) |
71 | d3f24367 | Kevin Wolf | { |
72 | d3f24367 | Kevin Wolf | char *q;
|
73 | d3f24367 | Kevin Wolf | |
74 | d3f24367 | Kevin Wolf | q = buf; |
75 | d3f24367 | Kevin Wolf | while (*p != '\0') { |
76 | d3f24367 | Kevin Wolf | if (*p == ',') { |
77 | d3f24367 | Kevin Wolf | if (*(p + 1) != ',') |
78 | d3f24367 | Kevin Wolf | break;
|
79 | d3f24367 | Kevin Wolf | p++; |
80 | d3f24367 | Kevin Wolf | } |
81 | d3f24367 | Kevin Wolf | if (q && (q - buf) < buf_size - 1) |
82 | d3f24367 | Kevin Wolf | *q++ = *p; |
83 | d3f24367 | Kevin Wolf | p++; |
84 | d3f24367 | Kevin Wolf | } |
85 | d3f24367 | Kevin Wolf | if (q)
|
86 | d3f24367 | Kevin Wolf | *q = '\0';
|
87 | d3f24367 | Kevin Wolf | |
88 | d3f24367 | Kevin Wolf | return p;
|
89 | d3f24367 | Kevin Wolf | } |
90 | d3f24367 | Kevin Wolf | |
91 | 62c5802e | Gerd Hoffmann | int get_next_param_value(char *buf, int buf_size, |
92 | 62c5802e | Gerd Hoffmann | const char *tag, const char **pstr) |
93 | 62c5802e | Gerd Hoffmann | { |
94 | 62c5802e | Gerd Hoffmann | const char *p; |
95 | 62c5802e | Gerd Hoffmann | char option[128]; |
96 | 62c5802e | Gerd Hoffmann | |
97 | 62c5802e | Gerd Hoffmann | p = *pstr; |
98 | 62c5802e | Gerd Hoffmann | for(;;) {
|
99 | 62c5802e | Gerd Hoffmann | p = get_opt_name(option, sizeof(option), p, '='); |
100 | 62c5802e | Gerd Hoffmann | if (*p != '=') |
101 | 62c5802e | Gerd Hoffmann | break;
|
102 | 62c5802e | Gerd Hoffmann | p++; |
103 | 62c5802e | Gerd Hoffmann | if (!strcmp(tag, option)) {
|
104 | 62c5802e | Gerd Hoffmann | *pstr = get_opt_value(buf, buf_size, p); |
105 | 62c5802e | Gerd Hoffmann | if (**pstr == ',') { |
106 | 62c5802e | Gerd Hoffmann | (*pstr)++; |
107 | 62c5802e | Gerd Hoffmann | } |
108 | 62c5802e | Gerd Hoffmann | return strlen(buf);
|
109 | 62c5802e | Gerd Hoffmann | } else {
|
110 | 62c5802e | Gerd Hoffmann | p = get_opt_value(NULL, 0, p); |
111 | 62c5802e | Gerd Hoffmann | } |
112 | 62c5802e | Gerd Hoffmann | if (*p != ',') |
113 | 62c5802e | Gerd Hoffmann | break;
|
114 | 62c5802e | Gerd Hoffmann | p++; |
115 | 62c5802e | Gerd Hoffmann | } |
116 | 62c5802e | Gerd Hoffmann | return 0; |
117 | 62c5802e | Gerd Hoffmann | } |
118 | 62c5802e | Gerd Hoffmann | |
119 | 62c5802e | Gerd Hoffmann | int get_param_value(char *buf, int buf_size, |
120 | 62c5802e | Gerd Hoffmann | const char *tag, const char *str) |
121 | 62c5802e | Gerd Hoffmann | { |
122 | 62c5802e | Gerd Hoffmann | return get_next_param_value(buf, buf_size, tag, &str);
|
123 | 62c5802e | Gerd Hoffmann | } |
124 | 62c5802e | Gerd Hoffmann | |
125 | 62c5802e | Gerd Hoffmann | int check_params(char *buf, int buf_size, |
126 | 62c5802e | Gerd Hoffmann | const char * const *params, const char *str) |
127 | 62c5802e | Gerd Hoffmann | { |
128 | 62c5802e | Gerd Hoffmann | const char *p; |
129 | 62c5802e | Gerd Hoffmann | int i;
|
130 | 62c5802e | Gerd Hoffmann | |
131 | 62c5802e | Gerd Hoffmann | p = str; |
132 | 62c5802e | Gerd Hoffmann | while (*p != '\0') { |
133 | 62c5802e | Gerd Hoffmann | p = get_opt_name(buf, buf_size, p, '=');
|
134 | 62c5802e | Gerd Hoffmann | if (*p != '=') { |
135 | 62c5802e | Gerd Hoffmann | return -1; |
136 | 62c5802e | Gerd Hoffmann | } |
137 | 62c5802e | Gerd Hoffmann | p++; |
138 | 62c5802e | Gerd Hoffmann | for (i = 0; params[i] != NULL; i++) { |
139 | 62c5802e | Gerd Hoffmann | if (!strcmp(params[i], buf)) {
|
140 | 62c5802e | Gerd Hoffmann | break;
|
141 | 62c5802e | Gerd Hoffmann | } |
142 | 62c5802e | Gerd Hoffmann | } |
143 | 62c5802e | Gerd Hoffmann | if (params[i] == NULL) { |
144 | 62c5802e | Gerd Hoffmann | return -1; |
145 | 62c5802e | Gerd Hoffmann | } |
146 | 62c5802e | Gerd Hoffmann | p = get_opt_value(NULL, 0, p); |
147 | 62c5802e | Gerd Hoffmann | if (*p != ',') { |
148 | 62c5802e | Gerd Hoffmann | break;
|
149 | 62c5802e | Gerd Hoffmann | } |
150 | 62c5802e | Gerd Hoffmann | p++; |
151 | 62c5802e | Gerd Hoffmann | } |
152 | 62c5802e | Gerd Hoffmann | return 0; |
153 | 62c5802e | Gerd Hoffmann | } |
154 | 62c5802e | Gerd Hoffmann | |
155 | d3f24367 | Kevin Wolf | /*
|
156 | d3f24367 | Kevin Wolf | * Searches an option list for an option with the given name
|
157 | d3f24367 | Kevin Wolf | */
|
158 | d3f24367 | Kevin Wolf | QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list, |
159 | d3f24367 | Kevin Wolf | const char *name) |
160 | d3f24367 | Kevin Wolf | { |
161 | d3f24367 | Kevin Wolf | while (list && list->name) {
|
162 | d3f24367 | Kevin Wolf | if (!strcmp(list->name, name)) {
|
163 | d3f24367 | Kevin Wolf | return list;
|
164 | d3f24367 | Kevin Wolf | } |
165 | d3f24367 | Kevin Wolf | list++; |
166 | d3f24367 | Kevin Wolf | } |
167 | d3f24367 | Kevin Wolf | |
168 | d3f24367 | Kevin Wolf | return NULL; |
169 | d3f24367 | Kevin Wolf | } |
170 | d3f24367 | Kevin Wolf | |
171 | 67b1355b | Gerd Hoffmann | static int parse_option_bool(const char *name, const char *value, int *ret) |
172 | 67b1355b | Gerd Hoffmann | { |
173 | 67b1355b | Gerd Hoffmann | if (value != NULL) { |
174 | 67b1355b | Gerd Hoffmann | if (!strcmp(value, "on")) { |
175 | 67b1355b | Gerd Hoffmann | *ret = 1;
|
176 | 67b1355b | Gerd Hoffmann | } else if (!strcmp(value, "off")) { |
177 | 67b1355b | Gerd Hoffmann | *ret = 0;
|
178 | 67b1355b | Gerd Hoffmann | } else {
|
179 | c64f27d4 | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "'on' or 'off'");
|
180 | 67b1355b | Gerd Hoffmann | return -1; |
181 | 67b1355b | Gerd Hoffmann | } |
182 | 67b1355b | Gerd Hoffmann | } else {
|
183 | 67b1355b | Gerd Hoffmann | *ret = 1;
|
184 | 67b1355b | Gerd Hoffmann | } |
185 | 67b1355b | Gerd Hoffmann | return 0; |
186 | 67b1355b | Gerd Hoffmann | } |
187 | 67b1355b | Gerd Hoffmann | |
188 | e27c88fe | Gerd Hoffmann | static int parse_option_number(const char *name, const char *value, uint64_t *ret) |
189 | e27c88fe | Gerd Hoffmann | { |
190 | e27c88fe | Gerd Hoffmann | char *postfix;
|
191 | e27c88fe | Gerd Hoffmann | uint64_t number; |
192 | e27c88fe | Gerd Hoffmann | |
193 | e27c88fe | Gerd Hoffmann | if (value != NULL) { |
194 | e27c88fe | Gerd Hoffmann | number = strtoull(value, &postfix, 0);
|
195 | e27c88fe | Gerd Hoffmann | if (*postfix != '\0') { |
196 | c64f27d4 | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number");
|
197 | e27c88fe | Gerd Hoffmann | return -1; |
198 | e27c88fe | Gerd Hoffmann | } |
199 | 21c9f4cd | Gerd Hoffmann | *ret = number; |
200 | e27c88fe | Gerd Hoffmann | } else {
|
201 | c64f27d4 | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number");
|
202 | e27c88fe | Gerd Hoffmann | return -1; |
203 | e27c88fe | Gerd Hoffmann | } |
204 | e27c88fe | Gerd Hoffmann | return 0; |
205 | e27c88fe | Gerd Hoffmann | } |
206 | e27c88fe | Gerd Hoffmann | |
207 | 7695019b | Gerd Hoffmann | static int parse_option_size(const char *name, const char *value, uint64_t *ret) |
208 | 7695019b | Gerd Hoffmann | { |
209 | 7695019b | Gerd Hoffmann | char *postfix;
|
210 | 7695019b | Gerd Hoffmann | double sizef;
|
211 | 7695019b | Gerd Hoffmann | |
212 | 7695019b | Gerd Hoffmann | if (value != NULL) { |
213 | 7695019b | Gerd Hoffmann | sizef = strtod(value, &postfix); |
214 | 7695019b | Gerd Hoffmann | switch (*postfix) {
|
215 | 7695019b | Gerd Hoffmann | case 'T': |
216 | 7695019b | Gerd Hoffmann | sizef *= 1024;
|
217 | 7695019b | Gerd Hoffmann | case 'G': |
218 | 7695019b | Gerd Hoffmann | sizef *= 1024;
|
219 | 7695019b | Gerd Hoffmann | case 'M': |
220 | 7695019b | Gerd Hoffmann | sizef *= 1024;
|
221 | 7695019b | Gerd Hoffmann | case 'K': |
222 | 7695019b | Gerd Hoffmann | case 'k': |
223 | 7695019b | Gerd Hoffmann | sizef *= 1024;
|
224 | 7695019b | Gerd Hoffmann | case 'b': |
225 | 7695019b | Gerd Hoffmann | case '\0': |
226 | 7695019b | Gerd Hoffmann | *ret = (uint64_t) sizef; |
227 | 7695019b | Gerd Hoffmann | break;
|
228 | 7695019b | Gerd Hoffmann | default:
|
229 | c64f27d4 | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size");
|
230 | c64f27d4 | Markus Armbruster | error_printf_unless_qmp("You may use k, M, G or T suffixes for "
|
231 | 7695019b | Gerd Hoffmann | "kilobytes, megabytes, gigabytes and terabytes.\n");
|
232 | 7695019b | Gerd Hoffmann | return -1; |
233 | 7695019b | Gerd Hoffmann | } |
234 | 7695019b | Gerd Hoffmann | } else {
|
235 | c64f27d4 | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size");
|
236 | 7695019b | Gerd Hoffmann | return -1; |
237 | 7695019b | Gerd Hoffmann | } |
238 | 7695019b | Gerd Hoffmann | return 0; |
239 | 7695019b | Gerd Hoffmann | } |
240 | 7695019b | Gerd Hoffmann | |
241 | d3f24367 | Kevin Wolf | /*
|
242 | d3f24367 | Kevin Wolf | * Sets the value of a parameter in a given option list. The parsing of the
|
243 | d3f24367 | Kevin Wolf | * value depends on the type of option:
|
244 | d3f24367 | Kevin Wolf | *
|
245 | d3f24367 | Kevin Wolf | * OPT_FLAG (uses value.n):
|
246 | d3f24367 | Kevin Wolf | * If no value is given, the flag is set to 1.
|
247 | d3f24367 | Kevin Wolf | * Otherwise the value must be "on" (set to 1) or "off" (set to 0)
|
248 | d3f24367 | Kevin Wolf | *
|
249 | d3f24367 | Kevin Wolf | * OPT_STRING (uses value.s):
|
250 | d3f24367 | Kevin Wolf | * value is strdup()ed and assigned as option value
|
251 | d3f24367 | Kevin Wolf | *
|
252 | d3f24367 | Kevin Wolf | * OPT_SIZE (uses value.n):
|
253 | d3f24367 | Kevin Wolf | * The value is converted to an integer. Suffixes for kilobytes etc. are
|
254 | d3f24367 | Kevin Wolf | * allowed (powers of 1024).
|
255 | d3f24367 | Kevin Wolf | *
|
256 | d3f24367 | Kevin Wolf | * Returns 0 on succes, -1 in error cases
|
257 | d3f24367 | Kevin Wolf | */
|
258 | d3f24367 | Kevin Wolf | int set_option_parameter(QEMUOptionParameter *list, const char *name, |
259 | d3f24367 | Kevin Wolf | const char *value) |
260 | d3f24367 | Kevin Wolf | { |
261 | 67b1355b | Gerd Hoffmann | int flag;
|
262 | 67b1355b | Gerd Hoffmann | |
263 | d3f24367 | Kevin Wolf | // Find a matching parameter
|
264 | d3f24367 | Kevin Wolf | list = get_option_parameter(list, name); |
265 | d3f24367 | Kevin Wolf | if (list == NULL) { |
266 | d3f24367 | Kevin Wolf | fprintf(stderr, "Unknown option '%s'\n", name);
|
267 | d3f24367 | Kevin Wolf | return -1; |
268 | d3f24367 | Kevin Wolf | } |
269 | d3f24367 | Kevin Wolf | |
270 | d3f24367 | Kevin Wolf | // Process parameter
|
271 | d3f24367 | Kevin Wolf | switch (list->type) {
|
272 | d3f24367 | Kevin Wolf | case OPT_FLAG:
|
273 | 3df04ac3 | Mark McLoughlin | if (parse_option_bool(name, value, &flag) == -1) |
274 | 67b1355b | Gerd Hoffmann | return -1; |
275 | 67b1355b | Gerd Hoffmann | list->value.n = flag; |
276 | d3f24367 | Kevin Wolf | break;
|
277 | d3f24367 | Kevin Wolf | |
278 | d3f24367 | Kevin Wolf | case OPT_STRING:
|
279 | d3f24367 | Kevin Wolf | if (value != NULL) { |
280 | d4c3fddd | Jean-Christophe DUBOIS | list->value.s = qemu_strdup(value); |
281 | d3f24367 | Kevin Wolf | } else {
|
282 | d3f24367 | Kevin Wolf | fprintf(stderr, "Option '%s' needs a parameter\n", name);
|
283 | d3f24367 | Kevin Wolf | return -1; |
284 | d3f24367 | Kevin Wolf | } |
285 | d3f24367 | Kevin Wolf | break;
|
286 | d3f24367 | Kevin Wolf | |
287 | d3f24367 | Kevin Wolf | case OPT_SIZE:
|
288 | 3df04ac3 | Mark McLoughlin | if (parse_option_size(name, value, &list->value.n) == -1) |
289 | d3f24367 | Kevin Wolf | return -1; |
290 | d3f24367 | Kevin Wolf | break;
|
291 | 7695019b | Gerd Hoffmann | |
292 | d3f24367 | Kevin Wolf | default:
|
293 | d3f24367 | Kevin Wolf | fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
|
294 | d3f24367 | Kevin Wolf | return -1; |
295 | d3f24367 | Kevin Wolf | } |
296 | d3f24367 | Kevin Wolf | |
297 | d3f24367 | Kevin Wolf | return 0; |
298 | d3f24367 | Kevin Wolf | } |
299 | d3f24367 | Kevin Wolf | |
300 | d3f24367 | Kevin Wolf | /*
|
301 | d3f24367 | Kevin Wolf | * Sets the given parameter to an integer instead of a string.
|
302 | d3f24367 | Kevin Wolf | * This function cannot be used to set string options.
|
303 | d3f24367 | Kevin Wolf | *
|
304 | d3f24367 | Kevin Wolf | * Returns 0 on success, -1 in error cases
|
305 | d3f24367 | Kevin Wolf | */
|
306 | d3f24367 | Kevin Wolf | int set_option_parameter_int(QEMUOptionParameter *list, const char *name, |
307 | d3f24367 | Kevin Wolf | uint64_t value) |
308 | d3f24367 | Kevin Wolf | { |
309 | d3f24367 | Kevin Wolf | // Find a matching parameter
|
310 | d3f24367 | Kevin Wolf | list = get_option_parameter(list, name); |
311 | d3f24367 | Kevin Wolf | if (list == NULL) { |
312 | d3f24367 | Kevin Wolf | fprintf(stderr, "Unknown option '%s'\n", name);
|
313 | d3f24367 | Kevin Wolf | return -1; |
314 | d3f24367 | Kevin Wolf | } |
315 | d3f24367 | Kevin Wolf | |
316 | d3f24367 | Kevin Wolf | // Process parameter
|
317 | d3f24367 | Kevin Wolf | switch (list->type) {
|
318 | d3f24367 | Kevin Wolf | case OPT_FLAG:
|
319 | d3f24367 | Kevin Wolf | case OPT_NUMBER:
|
320 | d3f24367 | Kevin Wolf | case OPT_SIZE:
|
321 | d3f24367 | Kevin Wolf | list->value.n = value; |
322 | d3f24367 | Kevin Wolf | break;
|
323 | d3f24367 | Kevin Wolf | |
324 | d3f24367 | Kevin Wolf | default:
|
325 | d3f24367 | Kevin Wolf | return -1; |
326 | d3f24367 | Kevin Wolf | } |
327 | d3f24367 | Kevin Wolf | |
328 | d3f24367 | Kevin Wolf | return 0; |
329 | d3f24367 | Kevin Wolf | } |
330 | d3f24367 | Kevin Wolf | |
331 | d3f24367 | Kevin Wolf | /*
|
332 | d3f24367 | Kevin Wolf | * Frees a option list. If it contains strings, the strings are freed as well.
|
333 | d3f24367 | Kevin Wolf | */
|
334 | d3f24367 | Kevin Wolf | void free_option_parameters(QEMUOptionParameter *list)
|
335 | d3f24367 | Kevin Wolf | { |
336 | d3f24367 | Kevin Wolf | QEMUOptionParameter *cur = list; |
337 | d3f24367 | Kevin Wolf | |
338 | d3f24367 | Kevin Wolf | while (cur && cur->name) {
|
339 | d3f24367 | Kevin Wolf | if (cur->type == OPT_STRING) {
|
340 | d4c3fddd | Jean-Christophe DUBOIS | qemu_free(cur->value.s); |
341 | d3f24367 | Kevin Wolf | } |
342 | d3f24367 | Kevin Wolf | cur++; |
343 | d3f24367 | Kevin Wolf | } |
344 | d3f24367 | Kevin Wolf | |
345 | d4c3fddd | Jean-Christophe DUBOIS | qemu_free(list); |
346 | d3f24367 | Kevin Wolf | } |
347 | d3f24367 | Kevin Wolf | |
348 | d3f24367 | Kevin Wolf | /*
|
349 | b50cbabc | MORITA Kazutaka | * Count valid options in list
|
350 | b50cbabc | MORITA Kazutaka | */
|
351 | b50cbabc | MORITA Kazutaka | static size_t count_option_parameters(QEMUOptionParameter *list)
|
352 | b50cbabc | MORITA Kazutaka | { |
353 | b50cbabc | MORITA Kazutaka | size_t num_options = 0;
|
354 | b50cbabc | MORITA Kazutaka | |
355 | b50cbabc | MORITA Kazutaka | while (list && list->name) {
|
356 | b50cbabc | MORITA Kazutaka | num_options++; |
357 | b50cbabc | MORITA Kazutaka | list++; |
358 | b50cbabc | MORITA Kazutaka | } |
359 | b50cbabc | MORITA Kazutaka | |
360 | b50cbabc | MORITA Kazutaka | return num_options;
|
361 | b50cbabc | MORITA Kazutaka | } |
362 | b50cbabc | MORITA Kazutaka | |
363 | b50cbabc | MORITA Kazutaka | /*
|
364 | b50cbabc | MORITA Kazutaka | * Append an option list (list) to an option list (dest).
|
365 | b50cbabc | MORITA Kazutaka | *
|
366 | b50cbabc | MORITA Kazutaka | * If dest is NULL, a new copy of list is created.
|
367 | b50cbabc | MORITA Kazutaka | *
|
368 | b50cbabc | MORITA Kazutaka | * Returns a pointer to the first element of dest (or the newly allocated copy)
|
369 | b50cbabc | MORITA Kazutaka | */
|
370 | b50cbabc | MORITA Kazutaka | QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, |
371 | b50cbabc | MORITA Kazutaka | QEMUOptionParameter *list) |
372 | b50cbabc | MORITA Kazutaka | { |
373 | b50cbabc | MORITA Kazutaka | size_t num_options, num_dest_options; |
374 | b50cbabc | MORITA Kazutaka | |
375 | b50cbabc | MORITA Kazutaka | num_options = count_option_parameters(dest); |
376 | b50cbabc | MORITA Kazutaka | num_dest_options = num_options; |
377 | b50cbabc | MORITA Kazutaka | |
378 | b50cbabc | MORITA Kazutaka | num_options += count_option_parameters(list); |
379 | b50cbabc | MORITA Kazutaka | |
380 | b50cbabc | MORITA Kazutaka | dest = qemu_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter)); |
381 | bd69fe84 | Kevin Wolf | dest[num_dest_options].name = NULL;
|
382 | b50cbabc | MORITA Kazutaka | |
383 | b50cbabc | MORITA Kazutaka | while (list && list->name) {
|
384 | b50cbabc | MORITA Kazutaka | if (get_option_parameter(dest, list->name) == NULL) { |
385 | b50cbabc | MORITA Kazutaka | dest[num_dest_options++] = *list; |
386 | b50cbabc | MORITA Kazutaka | dest[num_dest_options].name = NULL;
|
387 | b50cbabc | MORITA Kazutaka | } |
388 | b50cbabc | MORITA Kazutaka | list++; |
389 | b50cbabc | MORITA Kazutaka | } |
390 | b50cbabc | MORITA Kazutaka | |
391 | b50cbabc | MORITA Kazutaka | return dest;
|
392 | b50cbabc | MORITA Kazutaka | } |
393 | b50cbabc | MORITA Kazutaka | |
394 | b50cbabc | MORITA Kazutaka | /*
|
395 | d3f24367 | Kevin Wolf | * Parses a parameter string (param) into an option list (dest).
|
396 | d3f24367 | Kevin Wolf | *
|
397 | 0e72e753 | Stefan Hajnoczi | * list is the template option list. If dest is NULL, a new copy of list is
|
398 | 0e72e753 | Stefan Hajnoczi | * created. If list is NULL, this function fails.
|
399 | d3f24367 | Kevin Wolf | *
|
400 | d3f24367 | Kevin Wolf | * A parameter string consists of one or more parameters, separated by commas.
|
401 | d3f24367 | Kevin Wolf | * Each parameter consists of its name and possibly of a value. In the latter
|
402 | d3f24367 | Kevin Wolf | * case, the value is delimited by an = character. To specify a value which
|
403 | d3f24367 | Kevin Wolf | * contains commas, double each comma so it won't be recognized as the end of
|
404 | d3f24367 | Kevin Wolf | * the parameter.
|
405 | d3f24367 | Kevin Wolf | *
|
406 | d3f24367 | Kevin Wolf | * For more details of the parsing see above.
|
407 | d3f24367 | Kevin Wolf | *
|
408 | d3f24367 | Kevin Wolf | * Returns a pointer to the first element of dest (or the newly allocated copy)
|
409 | d3f24367 | Kevin Wolf | * or NULL in error cases
|
410 | d3f24367 | Kevin Wolf | */
|
411 | d3f24367 | Kevin Wolf | QEMUOptionParameter *parse_option_parameters(const char *param, |
412 | d3f24367 | Kevin Wolf | QEMUOptionParameter *list, QEMUOptionParameter *dest) |
413 | d3f24367 | Kevin Wolf | { |
414 | d3f24367 | Kevin Wolf | QEMUOptionParameter *allocated = NULL;
|
415 | d3f24367 | Kevin Wolf | char name[256]; |
416 | d3f24367 | Kevin Wolf | char value[256]; |
417 | d3f24367 | Kevin Wolf | char *param_delim, *value_delim;
|
418 | d3f24367 | Kevin Wolf | char next_delim;
|
419 | d3f24367 | Kevin Wolf | |
420 | d3f24367 | Kevin Wolf | if (list == NULL) { |
421 | d3f24367 | Kevin Wolf | return NULL; |
422 | d3f24367 | Kevin Wolf | } |
423 | d3f24367 | Kevin Wolf | |
424 | d3f24367 | Kevin Wolf | if (dest == NULL) { |
425 | 898c257b | Stefan Hajnoczi | dest = allocated = append_option_parameters(NULL, list);
|
426 | d3f24367 | Kevin Wolf | } |
427 | d3f24367 | Kevin Wolf | |
428 | d3f24367 | Kevin Wolf | while (*param) {
|
429 | d3f24367 | Kevin Wolf | |
430 | d3f24367 | Kevin Wolf | // Find parameter name and value in the string
|
431 | d3f24367 | Kevin Wolf | param_delim = strchr(param, ',');
|
432 | d3f24367 | Kevin Wolf | value_delim = strchr(param, '=');
|
433 | d3f24367 | Kevin Wolf | |
434 | d3f24367 | Kevin Wolf | if (value_delim && (value_delim < param_delim || !param_delim)) {
|
435 | d3f24367 | Kevin Wolf | next_delim = '=';
|
436 | d3f24367 | Kevin Wolf | } else {
|
437 | d3f24367 | Kevin Wolf | next_delim = ',';
|
438 | d3f24367 | Kevin Wolf | value_delim = NULL;
|
439 | d3f24367 | Kevin Wolf | } |
440 | d3f24367 | Kevin Wolf | |
441 | d3f24367 | Kevin Wolf | param = get_opt_name(name, sizeof(name), param, next_delim);
|
442 | d3f24367 | Kevin Wolf | if (value_delim) {
|
443 | d3f24367 | Kevin Wolf | param = get_opt_value(value, sizeof(value), param + 1); |
444 | d3f24367 | Kevin Wolf | } |
445 | d3f24367 | Kevin Wolf | if (*param != '\0') { |
446 | d3f24367 | Kevin Wolf | param++; |
447 | d3f24367 | Kevin Wolf | } |
448 | d3f24367 | Kevin Wolf | |
449 | d3f24367 | Kevin Wolf | // Set the parameter
|
450 | d3f24367 | Kevin Wolf | if (set_option_parameter(dest, name, value_delim ? value : NULL)) { |
451 | d3f24367 | Kevin Wolf | goto fail;
|
452 | d3f24367 | Kevin Wolf | } |
453 | d3f24367 | Kevin Wolf | } |
454 | d3f24367 | Kevin Wolf | |
455 | d3f24367 | Kevin Wolf | return dest;
|
456 | d3f24367 | Kevin Wolf | |
457 | d3f24367 | Kevin Wolf | fail:
|
458 | d3f24367 | Kevin Wolf | // Only free the list if it was newly allocated
|
459 | d3f24367 | Kevin Wolf | free_option_parameters(allocated); |
460 | d3f24367 | Kevin Wolf | return NULL; |
461 | d3f24367 | Kevin Wolf | } |
462 | d3f24367 | Kevin Wolf | |
463 | d3f24367 | Kevin Wolf | /*
|
464 | d3f24367 | Kevin Wolf | * Prints all options of a list that have a value to stdout
|
465 | d3f24367 | Kevin Wolf | */
|
466 | d3f24367 | Kevin Wolf | void print_option_parameters(QEMUOptionParameter *list)
|
467 | d3f24367 | Kevin Wolf | { |
468 | d3f24367 | Kevin Wolf | while (list && list->name) {
|
469 | d3f24367 | Kevin Wolf | switch (list->type) {
|
470 | d3f24367 | Kevin Wolf | case OPT_STRING:
|
471 | d3f24367 | Kevin Wolf | if (list->value.s != NULL) { |
472 | d3f24367 | Kevin Wolf | printf("%s='%s' ", list->name, list->value.s);
|
473 | d3f24367 | Kevin Wolf | } |
474 | d3f24367 | Kevin Wolf | break;
|
475 | d3f24367 | Kevin Wolf | case OPT_FLAG:
|
476 | d3f24367 | Kevin Wolf | printf("%s=%s ", list->name, list->value.n ? "on" : "off"); |
477 | d3f24367 | Kevin Wolf | break;
|
478 | d3f24367 | Kevin Wolf | case OPT_SIZE:
|
479 | d3f24367 | Kevin Wolf | case OPT_NUMBER:
|
480 | d3f24367 | Kevin Wolf | printf("%s=%" PRId64 " ", list->name, list->value.n); |
481 | d3f24367 | Kevin Wolf | break;
|
482 | d3f24367 | Kevin Wolf | default:
|
483 | d3f24367 | Kevin Wolf | printf("%s=(unkown type) ", list->name);
|
484 | d3f24367 | Kevin Wolf | break;
|
485 | d3f24367 | Kevin Wolf | } |
486 | d3f24367 | Kevin Wolf | list++; |
487 | d3f24367 | Kevin Wolf | } |
488 | d3f24367 | Kevin Wolf | } |
489 | db08adf5 | Kevin Wolf | |
490 | db08adf5 | Kevin Wolf | /*
|
491 | db08adf5 | Kevin Wolf | * Prints an overview of all available options
|
492 | db08adf5 | Kevin Wolf | */
|
493 | db08adf5 | Kevin Wolf | void print_option_help(QEMUOptionParameter *list)
|
494 | db08adf5 | Kevin Wolf | { |
495 | db08adf5 | Kevin Wolf | printf("Supported options:\n");
|
496 | db08adf5 | Kevin Wolf | while (list && list->name) {
|
497 | db08adf5 | Kevin Wolf | printf("%-16s %s\n", list->name,
|
498 | db08adf5 | Kevin Wolf | list->help ? list->help : "No description available");
|
499 | db08adf5 | Kevin Wolf | list++; |
500 | db08adf5 | Kevin Wolf | } |
501 | db08adf5 | Kevin Wolf | } |
502 | e27c88fe | Gerd Hoffmann | |
503 | e27c88fe | Gerd Hoffmann | /* ------------------------------------------------------------------ */
|
504 | e27c88fe | Gerd Hoffmann | |
505 | e27c88fe | Gerd Hoffmann | struct QemuOpt {
|
506 | e27c88fe | Gerd Hoffmann | const char *name; |
507 | e27c88fe | Gerd Hoffmann | const char *str; |
508 | e27c88fe | Gerd Hoffmann | |
509 | 238431a9 | Blue Swirl | const QemuOptDesc *desc;
|
510 | e27c88fe | Gerd Hoffmann | union {
|
511 | 1f5c1775 | Juan Quintela | int boolean;
|
512 | e27c88fe | Gerd Hoffmann | uint64_t uint; |
513 | e27c88fe | Gerd Hoffmann | } value; |
514 | e27c88fe | Gerd Hoffmann | |
515 | e27c88fe | Gerd Hoffmann | QemuOpts *opts; |
516 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(QemuOpt) next; |
517 | e27c88fe | Gerd Hoffmann | }; |
518 | e27c88fe | Gerd Hoffmann | |
519 | e27c88fe | Gerd Hoffmann | struct QemuOpts {
|
520 | b09417b9 | Jan Kiszka | char *id;
|
521 | e27c88fe | Gerd Hoffmann | QemuOptsList *list; |
522 | 827b0813 | Markus Armbruster | Location loc; |
523 | dc9ca4ba | Mark McLoughlin | QTAILQ_HEAD(QemuOptHead, QemuOpt) head; |
524 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(QemuOpts) next; |
525 | e27c88fe | Gerd Hoffmann | }; |
526 | e27c88fe | Gerd Hoffmann | |
527 | e27c88fe | Gerd Hoffmann | static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) |
528 | e27c88fe | Gerd Hoffmann | { |
529 | e27c88fe | Gerd Hoffmann | QemuOpt *opt; |
530 | e27c88fe | Gerd Hoffmann | |
531 | dc9ca4ba | Mark McLoughlin | QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) { |
532 | e27c88fe | Gerd Hoffmann | if (strcmp(opt->name, name) != 0) |
533 | e27c88fe | Gerd Hoffmann | continue;
|
534 | e27c88fe | Gerd Hoffmann | return opt;
|
535 | e27c88fe | Gerd Hoffmann | } |
536 | e27c88fe | Gerd Hoffmann | return NULL; |
537 | e27c88fe | Gerd Hoffmann | } |
538 | e27c88fe | Gerd Hoffmann | |
539 | e27c88fe | Gerd Hoffmann | const char *qemu_opt_get(QemuOpts *opts, const char *name) |
540 | e27c88fe | Gerd Hoffmann | { |
541 | e27c88fe | Gerd Hoffmann | QemuOpt *opt = qemu_opt_find(opts, name); |
542 | e27c88fe | Gerd Hoffmann | return opt ? opt->str : NULL; |
543 | e27c88fe | Gerd Hoffmann | } |
544 | e27c88fe | Gerd Hoffmann | |
545 | e27c88fe | Gerd Hoffmann | int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval) |
546 | e27c88fe | Gerd Hoffmann | { |
547 | e27c88fe | Gerd Hoffmann | QemuOpt *opt = qemu_opt_find(opts, name); |
548 | e27c88fe | Gerd Hoffmann | |
549 | e27c88fe | Gerd Hoffmann | if (opt == NULL) |
550 | e27c88fe | Gerd Hoffmann | return defval;
|
551 | e27c88fe | Gerd Hoffmann | assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL); |
552 | 1f5c1775 | Juan Quintela | return opt->value.boolean;
|
553 | e27c88fe | Gerd Hoffmann | } |
554 | e27c88fe | Gerd Hoffmann | |
555 | e27c88fe | Gerd Hoffmann | uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval) |
556 | e27c88fe | Gerd Hoffmann | { |
557 | e27c88fe | Gerd Hoffmann | QemuOpt *opt = qemu_opt_find(opts, name); |
558 | e27c88fe | Gerd Hoffmann | |
559 | e27c88fe | Gerd Hoffmann | if (opt == NULL) |
560 | e27c88fe | Gerd Hoffmann | return defval;
|
561 | e27c88fe | Gerd Hoffmann | assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER); |
562 | e27c88fe | Gerd Hoffmann | return opt->value.uint;
|
563 | e27c88fe | Gerd Hoffmann | } |
564 | e27c88fe | Gerd Hoffmann | |
565 | e27c88fe | Gerd Hoffmann | uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) |
566 | e27c88fe | Gerd Hoffmann | { |
567 | e27c88fe | Gerd Hoffmann | QemuOpt *opt = qemu_opt_find(opts, name); |
568 | e27c88fe | Gerd Hoffmann | |
569 | e27c88fe | Gerd Hoffmann | if (opt == NULL) |
570 | e27c88fe | Gerd Hoffmann | return defval;
|
571 | e27c88fe | Gerd Hoffmann | assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE); |
572 | e27c88fe | Gerd Hoffmann | return opt->value.uint;
|
573 | e27c88fe | Gerd Hoffmann | } |
574 | e27c88fe | Gerd Hoffmann | |
575 | e27c88fe | Gerd Hoffmann | static int qemu_opt_parse(QemuOpt *opt) |
576 | e27c88fe | Gerd Hoffmann | { |
577 | e27c88fe | Gerd Hoffmann | if (opt->desc == NULL) |
578 | e27c88fe | Gerd Hoffmann | return 0; |
579 | e27c88fe | Gerd Hoffmann | switch (opt->desc->type) {
|
580 | e27c88fe | Gerd Hoffmann | case QEMU_OPT_STRING:
|
581 | e27c88fe | Gerd Hoffmann | /* nothing */
|
582 | e27c88fe | Gerd Hoffmann | return 0; |
583 | e27c88fe | Gerd Hoffmann | case QEMU_OPT_BOOL:
|
584 | 1f5c1775 | Juan Quintela | return parse_option_bool(opt->name, opt->str, &opt->value.boolean);
|
585 | e27c88fe | Gerd Hoffmann | case QEMU_OPT_NUMBER:
|
586 | e27c88fe | Gerd Hoffmann | return parse_option_number(opt->name, opt->str, &opt->value.uint);
|
587 | e27c88fe | Gerd Hoffmann | case QEMU_OPT_SIZE:
|
588 | e27c88fe | Gerd Hoffmann | return parse_option_size(opt->name, opt->str, &opt->value.uint);
|
589 | e27c88fe | Gerd Hoffmann | default:
|
590 | e27c88fe | Gerd Hoffmann | abort(); |
591 | e27c88fe | Gerd Hoffmann | } |
592 | e27c88fe | Gerd Hoffmann | } |
593 | e27c88fe | Gerd Hoffmann | |
594 | e27c88fe | Gerd Hoffmann | static void qemu_opt_del(QemuOpt *opt) |
595 | e27c88fe | Gerd Hoffmann | { |
596 | 72cf2d4f | Blue Swirl | QTAILQ_REMOVE(&opt->opts->head, opt, next); |
597 | e27c88fe | Gerd Hoffmann | qemu_free((/* !const */ char*)opt->name); |
598 | e27c88fe | Gerd Hoffmann | qemu_free((/* !const */ char*)opt->str); |
599 | e27c88fe | Gerd Hoffmann | qemu_free(opt); |
600 | e27c88fe | Gerd Hoffmann | } |
601 | e27c88fe | Gerd Hoffmann | |
602 | e27c88fe | Gerd Hoffmann | int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) |
603 | e27c88fe | Gerd Hoffmann | { |
604 | e27c88fe | Gerd Hoffmann | QemuOpt *opt; |
605 | 238431a9 | Blue Swirl | const QemuOptDesc *desc = opts->list->desc;
|
606 | dc9ca4ba | Mark McLoughlin | int i;
|
607 | e27c88fe | Gerd Hoffmann | |
608 | dc9ca4ba | Mark McLoughlin | for (i = 0; desc[i].name != NULL; i++) { |
609 | dc9ca4ba | Mark McLoughlin | if (strcmp(desc[i].name, name) == 0) { |
610 | dc9ca4ba | Mark McLoughlin | break;
|
611 | e27c88fe | Gerd Hoffmann | } |
612 | dc9ca4ba | Mark McLoughlin | } |
613 | dc9ca4ba | Mark McLoughlin | if (desc[i].name == NULL) { |
614 | dc9ca4ba | Mark McLoughlin | if (i == 0) { |
615 | dc9ca4ba | Mark McLoughlin | /* empty list -> allow any */;
|
616 | dc9ca4ba | Mark McLoughlin | } else {
|
617 | c64f27d4 | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER, name); |
618 | dc9ca4ba | Mark McLoughlin | return -1; |
619 | e27c88fe | Gerd Hoffmann | } |
620 | e27c88fe | Gerd Hoffmann | } |
621 | dc9ca4ba | Mark McLoughlin | |
622 | dc9ca4ba | Mark McLoughlin | opt = qemu_mallocz(sizeof(*opt));
|
623 | dc9ca4ba | Mark McLoughlin | opt->name = qemu_strdup(name); |
624 | dc9ca4ba | Mark McLoughlin | opt->opts = opts; |
625 | dc9ca4ba | Mark McLoughlin | QTAILQ_INSERT_TAIL(&opts->head, opt, next); |
626 | dc9ca4ba | Mark McLoughlin | if (desc[i].name != NULL) { |
627 | dc9ca4ba | Mark McLoughlin | opt->desc = desc+i; |
628 | dc9ca4ba | Mark McLoughlin | } |
629 | e27c88fe | Gerd Hoffmann | if (value) {
|
630 | e27c88fe | Gerd Hoffmann | opt->str = qemu_strdup(value); |
631 | e27c88fe | Gerd Hoffmann | } |
632 | e27c88fe | Gerd Hoffmann | if (qemu_opt_parse(opt) < 0) { |
633 | e27c88fe | Gerd Hoffmann | qemu_opt_del(opt); |
634 | e27c88fe | Gerd Hoffmann | return -1; |
635 | e27c88fe | Gerd Hoffmann | } |
636 | e27c88fe | Gerd Hoffmann | return 0; |
637 | e27c88fe | Gerd Hoffmann | } |
638 | e27c88fe | Gerd Hoffmann | |
639 | 48026075 | Gerd Hoffmann | int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, |
640 | 48026075 | Gerd Hoffmann | int abort_on_failure)
|
641 | 48026075 | Gerd Hoffmann | { |
642 | 48026075 | Gerd Hoffmann | QemuOpt *opt; |
643 | 48026075 | Gerd Hoffmann | int rc = 0; |
644 | 48026075 | Gerd Hoffmann | |
645 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(opt, &opts->head, next) { |
646 | 48026075 | Gerd Hoffmann | rc = func(opt->name, opt->str, opaque); |
647 | 48026075 | Gerd Hoffmann | if (abort_on_failure && rc != 0) |
648 | 48026075 | Gerd Hoffmann | break;
|
649 | 48026075 | Gerd Hoffmann | } |
650 | 48026075 | Gerd Hoffmann | return rc;
|
651 | 48026075 | Gerd Hoffmann | } |
652 | 48026075 | Gerd Hoffmann | |
653 | e27c88fe | Gerd Hoffmann | QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id) |
654 | e27c88fe | Gerd Hoffmann | { |
655 | e27c88fe | Gerd Hoffmann | QemuOpts *opts; |
656 | e27c88fe | Gerd Hoffmann | |
657 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(opts, &list->head, next) { |
658 | e27c88fe | Gerd Hoffmann | if (!opts->id) {
|
659 | e27c88fe | Gerd Hoffmann | continue;
|
660 | e27c88fe | Gerd Hoffmann | } |
661 | e27c88fe | Gerd Hoffmann | if (strcmp(opts->id, id) != 0) { |
662 | e27c88fe | Gerd Hoffmann | continue;
|
663 | e27c88fe | Gerd Hoffmann | } |
664 | e27c88fe | Gerd Hoffmann | return opts;
|
665 | e27c88fe | Gerd Hoffmann | } |
666 | e27c88fe | Gerd Hoffmann | return NULL; |
667 | e27c88fe | Gerd Hoffmann | } |
668 | e27c88fe | Gerd Hoffmann | |
669 | b560a9ab | Markus Armbruster | static int id_wellformed(const char *id) |
670 | b560a9ab | Markus Armbruster | { |
671 | b560a9ab | Markus Armbruster | int i;
|
672 | b560a9ab | Markus Armbruster | |
673 | b560a9ab | Markus Armbruster | if (!qemu_isalpha(id[0])) { |
674 | b560a9ab | Markus Armbruster | return 0; |
675 | b560a9ab | Markus Armbruster | } |
676 | b560a9ab | Markus Armbruster | for (i = 1; id[i]; i++) { |
677 | b560a9ab | Markus Armbruster | if (!qemu_isalnum(id[i]) && !strchr("-._", id[i])) { |
678 | b560a9ab | Markus Armbruster | return 0; |
679 | b560a9ab | Markus Armbruster | } |
680 | b560a9ab | Markus Armbruster | } |
681 | b560a9ab | Markus Armbruster | return 1; |
682 | b560a9ab | Markus Armbruster | } |
683 | b560a9ab | Markus Armbruster | |
684 | e27c88fe | Gerd Hoffmann | QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists) |
685 | e27c88fe | Gerd Hoffmann | { |
686 | e27c88fe | Gerd Hoffmann | QemuOpts *opts = NULL;
|
687 | e27c88fe | Gerd Hoffmann | |
688 | e27c88fe | Gerd Hoffmann | if (id) {
|
689 | b560a9ab | Markus Armbruster | if (!id_wellformed(id)) {
|
690 | b560a9ab | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier"); |
691 | b560a9ab | Markus Armbruster | error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
|
692 | b560a9ab | Markus Armbruster | return NULL; |
693 | b560a9ab | Markus Armbruster | } |
694 | e27c88fe | Gerd Hoffmann | opts = qemu_opts_find(list, id); |
695 | e27c88fe | Gerd Hoffmann | if (opts != NULL) { |
696 | e27c88fe | Gerd Hoffmann | if (fail_if_exists) {
|
697 | 975b63a4 | Markus Armbruster | qerror_report(QERR_DUPLICATE_ID, id, list->name); |
698 | e27c88fe | Gerd Hoffmann | return NULL; |
699 | e27c88fe | Gerd Hoffmann | } else {
|
700 | e27c88fe | Gerd Hoffmann | return opts;
|
701 | e27c88fe | Gerd Hoffmann | } |
702 | e27c88fe | Gerd Hoffmann | } |
703 | e27c88fe | Gerd Hoffmann | } |
704 | e27c88fe | Gerd Hoffmann | opts = qemu_mallocz(sizeof(*opts));
|
705 | e27c88fe | Gerd Hoffmann | if (id) {
|
706 | e27c88fe | Gerd Hoffmann | opts->id = qemu_strdup(id); |
707 | e27c88fe | Gerd Hoffmann | } |
708 | e27c88fe | Gerd Hoffmann | opts->list = list; |
709 | 827b0813 | Markus Armbruster | loc_save(&opts->loc); |
710 | 72cf2d4f | Blue Swirl | QTAILQ_INIT(&opts->head); |
711 | 72cf2d4f | Blue Swirl | QTAILQ_INSERT_TAIL(&list->head, opts, next); |
712 | e27c88fe | Gerd Hoffmann | return opts;
|
713 | e27c88fe | Gerd Hoffmann | } |
714 | e27c88fe | Gerd Hoffmann | |
715 | bb67ab02 | Markus Armbruster | void qemu_opts_reset(QemuOptsList *list)
|
716 | bb67ab02 | Markus Armbruster | { |
717 | bb67ab02 | Markus Armbruster | QemuOpts *opts, *next_opts; |
718 | bb67ab02 | Markus Armbruster | |
719 | bb67ab02 | Markus Armbruster | QTAILQ_FOREACH_SAFE(opts, &list->head, next, next_opts) { |
720 | bb67ab02 | Markus Armbruster | qemu_opts_del(opts); |
721 | bb67ab02 | Markus Armbruster | } |
722 | bb67ab02 | Markus Armbruster | } |
723 | bb67ab02 | Markus Armbruster | |
724 | 94ac7268 | Markus Armbruster | void qemu_opts_loc_restore(QemuOpts *opts)
|
725 | 94ac7268 | Markus Armbruster | { |
726 | 94ac7268 | Markus Armbruster | loc_restore(&opts->loc); |
727 | 94ac7268 | Markus Armbruster | } |
728 | 94ac7268 | Markus Armbruster | |
729 | e27c88fe | Gerd Hoffmann | int qemu_opts_set(QemuOptsList *list, const char *id, |
730 | e27c88fe | Gerd Hoffmann | const char *name, const char *value) |
731 | e27c88fe | Gerd Hoffmann | { |
732 | e27c88fe | Gerd Hoffmann | QemuOpts *opts; |
733 | e27c88fe | Gerd Hoffmann | |
734 | e27c88fe | Gerd Hoffmann | opts = qemu_opts_create(list, id, 1);
|
735 | e27c88fe | Gerd Hoffmann | if (opts == NULL) { |
736 | e27c88fe | Gerd Hoffmann | return -1; |
737 | e27c88fe | Gerd Hoffmann | } |
738 | e27c88fe | Gerd Hoffmann | return qemu_opt_set(opts, name, value);
|
739 | e27c88fe | Gerd Hoffmann | } |
740 | e27c88fe | Gerd Hoffmann | |
741 | 48026075 | Gerd Hoffmann | const char *qemu_opts_id(QemuOpts *opts) |
742 | 48026075 | Gerd Hoffmann | { |
743 | 48026075 | Gerd Hoffmann | return opts->id;
|
744 | 48026075 | Gerd Hoffmann | } |
745 | 48026075 | Gerd Hoffmann | |
746 | e27c88fe | Gerd Hoffmann | void qemu_opts_del(QemuOpts *opts)
|
747 | e27c88fe | Gerd Hoffmann | { |
748 | e27c88fe | Gerd Hoffmann | QemuOpt *opt; |
749 | e27c88fe | Gerd Hoffmann | |
750 | e27c88fe | Gerd Hoffmann | for (;;) {
|
751 | 72cf2d4f | Blue Swirl | opt = QTAILQ_FIRST(&opts->head); |
752 | e27c88fe | Gerd Hoffmann | if (opt == NULL) |
753 | e27c88fe | Gerd Hoffmann | break;
|
754 | e27c88fe | Gerd Hoffmann | qemu_opt_del(opt); |
755 | e27c88fe | Gerd Hoffmann | } |
756 | 72cf2d4f | Blue Swirl | QTAILQ_REMOVE(&opts->list->head, opts, next); |
757 | b09417b9 | Jan Kiszka | qemu_free(opts->id); |
758 | e27c88fe | Gerd Hoffmann | qemu_free(opts); |
759 | e27c88fe | Gerd Hoffmann | } |
760 | e27c88fe | Gerd Hoffmann | |
761 | e27c88fe | Gerd Hoffmann | int qemu_opts_print(QemuOpts *opts, void *dummy) |
762 | e27c88fe | Gerd Hoffmann | { |
763 | e27c88fe | Gerd Hoffmann | QemuOpt *opt; |
764 | e27c88fe | Gerd Hoffmann | |
765 | e27c88fe | Gerd Hoffmann | fprintf(stderr, "%s: %s:", opts->list->name,
|
766 | e27c88fe | Gerd Hoffmann | opts->id ? opts->id : "<noid>");
|
767 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(opt, &opts->head, next) { |
768 | e27c88fe | Gerd Hoffmann | fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
|
769 | e27c88fe | Gerd Hoffmann | } |
770 | e27c88fe | Gerd Hoffmann | fprintf(stderr, "\n");
|
771 | e27c88fe | Gerd Hoffmann | return 0; |
772 | e27c88fe | Gerd Hoffmann | } |
773 | e27c88fe | Gerd Hoffmann | |
774 | 96729cbd | Gerd Hoffmann | int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname) |
775 | e27c88fe | Gerd Hoffmann | { |
776 | d318ff99 | Gerd Hoffmann | char option[128], value[1024]; |
777 | e27c88fe | Gerd Hoffmann | const char *p,*pe,*pc; |
778 | e27c88fe | Gerd Hoffmann | |
779 | 2cfa571f | Mark McLoughlin | for (p = params; *p != '\0'; p++) { |
780 | e27c88fe | Gerd Hoffmann | pe = strchr(p, '=');
|
781 | e27c88fe | Gerd Hoffmann | pc = strchr(p, ',');
|
782 | e27c88fe | Gerd Hoffmann | if (!pe || (pc && pc < pe)) {
|
783 | e27c88fe | Gerd Hoffmann | /* found "foo,more" */
|
784 | e27c88fe | Gerd Hoffmann | if (p == params && firstname) {
|
785 | e27c88fe | Gerd Hoffmann | /* implicitly named first option */
|
786 | e27c88fe | Gerd Hoffmann | pstrcpy(option, sizeof(option), firstname);
|
787 | e27c88fe | Gerd Hoffmann | p = get_opt_value(value, sizeof(value), p);
|
788 | e27c88fe | Gerd Hoffmann | } else {
|
789 | e27c88fe | Gerd Hoffmann | /* option without value, probably a flag */
|
790 | e27c88fe | Gerd Hoffmann | p = get_opt_name(option, sizeof(option), p, ','); |
791 | 96729cbd | Gerd Hoffmann | if (strncmp(option, "no", 2) == 0) { |
792 | e27c88fe | Gerd Hoffmann | memmove(option, option+2, strlen(option+2)+1); |
793 | e27c88fe | Gerd Hoffmann | pstrcpy(value, sizeof(value), "off"); |
794 | e27c88fe | Gerd Hoffmann | } else {
|
795 | e27c88fe | Gerd Hoffmann | pstrcpy(value, sizeof(value), "on"); |
796 | e27c88fe | Gerd Hoffmann | } |
797 | e27c88fe | Gerd Hoffmann | } |
798 | e27c88fe | Gerd Hoffmann | } else {
|
799 | e27c88fe | Gerd Hoffmann | /* found "foo=bar,more" */
|
800 | e27c88fe | Gerd Hoffmann | p = get_opt_name(option, sizeof(option), p, '='); |
801 | e27c88fe | Gerd Hoffmann | if (*p != '=') { |
802 | e27c88fe | Gerd Hoffmann | break;
|
803 | e27c88fe | Gerd Hoffmann | } |
804 | e27c88fe | Gerd Hoffmann | p++; |
805 | e27c88fe | Gerd Hoffmann | p = get_opt_value(value, sizeof(value), p);
|
806 | e27c88fe | Gerd Hoffmann | } |
807 | e27c88fe | Gerd Hoffmann | if (strcmp(option, "id") != 0) { |
808 | e27c88fe | Gerd Hoffmann | /* store and parse */
|
809 | 3df04ac3 | Mark McLoughlin | if (qemu_opt_set(opts, option, value) == -1) { |
810 | 96729cbd | Gerd Hoffmann | return -1; |
811 | e27c88fe | Gerd Hoffmann | } |
812 | e27c88fe | Gerd Hoffmann | } |
813 | e27c88fe | Gerd Hoffmann | if (*p != ',') { |
814 | e27c88fe | Gerd Hoffmann | break;
|
815 | e27c88fe | Gerd Hoffmann | } |
816 | e27c88fe | Gerd Hoffmann | } |
817 | 96729cbd | Gerd Hoffmann | return 0; |
818 | 96729cbd | Gerd Hoffmann | } |
819 | 96729cbd | Gerd Hoffmann | |
820 | 8212c64f | Markus Armbruster | QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, |
821 | 8212c64f | Markus Armbruster | int permit_abbrev)
|
822 | 96729cbd | Gerd Hoffmann | { |
823 | 8212c64f | Markus Armbruster | const char *firstname; |
824 | d318ff99 | Gerd Hoffmann | char value[1024], *id = NULL; |
825 | 96729cbd | Gerd Hoffmann | const char *p; |
826 | 96729cbd | Gerd Hoffmann | QemuOpts *opts; |
827 | 96729cbd | Gerd Hoffmann | |
828 | 8212c64f | Markus Armbruster | assert(!permit_abbrev || list->implied_opt_name); |
829 | 8212c64f | Markus Armbruster | firstname = permit_abbrev ? list->implied_opt_name : NULL;
|
830 | 8212c64f | Markus Armbruster | |
831 | 96729cbd | Gerd Hoffmann | if (strncmp(params, "id=", 3) == 0) { |
832 | 96729cbd | Gerd Hoffmann | get_opt_value(value, sizeof(value), params+3); |
833 | d510c5cf | Jan Kiszka | id = value; |
834 | 96729cbd | Gerd Hoffmann | } else if ((p = strstr(params, ",id=")) != NULL) { |
835 | 96729cbd | Gerd Hoffmann | get_opt_value(value, sizeof(value), p+4); |
836 | d510c5cf | Jan Kiszka | id = value; |
837 | 96729cbd | Gerd Hoffmann | } |
838 | 96729cbd | Gerd Hoffmann | opts = qemu_opts_create(list, id, 1);
|
839 | 96729cbd | Gerd Hoffmann | if (opts == NULL) |
840 | 96729cbd | Gerd Hoffmann | return NULL; |
841 | 96729cbd | Gerd Hoffmann | |
842 | 96729cbd | Gerd Hoffmann | if (qemu_opts_do_parse(opts, params, firstname) != 0) { |
843 | 96729cbd | Gerd Hoffmann | qemu_opts_del(opts); |
844 | 96729cbd | Gerd Hoffmann | return NULL; |
845 | 96729cbd | Gerd Hoffmann | } |
846 | 96729cbd | Gerd Hoffmann | |
847 | e27c88fe | Gerd Hoffmann | return opts;
|
848 | e27c88fe | Gerd Hoffmann | } |
849 | e27c88fe | Gerd Hoffmann | |
850 | 01e7f188 | Markus Armbruster | static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque) |
851 | 01e7f188 | Markus Armbruster | { |
852 | 01e7f188 | Markus Armbruster | char buf[32]; |
853 | 01e7f188 | Markus Armbruster | const char *value; |
854 | 01e7f188 | Markus Armbruster | int n;
|
855 | 01e7f188 | Markus Armbruster | |
856 | 01e7f188 | Markus Armbruster | if (!strcmp(key, "id")) { |
857 | 01e7f188 | Markus Armbruster | return;
|
858 | 01e7f188 | Markus Armbruster | } |
859 | 01e7f188 | Markus Armbruster | |
860 | 01e7f188 | Markus Armbruster | switch (qobject_type(obj)) {
|
861 | 01e7f188 | Markus Armbruster | case QTYPE_QSTRING:
|
862 | 01e7f188 | Markus Armbruster | value = qstring_get_str(qobject_to_qstring(obj)); |
863 | 01e7f188 | Markus Armbruster | break;
|
864 | 01e7f188 | Markus Armbruster | case QTYPE_QINT:
|
865 | 01e7f188 | Markus Armbruster | n = snprintf(buf, sizeof(buf), "%" PRId64, |
866 | 01e7f188 | Markus Armbruster | qint_get_int(qobject_to_qint(obj))); |
867 | 01e7f188 | Markus Armbruster | assert(n < sizeof(buf));
|
868 | 01e7f188 | Markus Armbruster | value = buf; |
869 | 01e7f188 | Markus Armbruster | break;
|
870 | 01e7f188 | Markus Armbruster | case QTYPE_QFLOAT:
|
871 | 01e7f188 | Markus Armbruster | n = snprintf(buf, sizeof(buf), "%.17g", |
872 | 01e7f188 | Markus Armbruster | qfloat_get_double(qobject_to_qfloat(obj))); |
873 | 01e7f188 | Markus Armbruster | assert(n < sizeof(buf));
|
874 | 01e7f188 | Markus Armbruster | value = buf; |
875 | 01e7f188 | Markus Armbruster | break;
|
876 | 01e7f188 | Markus Armbruster | case QTYPE_QBOOL:
|
877 | d35215f8 | Blue Swirl | pstrcpy(buf, sizeof(buf),
|
878 | d35215f8 | Blue Swirl | qbool_get_int(qobject_to_qbool(obj)) ? "on" : "off"); |
879 | 01e7f188 | Markus Armbruster | value = buf; |
880 | 01e7f188 | Markus Armbruster | break;
|
881 | 01e7f188 | Markus Armbruster | default:
|
882 | 01e7f188 | Markus Armbruster | return;
|
883 | 01e7f188 | Markus Armbruster | } |
884 | 01e7f188 | Markus Armbruster | qemu_opt_set(opaque, key, value); |
885 | 01e7f188 | Markus Armbruster | } |
886 | 01e7f188 | Markus Armbruster | |
887 | 01e7f188 | Markus Armbruster | /*
|
888 | 01e7f188 | Markus Armbruster | * Create QemuOpts from a QDict.
|
889 | 01e7f188 | Markus Armbruster | * Use value of key "id" as ID if it exists and is a QString.
|
890 | 01e7f188 | Markus Armbruster | * Only QStrings, QInts, QFloats and QBools are copied. Entries with
|
891 | 01e7f188 | Markus Armbruster | * other types are silently ignored.
|
892 | 01e7f188 | Markus Armbruster | */
|
893 | 01e7f188 | Markus Armbruster | QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict)
|
894 | 01e7f188 | Markus Armbruster | { |
895 | 01e7f188 | Markus Armbruster | QemuOpts *opts; |
896 | 01e7f188 | Markus Armbruster | |
897 | 01e7f188 | Markus Armbruster | opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1); |
898 | 01e7f188 | Markus Armbruster | if (opts == NULL) |
899 | 01e7f188 | Markus Armbruster | return NULL; |
900 | 01e7f188 | Markus Armbruster | |
901 | 01e7f188 | Markus Armbruster | qdict_iter(qdict, qemu_opts_from_qdict_1, opts); |
902 | 01e7f188 | Markus Armbruster | return opts;
|
903 | 01e7f188 | Markus Armbruster | } |
904 | 01e7f188 | Markus Armbruster | |
905 | 01e7f188 | Markus Armbruster | /*
|
906 | 01e7f188 | Markus Armbruster | * Convert from QemuOpts to QDict.
|
907 | 01e7f188 | Markus Armbruster | * The QDict values are of type QString.
|
908 | 01e7f188 | Markus Armbruster | * TODO We'll want to use types appropriate for opt->desc->type, but
|
909 | 01e7f188 | Markus Armbruster | * this is enough for now.
|
910 | 01e7f188 | Markus Armbruster | */
|
911 | 01e7f188 | Markus Armbruster | QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict) |
912 | 01e7f188 | Markus Armbruster | { |
913 | 01e7f188 | Markus Armbruster | QemuOpt *opt; |
914 | 01e7f188 | Markus Armbruster | QObject *val; |
915 | 01e7f188 | Markus Armbruster | |
916 | 01e7f188 | Markus Armbruster | if (!qdict) {
|
917 | 01e7f188 | Markus Armbruster | qdict = qdict_new(); |
918 | 01e7f188 | Markus Armbruster | } |
919 | 01e7f188 | Markus Armbruster | if (opts->id) {
|
920 | 01e7f188 | Markus Armbruster | qdict_put(qdict, "id", qstring_from_str(opts->id));
|
921 | 01e7f188 | Markus Armbruster | } |
922 | 01e7f188 | Markus Armbruster | QTAILQ_FOREACH(opt, &opts->head, next) { |
923 | 01e7f188 | Markus Armbruster | val = QOBJECT(qstring_from_str(opt->str)); |
924 | 01e7f188 | Markus Armbruster | qdict_put_obj(qdict, opt->name, val); |
925 | 01e7f188 | Markus Armbruster | } |
926 | 01e7f188 | Markus Armbruster | return qdict;
|
927 | 01e7f188 | Markus Armbruster | } |
928 | 01e7f188 | Markus Armbruster | |
929 | 5dc519ef | Mark McLoughlin | /* Validate parsed opts against descriptions where no
|
930 | 5dc519ef | Mark McLoughlin | * descriptions were provided in the QemuOptsList.
|
931 | 5dc519ef | Mark McLoughlin | */
|
932 | 238431a9 | Blue Swirl | int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc) |
933 | 5dc519ef | Mark McLoughlin | { |
934 | 5dc519ef | Mark McLoughlin | QemuOpt *opt; |
935 | 5dc519ef | Mark McLoughlin | |
936 | 5dc519ef | Mark McLoughlin | assert(opts->list->desc[0].name == NULL); |
937 | 5dc519ef | Mark McLoughlin | |
938 | 5dc519ef | Mark McLoughlin | QTAILQ_FOREACH(opt, &opts->head, next) { |
939 | 5dc519ef | Mark McLoughlin | int i;
|
940 | 5dc519ef | Mark McLoughlin | |
941 | 5dc519ef | Mark McLoughlin | for (i = 0; desc[i].name != NULL; i++) { |
942 | 5dc519ef | Mark McLoughlin | if (strcmp(desc[i].name, opt->name) == 0) { |
943 | 5dc519ef | Mark McLoughlin | break;
|
944 | 5dc519ef | Mark McLoughlin | } |
945 | 5dc519ef | Mark McLoughlin | } |
946 | 5dc519ef | Mark McLoughlin | if (desc[i].name == NULL) { |
947 | db716e9c | Markus Armbruster | qerror_report(QERR_INVALID_PARAMETER, opt->name); |
948 | 5dc519ef | Mark McLoughlin | return -1; |
949 | 5dc519ef | Mark McLoughlin | } |
950 | 5dc519ef | Mark McLoughlin | |
951 | 5dc519ef | Mark McLoughlin | opt->desc = &desc[i]; |
952 | 5dc519ef | Mark McLoughlin | |
953 | 5dc519ef | Mark McLoughlin | if (qemu_opt_parse(opt) < 0) { |
954 | 5dc519ef | Mark McLoughlin | return -1; |
955 | 5dc519ef | Mark McLoughlin | } |
956 | 5dc519ef | Mark McLoughlin | } |
957 | 5dc519ef | Mark McLoughlin | |
958 | 5dc519ef | Mark McLoughlin | return 0; |
959 | 5dc519ef | Mark McLoughlin | } |
960 | 5dc519ef | Mark McLoughlin | |
961 | e27c88fe | Gerd Hoffmann | int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, |
962 | e27c88fe | Gerd Hoffmann | int abort_on_failure)
|
963 | e27c88fe | Gerd Hoffmann | { |
964 | 827b0813 | Markus Armbruster | Location loc; |
965 | e27c88fe | Gerd Hoffmann | QemuOpts *opts; |
966 | e27c88fe | Gerd Hoffmann | int rc = 0; |
967 | e27c88fe | Gerd Hoffmann | |
968 | 827b0813 | Markus Armbruster | loc_push_none(&loc); |
969 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(opts, &list->head, next) { |
970 | 827b0813 | Markus Armbruster | loc_restore(&opts->loc); |
971 | 4a2594dd | Markus Armbruster | rc |= func(opts, opaque); |
972 | e27c88fe | Gerd Hoffmann | if (abort_on_failure && rc != 0) |
973 | e27c88fe | Gerd Hoffmann | break;
|
974 | e27c88fe | Gerd Hoffmann | } |
975 | 827b0813 | Markus Armbruster | loc_pop(&loc); |
976 | e27c88fe | Gerd Hoffmann | return rc;
|
977 | e27c88fe | Gerd Hoffmann | } |