shithub: hexen

Download patch

ref: 21d63fc61aaa77df6158532063393af9c12cc4ae
parent: abf5ff94061e3760bdbc54b8f2839fe77f57bdf4
author: Jacob Moody <moody@posixcafe.org>
date: Fri Jan 27 01:21:38 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/h2_main.c
+++ b/h2_main.c
@@ -210,23 +210,9 @@
 	// heap has been previously allocated, so we need to initialize the
 	// WAD files BEFORE the zone memory initialization.
 	ST_Message("W_Init: Init WADfiles.\n");
-	for(i = 0; i < nelem(wadfiles); i++){
-		if(wadfiles[i] == nil){
-			wadloc[i] = nil;
-			break;
-		} else
-			wadloc[i] = I_IdentifyWAD(wadfiles[i]);
-	}
-	W_InitMultipleFiles(wadloc);
+	I_SetupPath(wadfiles);
+	W_InitMultipleFiles(wadfiles);
 	W_CheckWADFiles();
-
-	strcpy(basedefault, wadloc[0]);
-	slash = strrchr(basedefault, '/');
-	if (!slash)
-		basedefault[0] = '\0';
-	else
-		slash[1] = '\0';
-	basePath = basedefault;
 
 	// Load defaults before initing other systems
 	ST_Message("M_LoadDefaults: Load system defaults.\n");
--- a/i_system.c
+++ b/i_system.c
@@ -119,31 +119,38 @@
 {
 }
 
-
-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/hexen/%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/hexen/%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/hexen/%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;
 }
--- 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
 //-----------------------------------------------------------------------------