comparison src/main/win32/SDL_win32_main.c @ 2286:41a6675d8700

Merged fix for bug #503 from SDL 1.2 revision 3487
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Dec 2007 19:29:20 +0000
parents c121d94672cb
children ae7799d16c87
comparison
equal deleted inserted replaced
2285:a5de28552be4 2286:41a6675d8700
23 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 23 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
24 /* seems to be undefined in Win CE although in online help */ 24 /* seems to be undefined in Win CE although in online help */
25 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) 25 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
26 #endif /* _WIN32_WCE < 300 */ 26 #endif /* _WIN32_WCE < 300 */
27 27
28 static void
29 UnEscapeQuotes(char *arg)
30 {
31 char *last = NULL;
32
33 while (*arg) {
34 if (*arg == '"' && *last == '\\') {
35 char *c_curr = arg;
36 char *c_last = last;
37
38 while (*c_curr) {
39 *c_last = *c_curr;
40 c_last = c_curr;
41 c_curr++;
42 }
43 *c_last = '\0';
44 }
45 last = arg;
46 arg++;
47 }
48 }
49
28 /* Parse a command line buffer into arguments */ 50 /* Parse a command line buffer into arguments */
29 static int 51 static int
30 ParseCommandLine(char *cmdline, char **argv) 52 ParseCommandLine(char *cmdline, char **argv)
31 { 53 {
32 char *bufp; 54 char *bufp;
33 int argc; 55 char *lastp = NULL;
34 56 int argc, last_argc;
35 argc = 0; 57
58 argc = last_argc = 0;
36 for (bufp = cmdline; *bufp;) { 59 for (bufp = cmdline; *bufp;) {
37 /* Skip leading whitespace */ 60 /* Skip leading whitespace */
38 while (isspace(*bufp)) { 61 while (isspace(*bufp)) {
39 ++bufp; 62 ++bufp;
40 } 63 }
46 argv[argc] = bufp; 69 argv[argc] = bufp;
47 } 70 }
48 ++argc; 71 ++argc;
49 } 72 }
50 /* Skip over word */ 73 /* Skip over word */
51 while (*bufp && (*bufp != '"')) { 74 while (*bufp && (*bufp != '"' || *lastp == '\\')) {
75 lastp = bufp;
52 ++bufp; 76 ++bufp;
53 } 77 }
54 } else { 78 } else {
55 if (*bufp) { 79 if (*bufp) {
56 if (argv) { 80 if (argv) {
67 if (argv) { 91 if (argv) {
68 *bufp = '\0'; 92 *bufp = '\0';
69 } 93 }
70 ++bufp; 94 ++bufp;
71 } 95 }
96
97 /* Strip out \ from \" sequences */
98 if (argv && last_argc != argc) {
99 UnEscapeQuotes(argv[last_argc]);
100 }
101 last_argc = argc;
72 } 102 }
73 if (argv) { 103 if (argv) {
74 argv[argc] = NULL; 104 argv[argc] = NULL;
75 } 105 }
76 return (argc); 106 return (argc);