aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-06-17 12:28:43 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-10-28 18:35:54 +0000
commit3a037cb22025e39279f8c93ccc8b5b20ee14e256 (patch)
treea08577269c6d11870a61d7b671ad4d6dfccf1268
parent6c40c332cd58b45b3fa05782744b55ce2ec02ce8 (diff)
downloadqemu-arm-3a037cb22025e39279f8c93ccc8b5b20ee14e256.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.c13
-rw-r--r--android-console.h2
-rw-r--r--monitor.c48
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
diff --git a/monitor.c b/monitor.c
index 2bba988a1e..4c2cae39ea 100644
--- a/monitor.c
+++ b/monitor.c
@@ -190,6 +190,8 @@ typedef struct MonitorQAPIEventState {
QObject *data; /* Event pending delayed dispatch */
} MonitorQAPIEventState;
+typedef void MonitorErrorPrintFn(struct Monitor *mon, const char *fmt, ...);
+
struct Monitor {
CharDriverState *chr;
int reset_seen;
@@ -213,6 +215,7 @@ struct Monitor {
QError *error;
const char *prompt;
const char *banner;
+ MonitorErrorPrintFn *print_error;
QLIST_HEAD(,mon_fd_t) fds;
QLIST_ENTRY(Monitor) entry;
};
@@ -3768,15 +3771,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;
@@ -3861,8 +3865,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)
@@ -3918,12 +3922,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;
@@ -3947,7 +3951,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));
@@ -3980,7 +3984,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));
@@ -4003,7 +4007,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));
@@ -4024,9 +4028,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;
@@ -4059,8 +4063,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));
@@ -4069,7 +4073,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);
@@ -4079,8 +4083,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;
}
@@ -5359,11 +5363,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;