Important Update:
- Remove unused: FunctionCore-ChannelBuffer - DataTreeCore: - Bug fix: Set Len=0 on element Clear() - SelectableBare/Core: - Move move BuildArgs() to SelectableBare - Make OutputHandle() to virtual method - UtilCore: - Bug fix: Handle NoCrLF correctly in BytesToSafeStr()
This commit is contained in:
@@ -873,82 +873,3 @@ bool CSelectableBare::Process()
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CSelectableBare::BuildArgs( const char * ExecPath, int &Count, char * Args[] )
|
||||
{
|
||||
bool ParamStarted = false;
|
||||
bool OpenQuotes = false;
|
||||
char * MatchPos = NULL;
|
||||
char * StartPos = NULL;
|
||||
int Len;
|
||||
|
||||
// Validate
|
||||
if (!ExecPath || !*ExecPath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Split params
|
||||
MatchPos = (char*)ExecPath;
|
||||
for (;;)
|
||||
{
|
||||
// Look for whitespace
|
||||
if (!ParamStarted)
|
||||
{
|
||||
// Quotes starts quoted parameter
|
||||
if (*MatchPos == '"') {
|
||||
ParamStarted = true;
|
||||
OpenQuotes = true;
|
||||
StartPos = MatchPos+1; // Skip starting quote
|
||||
}
|
||||
// Non-whitespace starts normal parameter
|
||||
else if ((*MatchPos != ' ') && (*MatchPos != 0)) {
|
||||
ParamStarted = true;
|
||||
StartPos = MatchPos;
|
||||
}
|
||||
}
|
||||
else if (OpenQuotes)
|
||||
{
|
||||
// Another quote ends parameter
|
||||
if (*MatchPos == '"') {
|
||||
Len = MatchPos-StartPos-1; // Skip end quote
|
||||
Args[Count] = (char*)malloc( Len+1 );
|
||||
strncpy( Args[Count], StartPos, Len );
|
||||
Args[Count][Len] = 0;
|
||||
Count++;
|
||||
ParamStarted = false;
|
||||
OpenQuotes = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Whitespace ends parameter
|
||||
if ((*MatchPos == ' ') || (*MatchPos == 0)) {
|
||||
Len = MatchPos-StartPos;
|
||||
Args[Count] = (char*)malloc( Len+1 );
|
||||
strncpy( Args[Count], StartPos, Len );
|
||||
Args[Count][Len] = 0;
|
||||
Count++;
|
||||
ParamStarted = false;
|
||||
}
|
||||
}
|
||||
// Next char, unless NULL
|
||||
if (*MatchPos)
|
||||
MatchPos++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// Check all parameters closed
|
||||
if (ParamStarted) {
|
||||
Count = 0;
|
||||
Args[0] = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set last Param to NULL
|
||||
Args[Count] = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user