From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGQ2k-0003cn-IA for qemu-devel@nongnu.org; Mon, 02 Sep 2013 05:03:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VGQ2b-0001N3-FO for qemu-devel@nongnu.org; Mon, 02 Sep 2013 05:03:30 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:57904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGQ2a-0001J9-R9 for qemu-devel@nongnu.org; Mon, 02 Sep 2013 05:03:21 -0400 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Sep 2013 18:54:37 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 9B2CD3578050 for ; Mon, 2 Sep 2013 19:03:15 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r828l3bO6816050 for ; Mon, 2 Sep 2013 18:47:03 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r8293FHg010477 for ; Mon, 2 Sep 2013 19:03:15 +1000 From: Lei Li Date: Mon, 2 Sep 2013 17:01:46 +0800 Message-Id: <1378112508-8970-3-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1378112508-8970-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1378112508-8970-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/4] hmp: factor out ringbuf_print_help() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Lei Li , anthony@codemonkey.ws, lcapitulino@redhat.com 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 --- 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