Description: support the use of DATADIR
 allow the use of a DATADIR define to denote which directory will store the
 data needed by fanwor (rooms, graphics, sounds)
Author: Joseph Nahmias <joe@nahmias.net>
Origin: vendor
Forwarded: not-needed
Last-Update: 2023-08-05
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/Makefile
+++ b/src/Makefile
@@ -19,10 +19,13 @@ CFL_sdl = $(shell sdl-config --cflags) $
 	  -Wall -Wmissing-prototypes -Wstrict-prototypes
 CFL_atari = 
 
+# directory where to find graphics, rooms, and sounds
+# On Debian, this should be set to /usr/share/fanwor
+DATADIR ?= .
 
 ARCHDIR=./arch/$(ARCH)
 
-CFLAGS += -I. -I./arch/$(ARCH) $(CFL_$(ARCH))
+CFLAGS += -I. -I./arch/$(ARCH) $(CFL_$(ARCH)) -DDATADIR=\"$(DATADIR)\"
 
 LDFLAGS += $(LIBS_$(ARCH))
 
--- a/src/arch/sdl/fwgraf.c
+++ b/src/arch/sdl/fwgraf.c
@@ -11,6 +11,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <linux/limits.h>
 
 #include <SDL.h>
 
@@ -302,11 +303,11 @@ void drawsprites(void)
 /* ***Show a picture and wait for a key*** */
 int showpicture(char *name)
 {
-	char fullname[128];
+	char fullname[PATH_MAX];
 	SDL_Surface *pic;
 	SDL_Rect rs, rd;
 
-	strcpy(fullname, "./graphics/");
+	strcpy(fullname, DATADIR "/graphics/");
 	strcat(fullname, name);
 	strcat(fullname, ".png");
 
--- a/src/arch/sdl/fwguiini.c
+++ b/src/arch/sdl/fwguiini.c
@@ -26,9 +26,9 @@
 
 
 /* Variables: */
-static const char *spritename = "./graphics/sprites.png";
-static const char *groundname = "./graphics/ground.png";
-static const char *fontname = "./graphics/font.png";
+static const char *spritename = DATADIR "/graphics/sprites.png";
+static const char *groundname = DATADIR "/graphics/ground.png";
+static const char *fontname = DATADIR "/graphics/font.png";
 
 
 /* *** Beim GEM anmelden + Keyboard/Joystick initialisieren *** */
--- a/src/fwdisk.c
+++ b/src/fwdisk.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <linux/limits.h>
 
 #include "level.h"
 #include "fwgui.h"
@@ -59,10 +60,10 @@ int loadroom(void)
 	static char *buf=0L;
 	char *sfbuf, *ffbuf;
 	int dx, dy, i;
-	char roomname[256];
+	char roomname[PATH_MAX];
 
 	/* Create file name */
-	strcpy(roomname, "rooms");
+	strcpy(roomname, DATADIR "/rooms");
 #ifdef USEBACKSLASH
 	strcat(roomname, "\\room");
 #else
--- a/src/arch/sdl/fwmusic.c
+++ b/src/arch/sdl/fwmusic.c
@@ -12,6 +12,7 @@
 #ifdef WITH_SOUND
 
 #include <SDL_mixer.h>
+#include <linux/limits.h>
 #include "fwmusic.h"
 
 #ifndef FALSE
@@ -84,7 +85,7 @@ long sound_init(void)
 	Uint16 audio_format;
 	int audio_channels;
 	int audio_buffers;
-	char aktsamname[32];
+	char aktsamname[PATH_MAX];
 	int i;
 
 	/* Initialize variables */
@@ -112,7 +113,7 @@ long sound_init(void)
 	/* Load the sample music files */
 	for (i = 0; i < SAM_ANZAHL; i++)
 	{
-		strcpy(aktsamname, "./sounds/");
+		strcpy(aktsamname, DATADIR "/sounds/");
 		strcat(aktsamname, samnames[i]);
 		samples[i] = Mix_LoadWAV(aktsamname);
 		if ( samples[i] == NULL )
--- a/src/fwmain.c
+++ b/src/fwmain.c
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
 	}
 
 	mod_init();
-	mod_play("./sounds/backgrnd.mod");
+	mod_play(DATADIR "/sounds/backgrnd.mod");
 
 	if (initgraf())
 	{
