]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/cmdline.cpp
fill in the fields of wxListItem in a wxListEvent before handling the event (closes...
[wxWidgets.git] / src / common / cmdline.cpp
index 787e4df468e18abe2f17381e7d970344fad84848..c0a7e4131c1fe19717173c52fe38302eb878f167 100644 (file)
@@ -74,7 +74,6 @@ struct wxCmdLineOption
                     int fl)
     {
         // wxCMD_LINE_USAGE_TEXT uses only description, shortName and longName is empty
-    #ifdef __WXDEBUG__
         if ( k != wxCMD_LINE_USAGE_TEXT )
         {
             wxASSERT_MSG
@@ -95,8 +94,6 @@ struct wxCmdLineOption
                 wxT("Long option contains invalid characters")
             );
         }
-    #endif // __WXDEBUG__
-
 
         kind = k;
 
@@ -450,7 +447,7 @@ void wxCmdLineParser::AddParam(const wxString& desc,
 {
     // do some consistency checks: a required parameter can't follow an
     // optional one and nothing should follow a parameter with MULTIPLE flag
-#ifdef __WXDEBUG__
+#if wxDEBUG_LEVEL
     if ( !m_data->m_paramDesc.IsEmpty() )
     {
         wxCmdLineParam& param = m_data->m_paramDesc.Last();
@@ -464,7 +461,7 @@ void wxCmdLineParser::AddParam(const wxString& desc,
                           _T("a required parameter can't follow an optional one") );
         }
     }
-#endif // Debug
+#endif // wxDEBUG_LEVEL
 
     wxCmdLineParam *param = new wxCmdLineParam(desc, type, flags);
 
@@ -779,15 +776,15 @@ int wxCmdLineParser::Parse(bool showUsage)
             }
             else // it's an option. not a switch
             {
-                switch ( (*p).GetValue() )
+                switch ( p == end ? '\0' : (*p).GetValue() )
                 {
-                    case _T('='):
-                    case _T(':'):
+                    case '=':
+                    case ':':
                         // the value follows
                         ++p;
                         break;
 
-                    case 0:
+                    case '\0':
                         // the value is in the next argument
                         if ( ++n == count )
                         {
@@ -872,8 +869,8 @@ int wxCmdLineParser::Parse(bool showUsage)
                         case wxCMD_LINE_VAL_DATE:
                             {
                                 wxDateTime dt;
-                                const char *res = dt.ParseDate(value);
-                                if ( !res || *res )
+                                wxString::const_iterator end;
+                                if ( !dt.ParseDate(value) || end != value.end() )
                                 {
                                     errorMsg << wxString::Format(_("Option '%s': '%s' cannot be converted to a date."),
                                                                  name.c_str(), value.c_str())
@@ -1280,15 +1277,15 @@ static wxString GetLongOptionName(wxString::const_iterator p,
  */
 
 /* static */
-wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline)
+wxArrayString
+wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline,
+                                     wxCmdLineSplitType type)
 {
     wxArrayString args;
 
     wxString arg;
     arg.reserve(1024);
 
-    bool isInsideQuotes = false;
-
     const wxString::const_iterator end = cmdline.end();
     wxString::const_iterator p = cmdline.begin();
 
@@ -1303,31 +1300,76 @@ wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline)
             break;
 
         // parse this parameter
-        bool lastBS = false;
+        bool lastBS = false,
+             isInsideQuotes = false;
+        wxChar chDelim = '\0';
         for ( arg.clear(); p != end; ++p )
         {
             const wxChar ch = *p;
-            if ( ch == '"' )
+
+            if ( type == wxCMD_LINE_SPLIT_DOS )
             {
-                if ( !lastBS )
+                if ( ch == '"' )
                 {
-                    isInsideQuotes = !isInsideQuotes;
+                    if ( !lastBS )
+                    {
+                        isInsideQuotes = !isInsideQuotes;
 
-                    // don't put quote in arg
-                    continue;
+                        // don't put quote in arg
+                        continue;
+                    }
+                    //else: quote has no special meaning but the backslash
+                    //      still remains -- makes no sense but this is what
+                    //      Windows does
+                }
+                // note that backslash does *not* quote the space, only quotes do
+                else if ( !isInsideQuotes && (ch == ' ' || ch == '\t') )
+                {
+                    ++p;    // skip this space anyhow
+                    break;
                 }
-                //else: quote has no special meaning but the backslash
-                //      still remains -- makes no sense but this is what
-                //      Windows does
+
+                lastBS = !lastBS && ch == '\\';
             }
-            // note that backslash does *not* quote the space, only quotes do
-            else if ( !isInsideQuotes && (ch == ' ' || ch == '\t') )
+            else // type == wxCMD_LINE_SPLIT_UNIX
             {
-                ++p;    // skip this space anyhow
-                break;
-            }
+                if ( !lastBS )
+                {
+                    if ( isInsideQuotes )
+                    {
+                        if ( ch == chDelim )
+                        {
+                            isInsideQuotes = false;
 
-            lastBS = ch == '\\';
+                            continue;   // don't use the quote itself
+                        }
+                    }
+                    else // not in quotes and not escaped
+                    {
+                        if ( ch == '\'' || ch == '"' )
+                        {
+                            isInsideQuotes = true;
+                            chDelim = ch;
+
+                            continue;   // don't use the quote itself
+                        }
+
+                        if ( ch == ' ' || ch == '\t' )
+                        {
+                            ++p;    // skip this space anyhow
+                            break;
+                        }
+                    }
+
+                    lastBS = ch == '\\';
+                    if ( lastBS )
+                        continue;
+                }
+                else // escaped by backslash, just use as is
+                {
+                    lastBS = false;
+                }
+            }
 
             arg += ch;
         }