-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArgIteratorWindows uses non-Unicode GetCommandLineA and a custom parser #2222
Comments
Here's ArgIteratorWindows re-written using CommandLineToArgvW: https://gist.github.com/ljmccarthy/ef3e4e828a940812ae9d23f4d3713053 Note I've had to add a deinit() function. |
Maybe this isn't the best approach. UCRT also has it's own parser, and it's not clear if it works exactly like CommandLineToArgvW. It seems this is a bit of a mess on Windows with no real standard, so perhaps the existing parser is fine. If we are linking with UCRT we could use it's parsed argv exported by the __argc and __argv/__wargv symbols, but it would still require a fallback for when we don't want to link to UCRT. |
See also #534 |
I agree. It also consumes bytes in every binary. I did some work on it https://github.com/shawnl/zig/tree/startup My real plan though is to have a startup function separate from main that does argument and environment parsing, and then it will return to the startup code, which will remove the environment, and then call main. If you have a Linux box type |
The rules for It looks like
Quote marks behave completely as expected if used anywhere else. It's just the program name (~= I'm not sure if this means Zig should avoid |
std.os.ArgIteratorWindows currently uses GetCommandLineA which doesn't support Unicode and implements it's own command line parser.
I'm sure it's a good parser, but there is already a Windows function to implement this called CommandLineToArgvW which can be used with the result of GetCommandLineW. I would suggest that using this instead would make sure that Zig doesn't parse command-lines differently to regular C/C++ programs on Windows and would reduce code size.
I have implemented a proof-of-concept using these Win32 functions, returning an array of UTF-8 strings:
https://gist.github.com/ljmccarthy/4f372f060d2d2e11b594ad9188fd4720
I'm also not a big for of the ArgIterator interface, which is rather painful to use, but I will create a separate issue for that :-)
The text was updated successfully, but these errors were encountered: