X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/07d09af8cc3321f7ff4743b1a288aa17594a2cfe..da2b4b7a57f816723ed26dbbeca0549b9ce6735a:/src/common/cmdline.cpp diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index 29399558f5..46517df3a2 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -28,6 +28,8 @@ #pragma hdrstop #endif +#if wxUSE_CMDLINE_PARSER + #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/log.h" @@ -62,6 +64,9 @@ struct wxCmdLineOption wxCmdLineParamType typ, int fl) { + wxASSERT_MSG( !shrt.empty() || !lng.empty(), + _T("option should have at least one name") ); + kind = k; shortName = shrt; @@ -155,7 +160,7 @@ struct wxCmdLineParserData // methods wxCmdLineParserData(); - void SetArguments(int argc, char **argv); + void SetArguments(int argc, wxChar **argv); void SetArguments(const wxString& cmdline); int FindOption(const wxString& name); @@ -180,7 +185,7 @@ wxCmdLineParserData::wxCmdLineParserData() #endif } -void wxCmdLineParserData::SetArguments(int argc, char **argv) +void wxCmdLineParserData::SetArguments(int argc, wxChar **argv) { m_arguments.Empty(); @@ -238,13 +243,16 @@ void wxCmdLineParserData::SetArguments(const wxString& cmdLine) int wxCmdLineParserData::FindOption(const wxString& name) { - size_t count = m_options.GetCount(); - for ( size_t n = 0; n < count; n++ ) + if ( !name.empty() ) { - if ( m_options[n].shortName == name ) + size_t count = m_options.GetCount(); + for ( size_t n = 0; n < count; n++ ) { - // found - return n; + if ( m_options[n].shortName == name ) + { + // found + return n; + } } } @@ -275,7 +283,7 @@ void wxCmdLineParser::Init() m_data = new wxCmdLineParserData; } -void wxCmdLineParser::SetCmdLine(int argc, char **argv) +void wxCmdLineParser::SetCmdLine(int argc, wxChar **argv) { m_data->SetArguments(argc, argv); } @@ -408,6 +416,9 @@ void wxCmdLineParser::AddParam(const wxString& desc, bool wxCmdLineParser::Found(const wxString& name) const { int i = m_data->FindOption(name); + if ( i == wxNOT_FOUND ) + i = m_data->FindOptionByLongName(name); + wxCHECK_MSG( i != wxNOT_FOUND, FALSE, _T("unknown switch") ); wxCmdLineOption& opt = m_data->m_options[(size_t)i]; @@ -420,6 +431,9 @@ bool wxCmdLineParser::Found(const wxString& name) const bool wxCmdLineParser::Found(const wxString& name, wxString *value) const { int i = m_data->FindOption(name); + if ( i == wxNOT_FOUND ) + i = m_data->FindOptionByLongName(name); + wxCHECK_MSG( i != wxNOT_FOUND, FALSE, _T("unknown option") ); wxCmdLineOption& opt = m_data->m_options[(size_t)i]; @@ -436,6 +450,9 @@ bool wxCmdLineParser::Found(const wxString& name, wxString *value) const bool wxCmdLineParser::Found(const wxString& name, long *value) const { int i = m_data->FindOption(name); + if ( i == wxNOT_FOUND ) + i = m_data->FindOptionByLongName(name); + wxCHECK_MSG( i != wxNOT_FOUND, FALSE, _T("unknown option") ); wxCmdLineOption& opt = m_data->m_options[(size_t)i]; @@ -452,6 +469,9 @@ bool wxCmdLineParser::Found(const wxString& name, long *value) const bool wxCmdLineParser::Found(const wxString& name, wxDateTime *value) const { int i = m_data->FindOption(name); + if ( i == wxNOT_FOUND ) + i = m_data->FindOptionByLongName(name); + wxCHECK_MSG( i != wxNOT_FOUND, FALSE, _T("unknown option") ); wxCmdLineOption& opt = m_data->m_options[(size_t)i]; @@ -478,12 +498,11 @@ wxString wxCmdLineParser::GetParam(size_t n) const // Resets switches and options void wxCmdLineParser::Reset() { - unsigned int i; - for (i = 0; i < m_data->m_options.Count(); i++) - { - wxCmdLineOption& opt = m_data->m_options[(size_t)i]; - opt.SetHasValue(FALSE); - } + for ( size_t i = 0; i < m_data->m_options.Count(); i++ ) + { + wxCmdLineOption& opt = m_data->m_options[i]; + opt.SetHasValue(FALSE); + } } @@ -502,7 +521,7 @@ int wxCmdLineParser::Parse() size_t countParam = m_data->m_paramDesc.GetCount(); - Reset(); + Reset(); // parse everything wxString arg; @@ -964,3 +983,5 @@ static wxString GetTypeName(wxCmdLineParamType type) return s; } + +#endif // wxUSE_CMDLINE_PARSER