]> gitweb.factorcode.org Git - factor.git/commitdiff
Use ParseCommandLineArgvw() on Windows again, instead of hand-rolled parser. Update...
authorSlava Pestov <slava@factorcode.org>
Mon, 18 Jan 2010 12:12:04 +0000 (06:12 -0600)
committerSlava Pestov <slava@factorcode.org>
Mon, 18 Jan 2010 12:12:04 +0000 (06:12 -0600)
Nmakefile
vm/main-windows-ce.cpp
vm/main-windows-nt.cpp
vm/os-windows.cpp
vm/os-windows.hpp

index e9384fdff8000b705384a9ad481c8b4769ad6169..405cf331e866217f457935811edf0825c7ab3ce2 100755 (executable)
--- a/Nmakefile
+++ b/Nmakefile
@@ -1,4 +1,4 @@
-LINK_CLFAGS = /nologo\r
+LINK_FLAGS = /nologo shell32.lib\r
 CL_FLAGS = /nologo /O2 /W3\r
 \r
 EXE_OBJS = factor.dll.lib vm\main-windows-nt.obj vm\factor.res\r
 CL_FLAGS = /nologo /O2 /W3\r
 \r
 EXE_OBJS = factor.dll.lib vm\main-windows-nt.obj vm\factor.res\r
@@ -66,6 +66,7 @@ factor.exe: $(EXE_OBJS)
 \r
 clean:\r
        del vm\*.obj\r
 \r
 clean:\r
        del vm\*.obj\r
+       del factor.lib\r
        del factor.com\r
        del factor.exe\r
        del factor.dll\r
        del factor.com\r
        del factor.exe\r
        del factor.dll\r
index e0b1d3b626c8b4023c4a41b496fe9cc6e9e2a3d8..ed5844167a5459598caef64e279f66d43e02484a 100755 (executable)
@@ -1,5 +1,120 @@
 #include "master.hpp"
 
 #include "master.hpp"
 
