[libvirt] [PATCH] virsh: Convert escape sequence string to uppercase
Eric Blake
eblake at redhat.com
Tue Dec 13 22:16:17 UTC 2011
On 12/13/2011 01:34 AM, Michal Privoznik wrote:
> Macro for translating escape sequence to char expects it to be
> all uppercase. Without this, various lowercase sequences are
> malformed: e.g. ^e gets translated to %.
> ---
> tools/virsh.c | 5 +++++
> 1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/tools/virsh.c b/tools/virsh.c
> index d58b827..ff8b3d2 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -17776,6 +17776,11 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
> if ((len == 2 && *optarg == '^') ||
> (len == 1 && *optarg != '^')) {
> ctl->escapeChar = optarg;
> + while (*optarg) {
> + if (islower(*optarg))
> + *optarg = toupper(*optarg);
> + optarg++;
> + }
This should be using functions gnulib's "c-ctype.h", so that we are
locale-independent. For that matter, c_toupper is nicer than toupper,
in that it is intentionally well-defined on all inputs, while toupper
requires pre-filtering with islower.
Also, why do we need a while loop? We only need to convert one byte,
since we just validated length. And if the user _didn't_ pass the '^a'
syntax, but passed a single character, I don't think we want to convert
optarg[0].
That is, I think this one-liner is a better patch:
diff --git i/tools/virsh.c w/tools/virsh.c
index a95784d..049fd24 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -17781,6 +17781,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
if ((len == 2 && *optarg == '^') ||
(len == 1 && *optarg != '^')) {
+ optarg[1] = c_toupper(optarg[1]);
ctl->escapeChar = optarg;
} else {
vshError(ctl, _("Invalid string '%s' for escape sequence"),
--
Eric Blake eblake at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111213/e0a65310/attachment-0001.sig>
More information about the libvir-list
mailing list