[PATCH v3 47/49] monitor: move monitor_hmp_print*() functions to hmp.c
Marc-André Lureau <[email protected]>
| Newsgroups | org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
Those functions are only used when CONFIG_HMP, compile them out, and add conditions for the calling code. Signed-off-by: Marc-André Lureau <[email protected]> # The commit message #2 will be skipped: # fixup! monitor: move monitor_hmp_print*() functions to hmp.c --- monitor/hmp.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ monitor/monitor.c | 49 ------------------------------------------------- util/error-report.c | 3 ++- util/qemu-print.c | 4 ++++ 4 files changed, 55 insertions(+), 50 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 10bcbe2a33cb..e3fc05f521a8 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1754,3 +1754,52 @@ static int get_monitor_def(MonitorHMP *hmp, int64_t *pval, const char *name) } return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval); } + +int monitor_hmp_vprintf(MonitorHMP *hmp, const char *fmt, va_list ap) +{ + g_autofree char *buf = g_strdup_vprintf(fmt, ap); + + if (!hmp) { + return -1; + } + + return monitor_puts(MONITOR(hmp), buf); +} + +int monitor_hmp_printf(MonitorHMP *hmp, const char *fmt, ...) +{ + int ret; + + va_list ap; + va_start(ap, fmt); + ret = monitor_hmp_vprintf(hmp, fmt, ap); + va_end(ap); + return ret; +} + +void monitor_hmp_printc(MonitorHMP *hmp, int c) +{ + monitor_hmp_printf(hmp, "'"); + switch (c) { + case '\'': + monitor_hmp_printf(hmp, "\\'"); + break; + case '\\': + monitor_hmp_printf(hmp, "\\\\"); + break; + case '\n': + monitor_hmp_printf(hmp, "\\n"); + break; + case '\r': + monitor_hmp_printf(hmp, "\\r"); + break; + default: + if (c >= 32 && c <= 126) { + monitor_hmp_printf(hmp, "%c", c); + } else { + monitor_hmp_printf(hmp, "\\x%02x", c); + } + break; + } + monitor_hmp_printf(hmp, "'"); +} diff --git a/monitor/monitor.c b/monitor/monitor.c index da0c8eda86b0..7979cd1cbcfd 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -272,55 +272,6 @@ int monitor_puts(Monitor *mon, const char *str) return monitor_puts_locked(mon, str); } -int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap) -{ - g_autofree char *buf = g_strdup_vprintf(fmt, ap); - - if (!mon) { - return -1; - } - - return monitor_puts(MONITOR(mon), buf); -} - -int monitor_hmp_printf(MonitorHMP *mon, const char *fmt, ...) -{ - int ret; - - va_list ap; - va_start(ap, fmt); - ret = monitor_hmp_vprintf(mon, fmt, ap); - va_end(ap); - return ret; -} - -void monitor_hmp_printc(MonitorHMP *mon, int c) -{ - monitor_hmp_printf(mon, "'"); - switch(c) { - case '\'': - monitor_hmp_printf(mon, "\\'"); - break; - case '\\': - monitor_hmp_printf(mon, "\\\\"); - break; - case '\n': - monitor_hmp_printf(mon, "\\n"); - break; - case '\r': - monitor_hmp_printf(mon, "\\r"); - break; - default: - if (c >= 32 && c <= 126) { - monitor_hmp_printf(mon, "%c", c); - } else { - monitor_hmp_printf(mon, "\\x%02x", c); - } - break; - } - monitor_hmp_printf(mon, "'"); -} - static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = { /* Limit guest-triggerable events to 1 per second */ [QAPI_EVENT_RTC_CHANGE] = { 1000 * SCALE_MS }, diff --git a/util/error-report.c b/util/error-report.c index c20e157780fa..68471d8055a1 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -35,12 +35,13 @@ const char *error_guest_name; static int G_GNUC_PRINTF(1, 0) error_vprintf_mon(const char *fmt, va_list ap) { +#ifdef CONFIG_HMP MonitorHMP *hmp = monitor_cur_hmp(); if (hmp) { return monitor_hmp_vprintf(hmp, fmt, ap); } - +#endif return vfprintf(stderr, fmt, ap); } diff --git a/util/qemu-print.c b/util/qemu-print.c index aabe670fda01..f4a7ce4c0682 100644 --- a/util/qemu-print.c +++ b/util/qemu-print.c @@ -21,10 +21,12 @@ */ int qemu_vprintf(const char *fmt, va_list ap) { +#ifdef CONFIG_HMP MonitorHMP *hmp = monitor_cur_hmp(); if (hmp) { return monitor_hmp_vprintf(hmp, fmt, ap); } +#endif return vprintf(fmt, ap); } @@ -52,10 +54,12 @@ int qemu_printf(const char *fmt, ...) */ int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) { +#ifdef CONFIG_HMP if (!stream) { MonitorHMP *hmp = monitor_cur_hmp(); return hmp ? monitor_hmp_vprintf(hmp, fmt, ap) : -1; } +#endif return vfprintf(stream, fmt, ap); } -- 2.55.0.543.g5ebe2ebe4ea8