]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sys_win.c
make WinMain commandline parser handle quoted strings
[xonotic/darkplaces.git] / sys_win.c
index 391f9c5a5661abc7eec93249cdc98584c1e538c9..4114fdcd12743a8cfa07e0212c4c5c59fb6a0059 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -109,7 +109,7 @@ void Sys_Quit (void)
        exit (0);
 }
 
-void Sys_Print(const char *text)
+void Sys_PrintToTerminal(const char *text)
 {
        DWORD dummy;
        extern HANDLE houtput;
@@ -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++;
+                               }
                        }
                }
        }