+/* 
+       Windows argument parsing ported to work on
+       int main(int argc, wchar_t **argv).
+
+       Based on MinGW's public domain char** version.
+*/
+
+VM_C_API int parse_tokens(wchar_t *string, wchar_t ***tokens, int length)
+{
+       /* Extract whitespace- and quotes- delimited tokens from the given string
+          and put them into the tokens array. Returns number of tokens
+          extracted. Length specifies the current size of tokens[].
+          THIS METHOD MODIFIES string.  */
+
+       const wchar_t *whitespace = L" \t\r\n";
+       wchar_t *tokenEnd = 0;
+       const wchar_t *quoteCharacters = L"\"\'";
+       wchar_t *end = string + wcslen(string);
+
+       if (string == NULL)
+               return length;
+
+       while (1)
+       {
+               const wchar_t *q;
+               /* Skip over initial whitespace.  */
+               string += wcsspn(string, whitespace);
+               if (*string == '\0')
+                       break;
+
+               for (q = quoteCharacters; *q; ++q)
+               {
+                       if (*string == *q)
+                               break;
+               }
+               if (*q)
+               {
+                       /* Token is quoted.  */
+                       wchar_t quote = *string++;
+                       tokenEnd = wcschr(string, quote);
+                       /* If there is no endquote, the token is the rest of the string.  */
+                       if (!tokenEnd)
+                               tokenEnd = end;
+               }
+               else
+               {
+                       tokenEnd = string + wcscspn(string, whitespace);
+               }
+
+               *tokenEnd = '\0';
+
+               {
+                       wchar_t **new_tokens;
+                       int newlen = length + 1;
+                       new_tokens = (wchar_t **)realloc (*tokens, sizeof (wchar_t**) * newlen);
+                       if (!new_tokens)
+                       {
+                               /* Out of memory.  */
+                               return -1;
+                       }
+
+                       *tokens = new_tokens;
+                       (*tokens)[length] = string;
+                       length = newlen;
+               }
+               if (tokenEnd == end)
+                       break;
+               string = tokenEnd + 1;
+       }
+       return length;
+}
+
+VM_C_API void parse_args(int *argc, wchar_t ***argv, wchar_t *cmdlinePtrW)
+{
+       int cmdlineLen = 0;
+
+       if (!cmdlinePtrW)
+               cmdlineLen = 0;
+       else
+               cmdlineLen = wcslen(cmdlinePtrW);
+
+       /* gets realloc()'d later */
+       *argc = 0;
+       *argv = (wchar_t **)malloc (sizeof (wchar_t**));
+
+       if (!*argv)
+               ExitProcess(1);
+
+#ifdef WINCE
+       wchar_t cmdnameBufW[MAX_UNICODE_PATH];
+
+       /* argv[0] is the path of invoked program - get this from CE.  */
+       cmdnameBufW[0] = 0;
+       GetModuleFileNameW(NULL, cmdnameBufW, sizeof (cmdnameBufW)/sizeof (cmdnameBufW[0]));
+
+       (*argv)[0] = wcsdup(cmdnameBufW);
+       if(!(*argv[0]))
+               ExitProcess(1);
+       /* Add one to account for argv[0] */
+       (*argc)++;
+#endif
+
+       if (cmdlineLen > 0)
+       {
+               wchar_t *string = wcsdup(cmdlinePtrW);
+               if(!string)
+                       ExitProcess(1);
+               *argc = parse_tokens(string, argv, *argc);
+               if (*argc < 0)
+                       ExitProcess(1);
+       }
+       (*argv)[*argc] = 0;
+       return;
+}
+
 int WINAPI WinMain(
        HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
 int WINAPI WinMain(
        HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
index 4fced136e8cbc8e61c0cd4a412c226af754d0e3a..64e2cce54b9b1486046448003cafe7b4bfab8a4e 100755 (executable)
@@ -21,7 +21,7 @@ int WINAPI WinMain(
        int argc;
        wchar_t **argv;
 
        int argc;
        wchar_t **argv;
 
-       factor::parse_args(&argc, &argv, (wchar_t *)GetCommandLine());
+       argv = CommandLineToArgvW(GetCommandLine(),&argc);
        wmain(argc,argv);
 
        // memory leak from malloc, wcsdup
        wmain(argc,argv);
 
        // memory leak from malloc, wcsdup
index ab55beacdbb26e59cab0cedef927458f64953fb0..df2a57f2e80de2aa3fa51fd00675d57f4086b93c 100755 (executable)
@@ -137,123 +137,4 @@ long getpagesize()
        return g_pagesize;
 }
 
        return g_pagesize;
 }
 
-/* 
-       Windows argument parsing ported to work on
-       int main(int argc, wchar_t **argv).
-
-       Based on MinGW's public domain char** version.
-
-       Used by WinMain() implementation in main-windows-ce.cpp
-       and main-windows-nt.cpp.
-
-*/
-
-VM_C_API int parse_tokens(wchar_t *string, wchar_t ***tokens, int length)
-{
-       /* Extract whitespace- and quotes- delimited tokens from the given string
-          and put them into the tokens array. Returns number of tokens
-          extracted. Length specifies the current size of tokens[].
-          THIS METHOD MODIFIES string.  */
-
-       const wchar_t *whitespace = L" \t\r\n";
-       wchar_t *tokenEnd = 0;
-       const wchar_t *quoteCharacters = L"\"\'";
-       wchar_t *end = string + wcslen(string);
-
-       if (string == NULL)
-               return length;
-
-       while (1)
-       {
-               const wchar_t *q;
-               /* Skip over initial whitespace.  */
-               string += wcsspn(string, whitespace);
-               if (*string == '\0')
-                       break;
-
-               for (q = quoteCharacters; *q; ++q)
-               {
-                       if (*string == *q)
-                               break;
-               }
-               if (*q)
-               {
-                       /* Token is quoted.  */
-                       wchar_t quote = *string++;
-                       tokenEnd = wcschr(string, quote);
-                       /* If there is no endquote, the token is the rest of the string.  */
-                       if (!tokenEnd)
-                               tokenEnd = end;
-               }
-               else
-               {
-                       tokenEnd = string + wcscspn(string, whitespace);
-               }
-
-               *tokenEnd = '\0';
-
-               {
-                       wchar_t **new_tokens;
-                       int newlen = length + 1;
-                       new_tokens = (wchar_t **)realloc (*tokens, sizeof (wchar_t**) * newlen);
-                       if (!new_tokens)
-                       {
-                               /* Out of memory.  */
-                               return -1;
-                       }
-
-                       *tokens = new_tokens;
-                       (*tokens)[length] = string;
-                       length = newlen;
-               }
-               if (tokenEnd == end)
-                       break;
-               string = tokenEnd + 1;
-       }
-       return length;
-}
-
-VM_C_API void parse_args(int *argc, wchar_t ***argv, wchar_t *cmdlinePtrW)
-{
-       int cmdlineLen = 0;
-
-       if (!cmdlinePtrW)
-               cmdlineLen = 0;
-       else
-               cmdlineLen = wcslen(cmdlinePtrW);
-
-       /* gets realloc()'d later */
-       *argc = 0;
-       *argv = (wchar_t **)malloc (sizeof (wchar_t**));
-
-       if (!*argv)
-               ExitProcess(1);
-
-#ifdef WINCE
-       wchar_t cmdnameBufW[MAX_UNICODE_PATH];
-
-       /* argv[0] is the path of invoked program - get this from CE.  */
-       cmdnameBufW[0] = 0;
-       GetModuleFileNameW(NULL, cmdnameBufW, sizeof (cmdnameBufW)/sizeof (cmdnameBufW[0]));
-
-       (*argv)[0] = wcsdup(cmdnameBufW);
-       if(!(*argv[0]))
-               ExitProcess(1);
-       /* Add one to account for argv[0] */
-       (*argc)++;
-#endif
-
-       if (cmdlineLen > 0)
-       {
-               wchar_t *argv1 = wcsdup(cmdlinePtrW);
-               if(!argv1)
-                       ExitProcess(1);
-               *argc = parse_tokens(argv1, argv, *argc);
-               if (*argc < 0)
-                       ExitProcess(1);
-       }
-       (*argv)[*argc] = 0;
-       return;
-}
-
 }
 }
index 13db2035bc034d861f72c12935e375aeb6b08f57..8a2dfe38f519c158c2b8bf9b0680b0c870541d86 100755 (executable)
@@ -51,8 +51,4 @@ u64 nano_count();
 void sleep_nanos(u64 nsec);
 long getpagesize();
 
 void sleep_nanos(u64 nsec);
 long getpagesize();
 
-/* Used by-main-windows-*.cpp */
-VM_C_API int parse_tokens(wchar_t* string, wchar_t*** tokens, int length);
-VM_C_API void parse_args(int *argc, wchar_t ***argv, wchar_t *cmdlinePtrW);
-
 }
 }