SDL/src
Sam Lantinga f8400cbba9 Fixed bug 4692 - Command line parsing
Galadrim

As I have seen, SDL implements its own command line parser for Windows in SDL_windows_main.c. Unfortunately, it doesn't seem to allow command line arguments with trailing backslashes if quoting is required.

Usually, when you write an application that gets command line arguments passed as argc and argv, the parsing is done by parse_cmdline. The Windows API also provides the function CommandLineToArgvW, so an application can parse itself if only the command line string is provided. Both functions behave almost identically according to their documentation. If the argument "\\" (including the quotes) is passed, they both turn it into a single backslash.

The SDL command line parser on the other hand doesn't recognize the second quote character as the closing character in this example and therefore includes it in the parsed argument. The parser does not count the number of backslashes preceding a quote. It always treats a quote as escaped if a backslash is in front of it. Therefore, it should be impossible to quote and escape an argument correctly, if it has a trailing backslash and contains characters that require quoting.

Of course, each application is allowed to implement its own parsing rules, so SDL is free to do so. But the problem I see is that there are arguments, that are impossible to be passed to the parser correctly, as I described above. Is there a reason, why SDL does not simply use CommandLineToArgvW instead of implementing its own parser?

Here are some links that show that correct argument parsing, as it is usually done in Windows, is quite complicated:

https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw

http://www.windowsinspired.com/how-a-windows-programs-splits-its-command-line-into-individual-arguments/
2019-07-31 09:11:20 -07:00
..
atomic Fixed memory barrier macro check so it isn't quite so fragile 2019-06-30 23:58:31 -07:00
audio use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
core Fixed bug 4739 - Android: loading native libs, generated by bundletool (Thanks akk0rd87) 2019-07-27 20:21:42 +02:00
cpuinfo Fixed bug 4557 - SDL_SIMDAlloc and *Free should be in the public interface 2019-06-08 14:54:37 -07:00
dynapi minor build fixes. 2019-07-31 00:05:28 +03:00
events Fixed bug 4704 - SDL_HINT_ANDROID_SEPERATE_MOUSE_AND_TOUCH on Windows? 2019-07-15 09:36:53 -07:00
file minor build fix. 2019-07-31 01:19:26 +03:00
filesystem Fixed bug 4726 - Fix for tvOS GetPrefPath 2019-07-18 19:33:17 -07:00
haptic Updated copyright for 2019 2019-01-04 22:01:14 -08:00
hidapi hidapi: Update repository URLs 2019-07-25 08:05:13 -05:00
joystick use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
libm Updated copyright for 2019 2019-01-04 22:01:14 -08:00
loadso Updated copyright for 2019 2019-01-04 22:01:14 -08:00
main Fixed bug 4692 - Command line parsing 2019-07-31 09:11:20 -07:00
power Updated copyright for 2019 2019-01-04 22:01:14 -08:00
render Android: concurrency issues, make sure Activity is in running State when calling 2019-06-28 16:38:42 +02:00
sensor Updated copyright for 2019 2019-01-04 22:01:14 -08:00
stdlib better readability.. 2019-07-31 00:07:15 +03:00
test use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
thread Hopefully fixed the mingw32 build 2019-03-19 17:20:54 -07:00
timer Updated copyright for 2019 2019-01-04 22:01:14 -08:00
video use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
SDL.c events: Make debug logging of the event queue a hint instead of an #ifdef. 2019-03-15 14:08:30 -04:00
SDL_assert.c minor build fixes. 2019-07-31 00:05:28 +03:00
SDL_assert_c.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_dataqueue.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_dataqueue.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_error.c Fix DirectInput error codes being lost 2019-03-16 18:11:09 -07:00
SDL_error_c.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_hints.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_internal.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_log.c Copypaste SDL_NSLog to UIKit backend, document it as such 2019-07-17 23:20:57 -04:00