Tony White fixed bug #503 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sat, 29 Dec 2007 18:58:09 +0000
branchSDL-1.2
changeset 41183c068a8c016f
parent 4117 dbb5f9556796
child 4119 98dee075dae0
Tony White fixed bug #503

Support escaped quotes on Win32 command lines.
src/main/win32/SDL_win32_main.c
     1.1 --- a/src/main/win32/SDL_win32_main.c	Sat Dec 29 18:50:33 2007 +0000
     1.2 +++ b/src/main/win32/SDL_win32_main.c	Sat Dec 29 18:58:09 2007 +0000
     1.3 @@ -53,13 +53,35 @@
     1.4  #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
     1.5  #endif /* _WIN32_WCE < 300 */
     1.6  
     1.7 +static void UnEscapeQuotes( char *arg )
     1.8 +{
     1.9 +	char *last = NULL;
    1.10 +
    1.11 +	while( *arg ) {
    1.12 +		if( *arg == '"' && *last == '\\' ) {
    1.13 +			char *c_curr = arg;
    1.14 +			char *c_last = last;
    1.15 +
    1.16 +			while( *c_curr ) {
    1.17 +				*c_last = *c_curr;
    1.18 +				c_last = c_curr;
    1.19 +				c_curr++;
    1.20 +			}
    1.21 +			*c_last = '\0';
    1.22 +		}
    1.23 +		last = arg;
    1.24 +		arg++;
    1.25 +	}
    1.26 +}
    1.27 +
    1.28  /* Parse a command line buffer into arguments */
    1.29  static int ParseCommandLine(char *cmdline, char **argv)
    1.30  {
    1.31  	char *bufp;
    1.32 -	int argc;
    1.33 +	char *lastp = NULL;
    1.34 +	int argc, last_argc;
    1.35  
    1.36 -	argc = 0;
    1.37 +	argc = last_argc = 0;
    1.38  	for ( bufp = cmdline; *bufp; ) {
    1.39  		/* Skip leading whitespace */
    1.40  		while ( isspace(*bufp) ) {
    1.41 @@ -75,7 +97,8 @@
    1.42  				++argc;
    1.43  			}
    1.44  			/* Skip over word */
    1.45 -			while ( *bufp && (*bufp != '"') ) {
    1.46 +			while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) {
    1.47 +				lastp = bufp;
    1.48  				++bufp;
    1.49  			}
    1.50  		} else {
    1.51 @@ -96,6 +119,12 @@
    1.52  			}
    1.53  			++bufp;
    1.54  		}
    1.55 +
    1.56 +		/* Strip out \ from \" sequences */
    1.57 +		if( argv && last_argc != argc ) {
    1.58 +			UnEscapeQuotes( argv[last_argc] );	
    1.59 +		}
    1.60 +		last_argc = argc;	
    1.61  	}
    1.62  	if ( argv ) {
    1.63  		argv[argc] = NULL;