From 2c6adb9fc9de28d6a7caab069a7e50acf3349167 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 16 Apr 2004 06:06:24 +0000 Subject: [PATCH] make WinMain commandline parser handle quoted strings git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4109 d7cf8633-e32d-0410-b094-e92efae38249 --- sys_win.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) 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++; + } } } } -- 2.39.2