]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/cmdline.cpp
Fix wxSnvprintf (and hence wxString::Format) for Unicode, when using
[wxWidgets.git] / src / common / cmdline.cpp
index 4911befc4e1f210274766e091b3a524a3f3e4126..9697a6d3ac588695a57bd8ddea59bf5b2d8b83af 100644 (file)
@@ -808,9 +808,17 @@ int wxCmdLineParser::Parse(bool showUsage)
                 }
                 else
                 {
-                    optName.Printf(_("%s (or %s)"),
-                                   opt.shortName.c_str(),
-                                   opt.longName.c_str());
+                    if ( AreLongOptionsEnabled() )
+                    {
+                        optName.Printf( _("%s (or %s)"),
+                                        opt.shortName.c_str(),
+                                        opt.longName.c_str() );
+                    }
+                    else
+                    {
+                        optName.Printf( wxT("%s"),
+                                        opt.shortName.c_str() );
+                    }
                 }
 
                 errorMsg << wxString::Format(_("The value for the option '%s' must be specified."),
@@ -842,14 +850,23 @@ int wxCmdLineParser::Parse(bool showUsage)
         }
     }
 
-    if ( !ok && errorMsg.length() != 0 )
+    // 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;
@@ -861,10 +878,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()
@@ -885,7 +907,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');
     }
@@ -1021,9 +1043,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;
@@ -1086,7 +1116,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"