X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9f83044fb8785568e186bee64db4f98b7a9ac9c6..f5ba273ecd799f652736ce2bc830283787302a56:/src/common/cmdline.cpp?ds=inline diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index f42ca0f098..40700df5af 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -32,9 +32,13 @@ #include "wx/string.h" #include "wx/log.h" #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/cmdline.h" @@ -75,7 +79,7 @@ struct wxCmdLineOption // types increases, so always use the accessor functions and don't access // the fields directly!) - void Check(wxCmdLineParamType typ) const + void Check(wxCmdLineParamType WXUNUSED_UNLESS_DEBUG(typ)) const { wxASSERT_MSG( type == typ, _T("type mismatch in wxCmdLineOption") ); } @@ -140,8 +144,8 @@ struct wxCmdLineParserData { // options wxString m_switchChars; // characters which may start an option - bool m_enableLongOptions; // TRUE if long options are enabled + wxString m_logo; // some extra text to show in Usage() // cmd line data wxArrayString m_arguments; // == argv, argc == m_arguments.GetCount() @@ -186,7 +190,7 @@ void wxCmdLineParserData::SetArguments(int argc, char **argv) } } -void wxCmdLineParserData::SetArguments(const wxString& cmdline) +void wxCmdLineParserData::SetArguments(const wxString& WXUNUSED(cmdline)) { // either use wxMSW wxApp::ConvertToStandardCommandArgs() or move its logic // here and use this method from it - but don't duplicate the code @@ -262,6 +266,11 @@ void wxCmdLineParser::EnableLongOptions(bool enable) m_data->m_enableLongOptions = enable; } +void wxCmdLineParser::SetLogo(const wxString& logo) +{ + m_data->m_logo = logo; +} + // ---------------------------------------------------------------------------- // command line construction // ---------------------------------------------------------------------------- @@ -273,7 +282,8 @@ void wxCmdLineParser::SetDesc(const wxCmdLineEntryDesc *desc) switch ( desc->kind ) { case wxCMD_LINE_SWITCH: - AddSwitch(desc->shortName, desc->longName, desc->description); + AddSwitch(desc->shortName, desc->longName, desc->description, + desc->flags); break; case wxCMD_LINE_OPTION: @@ -521,8 +531,13 @@ int wxCmdLineParser::Parse() } while ( optInd == wxNOT_FOUND ); - if ( (len > 0) && (len != name.length()) ) + len++; // compensates extra len-- above + if ( (optInd != wxNOT_FOUND) && (len != name.length()) ) { + // first of all, the option name is only part of this + // string + name = name.Left(len); + // our option is only part of this argument, there is // something else in it - it is either the value of this // option or other switches if it is a switch @@ -532,9 +547,10 @@ int wxCmdLineParser::Parse() // pretend that all the rest of the argument is the // next argument, in fact wxString arg2 = arg[0u]; - arg2 += name.Mid(len); + arg2 += arg.Mid(len + 1); // +1 for leading '-' m_data->m_arguments.Insert(arg2, n + 1); + count++; } //else: it's our value, we'll deal with it below } @@ -649,7 +665,7 @@ int wxCmdLineParser::Parse() const wxChar *res = dt.ParseDate(value); if ( !res || *res ) { - wxLogError(_("Options '%s': '%s' cannot " + wxLogError(_("Option '%s': '%s' cannot " "be converted to a date."), name.c_str(), value.c_str()); @@ -764,8 +780,17 @@ int wxCmdLineParser::Parse() void wxCmdLineParser::Usage() { + wxString appname = wxTheApp->GetAppName(); + if ( !appname ) + { + wxCHECK_RET( !m_data->m_arguments.IsEmpty(), _T("no program name") ); + + appname = wxFileNameFromPath(m_data->m_arguments[0]); + wxStripExtension(appname); + } + wxString brief, detailed; - brief.Printf(_("Usage: %s"), wxTheApp->GetAppName().c_str()); + brief.Printf(_("Usage: %s"), appname.c_str()); size_t n, count = m_data->m_options.GetCount(); for ( n = 0; n < count; n++ ) @@ -825,6 +850,11 @@ void wxCmdLineParser::Usage() } } + if ( !!m_data->m_logo ) + { + wxLogMessage(m_data->m_logo); + } + wxLogMessage(brief); wxLogMessage(detailed); }