4 Windows argument parsing ported to work on
5 int main(int argc, wchar_t **argv).
7 Based on MinGW's public domain char** version.
10 VM_C_API int parse_tokens(wchar_t *string, wchar_t ***tokens, int length)
12 /* Extract whitespace- and quotes- delimited tokens from the given string
13 and put them into the tokens array. Returns number of tokens
14 extracted. Length specifies the current size of tokens[].
15 THIS METHOD MODIFIES string. */
17 const wchar_t *whitespace = L" \t\r\n";
18 wchar_t *tokenEnd = 0;
19 const wchar_t *quoteCharacters = L"\"\'";
20 wchar_t *end = string + wcslen(string);
28 /* Skip over initial whitespace. */
29 string += wcsspn(string, whitespace);
33 for (q = quoteCharacters; *q; ++q)
40 /* Token is quoted. */
41 wchar_t quote = *string++;
42 tokenEnd = wcschr(string, quote);
43 /* If there is no endquote, the token is the rest of the string. */
49 tokenEnd = string + wcscspn(string, whitespace);
56 int newlen = length + 1;
57 new_tokens = (wchar_t **)realloc (*tokens, sizeof (wchar_t**) * newlen);
65 (*tokens)[length] = string;
70 string = tokenEnd + 1;
75 VM_C_API void parse_args(int *argc, wchar_t ***argv, wchar_t *cmdlinePtrW)
82 cmdlineLen = wcslen(cmdlinePtrW);
84 /* gets realloc()'d later */
86 *argv = (wchar_t **)malloc (sizeof (wchar_t**));
92 wchar_t cmdnameBufW[MAX_UNICODE_PATH];
94 /* argv[0] is the path of invoked program - get this from CE. */
96 GetModuleFileNameW(NULL, cmdnameBufW, sizeof (cmdnameBufW)/sizeof (cmdnameBufW[0]));
98 (*argv)[0] = wcsdup(cmdnameBufW);
101 /* Add one to account for argv[0] */
107 wchar_t *string = wcsdup(cmdlinePtrW);
110 *argc = parse_tokens(string, argv, *argc);
120 HINSTANCE hPrevInstance,
126 factor::parse_args(&__argc, &__argv, lpCmdLine);
127 factor::init_globals();
128 factor::start_standalone_factor(__argc,(LPWSTR*)__argv);
130 // memory leak from malloc, wcsdup