New LOC_FILE. Use it for tracking file name and line number in
qemu_config_parse(). We now report errors like
qemu:foo.conf:42: Did not find I2C bus for smbus-eeprom
In particular, gems like this message:
-device: no driver specified
become almost nice now:
qemu:foo.conf:44: -device: no driver specified
(A later commit will get rid of the bogus -device:)
-int qemu_config_parse(FILE *fp)
+int qemu_config_parse(FILE *fp, const char *fname)
{
char line[1024], group[64], id[64], arg[64], value[1024];
{
char line[1024], group[64], id[64], arg[64], value[1024];
QemuOptsList *list = NULL;
QemuOpts *opts = NULL;
QemuOptsList *list = NULL;
QemuOpts *opts = NULL;
while (fgets(line, sizeof(line), fp) != NULL) {
while (fgets(line, sizeof(line), fp) != NULL) {
+ loc_set_file(fname, ++lno);
if (line[0] == '\n') {
/* skip empty lines */
continue;
if (line[0] == '\n') {
/* skip empty lines */
continue;
/* group with id */
list = find_list(group);
if (list == NULL)
/* group with id */
list = find_list(group);
if (list == NULL)
opts = qemu_opts_create(list, id, 1);
continue;
}
opts = qemu_opts_create(list, id, 1);
continue;
}
/* group without id */
list = find_list(group);
if (list == NULL)
/* group without id */
list = find_list(group);
if (list == NULL)
opts = qemu_opts_create(list, NULL, 0);
continue;
}
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
/* arg = value */
if (opts == NULL) {
opts = qemu_opts_create(list, NULL, 0);
continue;
}
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
/* arg = value */
if (opts == NULL) {
- fprintf(stderr, "no group defined\n");
- return -1;
+ error_report("no group defined");
+ goto out;
}
if (qemu_opt_set(opts, arg, value) != 0) {
}
if (qemu_opt_set(opts, arg, value) != 0) {
- fprintf(stderr, "failed to set \"%s\" for %s\n",
- arg, group);
- return -1;
+ error_report("failed to set \"%s\" for %s", arg, group);
+ goto out;
- fprintf(stderr, "parse error: %s\n", line);
- return -1;
+ error_report("parse error");
+ goto out;
+ res = 0;
+out:
+ loc_pop(&loc);
+ return res;
void qemu_add_globals(void);
void qemu_config_write(FILE *fp);
void qemu_add_globals(void);
void qemu_config_write(FILE *fp);
-int qemu_config_parse(FILE *fp);
+int qemu_config_parse(FILE *fp, const char *fname);
#endif /* QEMU_CONFIG_H */
#endif /* QEMU_CONFIG_H */
cur_loc->kind = LOC_NONE;
}
cur_loc->kind = LOC_NONE;
}
+/*
+ * Change the current location to file FNAME, line LNO.
+ */
+void loc_set_file(const char *fname, int lno)
+{
+ assert (fname || cur_loc->kind == LOC_FILE);
+ cur_loc->kind = LOC_FILE;
+ cur_loc->num = lno;
+ if (fname) {
+ cur_loc->ptr = fname;
+ }
+}
+
static const char *progname;
/*
static const char *progname;
/*
sep = " ";
}
switch (cur_loc->kind) {
sep = " ";
}
switch (cur_loc->kind) {
+ case LOC_FILE:
+ error_printf("%s:", (const char *)cur_loc->ptr);
+ if (cur_loc->num) {
+ error_printf("%d:", cur_loc->num);
+ }
+ error_printf(" ");
+ break;
default:
error_printf(sep);
}
default:
error_printf(sep);
}
typedef struct Location {
/* all members are private to qemu-error.c */
typedef struct Location {
/* all members are private to qemu-error.c */
- enum { LOC_NONE } kind;
+ enum { LOC_NONE, LOC_FILE } kind;
int num;
const void *ptr;
struct Location *prev;
int num;
const void *ptr;
struct Location *prev;
Location *loc_save(Location *loc);
void loc_restore(Location *loc);
void loc_set_none(void);
Location *loc_save(Location *loc);
void loc_restore(Location *loc);
void loc_set_none(void);
+void loc_set_file(const char *fname, int lno);
void error_vprintf(const char *fmt, va_list ap);
void error_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
void error_vprintf(const char *fmt, va_list ap);
void error_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
- fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r");
+
+ fname = CONFIG_QEMU_CONFDIR "/qemu.conf";
+ fp = fopen(fname, "r");
- if (qemu_config_parse(fp) != 0) {
+ if (qemu_config_parse(fp, fname) != 0) {
- fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r");
+ fname = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf";
+ fp = fopen(fname, "r");
- if (qemu_config_parse(fp) != 0) {
+ if (qemu_config_parse(fp, fname) != 0) {
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
exit(1);
}
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
exit(1);
}
- if (qemu_config_parse(fp) != 0) {
+ if (qemu_config_parse(fp, optarg) != 0) {