Mercurial > sdl-ios-xcode
comparison src/main/win32/SDL_win32_main.c @ 4118:3c068a8c016f SDL-1.2
Tony White fixed bug #503
Support escaped quotes on Win32 command lines.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 29 Dec 2007 18:58:09 +0000 |
parents | 70e77cbba87c |
children | 8b8314cc34a6 |
comparison
equal
deleted
inserted
replaced
4117:dbb5f9556796 | 4118:3c068a8c016f |
---|---|
51 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 | 51 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 |
52 /* seems to be undefined in Win CE although in online help */ | 52 /* seems to be undefined in Win CE although in online help */ |
53 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) | 53 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) |
54 #endif /* _WIN32_WCE < 300 */ | 54 #endif /* _WIN32_WCE < 300 */ |
55 | 55 |
56 static void UnEscapeQuotes( char *arg ) | |
57 { | |
58 char *last = NULL; | |
59 | |
60 while( *arg ) { | |
61 if( *arg == '"' && *last == '\\' ) { | |
62 char *c_curr = arg; | |
63 char *c_last = last; | |
64 | |
65 while( *c_curr ) { | |
66 *c_last = *c_curr; | |
67 c_last = c_curr; | |
68 c_curr++; | |
69 } | |
70 *c_last = '\0'; | |
71 } | |
72 last = arg; | |
73 arg++; | |
74 } | |
75 } | |
76 | |
56 /* Parse a command line buffer into arguments */ | 77 /* Parse a command line buffer into arguments */ |
57 static int ParseCommandLine(char *cmdline, char **argv) | 78 static int ParseCommandLine(char *cmdline, char **argv) |
58 { | 79 { |
59 char *bufp; | 80 char *bufp; |
60 int argc; | 81 char *lastp = NULL; |
61 | 82 int argc, last_argc; |
62 argc = 0; | 83 |
84 argc = last_argc = 0; | |
63 for ( bufp = cmdline; *bufp; ) { | 85 for ( bufp = cmdline; *bufp; ) { |
64 /* Skip leading whitespace */ | 86 /* Skip leading whitespace */ |
65 while ( isspace(*bufp) ) { | 87 while ( isspace(*bufp) ) { |
66 ++bufp; | 88 ++bufp; |
67 } | 89 } |
73 argv[argc] = bufp; | 95 argv[argc] = bufp; |
74 } | 96 } |
75 ++argc; | 97 ++argc; |
76 } | 98 } |
77 /* Skip over word */ | 99 /* Skip over word */ |
78 while ( *bufp && (*bufp != '"') ) { | 100 while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) { |
101 lastp = bufp; | |
79 ++bufp; | 102 ++bufp; |
80 } | 103 } |
81 } else { | 104 } else { |
82 if ( *bufp ) { | 105 if ( *bufp ) { |
83 if ( argv ) { | 106 if ( argv ) { |
94 if ( argv ) { | 117 if ( argv ) { |
95 *bufp = '\0'; | 118 *bufp = '\0'; |
96 } | 119 } |
97 ++bufp; | 120 ++bufp; |
98 } | 121 } |
122 | |
123 /* Strip out \ from \" sequences */ | |
124 if( argv && last_argc != argc ) { | |
125 UnEscapeQuotes( argv[last_argc] ); | |
126 } | |
127 last_argc = argc; | |
99 } | 128 } |
100 if ( argv ) { | 129 if ( argv ) { |
101 argv[argc] = NULL; | 130 argv[argc] = NULL; |
102 } | 131 } |
103 return(argc); | 132 return(argc); |