diff options
author | tma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-10-15 11:36:51 +0000 |
---|---|---|
committer | tma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-10-15 11:36:51 +0000 |
commit | 3938c390cfb257dff78074f9ad21841b6b2036d9 (patch) | |
tree | c5dcb0f8c907bf3436dc32b3ee72799c06f419f9 /code/tools | |
parent | dd40ddbbb84dd156bc404e561a40b861f9e4184d (diff) | |
download | ioquake3-aero-3938c390cfb257dff78074f9ad21841b6b2036d9.tar.gz ioquake3-aero-3938c390cfb257dff78074f9ad21841b6b2036d9.zip |
* Make LCC's handling of -D arguments on windows consistent with other plaftorms
git-svn-id: svn://svn.icculus.org/quake3/trunk@1668 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/tools')
-rw-r--r-- | code/tools/lcc/etc/lcc.c | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/code/tools/lcc/etc/lcc.c b/code/tools/lcc/etc/lcc.c index 13ed690..a168852 100644 --- a/code/tools/lcc/etc/lcc.c +++ b/code/tools/lcc/etc/lcc.c @@ -217,14 +217,74 @@ char *basename(char *name) { #ifdef WIN32 #include <process.h> + +static char *escapeDoubleQuotes(const char *string) { + int stringLength = strlen(string); + int bufferSize = stringLength + 1; + int i, j; + char *newString; + + if (string == NULL) + return NULL; + + for (i = 0; i < stringLength; i++) { + if (string[i] == '"') + bufferSize++; + } + + newString = (char*)malloc(bufferSize); + + if (newString == NULL) + return NULL; + + for (i = 0, j = 0; i < stringLength; i++) { + if (string[i] == '"') + newString[j++] = '\\'; + + newString[j++] = string[i]; + } + + newString[j] = '\0'; + + return newString; +} + +static int spawn(const char *cmdname, char **argv) { + int argc = 0; + char **newArgv = argv; + int i; + intptr_t exitStatus; + + // _spawnvp removes double quotes from arguments, so we + // have to escape them manually + while (*newArgv++ != NULL) + argc++; + + newArgv = (char **)malloc(sizeof(char*) * (argc + 1)); + + for (i = 0; i < argc; i++) + newArgv[i] = escapeDoubleQuotes(argv[i]); + + newArgv[argc] = NULL; + + exitStatus = _spawnvp(_P_WAIT, cmdname, (const char *const *)newArgv); + + for (i = 0; i < argc; i++) + free(newArgv[i]); + + free(newArgv); + return exitStatus; +} + #else + #define _P_WAIT 0 #ifndef __sun extern int fork(void); #endif extern int wait(int *); -static int _spawnvp(int mode, const char *cmdname, char *argv[]) { +static int spawn(const char *cmdname, char **argv) { int pid, n, status; switch (pid = fork()) { @@ -292,11 +352,7 @@ static int callsys(char **av) { fprintf(stderr, "\n"); } if (verbose < 2) -#ifndef WIN32 - status = _spawnvp(_P_WAIT, executable, argv); -#else - status = _spawnvp(_P_WAIT, executable, (const char* const*)argv); -#endif + status = spawn(executable, argv); if (status == -1) { fprintf(stderr, "%s: ", progname); perror(argv[0]); |