Skip to content

Commit 51206d0

Browse files
committed
support property DATADIR for data files of games away from binary lauch place
this solve in a place the #1 problem
1 parent 8460157 commit 51206d0

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CONFIG ?= config.default
44

55
BINARY ?= wolf3d
66
PREFIX ?= /usr/local
7-
MANPREFIX ?= $(PREFIX)
7+
DATADIR ?= $(PREFIX)/share/games/wolf3d/
88

99
INSTALL ?= install
1010
INSTALL_PROGRAM ?= $(INSTALL) -m 555 -s
@@ -27,6 +27,10 @@ CFLAGS += -Wwrite-strings
2727
CFLAGS += -Wcast-align
2828

2929

30+
ifdef DATADIR
31+
CFLAGS += -DDATADIR=\"$(DATADIR)\"
32+
endif
33+
3034
CCFLAGS += $(CFLAGS)
3135
CCFLAGS += -std=gnu99
3236
CCFLAGS += -Werror-implicit-function-declaration

id_ca.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ int numEpisodesMissing = 0;
8383
char extension[5]; // Need a string, not constant to change cache files
8484
char graphext[5];
8585
char audioext[5];
86-
static const char gheadname[] = "vgahead.";
87-
static const char gfilename[] = "vgagraph.";
88-
static const char gdictname[] = "vgadict.";
89-
static const char mheadname[] = "maphead.";
90-
static const char mfilename[] = "maptemp.";
91-
static const char aheadname[] = "audiohed.";
92-
static const char afilename[] = "audiot.";
86+
static const char gheadname[] = DATADIR "vgahead.";
87+
static const char gfilename[] = DATADIR "vgagraph.";
88+
static const char gdictname[] = DATADIR "vgadict.";
89+
static const char mheadname[] = DATADIR "maphead.";
90+
static const char mfilename[] = DATADIR "maptemp.";
91+
static const char mfilecama[] = DATADIR "gamemaps.";
92+
static const char aheadname[] = DATADIR "audiohed.";
93+
static const char afilename[] = DATADIR "audiot.";
9394

9495
void CA_CannotOpen(const char *string);
9596

@@ -445,7 +446,7 @@ void CA_RLEWexpand (word *source, word *dest, int32_t length, word rlewtag)
445446

