Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merged fix for bug #503 from SDL 1.2 revision 3487
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 29, 2007
1 parent f157e87 commit 73cfb17
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/main/win32/SDL_win32_main.c
Expand Up @@ -25,14 +25,37 @@
#define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
#endif /* _WIN32_WCE < 300 */

static void
UnEscapeQuotes(char *arg)
{
char *last = NULL;

while (*arg) {
if (*arg == '"' && *last == '\\') {
char *c_curr = arg;
char *c_last = last;

while (*c_curr) {
*c_last = *c_curr;
c_last = c_curr;
c_curr++;
}
*c_last = '\0';
}
last = arg;
arg++;
}
}

/* Parse a command line buffer into arguments */
static int
ParseCommandLine(char *cmdline, char **argv)
{
char *bufp;
int argc;
char *lastp = NULL;
int argc, last_argc;

argc = 0;
argc = last_argc = 0;
for (bufp = cmdline; *bufp;) {
/* Skip leading whitespace */
while (isspace(*bufp)) {
Expand All @@ -48,7 +71,8 @@ ParseCommandLine(char *cmdline, char **argv)
++argc;
}
/* Skip over word */
while (*bufp && (*bufp != '"')) {
while (*bufp && (*bufp != '"' || *lastp == '\\')) {
lastp = bufp;
++bufp;
}
} else {
Expand All @@ -69,6 +93,12 @@ ParseCommandLine(char *cmdline, char **argv)
}
++bufp;
}

/* Strip out \ from \" sequences */
if (argv && last_argc != argc) {
UnEscapeQuotes(argv[last_argc]);
}
last_argc = argc;
}
if (argv) {
argv[argc] = NULL;
Expand Down

0 comments on commit 73cfb17

Please sign in to comment.