mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-05-09 03:58:14 +03:00
ioquake3 porting
This commit is contained in:
parent
2704b798e2
commit
ca3340b158
449 changed files with 104109 additions and 77701 deletions
|
@ -11,7 +11,12 @@ static char rcsid[] = "Id: dummy rcsid";
|
|||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#ifdef WIN32
|
||||
#include <process.h> /* getpid() */
|
||||
#include <io.h> /* access() */
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef TEMPDIR
|
||||
#define TEMPDIR "/tmp"
|
||||
|
@ -217,14 +222,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 +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]);
|
||||
|
@ -575,7 +636,7 @@ static void opt(char *arg) {
|
|||
clist = append(&arg[3], clist);
|
||||
return;
|
||||
}
|
||||
break; /* and fall thru */
|
||||
break; /* and fall through */
|
||||
case 'a':
|
||||
alist = append(&arg[3], alist);
|
||||
return;
|
||||
|
@ -757,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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue