X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/97d590469d4aaa67459aa4f041ea9bfa409dbecb..abfcca57dd0d805ceec9e19c4be207614d79252a:/src/common/cmdline.cpp diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index a8764a296f..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; @@ -98,7 +103,7 @@ struct wxCmdLineOption void SetDateVal(const wxDateTime val) { Check(wxCMD_LINE_VAL_DATE); m_dateVal = val; m_hasVal = TRUE; } - void SetHasValue() { m_hasVal = TRUE; } + void SetHasValue(bool hasValue = TRUE) { m_hasVal = hasValue; } bool HasValue() const { return m_hasVal; } public: @@ -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]; @@ -475,6 +495,17 @@ wxString wxCmdLineParser::GetParam(size_t n) const return m_data->m_parameters[n]; } +// Resets switches and options +void wxCmdLineParser::Reset() +{ + for ( size_t i = 0; i < m_data->m_options.Count(); i++ ) + { + wxCmdLineOption& opt = m_data->m_options[i]; + opt.SetHasValue(FALSE); + } +} + + // ---------------------------------------------------------------------------- // the real work is done here // ---------------------------------------------------------------------------- @@ -490,6 +521,8 @@ int wxCmdLineParser::Parse() size_t countParam = m_data->m_paramDesc.GetCount(); + Reset(); + // parse everything wxString arg; size_t count = m_data->m_arguments.GetCount(); @@ -950,3 +983,5 @@ static wxString GetTypeName(wxCmdLineParamType type) return s; } + +#endif // wxUSE_CMDLINE_PARSER