STYLE: Fix line-too-long
[cmake.git] / Source / WXDialog / CommandLineInfo.cpp
blob261c3d939bf4f1cb91e8cbff2fa4ed6a73512fa9
1 /*=========================================================================
3 Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
4 Module: $RCSfile: CommandLineInfo.cpp,v $
5 Language: C++
6 Date: $Date: 2005-08-10 20:18:54 $
7 Version: $Revision: 1.4 $
9 Author: Jorgen Bodde
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"
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
27 #ifndef WX_PRECOMP
28 #include "wx/wx.h"
29 #endif
31 #include "CommandLineInfo.h"
33 #include "cmSystemTools.h"
35 ///////////////////////////////////////////////////////////////
36 // cmCommandLineInfo
38 cmCommandLineInfo::cmCommandLineInfo()
40 m_WhereSource = _("");
41 m_WhereBuild = _("");
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[])
57 bool result = true;
58 wxString cachePath;
60 // parse all commands
61 int cc = 1;
62 if(argc < cc)
63 return true; // no command line options
65 while(cc < argc)
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);
73 if(next_argc > 0)
74 cc += next_argc;
75 else
76 return false; // sorry error while parsing
78 else
80 // gather all what is left
81 for(int leftcc = cc; leftcc < argc; leftcc++)
83 if(cc != leftcc)
84 m_WhereBuild << _(" ");
85 m_WhereBuild << argv[leftcc];
87 break;
91 m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]).c_str();
93 return true;
96 ///////////////////////////////////////////////////////////////
97 int cmCommandLineInfo::GetBoolValue(const wxString& v) {
99 wxString value = v.Lower();
101 if (!value.Cmp("1") ||
102 !value.Cmp("on") ||
103 !value.Cmp("true") ||
104 !value.Cmp("yes"))
106 // true
107 return 1;
109 else if (!value.Cmp("0") ||
110 !value.Cmp("off") ||
111 !value.Cmp("false") ||
112 !value.Cmp("no"))
114 // false
115 return -1;
118 // not recognised
119 return 0;
122 ///////////////////////////////////////////////////////////////
123 // Parse param
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
130 if(param.Len() > 1)
132 // determine switch type
133 switch (param.GetChar(1))
135 case 'G':
136 // when it's G<.....> we split else we take the
137 // other argc
138 if(param.Len() > 2)
140 m_GeneratorChoiceString = GetStringParam(param.Mid(2));
141 return 1; // one arg is passed
143 else
145 if((arg_index+1) < argc)
147 m_GeneratorChoiceString = GetStringParam(wxString(argv[arg_index+1]));
148 return 2; // two args are passed
151 // no luck
152 return 0;
154 case 'Q':
155 m_ExitAfterLoad = true;
156 return 1;
158 // unknown param
159 default:
160 break;
164 // error, unrecognised or too small arg
165 return 0;
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)
176 if(mystr.Len() < 2)
177 return str;
179 // if we have quotes
180 if(mystr.GetChar(0) == '\"' && mystr.Last() == '\"')
182 // when we only have 2 in size, return empty string
183 if(mystr.Len() == 2)
184 return wxEmptyString;
186 // now remove the outer and inner, and return
187 return mystr.Mid(1, mystr.Len()-1);
190 return str;