- Removed the BuildString() override that took a char** argv, because it was used nowhere.

- Fixed: BuildString() failed to properly generate command lines for arguments with embedded "
  characters.

SVN r4025 (trunk)
This commit is contained in:
Randy Heit 2013-01-11 03:21:46 +00:00
parent 3111b6e7b0
commit 6a3b07c441
2 changed files with 18 additions and 29 deletions

View file

@ -1019,32 +1019,7 @@ FConsoleAlias::~FConsoleAlias ()
m_Command[1] = m_Command[0] = FString(); m_Command[1] = m_Command[0] = FString();
} }
FString BuildString (int argc, char **argv) // Given an argument vector, reconstitute the command line it could have been produced from.
{
if (argc == 1)
{
return *argv;
}
else
{
FString buf;
int arg;
for (arg = 0; arg < argc; arg++)
{
if (strchr (argv[arg], ' '))
{
buf.AppendFormat ("\"%s\" ", argv[arg]);
}
else
{
buf.AppendFormat ("%s ", argv[arg]);
}
}
return buf;
}
}
FString BuildString (int argc, FString *argv) FString BuildString (int argc, FString *argv)
{ {
if (argc == 1) if (argc == 1)
@ -1058,8 +1033,23 @@ FString BuildString (int argc, FString *argv)
for (arg = 0; arg < argc; arg++) for (arg = 0; arg < argc; arg++)
{ {
if (strchr (argv[arg], ' ')) if (strchr(argv[arg], '"'))
{ { // If it contains one or more quotes, we need to escape them.
buf << '"';
long substr_start = 0, quotepos;
while ((quotepos = argv[arg].IndexOf('"', substr_start)) >= 0)
{
if (substr_start < quotepos)
{
buf << argv[arg].Mid(substr_start, quotepos - substr_start);
}
buf << "\\\"";
substr_start = quotepos + 1;
}
buf << argv[arg].Mid(substr_start) << "\" ";
}
else if (strchr(argv[arg], ' '))
{ // If it contains a space, it needs to be quoted.
buf << '"' << argv[arg] << "\" "; buf << '"' << argv[arg] << "\" ";
} }
else else

View file

@ -61,7 +61,6 @@ void C_SetAlias (const char *name, const char *cmd);
void C_ClearAliases (); void C_ClearAliases ();
// build a single string out of multiple strings // build a single string out of multiple strings
FString BuildString (int argc, char **argv);
FString BuildString (int argc, FString *argv); FString BuildString (int argc, FString *argv);
// Class that can parse command lines // Class that can parse command lines