[PATCH] qbsp: Add -wadpath option

Add the "-wadpath" command-line argument to allow the user to specify a
directory where wad files can be found. If no wadpath is given, the path
defaults to the directory where the map file is located. Absolute path names
in the worldspawn "wad" key should also work.

Signed-off-by: Tyrann <tyrann@disenchant.net>
This commit is contained in:
Tyrann 2007-08-19 05:32:46 +09:30
parent eb7c5d5cca
commit 165055db7b
4 changed files with 49 additions and 3 deletions

View File

@ -107,3 +107,20 @@ StripExtension(char *path)
if (length)
path[length] = 0;
}
void
StripFilename(char *path)
{
int length;
length = strlen(path) - 1;
while (length > 0 && path[length] != PATHSEPERATOR)
length--;
path[length] = '\0';
}
int
IsAbsolutePath(const char *path)
{
return path[0] == '/' || (isalpha(path[0]) && path[1] == ':');
}

View File

@ -315,6 +315,7 @@ PrintOptions(void)
printf(" -nopercent Prevents output of percent completion information\n");
printf(" -leakdist [n] Space between leakfile points (default 2)\n");
printf(" -subdivide [n] Use different texture subdivision (default 240)\n");
printf(" -wadpath <dir> Search this directory for wad files\n");
printf(" sourcefile .MAP file to process\n");
printf(" destfile .BSP file to output\n");
@ -433,6 +434,12 @@ ParseOptions(char *szOptions)
Message(msgError, errInvalidOption, szTok);
options.dxSubdivide = atoi(szTok2);
szTok = szTok2;
} else if (!strcasecmp(szTok, "wadpath")) {
szTok2 = GetTok(szTok + strlen(szTok) + 1, szEnd);
if (!szTok2)
Message(msgError, errInvalidOption, szTok);
strcpy(options.wadPath, szTok2);
szTok = szTok2;
} else if (!strcasecmp(szTok, "?") || !strcasecmp(szTok, "help"))
PrintOptions();
else
@ -467,7 +474,7 @@ InitQBSP(int argc, char **argv)
options.dxLeakDist = 2;
options.dxSubdivide = 240;
options.fVerbose = true;
options.szMapName[0] = options.szBSPName[0] = 0;
options.szMapName[0] = options.szBSPName[0] = options.wadPath[0] = 0;
length = LoadFile("qbsp.ini", (void *)&szBuf, false);
if (length) {
@ -509,6 +516,12 @@ InitQBSP(int argc, char **argv)
if (options.szBSPName[0] == 0)
strcpy(options.szBSPName, options.szMapName);
/* If no wadpath given, default to the map directory */
if (options.wadPath[0] == 0) {
strcpy(options.wadPath, options.szMapName);
StripFilename(options.wadPath);
}
// Remove already existing files
if (!options.fOnlyents) {
StripExtension(options.szBSPName);

View File

@ -163,6 +163,8 @@ double I_FloatTime(void);
void DefaultExtension(char *path, char *extension);
void StripExtension(char *path);
void StripFilename(char *path);
int IsAbsolutePath(const char *path);
char *copystring(char *s);
@ -525,6 +527,7 @@ typedef struct options_s {
int dxLeakDist;
char szMapName[512];
char szBSPName[512];
char wadPath[512];
} options_t;
extern options_t options;

View File

@ -57,6 +57,8 @@ WADList_Init(wad_t **wads, char *wadstring)
int i, len, numwads;
wad_t *tmp, *w;
char *fname;
char *fpath;
int pathlen;
numwads = 0;
*wads = NULL;
@ -83,14 +85,25 @@ WADList_Init(wad_t **wads, char *wadstring)
while (wadstring[i] != 0 && wadstring[i] != ';')
i++;
wadstring[i++] = 0;
w->file = fopen(fname, "rb");
if (!options.wadPath[0] || IsAbsolutePath(fname))
fpath = copystring(fname);
else {
pathlen = strlen(options.wadPath) + strlen(fname) + 1;
fpath = AllocMem(OTHER, pathlen + 1, false);
sprintf(fpath, "%s/%s", options.wadPath, fname);
}
w->file = fopen(fpath, "rb");
if (w->file) {
if (options.fVerbose)
Message(msgLiteral, "Opened WAD: %s\n", fpath);
if (!WAD_LoadInfo(w)) {
Message(msgWarning, warnNotWad, fname);
Message(msgWarning, warnNotWad, fpath);
fclose(w->file);
} else
w++;
}
FreeMem(fpath, OTHER, strlen(fpath) + 1);
}
/* Re-allocate just the required amount */