4 Windows CE argument parsing ported to work on
5 int main(int argc, wchar_t **argv).
7 This would not be necessary if Windows CE had CommandLineToArgvW.
9 Based on MinGW's public domain char** version.
17 parse_tokens(wchar_t* string
, wchar_t*** tokens
, int length
)
19 /* Extract whitespace- and quotes- delimited tokens from the given string
20 and put them into the tokens array. Returns number of tokens
21 extracted. Length specifies the current size of tokens[].
22 THIS METHOD MODIFIES string. */
24 const wchar_t* whitespace
= L
" \t\r\n";
25 wchar_t* tokenEnd
= 0;
26 const wchar_t* quoteCharacters
= L
"\"\'";
27 wchar_t *end
= string
+ wcslen(string
);
35 /* Skip over initial whitespace. */
36 string
+= wcsspn(string
, whitespace
);
40 for (q
= quoteCharacters
; *q
; ++q
)
47 /* Token is quoted. */
48 wchar_t quote
= *string
++;
49 tokenEnd
= wcschr(string
, quote
);
50 /* If there is no endquote, the token is the rest of the string. */
56 tokenEnd
= string
+ wcscspn(string
, whitespace
);
63 int newlen
= length
+ 1;
64 new_tokens
= realloc (*tokens
, sizeof (wchar_t**) * newlen
);
72 (*tokens
)[length
] = string
;
77 string
= tokenEnd
+ 1;
83 parse_args(int *argc
, wchar_t ***argv
, wchar_t *cmdlinePtrW
)
85 wchar_t cmdnameBufW
[MAX_UNICODE_PATH
];
89 /* argv[0] is the path of invoked program - get this from CE. */
91 modlen
= GetModuleFileNameW(NULL
, cmdnameBufW
, sizeof (cmdnameBufW
)/sizeof (cmdnameBufW
[0]));
96 cmdlineLen
= wcslen(cmdlinePtrW
);
98 /* gets realloc()'d later */
99 *argv
= malloc (sizeof (wchar_t**) * 1);
103 (*argv
)[0] = wcsdup(cmdnameBufW
);
106 /* Add one to account for argv[0] */
111 wchar_t* argv1
= (*argv
)[0] + wcslen((*argv
)[0]) + 1;
112 argv1
= wcsdup(cmdlinePtrW
);
115 *argc
= parse_tokens(argv1
, argv
, 1);
126 HINSTANCE hPrevInstance
,
130 parse_args(&__argc
, &__argv
, lpCmdLine
);
131 start_standalone_factor(__argc
,(LPWSTR
*)__argv
);
132 // memory leak from malloc, wcsdup