src/main/win32/SDL_win32_main.c
changeset 2286 41a6675d8700
parent 1895 c121d94672cb
child 4511 ae7799d16c87
     1.1 --- a/src/main/win32/SDL_win32_main.c	Sat Dec 29 06:17:31 2007 +0000
     1.2 +++ b/src/main/win32/SDL_win32_main.c	Sat Dec 29 19:29:20 2007 +0000
     1.3 @@ -25,14 +25,37 @@
     1.4  #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
     1.5  #endif /* _WIN32_WCE < 300 */
     1.6  
     1.7 +static void
     1.8 +UnEscapeQuotes(char *arg)
     1.9 +{
    1.10 +    char *last = NULL;
    1.11 +
    1.12 +    while (*arg) {
    1.13 +        if (*arg == '"' && *last == '\\') {
    1.14 +            char *c_curr = arg;
    1.15 +            char *c_last = last;
    1.16 +
    1.17 +            while (*c_curr) {
    1.18 +                *c_last = *c_curr;
    1.19 +                c_last = c_curr;
    1.20 +                c_curr++;
    1.21 +            }
    1.22 +            *c_last = '\0';
    1.23 +        }
    1.24 +        last = arg;
    1.25 +        arg++;
    1.26 +    }
    1.27 +}
    1.28 +
    1.29  /* Parse a command line buffer into arguments */
    1.30  static int
    1.31  ParseCommandLine(char *cmdline, char **argv)
    1.32  {
    1.33      char *bufp;
    1.34 -    int argc;
    1.35 +    char *lastp = NULL;
    1.36 +    int argc, last_argc;
    1.37  
    1.38 -    argc = 0;
    1.39 +    argc = last_argc = 0;
    1.40      for (bufp = cmdline; *bufp;) {
    1.41          /* Skip leading whitespace */
    1.42          while (isspace(*bufp)) {
    1.43 @@ -48,7 +71,8 @@
    1.44                  ++argc;
    1.45              }
    1.46              /* Skip over word */
    1.47 -            while (*bufp && (*bufp != '"')) {
    1.48 +            while (*bufp && (*bufp != '"' || *lastp == '\\')) {
    1.49 +                lastp = bufp;
    1.50                  ++bufp;
    1.51              }
    1.52          } else {
    1.53 @@ -69,6 +93,12 @@
    1.54              }
    1.55              ++bufp;
    1.56          }
    1.57 +
    1.58 +        /* Strip out \ from \" sequences */
    1.59 +        if (argv && last_argc != argc) {
    1.60 +            UnEscapeQuotes(argv[last_argc]);
    1.61 +        }
    1.62 +        last_argc = argc;
    1.63      }
    1.64      if (argv) {
    1.65          argv[argc] = NULL;