summaryrefslogtreecommitdiffstats
path: root/games/wolf4sdl/datadir.diff
blob: b62ea0be089961e015aad539c798b41c70da2c6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
diff -Naur Wolf4SDL-1.7-src.orig//Makefile Wolf4SDL-1.7-src/Makefile
--- Wolf4SDL-1.7-src.orig//Makefile	2008-02-18 01:54:38.000000000 -0500
+++ Wolf4SDL-1.7-src/Makefile	2012-01-13 16:43:43.000000000 -0500
@@ -17,6 +17,7 @@
 LDFLAGS_SDL ?= $(shell $(SDL_CONFIG) --libs)
 
 
+CFLAGS += -DPREFIX='"$(PREFIX)"'
 CFLAGS += $(CFLAGS_SDL)
 
 #CFLAGS += -Wall
@@ -64,6 +65,7 @@
 SRCS += wl_play.cpp
 SRCS += wl_state.cpp
 SRCS += wl_text.cpp
+SRCS += datafile.cpp
 
 DEPS = $(filter %.d, $(SRCS:.c=.d) $(SRCS:.cpp=.d))
 OBJS = $(filter %.o, $(SRCS:.c=.o) $(SRCS:.cpp=.o))
diff -Naur Wolf4SDL-1.7-src.orig//datafile.cpp Wolf4SDL-1.7-src/datafile.cpp
--- Wolf4SDL-1.7-src.orig//datafile.cpp	1969-12-31 19:00:00.000000000 -0500
+++ Wolf4SDL-1.7-src/datafile.cpp	2012-01-13 16:41:32.000000000 -0500
@@ -0,0 +1,60 @@
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "datafile.h"
+
+static char *datapath = NULL;
+
+static void set_data_path(void) {
+	if(datapath) return;
+	datapath = getenv("WOLF4PATH");
+	if(datapath) return;
+
+	// 20120113 bkw: should this be "C:\\WOLF3D" on Windows?
+	datapath = (char *)PREFIX "/share/games/wolf3d";
+}
+
+int datafile_exists(const char *file) {
+	char datafile[PATH_MAX];
+	struct stat statbuf;
+
+	set_data_path();
+
+	if(stat(file, &statbuf))
+		return 1;
+
+	sprintf(datafile, "%s/%s", datapath, file);
+	return stat(datafile, &statbuf);
+}
+
+int datafile_open(const char *file, int flags) {
+	char datafile[PATH_MAX];
+	int handle;
+
+	set_data_path();
+
+	if( (handle = open(file, flags)) > 0 )
+		return handle;
+
+	sprintf(datafile, "%s/%s", datapath, file);
+	return open(datafile, flags);
+}
+
+FILE *datafile_fopen(const char *file, const char *mode) {
+	char datafile[PATH_MAX];
+	FILE *f;
+
+	set_data_path();
+
+	if( (f = fopen(file, mode)) )
+		return f;
+
+	sprintf(datafile, "%s/%s", datapath, file);
+	return fopen(datafile, mode);
+}
diff -Naur Wolf4SDL-1.7-src.orig//datafile.h Wolf4SDL-1.7-src/datafile.h
--- Wolf4SDL-1.7-src.orig//datafile.h	1969-12-31 19:00:00.000000000 -0500
+++ Wolf4SDL-1.7-src/datafile.h	2012-01-13 16:41:41.000000000 -0500
@@ -0,0 +1,22 @@
+
+#include <stdio.h>
+/*
+20120113 bkw:
+Functions for loading game data files.
+
+All these functions search for files in:
+
+- The current directory
+- The directory specified by $WOLF4PATH if set
+- If WOLF4PATH not set, fall back to PREFIX/share/games/wolf3d
+
+*/
+
+/* returns true if file exists in the data path, otherwise false */
+int datafile_exists(const char *file);
+
+/* returns a filehandle to the file if found, or -1 if not */
+int datafile_open(const char *file, int flags);
+
+/* returns a FILE* if found, or NULL if not */
+FILE *datafile_fopen(const char *file, const char *mode);
diff -Naur Wolf4SDL-1.7-src.orig//id_ca.cpp Wolf4SDL-1.7-src/id_ca.cpp
--- Wolf4SDL-1.7-src.orig//id_ca.cpp	2009-02-24 15:13:22.000000000 -0500
+++ Wolf4SDL-1.7-src/id_ca.cpp	2012-01-13 16:40:25.000000000 -0500
@@ -24,6 +24,7 @@
     #include <unistd.h>
 #endif
 
+#include "datafile.h"
 #include "wl_def.h"
 #pragma hdrstop
 
