1 /*=========================================================================
3 Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
4 Module: $RCSfile: CommandLineInfo.cpp,v $
6 Date: $Date: 2005-08-10 20:18:54 $
7 Version: $Revision: 1.4 $
11 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
12 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
14 This software is distributed WITHOUT ANY WARRANTY; without even
15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 PURPOSE. See the above copyright notices for more information.
18 =========================================================================*/
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
31 #include "CommandLineInfo.h"
33 #include "cmSystemTools.h"
35 ///////////////////////////////////////////////////////////////
38 cmCommandLineInfo::cmCommandLineInfo()
40 m_WhereSource
= _("");
42 m_AdvancedValues
= false;
43 m_GeneratorChoiceString
.Empty();
44 m_LastUnknownParameter
= "";
45 m_ValidArguments
= "";
46 m_ExitAfterLoad
= false;
49 ///////////////////////////////////////////////////////////////
50 cmCommandLineInfo::~cmCommandLineInfo()
54 ///////////////////////////////////////////////////////////////
55 bool cmCommandLineInfo::ParseCommandLine(int argc
, char* argv
[])
63 return true; // no command line options
67 wxString arg
= argv
[cc
];
69 // if we have a switch
70 if(arg
.Len() > 1 && arg
.GetChar(0) == '-')
72 int next_argc
= ParseSwitch(argv
, cc
, argc
);
76 return false; // sorry error while parsing
80 // gather all what is left
81 for(int leftcc
= cc
; leftcc
< argc
; leftcc
++)
84 m_WhereBuild
<< _(" ");
85 m_WhereBuild
<< argv
[leftcc
];
91 m_ExecutablePath
= cmSystemTools::GetFilenamePath(argv
[0]).c_str();
96 ///////////////////////////////////////////////////////////////
97 int cmCommandLineInfo::GetBoolValue(const wxString
& v
) {
99 wxString value
= v
.Lower();
101 if (!value
.Cmp("1") ||
103 !value
.Cmp("true") ||
109 else if (!value
.Cmp("0") ||
111 !value
.Cmp("false") ||
122 ///////////////////////////////////////////////////////////////
125 size_t cmCommandLineInfo::ParseSwitch(char **argv
, int arg_index
, int argc
)
127 wxString param
= argv
[arg_index
];
129 // we need this for a switch, at least 2
132 // determine switch type
133 switch (param
.GetChar(1))
136 // when it's G<.....> we split else we take the
140 m_GeneratorChoiceString
= GetStringParam(param
.Mid(2));
141 return 1; // one arg is passed
145 if((arg_index
+1) < argc
)
147 m_GeneratorChoiceString
= GetStringParam(wxString(argv
[arg_index
+1]));
148 return 2; // two args are passed
155 m_ExitAfterLoad
= true;
164 // error, unrecognised or too small arg
168 // When the string param given has string quotes around it
169 // we remove them and we pass back the string. If not, we
170 // simply pass back the string as-is
171 wxString
cmCommandLineInfo::GetStringParam(const wxString
&str
)
173 wxString mystr
= str
.Strip(wxString::both
);
175 // if we have only one (or no chars return the current string)
180 if(mystr
.GetChar(0) == '\"' && mystr
.Last() == '\"')
182 // when we only have 2 in size, return empty string
184 return wxEmptyString
;
186 // now remove the outer and inner, and return
187 return mystr
.Mid(1, mystr
.Len()-1);