[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/4] hmp: factor out ringbuf_print_help()
From: |
Lei Li |
Subject: |
[Qemu-devel] [PATCH 2/4] hmp: factor out ringbuf_print_help() |
Date: |
Mon, 2 Sep 2013 17:01:46 +0800 |
Factor out ringbuf_print_help(), which will be called in
hmp_read_ringbuf_cb() reading data that can be written with
monitor_printf() to the console from ringbuf backend.
Signed-off-by: Lei Li <address@hidden>
---
hmp.c | 31 +++++++++++++++++++------------
1 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/hmp.c b/hmp.c
index fcca6ae..624ed6f 100644
--- a/hmp.c
+++ b/hmp.c
@@ -752,6 +752,24 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, &errp);
}
+static void ringbuf_print_help(Monitor *mon, const char *data)
+{
+ int i;
+
+ for (i = 0; data[i]; i++) {
+ unsigned char ch = data[i];
+
+ if (ch == '\\') {
+ monitor_printf(mon, "\\\\");
+ } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
+ monitor_printf(mon, "\\u%04X", ch);
+ } else {
+ monitor_printf(mon, "%c", ch);
+ }
+
+ }
+}
+
void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
{
const char *chardev = qdict_get_str(qdict, "device");
@@ -769,7 +787,6 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
const char *chardev = qdict_get_str(qdict, "device");
char *data;
Error *errp = NULL;
- int i;
data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
if (errp) {
@@ -778,18 +795,8 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
return;
}
- for (i = 0; data[i]; i++) {
- unsigned char ch = data[i];
-
- if (ch == '\\') {
- monitor_printf(mon, "\\\\");
- } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
- monitor_printf(mon, "\\u%04X", ch);
- } else {
- monitor_printf(mon, "%c", ch);
- }
+ ringbuf_print_help(mon, data);
- }
monitor_printf(mon, "\n");
g_free(data);
}
--
1.7.7.6