ref: 7338feb3744ed2f0a63bababbbdf3d55de143bb6
parent: 7436839e3df26d85827dc0cb16b90264ab9d5e38
author: Jacob Moody <moody@posixcafe.org>
date: Fri Jan 27 01:20:31 EST 2023
rework cfg/wad dirs /sys/games/lib/$IWAD for wad directory $home/lib/$PWAD for saves and configuration Our IWAD is hardcoded, and we just take the last given file for the PWAD.
--- a/d_main.c
+++ b/d_main.c
@@ -863,12 +863,6 @@
startmap = 1;
autostart = false;
- // wadfiles[0] is a char * to the main wad
- if (!I_IdentifyWAD(wadfiles[0]))
- { // Change to look for shareware wad
- wadfiles[0] = SHAREWAREWADNAME;
- }
-
// -FILE [filename] [filename] ...
// Add files to the wad list.
p = M_CheckParm("-file");
@@ -951,24 +945,9 @@
printf("Z_Init: Init zone memory allocation daemon.\n");
Z_Init();
- for(i = 0; i < nelem(wadfiles); i++){
- if(wadfiles[i] == nil){
- wadloc[i] = nil;
- break;
- } else
- wadloc[i] = I_IdentifyWAD(wadfiles[i]);
- print("%s %s\n", wadfiles[i], wadloc[i]);
- }
printf("W_Init: Init WADfiles.\n");
- W_InitMultipleFiles(wadloc);
-
- strcpy(basedefault, wadloc[0]);
- slash = strrchr(basedefault, '/');
- if (!slash)
- basedefault[0] = '\0';
- else
- slash[1] = '\0';
- basePath = basedefault;
+ I_SetupPath(wadfiles);
+ W_InitMultipleFiles(wadfiles);
if (W_CheckNumForName("E2M1") == -1)
{ // Can't find episode 2 maps, must be the shareware WAD
--- a/i_system.c
+++ b/i_system.c
@@ -118,31 +118,39 @@
{
}
-
-char* I_IdentifyWAD(char *wadname)
+static char* strip(char *s)
{
- static char path[1024];
- char *home;
+ char *p;
- snprint(path, sizeof path, wadname);
- if (I_FileExists (path))
- return path;
+ if(p = strstr(s, ".wad"))
+ *p = '\0';
+ if(p = strrchr(s, '/'))
+ return p;
+ return s;
+}
- if(home = getenv("home")){
- snprintf(path, sizeof path, "%s/lib/heretic/%s", home, wadname);
- free(home);
+static char bpd[512];
+static char wd[512];
- if (I_FileExists (path))
- return path;
- }
+void I_SetupPath(char **wads)
+{
+ char **s;
+ char *home;
+ char *cfg, *data;
+ char buf[512];
- snprintf(path, sizeof path, "/sys/lib/heretic/%s", wadname);
- if (I_FileExists (path))
- return path;
+ strcpy(buf, *wads);
+ snprint(wd, sizeof wd, "/sys/games/lib/%s/", strip(buf));
- snprintf(path, sizeof path, "/sys/games/lib/heretic/%s", wadname);
- if (I_FileExists (path))
- return path;
+ for(s = wads; *s; s++)
+ cfg = *s;
- return nil;
+ strcpy(buf, cfg);
+ home = getenv("home");
+ snprint(bpd, sizeof bpd, "%s/lib/%s/", home, strip(buf));
+ free(home);
+
+ basePath = bpd;
+ waddir = wd;
+ print("TEST %s %s\n", basePath, waddir);
}
--- a/i_system.h
+++ b/i_system.h
@@ -99,7 +99,7 @@
int I_Seek(int handle, int n);
int I_Read(int handle, void *buf, int n);
-char* I_IdentifyWAD(char *wadname);
+void I_SetupPath(char **wads);
#endif
//-----------------------------------------------------------------------------
--- a/w_wad.c
+++ b/w_wad.c
@@ -102,8 +102,27 @@
filelump_t *freeFileInfo;
int i;
- handle = open(filename, OREAD);
- if (handle < 0)
+ handle = -1;
+ /* try the directory from the command line or
+ * from the shared data environment variable.
+ */
+ if (waddir && *waddir)
+ {
+ snprintf (path, sizeof(path), "%s/%s", waddir, filename);
+ handle = open(path, OREAD);
+ }
+#if !defined(_NO_USERDIRS)
+ if (handle == -1) /* Try UserDIR */
+ {
+ snprintf (path, sizeof(path), "%s%s", basePath, filename);
+ handle = open(path, OREAD);
+ }
+#endif /* !_NO_USERDIRS */
+ if (handle == -1) /* Now try CWD */
+ {
+ handle = open(filename, OREAD);
+ }
+ if (handle == -1)
return; /* Didn't find the file. */
startlump = numlumps;