From: havoc Date: Fri, 16 Apr 2004 06:06:24 +0000 (+0000) Subject: make WinMain commandline parser handle quoted strings X-Git-Tag: xonotic-v0.1.0preview~5911 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2c6adb9fc9de28d6a7caab069a7e50acf3349167;p=xonotic%2Fdarkplaces.git make WinMain commandline parser handle quoted strings git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4109 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/sys_win.c b/sys_win.c index d839902d..4114fdcd 100644 --- 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++; + } } } }