X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..f303d69f934a76c56e14713a0748fdd10635e462:/src/common/cmdline.cpp diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index 9ba2c2a154..12012e6807 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -6,7 +6,7 @@ // Created: 05.01.00 // RCS-ID: $Id$ // Copyright: (c) 2000 Vadim Zeitlin -// Licence: wxWidgets licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "cmdline.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -38,13 +34,13 @@ #include "wx/intl.h" #include "wx/app.h" #include "wx/dynarray.h" - #include "wx/filefn.h" #endif //WX_PRECOMP #include #include "wx/datetime.h" #include "wx/msgout.h" +#include "wx/filename.h" // ---------------------------------------------------------------------------- // private functions @@ -86,7 +82,7 @@ struct wxCmdLineOption GetLongOptionName(lng).Len() == lng.Len(), wxT("Long option contains invalid characters") ); - + kind = k; @@ -124,7 +120,7 @@ struct wxCmdLineOption void SetStrVal(const wxString& val) { Check(wxCMD_LINE_VAL_STRING); m_strVal = val; m_hasVal = true; } #if wxUSE_DATETIME - void SetDateVal(const wxDateTime val) + void SetDateVal(const wxDateTime& val) { Check(wxCMD_LINE_VAL_DATE); m_dateVal = val; m_hasVal = true; } #endif // wxUSE_DATETIME @@ -170,8 +166,8 @@ WX_DECLARE_OBJARRAY(wxCmdLineParam, wxArrayParams); #include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxArrayOptions); -WX_DEFINE_OBJARRAY(wxArrayParams); +WX_DEFINE_OBJARRAY(wxArrayOptions) +WX_DEFINE_OBJARRAY(wxArrayParams) // the parser internal state struct wxCmdLineParserData @@ -189,7 +185,10 @@ struct wxCmdLineParserData // methods wxCmdLineParserData(); + void SetArguments(int argc, char **argv); +#if wxUSE_UNICODE void SetArguments(int argc, wxChar **argv); +#endif // wxUSE_UNICODE void SetArguments(const wxString& cmdline); int FindOption(const wxString& name); @@ -214,6 +213,18 @@ wxCmdLineParserData::wxCmdLineParserData() #endif } +void wxCmdLineParserData::SetArguments(int argc, char **argv) +{ + m_arguments.clear(); + + for ( int n = 0; n < argc; n++ ) + { + m_arguments.push_back(wxString::FromAscii(argv[n])); + } +} + +#if wxUSE_UNICODE + void wxCmdLineParserData::SetArguments(int argc, wxChar **argv) { m_arguments.clear(); @@ -224,11 +235,16 @@ void wxCmdLineParserData::SetArguments(int argc, wxChar **argv) } } +#endif // wxUSE_UNICODE + void wxCmdLineParserData::SetArguments(const wxString& cmdLine) { m_arguments.clear(); - m_arguments.push_back(wxTheApp->GetAppName()); + if(wxTheApp && wxTheApp->argc > 0) + m_arguments.push_back(wxTheApp->argv[0]); + else + m_arguments.push_back(wxEmptyString); wxArrayString args = wxCmdLineParser::ConvertStringToArgs(cmdLine); @@ -277,11 +293,20 @@ void wxCmdLineParser::Init() m_data = new wxCmdLineParserData; } +void wxCmdLineParser::SetCmdLine(int argc, char **argv) +{ + m_data->SetArguments(argc, argv); +} + +#if wxUSE_UNICODE + void wxCmdLineParser::SetCmdLine(int argc, wxChar **argv) { m_data->SetArguments(argc, argv); } +#endif // wxUSE_UNICODE + void wxCmdLineParser::SetCmdLine(const wxString& cmdline) { m_data->SetArguments(cmdline); @@ -903,14 +928,15 @@ void wxCmdLineParser::Usage() wxString wxCmdLineParser::GetUsageString() { - wxString appname = wxTheApp->GetAppName(); - if ( !appname ) + wxString appname; + if ( m_data->m_arguments.empty() ) { - wxCHECK_MSG( m_data->m_arguments.size() != 0, wxEmptyString, - _T("no program name") ); - - appname = wxFileNameFromPath(m_data->m_arguments[0]); - wxStripExtension(appname); + if ( wxTheApp ) + appname = wxTheApp->GetAppName(); + } + else // use argv[0] + { + appname = wxFileName(m_data->m_arguments[0]).GetName(); } // we construct the brief cmd line desc on the fly, but not the detailed @@ -1197,4 +1223,3 @@ wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxChar *p) return args; } -