]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
make WinMain commandline parser handle quoted strings
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Apr 2004 06:06:24 +0000 (06:06 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Apr 2004 06:06:24 +0000 (06:06 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4109 d7cf8633-e32d-0410-b094-e92efae38249

sys_win.c

index d839902d43d83e3ebf99eb27a0c0a60f8c7cafdd..4114fdcd12743a8cfa07e0212c4c5c59fb6a0059 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -344,23 +344,46 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        GetModuleFileNameA(NULL, program_name, sizeof(program_name) - 1);
        argv[0] = program_name;
 
+       // FIXME: this tokenizer is rather redundent, call a more general one
        while (*lpCmdLine && (com_argc < MAX_NUM_ARGVS))
        {
-               while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
+               while (*lpCmdLine && *lpCmdLine <= 32)
                        lpCmdLine++;
 
                if (*lpCmdLine)
                {
-                       argv[com_argc] = lpCmdLine;
-                       com_argc++;
+                       if (*lpCmdLine == '\"')
+                       {
+                               // quoted string
+                               argv[com_argc] = lpCmdLine;
+                               com_argc++;
 
-                       while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
-                               lpCmdLine++;
+                               while (*lpCmdLine && (*lpCmdLine != '\"'))
+                                       lpCmdLine++;
 
-                       if (*lpCmdLine)
+                               if (*lpCmdLine)
+                               {
+                                       *lpCmdLine = 0;
+                                       lpCmdLine++;
+                               }
+
+                               if (*lpCmdLine == '\"')
+                                       lpCmdLine++;
+                       }
+                       else
                        {
-                               *lpCmdLine = 0;
-                               lpCmdLine++;
+                               // unquoted word
+                               argv[com_argc] = lpCmdLine;
+                               com_argc++;
+
+                               while (*lpCmdLine && *lpCmdLine > 32)
+                                       lpCmdLine++;
+
+                               if (*lpCmdLine)
+                               {
+                                       *lpCmdLine = 0;
+                                       lpCmdLine++;
+                               }
                        }
                }
        }