From 60d92bbdcfc22c7248989ad7efb856989d299daa Mon Sep 17 00:00:00 2001 From: /dev/humancontroller Date: Thu, 13 Apr 2017 11:30:00 +0000 Subject: update the tools to the latest revision URL: https://github.com/darklegion/tremulous revision: c862a5340c8de44dcc7abaff170c20c04f9340e8, equivalently f45fbef604e05144057dec8d1dbfc5d4f5a2a822 --- src/tools/lcc/etc/bytecode.c | 4 ++ src/tools/lcc/etc/lcc.c | 90 +++++++++++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 22 deletions(-) (limited to 'src/tools/lcc/etc') diff --git a/src/tools/lcc/etc/bytecode.c b/src/tools/lcc/etc/bytecode.c index fe4178f..a5855de 100644 --- a/src/tools/lcc/etc/bytecode.c +++ b/src/tools/lcc/etc/bytecode.c @@ -52,6 +52,10 @@ int option(char *arg) { cpp[0] = concat(&arg[8], "/q3cpp" BINEXT); include[0] = concat("-I", concat(&arg[8], "/include")); com[0] = concat(&arg[8], "/q3rcc" BINEXT); + } else if (strncmp(arg, "-lcppdir=", 9) == 0) { + cpp[0] = concat(&arg[9], "/q3cpp" BINEXT); + } else if (strncmp(arg, "-lrccdir=", 9) == 0) { + com[0] = concat(&arg[9], "/q3rcc" BINEXT); } else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-pg") == 0) { fprintf( stderr, "no profiling supported, %s ignored.\n", arg); } else if (strcmp(arg, "-b") == 0) diff --git a/src/tools/lcc/etc/lcc.c b/src/tools/lcc/etc/lcc.c index cac01b9..aa3e789 100644 --- a/src/tools/lcc/etc/lcc.c +++ b/src/tools/lcc/etc/lcc.c @@ -11,7 +11,12 @@ static char rcsid[] = "Id: dummy rcsid"; #include #include #include +#ifdef WIN32 +#include /* getpid() */ +#include /* access() */ +#else #include +#endif #ifndef TEMPDIR #define TEMPDIR "/tmp" @@ -217,14 +222,74 @@ char *basename(char *name) { #ifdef WIN32 #include + +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 +357,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]); @@ -526,10 +587,6 @@ static void help(void) { #define xx(v) if ((s = getenv(#v))) fprintf(stderr, #v "=%s\n", s) xx(LCCINPUTS); xx(LCCDIR); -#ifdef WIN32 - xx(include); - xx(lib); -#endif #undef xx } @@ -537,9 +594,6 @@ static void help(void) { static void initinputs(void) { char *s = getenv("LCCINPUTS"); List b; -#ifdef WIN32 - List list; -#endif if (s == 0 || (s = inputs)[0] == 0) s = "."; @@ -556,13 +610,6 @@ static void initinputs(void) { b->str = ""; } while (b != lccinputs); } -#ifdef WIN32 - if ((list = b = path2list(getenv("include")))) - do { - b = b->link; - ilist = append(stringf("-I\"%s\"", b->str), ilist); - } while (b != list); -#endif } /* interrupt - catch interrupt signals */ @@ -771,10 +818,9 @@ char *strsave(const char *str) { char *stringf(const char *fmt, ...) { char buf[1024]; va_list ap; - int n; va_start(ap, fmt); - n = vsprintf(buf, fmt, ap); + vsprintf(buf, fmt, ap); va_end(ap); return strsave(buf); } -- cgit