Commit 85e000fa authored by Marian Durkovic's avatar Marian Durkovic

VLM quoting magic for partially quoted strings

parent a658df6d
...@@ -261,26 +261,37 @@ static const char quotes[] = "\"'"; ...@@ -261,26 +261,37 @@ static const char quotes[] = "\"'";
*/ */
static const char *FindCommandEnd (const char *psz_sent) static const char *FindCommandEnd (const char *psz_sent)
{ {
const char quote = strchr (quotes, psz_sent[0]) ? psz_sent[0] : 0; char c, quote = 0;
char c;
if (quote)
psz_sent++; // skip opening quote
while ((c = *psz_sent) != '\0') while ((c = *psz_sent) != '\0')
{ {
if ((quote == '"') && (c == '\\')) if (!quote)
{ {
psz_sent++; // move past backslash if (strchr(quotes,c)) // opening quote
if (*psz_sent == '\0') quote = c;
return NULL; // cannot escape "nothing" else
if (isspace(c)) // non-escaped space
return psz_sent;
else
if( c == '\\' )
{
psz_sent++; // skip escaped character
if (*psz_sent == '\0')
return psz_sent;
}
} }
else else
if (c == quote) // non-escaped matching quote {
return psz_sent + 1; if (c == quote) // non-escaped matching quote
else quote = 0;
if ((!quote) && isspace(c)) // non-escaped blank else
return psz_sent; if ((quote == '"') && (c == '\\'))
{
psz_sent++; // skip escaped character
if (*psz_sent == '\0')
return NULL; // error, closing quote missing
}
}
psz_sent++; psz_sent++;
} }
...@@ -301,36 +312,64 @@ static const char *FindCommandEnd (const char *psz_sent) ...@@ -301,36 +312,64 @@ static const char *FindCommandEnd (const char *psz_sent)
*/ */
static int Unescape (char *out, const char *in) static int Unescape (char *out, const char *in)
{ {
const char quote = strchr (quotes, in[0]) ? in[0] : 0; char c, quote = 0;
if (quote) while ((c = *in++) != '\0')
in++; // skips opening quote
for (;;)
{ {
char c = *in++; if (!quote)
if ((c == '\0') || (c == quote))
break;
if ((quote == '"') && (c == '\\'))
{ {
switch (c = *in++) if (strchr(quotes,c)) // opening quote
{ {
case '"': quote = c;
*out++ = '"'; continue;
continue; }
else
case '\\': if( c == '\\' )
*out++ = '\\'; {
switch (c = *in++)
{
case '"':
case '\'':
case '\\':
*out++ = c;
continue;
case '\0':
*out = '\0';
return 0;
}
if (isspace(c))
{
*out++ = c;
continue; continue;
}
case '\0': // should never happen /* None of the special cases - copy the backslash */
*out = '\0'; *out++ = '\\';
return -1; }
}
else
{
if (c == quote) // non-escaped matching quote
{
quote = 0;
continue;
}
if ((quote == '"') && (c == '\\'))
{
switch (c = *in++)
{
case '"':
case '\\':
*out++ = c;
continue;
case '\0': // should never happen
*out = '\0';
return -1;
}
/* None of the special cases - copy the backslash */
*out++ = '\\';
} }
/* None of the special cases - copy the backslash */
*out++ = '\\';
} }
*out++ = c; *out++ = c;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment