From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB1nQ-0004zS-35 for qemu-devel@nongnu.org; Fri, 03 Jul 2015 10:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZB1nP-0002VX-4i for qemu-devel@nongnu.org; Fri, 03 Jul 2015 10:18:28 -0400 From: Markus Armbruster References: <87616175u3.fsf@blackfin.pond.sub.org> <5596927F.5000407@gmail.com> Date: Fri, 03 Jul 2015 16:18:18 +0200 In-Reply-To: <5596927F.5000407@gmail.com> (=?utf-8?B?IkvFkXbDoWfDsyBab2x0?= =?utf-8?B?w6FuIidz?= message of "Fri, 3 Jul 2015 15:47:43 +0200") Message-ID: <87y4ix1g0l.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] opts: produce valid command line in qemu_opts_print List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?B?S8WRdsOhZ8OzIFpvbHTDoW4=?= Cc: qemu-trivial@nongnu.org, Kevin Wolf , qemu-devel@nongnu.org, "open list:Block layer core" "K=C5=91v=C3=A1g=C3=B3 Zolt=C3=A1n" writes: > 2015-07-03 15:01 keltez=C3=A9ssel, Markus Armbruster =C3=ADrta: >> "K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n" writes: >> >>> This will let us print options in a format that the user would actually >>> write it on the command line (foo=3Dbar,baz=3Dasd,etc=3Ddef), without >>> prepending a spurious comma at the beginning of the list, or quoting >>> values unnecessarily. This patch provides the following changes: >>> * write and id=3D, if the option has an id >>> * do not print separator before the first element >>> * do not quote string arguments >>> * properly escape commas (,) for QEMU >>> >>> Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n >>> --- >>> >>> Changes from patch submitted as part of `qapi flattening': >>> * no longer tries to do proper escaping for the shell >>> >>> block.c | 2 +- >>> util/qemu-option.c | 30 +++++++++++++++++++++++++++--- >>> 2 files changed, 28 insertions(+), 4 deletions(-) >>> >>> diff --git a/block.c b/block.c >>> index 7e130cc..78a5304 100644 >>> --- a/block.c >>> +++ b/block.c >>> @@ -3813,7 +3813,7 @@ void bdrv_img_create(const char *filename, const = char *fmt, >>> } >>> >>> if (!quiet) { >>> - printf("Formatting '%s', fmt=3D%s", filename, fmt); >>> + printf("Formatting '%s', fmt=3D%s ", filename, fmt); >>> qemu_opts_print(opts, " "); >>> puts(""); >>> } >>> diff --git a/util/qemu-option.c b/util/qemu-option.c >>> index efe9d27..55ef172 100644 >>> --- a/util/qemu-option.c >>> +++ b/util/qemu-option.c >>> @@ -730,14 +730,36 @@ void qemu_opts_del(QemuOpts *opts) >>> g_free(opts); >>> } >>> >>> -void qemu_opts_print(QemuOpts *opts, const char *sep) >>> +/* print value, escaping any commas in value */ >>> +static void escaped_print(const char *value) >> >> Have you searched the tree for existing code doing this? > > I didn't found any function like that. Okay. >>> +{ >>> + const char *ptr; >>> + >>> + for (ptr =3D value; *ptr; ++ptr) { >>> + if (*ptr =3D=3D ',') { >>> + printf(",,"); >>> + } else { >>> + putchar(*ptr); >>> + } >>> + } >> >> Slightly simpler: >> >> if (*ptr =3D=3D ',') { >> putchar(','); >> } >> putchar(*ptr); >> >> Matter of taste. > > I also like it better that way. Should I send a v2 patch? If it's not too much trouble... Feel free to keep my R-by then.