[libvirt] [PATCH 7/8] virsh: support single quote
Some use may type command like this at the virsh shell: virsh # somecmd 'some arg' because some users often use single quote in linux shell. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- diff --git a/tools/virsh.c b/tools/virsh.c index b96071d..a5b438b 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -10213,6 +10213,7 @@ static int vshCommandArgvParse(vshControl *ctl, int nargs, char **argv) static int vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res) { +bool single_quote = false; bool double_quote = false; int sz = 0; char *p = parser-pos, *q; @@ -10232,14 +10233,23 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res) copy: while (*p) { /* end of token is blank space or ';' */ -if (!double_quote (*p == ' ' || *p == '\t' || *p == ';')) +if (!double_quote !single_quote + (*p == ' ' || *p == '\t' || *p == ';')) break; -if (*p == '\\') { /* escape */ +if (!double_quote *p == '\'') { /* single quote */ +single_quote = !single_quote; +p++; +continue; +} else if (!single_quote *p == '\\') { /* escape */ +/* + * The same as the bash, a \ in is an escaper, + * but a \ in '' is not an escaper. + */ p++; if (*p == '\0') break; -} else if (*p == '') { /* double quote */ +} else if (!single_quote *p == '') { /* double quote */ double_quote = !double_quote; p++; continue; -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 7/8] virsh: support single quote
On 10/12/2010 01:14 AM, Lai Jiangshan wrote: Some use may type command like this at the virsh shell: virsh # somecmd 'some arg' because some users often use single quote in linux shell. Signed-off-by: Lai Jiangshanla...@cn.fujitsu.com --- diff --git a/tools/virsh.c b/tools/virsh.c index b96071d..a5b438b 100644 Tests would be nice. I'll see about adding some in another patch, probably by adding a 'virsh echo ...' command that echoes its arguments for reuse. +if (!double_quote !single_quote + (*p == ' ' || *p == '\t' || *p == ';')) Convention on this project is to line break after operators rather than before. It's not a hard-fast rule, but as long as I'm on a roll of tweaking every one of your patches... :) [And pardon Thunderbird's stupid bug that mangles the spacing before any word beginning with , , or in the quoted portions of my message.] ACK with this squashed in: diff --git i/tools/virsh.c w/tools/virsh.c index c38f91d..e21bbf2 100644 --- i/tools/virsh.c +++ w/tools/virsh.c @@ -10257,8 +10257,8 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res) while (*p) { /* end of token is blank space or ';' */ -if (!double_quote !single_quote - (*p == ' ' || *p == '\t' || *p == ';')) +if (!double_quote !single_quote +(*p == ' ' || *p == '\t' || *p == ';')) break; if (!double_quote *p == '\'') { /* single quote */ -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list