extern "C" void CommandLineToArgs(TCHAR szCommandLine[], int *argc, LPTSTR argv[])
{
// Parse command line into individual arguments - arg/argv style.
int i, iArgc = 0;
BOOL fInQuotes, bEndFound = FALSE;
TCHAR *p = szCommandLine;
if(!szCommandLine || !argc || !argv)
return;
for(i = 0; i < *argc && !bEndFound; i++)
{
// Clear our quote flag
fInQuotes = FALSE;
// Move past and zero out any leading whitespace
while( *p && _istspace(*p) )
*(p++) = TEXT('\0');
// If the next character is a quote, move over it and remember that we saw it
if (*p == TEXT('\"'))
{
*(p++) = TEXT('\0');
fInQuotes = TRUE;
}
// Point the current argument to our current location
argv[i] = p;
// If this argument contains some text, then update our argument count
if (*p)
iArgc = i + 1;
// Move over valid text of this argument.
while (*p)
{
if (fInQuotes)
{
// If in quotes, we only break out when we see another quote.
if (*p == TEXT('\"'))
{
*(p++) = TEXT('\0');
break;
}
}
else
{
// If we are not in quotes and we see a quote, replace it with a space
// and set "fInQuotes" to TRUE
if (*p == TEXT('\"'))
{
*(p++) = TEXT(' ');
fInQuotes = TRUE;
} // If we are not in quotes and we see whitespace, then we break out
else if (_istspace(*p))
{
*(p++) = TEXT('\0');
break;
}
}
// Move to the next character
p++;
}
if(!*p)
bEndFound = TRUE;
}
*argc = iArgc;
}