From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7kF-0001xm-Os for qemu-devel@nongnu.org; Mon, 09 Sep 2013 16:07:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJ7k9-0004Ar-O9 for qemu-devel@nongnu.org; Mon, 09 Sep 2013 16:07:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7k9-00049g-Ej for qemu-devel@nongnu.org; Mon, 09 Sep 2013 16:07:29 -0400 Date: Mon, 9 Sep 2013 15:15:18 -0400 From: Luiz Capitulino Message-ID: <20130909151518.09dca657@redhat.com> In-Reply-To: <1378112508-8970-3-git-send-email-lilei@linux.vnet.ibm.com> References: <1378112508-8970-1-git-send-email-lilei@linux.vnet.ibm.com> <1378112508-8970-3-git-send-email-lilei@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/4] hmp: factor out ringbuf_print_help() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lei Li Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws On Mon, 2 Sep 2013 17:01:46 +0800 Lei Li wrote: > 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) That's a very bad name. You could call it ringbuf_print_contents(), but then I think you should pass a size parameter. Or, you call it ringbuf_print_char() and keep the loop in the caller. > +{ > + 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); > }