@@ -185,7 +186,7 @@
 {
     int32_t size;
 
-    const int handle = open(filename, O_RDONLY | O_BINARY);
+    const int handle = datafile_open(filename, O_RDONLY | O_BINARY);
     if (handle == -1)
         return false;
 
@@ -463,7 +464,7 @@
     strcpy(fname,gdictname);
     strcat(fname,graphext);
 
-    handle = open(fname, O_RDONLY | O_BINARY);
+    handle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (handle == -1)
         CA_CannotOpen(fname);
 
@@ -474,7 +475,7 @@
     strcpy(fname,gheadname);
     strcat(fname,graphext);
 
-    handle = open(fname, O_RDONLY | O_BINARY);
+    handle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (handle == -1)
         CA_CannotOpen(fname);
 
@@ -513,7 +514,7 @@
     strcpy(fname,gfilename);
     strcat(fname,graphext);
 
-    grhandle = open(fname, O_RDONLY | O_BINARY);
+    grhandle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (grhandle == -1)
         CA_CannotOpen(fname);
 
@@ -555,7 +556,7 @@
     strcpy(fname,mheadname);
     strcat(fname,extension);
 
-    handle = open(fname, O_RDONLY | O_BINARY);
+    handle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (handle == -1)
         CA_CannotOpen(fname);
 
@@ -574,14 +575,14 @@
     strcpy(fname, "gamemaps.");
     strcat(fname, extension);
 
-    maphandle = open(fname, O_RDONLY | O_BINARY);
+    maphandle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (maphandle == -1)
         CA_CannotOpen(fname);
 #else
     strcpy(fname,mfilename);
     strcat(fname,extension);
 
-    maphandle = open(fname, O_RDONLY | O_BINARY);
+    maphandle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (maphandle == -1)
         CA_CannotOpen(fname);
 #endif
@@ -646,7 +647,7 @@
     strcpy(fname,afilename);
     strcat(fname,audioext);
 
-    audiohandle = open(fname, O_RDONLY | O_BINARY);
+    audiohandle = datafile_open(fname, O_RDONLY | O_BINARY);
     if (audiohandle == -1)
         CA_CannotOpen(fname);
 }
diff -Naur Wolf4SDL-1.7-src.orig//id_pm.cpp Wolf4SDL-1.7-src/id_pm.cpp
--- Wolf4SDL-1.7-src.orig//id_pm.cpp	2008-05-25 04:40:50.000000000 -0400
+++ Wolf4SDL-1.7-src/id_pm.cpp	2012-01-13 16:42:23.000000000 -0500
@@ -1,3 +1,4 @@
+#include "datafile.h"
 #include "wl_def.h"
 
 int ChunksInFile;
@@ -19,7 +20,7 @@
     char fname[13] = "vswap.";
     strcat(fname,extension);
 
-    FILE *file = fopen(fname,"rb");
+    FILE *file = datafile_fopen(fname,"rb");
     if(!file)
         CA_CannotOpen(fname);
 
diff -Naur Wolf4SDL-1.7-src.orig//wl_menu.cpp Wolf4SDL-1.7-src/wl_menu.cpp
--- Wolf4SDL-1.7-src.orig//wl_menu.cpp	2010-11-01 13:17:58.000000000 -0400
+++ Wolf4SDL-1.7-src/wl_menu.cpp	2012-01-13 16:55:02.000000000 -0500
@@ -14,6 +14,7 @@
     #include <unistd.h>
 #endif
 
+#include "datafile.h"
 #include "wl_def.h"
 #pragma hdrstop
 
@@ -4029,12 +4030,12 @@
 //
 #ifdef JAPAN
 #ifdef JAPDEMO
-    if(!stat("vswap.wj1", &statbuf))
+    if(datafile_exists("vswap.wj1"))
     {
         strcpy (extension, "wj1");
         numEpisodesMissing = 5;
 #else
-    if(!stat("vswap.wj6", &statbuf))
+    if(datafile_exists("vswap.wj6"))
     {
         strcpy (extension, "wj6");
 #endif
@@ -4052,7 +4053,7 @@
 // ENGLISH
 //
 #ifdef UPLOAD
-    if(!stat("vswap.wl1", &statbuf))
+    if(datafile_exists("vswap.wl1"))
     {
         strcpy (extension, "wl1");
         numEpisodesMissing = 5;
@@ -4061,7 +4062,7 @@
         Quit ("NO WOLFENSTEIN 3-D DATA FILES to be found!");
 #else
 #ifndef SPEAR
-    if(!stat("vswap.wl6", &statbuf))
+    if(datafile_exists("vswap.wl6"))
     {
         strcpy (extension, "wl6");
         NewEmenu[2].active =
@@ -4074,7 +4075,7 @@
     }
     else
     {
-        if(!stat("vswap.wl3", &statbuf))
+        if(datafile_exists("vswap.wl3"))
         {
             strcpy (extension, "wl3");
             numEpisodesMissing = 3;
@@ -4082,7 +4083,7 @@
         }
         else
         {
-            if(!stat("vswap.wl1", &statbuf))
+            if(datafile_exists("vswap.wl1"))
             {
                 strcpy (extension, "wl1");
                 numEpisodesMissing = 5;
@@ -4099,28 +4100,28 @@
 #ifndef SPEARDEMO
     if(param_mission == 0)
     {
-        if(!stat("vswap.sod", &statbuf))
+        if(datafile_exists("vswap.sod"))
             strcpy (extension, "sod");
         else
             Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
     }
     else if(param_mission == 1)
     {
-        if(!stat("vswap.sd1", &statbuf))
+        if(datafile_exists("vswap.sd1"))
             strcpy (extension, "sd1");
         else
             Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
     }
     else if(param_mission == 2)
     {
-        if(!stat("vswap.sd2", &statbuf))
+        if(datafile_exists("vswap.sd2"))
             strcpy (extension, "sd2");
         else
             Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
     }
     else if(param_mission == 3)
     {
-        if(!stat("vswap.sd3", &statbuf))
+        if(datafile_exists("vswap.sd3"))
             strcpy (extension, "sd3");
         else
             Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
@@ -4130,7 +4131,7 @@
     strcpy (graphext, "sod");
     strcpy (audioext, "sod");
 #else
-    if(!stat("vswap.sdm", &statbuf))
+    if(datafile_exists("vswap.sdm"))
     {
         strcpy (extension, "sdm");
     }