Implemented new parser which can handle:

-G"generator" (legacy format)
-G "generator" (new format)
This commit is contained in:
Jorgen Bodde 2005-08-10 16:18:54 -04:00
parent e59e9d0e59
commit f958cc639c
3 changed files with 73 additions and 41 deletions

View File

@ -37,8 +37,8 @@
cmCommandLineInfo::cmCommandLineInfo() cmCommandLineInfo::cmCommandLineInfo()
{ {
m_WhereSource = ""; m_WhereSource = _("");
m_WhereBuild = ""; m_WhereBuild = _("");
m_AdvancedValues = false; m_AdvancedValues = false;
m_GeneratorChoiceString.Empty(); m_GeneratorChoiceString.Empty();
m_LastUnknownParameter = ""; m_LastUnknownParameter = "";
@ -57,29 +57,40 @@ bool cmCommandLineInfo::ParseCommandLine(int argc, char* argv[])
bool result = true; bool result = true;
wxString cachePath; wxString cachePath;
for ( int cc = 1; cc < argc && result; cc ++ ) // parse all commands
{ int cc = 1;
// skip (empty ???) params if(argc < cc)
if ( strlen(argv[cc]) < 1 ) return true; // no command line options
continue;
// judge argument and parse while(cc < argc)
wxString argument(argv[cc]); {
if((argument.Len() > 1) && argument.GetChar(0) == '-') wxString arg = argv[cc];
result = ParseArgument(argument.Mid(1));
// if we have a switch
if(arg.Len() > 1 && arg.GetChar(0) == '-')
{
int next_argc = ParseSwitch(argv, cc, argc);
if(next_argc > 0)
cc += next_argc;
else
return false; // sorry error while parsing
}
else else
{ {
// ok this is the last of the arguments, the rest of the string(s) // gather all what is left
// we concatenate to the cache path or something else for(int leftcc = cc; leftcc < argc; leftcc++)
if(cc > 1) {
cachePath << " "; if(cc != leftcc)
cachePath << argument; m_WhereBuild << _(" ");
m_WhereBuild << argv[leftcc];
}
break;
} }
} }
m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]).c_str(); m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]).c_str();
return result; return true;
} }
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@ -111,24 +122,38 @@ int cmCommandLineInfo::GetBoolValue(const wxString& v) {
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Parse param // Parse param
bool cmCommandLineInfo::ParseArgument(const wxString& sParam) size_t cmCommandLineInfo::ParseSwitch(char **argv, int arg_index, int argc)
{ {
bool result = false; wxString param = argv[arg_index];
if(sParam.Len() > 1) // we need this for a switch, at least 2
if(param.Len() > 1)
{ {
wxString value = sParam.Mid(1); // determine switch type
switch (sParam[0]) switch (param.GetChar(1))
{ {
case 'G': case 'G':
m_GeneratorChoiceString = GetStringParam(value); // when it's G<.....> we split else we take the
result = true; // other argc
break; if(param.Len() > 2)
{
m_GeneratorChoiceString = GetStringParam(param.Mid(2));
return 1; // one arg is passed
}
else
{
if((arg_index+1) < argc)
{
m_GeneratorChoiceString = GetStringParam(wxString(argv[arg_index+1]));
return 2; // two args are passed
}
}
// no luck
return 0;
case 'Q': case 'Q':
m_ExitAfterLoad = true; m_ExitAfterLoad = true;
result = true; return 1;
break;
// unknown param // unknown param
default: default:
@ -136,7 +161,8 @@ bool cmCommandLineInfo::ParseArgument(const wxString& sParam)
} }
} }
return result; // error, unrecognised or too small arg
return 0;
} }
// When the string param given has string quotes around it // When the string param given has string quotes around it

View File

@ -52,7 +52,7 @@ public:
private: private:
// Parse one argument // Parse one argument
bool ParseArgument(const wxString& sParam); size_t ParseSwitch(char **argv, int arg_index, int argc);
// Return boolean value of the string // Return boolean value of the string
static int GetBoolValue(const wxString&); static int GetBoolValue(const wxString&);

File diff suppressed because one or more lines are too long