X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33293a32fe18ff90ed0154092554b089ef84c71b..05159a2750ed2cc5945a85bc5fc6849ad1a30e75:/src/common/cmdline.cpp diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index 524ee1f43a..6a21925fe7 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -86,6 +86,7 @@ struct wxCmdLineOption GetLongOptionName(lng).Len() == lng.Len(), wxT("Long option contains invalid characters") ); + kind = k; @@ -561,7 +562,7 @@ int wxCmdLineParser::Parse(bool showUsage) optInd = m_data->FindOptionByLongName(name); if ( optInd == wxNOT_FOUND ) { - errorMsg << wxString::Format(_("Unknown long option '%s'"), name.c_str()) << "\n"; + errorMsg << wxString::Format(_("Unknown long option '%s'"), name.c_str()) << wxT("\n"); } } else @@ -570,7 +571,7 @@ int wxCmdLineParser::Parse(bool showUsage) // Print the argument including leading "--" name.Prepend( wxT("--") ); - errorMsg << wxString::Format(_("Unknown option '%s'"), name.c_str()) << "\n"; + errorMsg << wxString::Format(_("Unknown option '%s'"), name.c_str()) << wxT("\n"); } } @@ -591,7 +592,7 @@ int wxCmdLineParser::Parse(bool showUsage) { // we couldn't find a valid option name in the // beginning of this string - errorMsg << wxString::Format(_("Unknown option '%s'"), name.c_str()) << "\n"; + errorMsg << wxString::Format(_("Unknown option '%s'"), name.c_str()) << wxT("\n"); break; } @@ -663,7 +664,7 @@ int wxCmdLineParser::Parse(bool showUsage) if ( *p++ != _T('=') ) { - errorMsg << wxString::Format(_("Option '%s' requires a value, '=' expected."), name.c_str()) << "\n"; + errorMsg << wxString::Format(_("Option '%s' requires a value, '=' expected."), name.c_str()) << wxT("\n"); ok = FALSE; } @@ -684,7 +685,7 @@ int wxCmdLineParser::Parse(bool showUsage) { // ... but there is none errorMsg << wxString::Format(_("Option '%s' requires a value."), - name.c_str()) << "\n"; + name.c_str()) << wxT("\n"); ok = FALSE; } @@ -701,7 +702,7 @@ int wxCmdLineParser::Parse(bool showUsage) if ( opt.flags & wxCMD_LINE_NEEDS_SEPARATOR ) { errorMsg << wxString::Format(_("Separator expected after the option '%s'."), - name.c_str()) << "\n"; + name.c_str()) << wxT("\n"); ok = FALSE; } @@ -731,7 +732,7 @@ int wxCmdLineParser::Parse(bool showUsage) else { errorMsg << wxString::Format(_("'%s' is not a correct numeric value for option '%s'."), - value.c_str(), name.c_str()) << "\n"; + value.c_str(), name.c_str()) << wxT("\n"); ok = FALSE; } @@ -745,7 +746,7 @@ int wxCmdLineParser::Parse(bool showUsage) if ( !res || *res ) { errorMsg << wxString::Format(_("Option '%s': '%s' cannot be converted to a date."), - name.c_str(), value.c_str()) << "\n"; + name.c_str(), value.c_str()) << wxT("\n"); ok = FALSE; } @@ -785,7 +786,7 @@ int wxCmdLineParser::Parse(bool showUsage) } else { - errorMsg << wxString::Format(_("Unexpected parameter '%s'"), arg.c_str()) << "\n"; + errorMsg << wxString::Format(_("Unexpected parameter '%s'"), arg.c_str()) << wxT("\n"); ok = FALSE; } @@ -822,7 +823,7 @@ int wxCmdLineParser::Parse(bool showUsage) } errorMsg << wxString::Format(_("The value for the option '%s' must be specified."), - optName.c_str()) << "\n"; + optName.c_str()) << wxT("\n"); ok = FALSE; } @@ -843,21 +844,30 @@ int wxCmdLineParser::Parse(bool showUsage) if ( !(param.flags & wxCMD_LINE_PARAM_OPTIONAL) ) { errorMsg << wxString::Format(_("The required parameter '%s' was not specified."), - param.description.c_str()) << "\n"; + param.description.c_str()) << wxT("\n"); ok = FALSE; } } } - if ( !ok && (errorMsg.length() != 0 || helpRequested) ) + // if there was an error during parsing the command line, show this error + // and also the usage message if it had been requested + if ( !ok && (!errorMsg.empty() || (helpRequested && showUsage)) ) { - wxString usage; wxMessageOutput* msgOut = wxMessageOutput::Get(); - wxASSERT(msgOut); - if ( showUsage ) usage = GetUsageString(); if ( msgOut ) + { + wxString usage; + if ( showUsage ) + usage = GetUsageString(); + msgOut->Printf( wxT("%s%s"), usage.c_str(), errorMsg.c_str() ); + } + else + { + wxFAIL_MSG( _T("no wxMessageOutput object?") ); + } } return ok ? 0 : helpRequested ? -1 : 1; @@ -869,10 +879,15 @@ int wxCmdLineParser::Parse(bool showUsage) void wxCmdLineParser::Usage() { - wxString usage = GetUsageString(); wxMessageOutput* msgOut = wxMessageOutput::Get(); if ( msgOut ) - msgOut->Printf( wxT("%s"), usage.c_str() ); + { + msgOut->Printf( wxT("%s"), GetUsageString().c_str() ); + } + else + { + wxFAIL_MSG( _T("no wxMessageOutput object?") ); + } } wxString wxCmdLineParser::GetUsageString() @@ -893,7 +908,7 @@ wxString wxCmdLineParser::GetUsageString() wxString usage; wxArrayString namesOptions, descOptions; - if ( !!m_data->m_logo ) + if ( !m_data->m_logo.empty() ) { usage << m_data->m_logo << _T('\n'); } @@ -1029,9 +1044,17 @@ static wxString GetTypeName(wxCmdLineParamType type) wxFAIL_MSG( _T("unknown option type") ); // still fall through - case wxCMD_LINE_VAL_STRING: s = _("str"); break; - case wxCMD_LINE_VAL_NUMBER: s = _("num"); break; - case wxCMD_LINE_VAL_DATE: s = _("date"); break; + case wxCMD_LINE_VAL_STRING: + s = _("str"); + break; + + case wxCMD_LINE_VAL_NUMBER: + s = _("num"); + break; + + case wxCMD_LINE_VAL_DATE: + s = _("date"); + break; } return s; @@ -1094,7 +1117,7 @@ static wxString GetLongOptionName(const wxChar *p) In particular, to pass a single argument containing a space to the program it should be quoted: - + myprog.exe foo bar -> argc = 3, argv[1] = "foo", argv[2] = "bar" myprog.exe "foo bar" -> argc = 2, argv[1] = "foo bar"