2005-06-30 23:54:14 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Author: Jorgen Bodde
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
|
2005-08-09 01:14:08 +04:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2005-06-30 23:54:14 +04:00
|
|
|
#include "CommandLineInfo.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// cmCommandLineInfo
|
|
|
|
|
|
|
|
cmCommandLineInfo::cmCommandLineInfo()
|
|
|
|
{
|
2005-08-11 00:18:54 +04:00
|
|
|
m_WhereSource = _("");
|
|
|
|
m_WhereBuild = _("");
|
2005-08-09 23:42:49 +04:00
|
|
|
m_AdvancedValues = false;
|
|
|
|
m_GeneratorChoiceString.Empty();
|
|
|
|
m_LastUnknownParameter = "";
|
|
|
|
m_ValidArguments = "";
|
|
|
|
m_ExitAfterLoad = false;
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
cmCommandLineInfo::~cmCommandLineInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
2005-08-09 23:42:49 +04:00
|
|
|
bool cmCommandLineInfo::ParseCommandLine(int argc, char* argv[])
|
2005-06-30 23:54:14 +04:00
|
|
|
{
|
2005-08-09 23:42:49 +04:00
|
|
|
bool result = true;
|
|
|
|
wxString cachePath;
|
|
|
|
|
2005-08-11 00:18:54 +04:00
|
|
|
// parse all commands
|
|
|
|
int cc = 1;
|
|
|
|
if(argc < cc)
|
|
|
|
return true; // no command line options
|
|
|
|
|
|
|
|
while(cc < argc)
|
2005-06-30 23:54:14 +04:00
|
|
|
{
|
2005-08-11 00:18:54 +04:00
|
|
|
wxString arg = argv[cc];
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2005-08-09 23:42:49 +04:00
|
|
|
else
|
|
|
|
{
|
2005-08-11 00:18:54 +04:00
|
|
|
// gather all what is left
|
|
|
|
for(int leftcc = cc; leftcc < argc; leftcc++)
|
|
|
|
{
|
|
|
|
if(cc != leftcc)
|
|
|
|
m_WhereBuild << _(" ");
|
|
|
|
m_WhereBuild << argv[leftcc];
|
|
|
|
}
|
|
|
|
break;
|
2005-08-09 23:42:49 +04:00
|
|
|
}
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
2005-08-11 00:18:54 +04:00
|
|
|
|
2005-08-09 23:42:49 +04:00
|
|
|
m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]).c_str();
|
|
|
|
|
2005-08-11 00:18:54 +04:00
|
|
|
return true;
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
2005-08-09 23:42:49 +04:00
|
|
|
int cmCommandLineInfo::GetBoolValue(const wxString& v) {
|
|
|
|
|
|
|
|
wxString value = v.Lower();
|
|
|
|
|
|
|
|
if (!value.Cmp("1") ||
|
|
|
|
!value.Cmp("on") ||
|
|
|
|
!value.Cmp("true") ||
|
|
|
|
!value.Cmp("yes"))
|
2005-06-30 23:54:14 +04:00
|
|
|
{
|
2005-08-09 23:42:49 +04:00
|
|
|
// true
|
|
|
|
return 1;
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
2005-08-09 23:42:49 +04:00
|
|
|
else if (!value.Cmp("0") ||
|
|
|
|
!value.Cmp("off") ||
|
|
|
|
!value.Cmp("false") ||
|
|
|
|
!value.Cmp("no"))
|
2005-06-30 23:54:14 +04:00
|
|
|
{
|
2005-08-09 23:42:49 +04:00
|
|
|
// false
|
|
|
|
return -1;
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
2005-08-09 23:42:49 +04:00
|
|
|
|
|
|
|
// not recognised
|
|
|
|
return 0;
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Parse param
|
|
|
|
|
2005-08-11 00:18:54 +04:00
|
|
|
size_t cmCommandLineInfo::ParseSwitch(char **argv, int arg_index, int argc)
|
|
|
|
{
|
|
|
|
wxString param = argv[arg_index];
|
2005-08-09 01:14:08 +04:00
|
|
|
|
2005-08-11 00:18:54 +04:00
|
|
|
// we need this for a switch, at least 2
|
|
|
|
if(param.Len() > 1)
|
2005-08-09 23:42:49 +04:00
|
|
|
{
|
2005-08-11 00:18:54 +04:00
|
|
|
// determine switch type
|
|
|
|
switch (param.GetChar(1))
|
2005-08-09 01:14:08 +04:00
|
|
|
{
|
2005-08-11 00:18:54 +04:00
|
|
|
case 'G':
|
|
|
|
// when it's G<.....> we split else we take the
|
|
|
|
// other argc
|
|
|
|
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':
|
|
|
|
m_ExitAfterLoad = true;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// unknown param
|
|
|
|
default:
|
|
|
|
break;
|
2005-08-09 01:14:08 +04:00
|
|
|
}
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
2005-08-09 23:42:49 +04:00
|
|
|
|
2005-08-11 00:18:54 +04:00
|
|
|
// error, unrecognised or too small arg
|
|
|
|
return 0;
|
2005-08-09 01:14:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// When the string param given has string quotes around it
|
|
|
|
// we remove them and we pass back the string. If not, we
|
|
|
|
// simply pass back the string as-is
|
2005-08-09 23:42:49 +04:00
|
|
|
wxString cmCommandLineInfo::GetStringParam(const wxString &str)
|
2005-08-09 01:14:08 +04:00
|
|
|
{
|
2005-08-09 23:42:49 +04:00
|
|
|
wxString mystr = str.Strip(wxString::both);
|
2005-08-09 01:14:08 +04:00
|
|
|
|
|
|
|
// if we have only one (or no chars return the current string)
|
2005-08-09 23:42:49 +04:00
|
|
|
if(mystr.Len() < 2)
|
2005-08-09 01:14:08 +04:00
|
|
|
return str;
|
|
|
|
|
|
|
|
// if we have quotes
|
2005-08-09 23:42:49 +04:00
|
|
|
if(mystr.GetChar(0) == '\"' && mystr.Last() == '\"')
|
2005-06-30 23:54:14 +04:00
|
|
|
{
|
2005-08-09 01:14:08 +04:00
|
|
|
// when we only have 2 in size, return empty string
|
2005-08-09 23:42:49 +04:00
|
|
|
if(mystr.Len() == 2)
|
2005-08-09 01:14:08 +04:00
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
// now remove the outer and inner, and return
|
2005-08-09 23:42:49 +04:00
|
|
|
return mystr.Mid(1, mystr.Len()-1);
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|
2005-08-09 01:14:08 +04:00
|
|
|
|
|
|
|
return str;
|
2005-06-30 23:54:14 +04:00
|
|
|
}
|