From patchwork Mon Sep 2 09:01:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 271832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A733F2C00A4 for ; Mon, 2 Sep 2013 19:05:27 +1000 (EST) Received: from localhost ([::1]:38090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGQ4b-00065I-Ns for incoming@patchwork.ozlabs.org; Mon, 02 Sep 2013 05:05:25 -0400 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 d23dlp03.au.ibm.com (202.81.31.214) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 2 Sep 2013 18:54:35 +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 Received: from localhost.cn.ibm.com ([9.115.122.43]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r82939Ev010338; Mon, 2 Sep 2013 19:03:14 +1000 From: Lei Li To: qemu-devel@nongnu.org Date: Mon, 2 Sep 2013 17:01:46 +0800 Message-Id: <1378112508-8970-3-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 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> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13090208-7014-0000-0000-0000038CA097 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.148 Cc: Lei Li , anthony@codemonkey.ws, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 2/4] hmp: factor out ringbuf_print_help() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); }