next_arg. slight oversight, when backslashing a needle we need to left shift the string 1 char.

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@574 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Peter Kallden 2004-01-22 09:03:06 +00:00
parent f1363402cd
commit d1e409f1f6

View File

@ -750,28 +750,45 @@ next_arg(char *src, char needle)
{ {
char *nextval; char *nextval;
char *p; char *p;
char *mvp = 0;
// EOS /* EOS */
if (*src == (char) 0x00) if (*src == (char) 0x00)
return 0; return 0;
p = src; p = src;
// skip escaped needles. /* skip escaped needles */
while( (nextval = strchr(p, needle) ) ) while( (nextval = strchr(p, needle) ) )
{ {
if( *(nextval-1) != '\\' ) mvp = nextval - 1;
break; /* found backslashed needle */
if( *mvp == '\\' && (mvp > src) )
{
/* move string one to the left */
while( *(mvp+1) != (char)0x00 )
{
*mvp = *(mvp+1);
*mvp++;
}
*mvp = (char)0x00;
p = nextval;
}
else
{
p = nextval +1; p = nextval +1;
break;
} }
// more args available }
/* more args available */
if (nextval) if (nextval)
{ {
*nextval = (char) 0x00; *nextval = (char) 0x00;
return ++nextval; return ++nextval;
} }
// no more args after this, jump to EOS /* no more args after this, jump to EOS */
nextval = src + strlen(src); nextval = src + strlen(src);
return nextval; return nextval;
} }