diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2014-06-17 12:28:43 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2014-06-23 16:20:42 +0100 |
commit | 8d3447debbb77837eaff500242216faeb27e4711 (patch) | |
tree | a393d046cf761ead550340acd5ef8e5ce89a4cda | |
parent | 4e9cc7dda298b9292b722d7a42900825e1307b8a (diff) | |
download | qemu-arm-8d3447debbb77837eaff500242216faeb27e4711.tar.gz |
android-console: Add KO: prefix to parser syntax error messages
Indirect all the syntax error messages from the command parser
through a function pointer, so the Android console can override
it to put the KO: prefix on them.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | android-console.c | 13 | ||||
-rw-r--r-- | android-console.h | 2 | ||||
-rw-r--r-- | monitor.c | 48 |
3 files changed, 42 insertions, 21 deletions
diff --git a/android-console.c b/android-console.c index 50f8b2cebd..1ff3341174 100644 --- a/android-console.c +++ b/android-console.c @@ -30,6 +30,19 @@ typedef struct { GList *redir_list; +void android_monitor_print_error(Monitor *mon, const char *fmt, ...) +{ + /* Print an error (typically a syntax error from the parser), with + * the required "KO: " prefix. + */ + va_list ap; + + monitor_printf(mon, "KO: "); + va_start(ap, fmt); + monitor_vprintf(mon, fmt, ap); + va_end(ap); +} + void android_console_kill(Monitor *mon, const QDict *qdict) { monitor_printf(mon, "OK: killing emulator, bye bye\n"); diff --git a/android-console.h b/android-console.h index 2ad08793c5..2786b64e03 100644 --- a/android-console.h +++ b/android-console.h @@ -28,4 +28,6 @@ void android_console_redir_list(Monitor *mon, const QDict *qdict); void android_console_redir_add(Monitor *mon, const QDict *qdict); void android_console_redir_del(Monitor *mon, const QDict *qdict); +void android_monitor_print_error(Monitor *mon, const char *fmt, ...); + #endif @@ -186,6 +186,8 @@ typedef struct MonitorEventState { QObject *data; /* Event pending delayed dispatch */ } MonitorEventState; +typedef void MonitorErrorPrintFn(struct Monitor *mon, const char *fmt, ...); + struct Monitor { CharDriverState *chr; int mux_out; @@ -204,6 +206,7 @@ struct Monitor { QError *error; const char *prompt; const char *banner; + MonitorErrorPrintFn *print_error; QLIST_HEAD(,mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; }; @@ -3797,15 +3800,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, if (ret < 0) { switch(c) { case 'F': - monitor_printf(mon, "%s: filename expected\n", - cmdname); + mon->print_error(mon, "%s: filename expected\n", + cmdname); break; case 'B': - monitor_printf(mon, "%s: block device name expected\n", - cmdname); + mon->print_error(mon, + "%s: block device name expected\n", + cmdname); break; default: - monitor_printf(mon, "%s: string expected\n", cmdname); + mon->print_error(mon, "%s: string expected\n", cmdname); break; } goto fail; @@ -3890,8 +3894,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } next: if (*p != '\0' && !qemu_isspace(*p)) { - monitor_printf(mon, "invalid char in format: '%c'\n", - *p); + mon->print_error(mon, "invalid char in format: '%c'\n", + *p); goto fail; } if (format < 0) @@ -3947,12 +3951,12 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, goto fail; /* Check if 'i' is greater than 32-bit */ if ((c == 'i') && ((val >> 32) & 0xffffffff)) { - monitor_printf(mon, "\'%s\' has failed: ", cmdname); - monitor_printf(mon, "integer is for 32-bit values\n"); + mon->print_error(mon, "\'%s\' has failed: ", cmdname); + mon->print_error(mon, "integer is for 32-bit values\n"); goto fail; } else if (c == 'M') { if (val < 0) { - monitor_printf(mon, "enter a positive value\n"); + mon->print_error(mon, "enter a positive value\n"); goto fail; } val <<= 20; @@ -3976,7 +3980,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } val = strtosz(p, &end); if (val < 0) { - monitor_printf(mon, "invalid size\n"); + mon->print_error(mon, "invalid size\n"); goto fail; } qdict_put(qdict, key, qint_from_int(val)); @@ -4009,7 +4013,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } } if (*p && !qemu_isspace(*p)) { - monitor_printf(mon, "Unknown unit suffix\n"); + mon->print_error(mon, "Unknown unit suffix\n"); goto fail; } qdict_put(qdict, key, qfloat_from_double(val)); @@ -4032,7 +4036,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) { val = 0; } else { - monitor_printf(mon, "Expected 'on' or 'off'\n"); + mon->print_error(mon, "Expected 'on' or 'off'\n"); goto fail; } qdict_put(qdict, key, qbool_from_int(val)); @@ -4053,9 +4057,9 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, p++; if(c != *p) { if(!is_valid_option(p, typestr)) { - - monitor_printf(mon, "%s: unsupported option -%c\n", - cmdname, *p); + mon->print_error(mon, + "%s: unsupported option -%c\n", + cmdname, *p); goto fail; } else { skip_key = 1; @@ -4088,8 +4092,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } len = strlen(p); if (len <= 0) { - monitor_printf(mon, "%s: string expected\n", - cmdname); + mon->print_error(mon, "%s: string expected\n", + cmdname); break; } qdict_put(qdict, key, qstring_from_str(p)); @@ -4098,7 +4102,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, break; default: bad_type: - monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); + mon->print_error(mon, "%s: unknown type '%c'\n", cmdname, c); goto fail; } g_free(key); @@ -4108,8 +4112,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, while (qemu_isspace(*p)) p++; if (*p != '\0') { - monitor_printf(mon, "%s: extraneous characters at the end of line\n", - cmdname); + mon->print_error(mon, "%s: extraneous characters at the end of line\n", + cmdname); goto fail; } @@ -5201,11 +5205,13 @@ void monitor_init(CharDriverState *chr, int flags) mon->prompt = "(qemu) "; mon->banner = "QEMU " QEMU_VERSION " monitor - type 'help' for more information"; + mon->print_error = monitor_printf; if (flags & MONITOR_ANDROID_CONSOLE) { mon->cmd_table = android_cmds; mon->prompt = ""; mon->banner = "Android Console: type 'help' for a list of commands"; + mon->print_error = android_monitor_print_error; } mon->chr = chr; |