446447
void CAL_SetupGrFile (void)
447448
{
448-
char fname[13];
449+
char fname[13 + sizeof(DATADIR)];
449450
int handle;
450451
byte *compseg;
451452

@@ -547,7 +548,7 @@ void CAL_SetupMapFile (void)
547548
int i;
548549
int handle;
549550
int32_t length,pos;
550-
char fname[13];
551+
char fname[13 + sizeof(DATADIR)];
551552

552553
//
553554
// load maphead.ext (offsets and tileinfo for map file)
@@ -571,7 +572,7 @@ void CAL_SetupMapFile (void)
571572
// open the data file
572573
//
573574
#ifdef CARMACIZED
574-
strcpy(fname, "gamemaps.");
575+
strcpy(fname, mfilecama);
575576
strcat(fname, extension);
576577

577578
maphandle = open(fname, O_RDONLY | O_BINARY);
@@ -627,7 +628,7 @@ void CAL_SetupMapFile (void)
627628

628629
void CAL_SetupAudioFile (void)
629630
{
630-
char fname[13];
631+
char fname[13 + sizeof(DATADIR)];
631632

632633
//
633634
// load audiohed.ext (offsets for audio file)

id_pm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ uint8_t **PMPages;
1616

1717
void PM_Startup()
1818
{
19-
char fname[13] = "vswap.";
19+
char fname[13 + sizeof(DATADIR)] = DATADIR "vswap.";
2020
strcat(fname,extension);
2121

2222
FILE *file = fopen(fname,"rb");

version.h

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#define _VERSION_H_
33

44
#ifndef VERSIONALREADYCHOSEN // used for batch compiling
5+
6+
#ifndef DATADIR
7+
#define DATADIR "/usr/share/games/wolf3d/"
8+
#endif
59

610
/* Defines used for different versions */
711

wl_menu.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -4029,12 +4029,12 @@ CheckForEpisodes (void)
40294029
//
40304030
#ifdef JAPAN
40314031
#ifdef JAPDEMO
4032-
if(!stat("vswap.wj1", &statbuf))
4032+
if(!stat(DATADIR "vswap.wj1", &statbuf))
40334033
{
40344034
strcpy (extension, "wj1");
40354035
numEpisodesMissing = 5;
40364036
#else
4037-
if(!stat("vswap.wj6", &statbuf))
4037+
if(!stat(DATADIR "vswap.wj6", &statbuf))
40384038
{
40394039
strcpy (extension, "wj6");
40404040
#endif
@@ -4052,7 +4052,7 @@ CheckForEpisodes (void)
40524052
// ENGLISH
40534053
//
40544054
#ifdef UPLOAD
4055-
if(!stat("vswap.wl1", &statbuf))
4055+
if(!stat(DATADIR "vswap.wl1", &statbuf))
40564056
{
40574057
strcpy (extension, "wl1");
40584058
numEpisodesMissing = 5;
@@ -4061,7 +4061,7 @@ CheckForEpisodes (void)
40614061
Quit ("NO WOLFENSTEIN 3-D DATA FILES to be found!");
40624062
#else
40634063
#ifndef SPEAR
4064-
if(!stat("vswap.wl6", &statbuf))
4064+
if(!stat(DATADIR "vswap.wl6", &statbuf))
40654065
{
40664066
strcpy (extension, "wl6");
40674067
NewEmenu[2].active =
@@ -4074,15 +4074,15 @@ CheckForEpisodes (void)
40744074
}
40754075
else
40764076
{
4077-
if(!stat("vswap.wl3", &statbuf))
4077+
if(!stat(DATADIR "vswap.wl3", &statbuf))
40784078
{
40794079
strcpy (extension, "wl3");
40804080
numEpisodesMissing = 3;
40814081
NewEmenu[2].active = NewEmenu[4].active = EpisodeSelect[1] = EpisodeSelect[2] = 1;
40824082
}
40834083
else
40844084
{
4085-
if(!stat("vswap.wl1", &statbuf))
4085+
if(!stat(DATADIR "vswap.wl1", &statbuf))
40864086
{
40874087
strcpy (extension, "wl1");
40884088
numEpisodesMissing = 5;
@@ -4099,28 +4099,28 @@ CheckForEpisodes (void)
40994099
#ifndef SPEARDEMO
41004100
if(param_mission == 0)
41014101
{
4102-
if(!stat("vswap.sod", &statbuf))
4102+
if(!stat(DATADIR "vswap.sod", &statbuf))
41034103
strcpy (extension, "sod");
41044104
else
41054105
Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
41064106
}
41074107
else if(param_mission == 1)
41084108
{
4109-
if(!stat("vswap.sd1", &statbuf))
4109+
if(!stat(DATADIR "vswap.sd1", &statbuf))
41104110
strcpy (extension, "sd1");
41114111
else
41124112
Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
41134113
}
41144114
else if(param_mission == 2)
41154115
{
4116-
if(!stat("vswap.sd2", &statbuf))
4116+
if(!stat(DATADIR "vswap.sd2", &statbuf))
41174117
strcpy (extension, "sd2");
41184118
else
41194119
Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
41204120
}
41214121
else if(param_mission == 3)
41224122
{
4123-
if(!stat("vswap.sd3", &statbuf))
4123+
if(!stat(DATADIR "vswap.sd3", &statbuf))
41244124
strcpy (extension, "sd3");
41254125
else
41264126
Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
@@ -4130,7 +4130,7 @@ CheckForEpisodes (void)
41304130
strcpy (graphext, "sod");
41314131
strcpy (audioext, "sod");
41324132
#else
4133-
if(!stat("vswap.sdm", &statbuf))
4133+
if(!stat(DATADIR "vswap.sdm", &statbuf))
41344134
{
41354135
strcpy (extension, "sdm");
41364136
}

0 commit comments

Comments
 (0)