Revision cf5a65aa qemu-config.c
b/qemu-config.c | ||
---|---|---|
425 | 425 |
} |
426 | 426 |
} |
427 | 427 |
|
428 |
int qemu_config_parse(FILE *fp) |
|
428 |
int qemu_config_parse(FILE *fp, const char *fname)
|
|
429 | 429 |
{ |
430 | 430 |
char line[1024], group[64], id[64], arg[64], value[1024]; |
431 |
Location loc; |
|
431 | 432 |
QemuOptsList *list = NULL; |
432 | 433 |
QemuOpts *opts = NULL; |
434 |
int res = -1, lno = 0; |
|
433 | 435 |
|
436 |
loc_push_none(&loc); |
|
434 | 437 |
while (fgets(line, sizeof(line), fp) != NULL) { |
438 |
loc_set_file(fname, ++lno); |
|
435 | 439 |
if (line[0] == '\n') { |
436 | 440 |
/* skip empty lines */ |
437 | 441 |
continue; |
... | ... | |
444 | 448 |
/* group with id */ |
445 | 449 |
list = find_list(group); |
446 | 450 |
if (list == NULL) |
447 |
return -1;
|
|
451 |
goto out;
|
|
448 | 452 |
opts = qemu_opts_create(list, id, 1); |
449 | 453 |
continue; |
450 | 454 |
} |
... | ... | |
452 | 456 |
/* group without id */ |
453 | 457 |
list = find_list(group); |
454 | 458 |
if (list == NULL) |
455 |
return -1;
|
|
459 |
goto out;
|
|
456 | 460 |
opts = qemu_opts_create(list, NULL, 0); |
457 | 461 |
continue; |
458 | 462 |
} |
459 | 463 |
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { |
460 | 464 |
/* arg = value */ |
461 | 465 |
if (opts == NULL) { |
462 |
fprintf(stderr, "no group defined\n");
|
|
463 |
return -1;
|
|
466 |
error_report("no group defined");
|
|
467 |
goto out;
|
|
464 | 468 |
} |
465 | 469 |
if (qemu_opt_set(opts, arg, value) != 0) { |
466 |
fprintf(stderr, "failed to set \"%s\" for %s\n", |
|
467 |
arg, group); |
|
468 |
return -1; |
|
470 |
error_report("failed to set \"%s\" for %s", arg, group); |
|
471 |
goto out; |
|
469 | 472 |
} |
470 | 473 |
continue; |
471 | 474 |
} |
472 |
fprintf(stderr, "parse error: %s\n", line);
|
|
473 |
return -1;
|
|
475 |
error_report("parse error");
|
|
476 |
goto out;
|
|
474 | 477 |
} |
475 |
return 0; |
|
478 |
res = 0; |
|
479 |
out: |
|
480 |
loc_pop(&loc); |
|
481 |
return res; |
|
476 | 482 |
} |
Also available in: Unified diff