Codebase list alex4 / 4563594
alex4: Honor the HOME environment variable (Closes: #507950) git-svn-id: file:///svn/pkg-games/packages/trunk/alex4@9672 8808ee5c-780a-0410-9abb-a8188df92ce5 Peter De Wachter 15 years ago
3 changed file(s) with 777 addition(s) and 815 deletion(s). Raw diff Collapse all Expand all
55 [ Peter De Wachter ]
66 * Fixed a bug that the made level selection screen unresponsive on
77 some systems.
8 * Honor the HOME environment variable. (Closes: #507950)
89
9 -- Peter De Wachter <pdewacht@gmail.com> Tue, 05 May 2009 02:07:13 +0200
10 -- Peter De Wachter <pdewacht@gmail.com> Tue, 05 May 2009 02:08:14 +0200
1011
1112 alex4 (1.1-2) unstable; urgency=low
1213
+0
-814
debian/patches/from-fedora.patch less more
0 Hans de Goede's patch for Fedora.
1
2 Index: alex4-1.1/src/main.c
3 ===================================================================
4 --- alex4-1.1.orig/src/main.c 2008-01-26 21:33:48.000000000 +0100
5 +++ alex4-1.1/src/main.c 2008-01-26 21:34:05.000000000 +0100
6 @@ -38,6 +38,7 @@
7 #include "main.h"
8 #include "edit.h"
9 #include "shooter.h"
10 +#include "unix.h"
11
12 #include "../data/data.h"
13
14 @@ -66,7 +67,6 @@
15 Tscroller hscroll;
16 Thisc *hisc_table;
17 Thisc *hisc_table_space;
18 -char working_directory[1024];
19
20 // the map
21 Tmap *map = NULL;
22 @@ -126,6 +126,7 @@
23 int playing_original_game = 1;
24 int init_ok = 0;
25
26 +static FILE* log_fp = NULL;
27
28
29 // // // // // // // // // // // // // // // // // // // // //
30 @@ -154,20 +155,18 @@
31 // loggs the text to the text file
32 void log2file(char *format, ...) {
33 va_list ptr; /* get an arg pointer */
34 - FILE *fp;
35
36 - fp = fopen("log.txt", "at");
37 - if (fp) {
38 + if (log_fp) {
39 /* initialize ptr to point to the first argument after the format string */
40 va_start(ptr, format);
41
42 /* Write to logfile. */
43 - vfprintf(fp, format, ptr); // Write passed text.
44 - fprintf(fp, "\n"); // New line..
45 + vfprintf(log_fp, format, ptr); // Write passed text.
46 + fprintf(log_fp, "\n"); // New line..
47
48 va_end(ptr);
49
50 - fclose(fp);
51 + fflush(log_fp);
52 }
53
54 }
55 @@ -618,6 +617,10 @@
56 BITMAP *bmp;
57 int i;
58 int w, h;
59 +#ifdef __unix__
60 + char filename[512];
61 + char *homedir = get_homedir();
62 +#endif
63
64 log2file("\nInit routines:");
65
66 @@ -625,7 +628,13 @@
67 log2file(" initializing allegro");
68 text_mode(-1);
69 garble_string(init_string, 53);
70 +#ifdef __unix__
71 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
72 + homedir? homedir:".");
73 + override_config_file(filename);
74 +#else
75 set_config_file("alex4.ini");
76 +#endif
77 set_window_close_button(FALSE);
78
79 // install timers
80 @@ -695,6 +704,7 @@
81 textout_centre(swap_screen, font, "loading...", 320, 200, 1);
82 blit_to_screen(swap_screen);
83
84 +#ifndef __unix__
85 // set switch modes and callbacks
86 if (set_display_switch_mode(SWITCH_PAUSE) < 0)
87 log2file(" * display switch mode failed");
88 @@ -702,6 +712,7 @@
89 log2file(" * display switch in failed");
90 if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
91 log2file(" * display switch out failed");
92 +#endif
93
94
95 // set win title (no! really???)
96 @@ -718,7 +729,7 @@
97 // load data
98 log2file(" loading data");
99 packfile_password(init_string);
100 - data = load_datafile("data/data.dat");
101 + data = load_datafile(DATADIR "data.dat");
102 packfile_password(NULL);
103 if (data == NULL) {
104 log2file(" *** failed");
105 @@ -728,7 +739,13 @@
106
107 // load options
108 log2file(" loading options");
109 +#ifdef __unix__
110 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
111 + homedir? homedir:".");
112 + pf = pack_fopen(filename, "rp");
113 +#else
114 pf = pack_fopen("alex4.sav", "rp");
115 +#endif
116 if (pf) {
117 load_options(&options, pf);
118 pack_fclose(pf);
119 @@ -740,7 +757,13 @@
120
121 // loading highscores
122 log2file(" loading hiscores");
123 +#ifdef __unix__
124 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
125 + homedir? homedir:".");
126 + pf = pack_fopen(filename, "rp");
127 +#else
128 pf = pack_fopen("alex4.hi", "rp");
129 +#endif
130 if (pf) {
131 load_hisc_table(hisc_table, pf);
132 load_hisc_table(hisc_table_space, pf);
133 @@ -776,7 +799,7 @@
134 log2file(" loading original maps");
135 packfile_password(init_string);
136 num_levels = -1; // skip end object when counting
137 - maps = load_datafile_callback("data/maps.dat", count_maps_callback);
138 + maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
139 packfile_password(NULL);
140 if (maps == NULL) {
141 log2file(" *** failed");
142 @@ -835,11 +858,12 @@
143 // install sound
144 log2file(" installing sound");
145 set_volume_per_voice(0);
146 - switch(get_config_int("sound", "sound_device", 0)) {
147 + switch(get_config_int("sound", "sound_device", 1)) {
148 case 1:
149 i = DIGI_AUTODETECT;
150 log2file(" DIGI_AUTODETECT selected (%d)", i);
151 break;
152 +#ifdef ALLEGRO_WINDOWS
153 case 2:
154 i = DIGI_DIRECTX(0);
155 log2file(" DIGI_DIRECTX(0) selected (%d)", i);
156 @@ -848,6 +872,20 @@
157 i = DIGI_DIRECTAMX(0);
158 log2file(" DIGI_DIRECTAMX(0) selected (%d)", i);
159 break;
160 +#elif defined ALLEGRO_UNIX
161 +#ifdef DIGI_OSS
162 + case 2:
163 + i = DIGI_OSS;
164 + log2file(" DIGI_OSS selected (%d)", i);
165 + break;
166 +#endif
167 +#ifdef DIGI_ALSA
168 + case 3:
169 + i = DIGI_ALSA;
170 + log2file(" DIGI_ALSA selected (%d)", i);
171 + break;
172 +#endif
173 +#endif
174 default:
175 i = -770405; // dummy number
176 got_sound = 0;
177 @@ -870,9 +908,9 @@
178 if (get_config_int("sound", "use_sound_datafile", 1)) {
179 log2file(" loading sound datafile");
180 packfile_password(init_string);
181 - sfx_data = load_datafile("data/sfx_44.dat");
182 + sfx_data = load_datafile(DATADIR "sfx_44.dat");
183 if (sfx_data == NULL) {
184 - sfx_data = load_datafile("data/sfx_22.dat");
185 + sfx_data = load_datafile(DATADIR "sfx_22.dat");
186 log2file(" sfx_44.dat not found");
187 s = 0;
188 }
189 @@ -971,6 +1009,10 @@
190 void uninit_game() {
191 int i;
192 PACKFILE *pf;
193 +#ifdef __unix__
194 + char filename[512];
195 + char *homedir = get_homedir();
196 +#endif
197
198 log2file("\nExit routines:");
199
200 @@ -989,14 +1031,26 @@
201 // only save if everything was inited ok!
202 if (init_ok) {
203 log2file(" saving options");
204 +#ifdef __unix__
205 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
206 + homedir? homedir:".");
207 + pf = pack_fopen(filename, "wp");
208 +#else
209 pf = pack_fopen("alex4.sav", "wp");
210 +#endif
211 if (pf) {
212 save_options(&options, pf);
213 pack_fclose(pf);
214 }
215
216 log2file(" saving highscores");
217 +#ifdef __unix__
218 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
219 + homedir? homedir:".");
220 + pf = pack_fopen(filename, "wp");
221 +#else
222 pf = pack_fopen("alex4.hi", "wp");
223 +#endif
224 if (pf) {
225 save_hisc_table(hisc_table, pf);
226 save_hisc_table(hisc_table_space, pf);
227 @@ -1289,7 +1343,7 @@
228 // poll music machine
229 if (got_sound) al_poll_duh(dp);
230
231 - if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
232 + if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
233 mode = 2;
234 }
235
236 @@ -1343,7 +1397,7 @@
237 if (space) {
238 // get space bg
239 packfile_password(init_string);
240 - df = load_datafile_object("data/a45.dat", "BG1");
241 + df = load_datafile_object(DATADIR "a45.dat", "BG1");
242 packfile_password(NULL);
243 if (df != NULL) {
244 bg = df->dat;
245 @@ -2149,7 +2203,7 @@
246
247 // calculates camera pos for map m considering player p
248 void calculate_camera_pos(Tplayer *p, Tmap *m) {
249 - static camera_type = 1;
250 + static int camera_type = 1;
251
252 if (p->actor->status == AC_BALL) {
253 camera_type = 2;
254 @@ -2841,6 +2895,10 @@
255 }
256 else {
257 PACKFILE *pf;
258 +#ifdef __unix__
259 + char filename[512];
260 + char *homedir = get_homedir();
261 +#endif
262 log2file(" level complete");
263 if (got_sound) stop_music();
264 if (level < MAX_LEVELS && playing_original_game) {
265 @@ -2875,7 +2933,14 @@
266
267 // save options
268 log2file(" saving options");
269 +#ifdef __unix__
270 + snprintf(filename, sizeof(filename),
271 + "%s/.alex4/alex4.sav",
272 + homedir? homedir:".");
273 + pf = pack_fopen(filename, "wp");
274 +#else
275 pf = pack_fopen("alex4.sav", "wp");
276 +#endif
277 if (pf) {
278 save_options(&options, pf);
279 pack_fclose(pf);
280 @@ -2969,24 +3034,36 @@
281
282 // main
283 int main(int argc, char **argv) {
284 - FILE *fp;
285 int i;
286 char full_path[1024];
287 +#ifndef __unix__
288 + char working_directory[1024];
289 +#else
290 + char *homedir = get_homedir();
291 +#endif
292
293 // init allegro
294 allegro_init();
295
296 +#ifdef __unix__
297 + // start logfile
298 + snprintf(full_path, sizeof(full_path), "%s/.alex4",
299 + homedir? homedir:".");
300 + check_and_create_dir(full_path);
301 + snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
302 + homedir? homedir:".");
303 + log_fp = fopen(full_path, "wt");
304 +#else
305 // get working directory
306 get_executable_name(full_path, 1024);
307 replace_filename(working_directory, full_path, "", 1024);
308 chdir(working_directory);
309
310 -
311 // start logfile
312 - fp = fopen("log.txt", "wt");
313 - if (fp) {
314 - fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
315 - fclose(fp);
316 + log_fp = fopen("log.txt", "wt");
317 +#endif
318 + if (log_fp) {
319 + fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
320 }
321
322 // log program arguments
323 @@ -2994,7 +3071,9 @@
324 for(i = 0; i < argc; i ++) {
325 log2file(" %s", argv[i]);
326 }
327 +#ifndef __unix__
328 log2file("Working directory is:\n %s", working_directory);
329 +#endif
330
331 // test wether to play real game
332 // or custom levels
333 @@ -3022,6 +3101,8 @@
334 uninit_game();
335 allegro_exit();
336 log2file("\nDone...\n");
337 + if (log_fp)
338 + fclose(log_fp);
339
340 return 0;
341 } END_OF_MAIN();
342 Index: alex4-1.1/src/player.h
343 ===================================================================
344 --- alex4-1.1.orig/src/player.h 2008-01-26 21:33:48.000000000 +0100
345 +++ alex4-1.1/src/player.h 2008-01-26 21:34:05.000000000 +0100
346 @@ -60,4 +60,4 @@
347 void wound_player(Tplayer *p);
348 void kill_player(Tplayer *p);
349
350 -#endif
351 \ No newline at end of file
352 +#endif
353 Index: alex4-1.1/src/map.h
354 ===================================================================
355 --- alex4-1.1.orig/src/map.h 2008-01-26 21:33:48.000000000 +0100
356 +++ alex4-1.1/src/map.h 2008-01-26 21:34:05.000000000 +0100
357 @@ -111,4 +111,4 @@
358
359
360
361 -#endif
362 \ No newline at end of file
363 +#endif
364 Index: alex4-1.1/src/unix.c
365 ===================================================================
366 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
367 +++ alex4-1.1/src/unix.c 2008-01-26 21:36:41.000000000 +0100
368 @@ -0,0 +1,82 @@
369 +#ifdef __unix__
370 +#include <stdio.h>
371 +#include <stdlib.h>
372 +#include <unistd.h>
373 +#include <pwd.h>
374 +#include <errno.h>
375 +#include <sys/types.h>
376 +#include <sys/stat.h>
377 +#if defined(__DECC) && defined(VMS)
378 +#include <unixlib.h>
379 +static char *vms_to_unix_buffer = NULL;
380 +static int convert_vms_to_unix(char *vms_dir_name)
381 +{
382 + vms_to_unix_buffer = vms_dir_name;
383 +}
384 +#endif
385 +
386 +char *get_homedir(void)
387 +{
388 + struct passwd *pw;
389 +
390 + if (!(pw = getpwuid(getuid())))
391 + {
392 + fprintf(stderr, "Who are you? Not found in passwd database!!\n");
393 + return getenv("HOME");
394 + }
395 +
396 +#if defined(__DECC) && defined(VMS)
397 + /* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
398 + Format. */
399 + decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
400 + return vms_to_unix_buffer;
401 +#else
402 + return pw->pw_dir;
403 +#endif
404 +}
405 +//-----------------------------------------------------------------------------
406 +int check_and_create_dir(const char *name)
407 +{
408 + struct stat stat_buffer;
409 +
410 + if (stat(name, &stat_buffer))
411 + {
412 + /* error check if it doesn't exist or something else is wrong */
413 + if (errno == ENOENT)
414 + {
415 + /* doesn't exist letts create it ;) */
416 +#ifdef BSD43
417 + if (mkdir(name, 0775))
418 +#else
419 + if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
420 +#endif
421 + {
422 + fprintf(stderr, "Error creating dir %s", name);
423 + perror(" ");
424 + return -1;
425 + }
426 + }
427 + else
428 + {
429 + /* something else went wrong yell about it */
430 + fprintf(stderr, "Error opening %s", name);
431 + perror(" ");
432 + return -1;
433 + }
434 + }
435 + else
436 + {
437 + /* file exists check it's a dir otherwise yell about it */
438 +#ifdef BSD43
439 + if (!(S_IFDIR & stat_buffer.st_mode))
440 +#else
441 + if (!S_ISDIR(stat_buffer.st_mode))
442 +#endif
443 + {
444 + fprintf(stderr,"Error %s exists but isn't a dir\n", name);
445 + return -1;
446 + }
447 + }
448 + return 0;
449 +}
450 +#endif
451 Index: alex4-1.1/src/Makefile
452 ===================================================================
453 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
454 +++ alex4-1.1/src/Makefile 2008-01-26 21:36:26.000000000 +0100
455 @@ -0,0 +1,24 @@
456 +PREFIX = /usr/local
457 +DATADIR = $(PREFIX)/share/$(TARGET)
458 +CFLAGS = -g -Wall -Wno-deprecated-declarations -O2
459 +LDFLAGS = `allegro-config --libs` -laldmb -ldumb
460 +DEFINES = -DDATADIR=\"$(DATADIR)/\"
461 +OBJS = actor.o edit.o map.o player.o shooter.o unix.o \
462 + bullet.o hisc.o options.o script.o timer.o \
463 + control.o main.o particle.o scroller.o token.o
464 +TARGET = alex4
465 +
466 +$(TARGET): $(OBJS)
467 + $(CC) $(LDFLAGS) -o $@ $^
468 +
469 +%.o: %.c
470 + $(CC) $(CFLAGS) $(DEFINES) -o $@ -c $<
471 +
472 +install: $(TARGET)
473 + mkdir -p $(PREFIX)/bin
474 + mkdir -p $(DATADIR)
475 + install -p -m 755 $(TARGET) $(PREFIX)/bin
476 + install -p -m 644 ../data/*.dat $(DATADIR)
477 +
478 +clean:
479 + rm -f $(OBJS) $(TARGET) *~
480 Index: alex4-1.1/src/token.h
481 ===================================================================
482 --- alex4-1.1.orig/src/token.h 2008-01-26 21:33:48.000000000 +0100
483 +++ alex4-1.1/src/token.h 2008-01-26 21:34:05.000000000 +0100
484 @@ -41,4 +41,4 @@
485 Ttoken *tokenize(char *str);
486
487
488 -#endif
489 \ No newline at end of file
490 +#endif
491 Index: alex4-1.1/src/shooter.c
492 ===================================================================
493 --- alex4-1.1.orig/src/shooter.c 2008-01-26 21:33:49.000000000 +0100
494 +++ alex4-1.1/src/shooter.c 2008-01-26 21:34:05.000000000 +0100
495 @@ -1372,7 +1372,7 @@
496 // load data
497 log2file(" loading shooter data");
498 packfile_password(get_init_string());
499 - s_data = load_datafile("data/a45.dat");
500 + s_data = load_datafile(DATADIR "a45.dat");
501 if (!s_data) {
502 log2file(" *** failed");
503 return -1;
504 Index: alex4-1.1/src/particle.h
505 ===================================================================
506 --- alex4-1.1.orig/src/particle.h 2008-01-26 21:33:49.000000000 +0100
507 +++ alex4-1.1/src/particle.h 2008-01-26 21:34:05.000000000 +0100
508 @@ -54,4 +54,4 @@
509 void update_particle_with_map(Tparticle *p, Tmap *m);
510 void create_burst(Tparticle *ps, int x, int y, int spread, int num, int life, int bmp);
511
512 -#endif
513 \ No newline at end of file
514 +#endif
515 Index: alex4-1.1/src/unix.h
516 ===================================================================
517 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
518 +++ alex4-1.1/src/unix.h 2008-01-26 21:34:05.000000000 +0100
519 @@ -0,0 +1,6 @@
520 +#ifdef __unix__
521 +
522 +char *get_homedir();
523 +int check_and_create_dir(const char *name);
524 +
525 +#endif
526 Index: alex4-1.1/src/scroller.h
527 ===================================================================
528 --- alex4-1.1.orig/src/scroller.h 2008-01-26 21:33:49.000000000 +0100
529 +++ alex4-1.1/src/scroller.h 2008-01-26 21:34:05.000000000 +0100
530 @@ -51,4 +51,4 @@
531
532
533
534 -#endif
535 \ No newline at end of file
536 +#endif
537 Index: alex4-1.1/src/map.c
538 ===================================================================
539 --- alex4-1.1.orig/src/map.c 2008-01-26 21:33:49.000000000 +0100
540 +++ alex4-1.1/src/map.c 2008-01-26 21:34:05.000000000 +0100
541 @@ -24,6 +24,7 @@
542 #include <stdlib.h>
543 #include <stdio.h>
544 #include <string.h>
545 +#include <endian.h>
546 #include "allegro.h"
547 #include "map.h"
548 #include "timer.h"
549 @@ -64,7 +65,41 @@
550
551 return m;
552 }
553 -
554 +
555 +static void mem_to_int(int *dest, unsigned char *mem)
556 +{
557 +#if __BYTE_ORDER == __LITTLE_ENDIAN
558 + memcpy(dest, mem, 4);
559 +#else
560 + *dest = mem[0] | (((int)mem[1]) << 8) | (((int)mem[2]) << 16) |
561 + (((int)mem[3]) << 24);
562 +#endif
563 +}
564 +
565 +static void fread_int(int *dest, FILE *fp)
566 +{
567 +#if __BYTE_ORDER == __LITTLE_ENDIAN
568 + fread(dest, 4, 1, fp);
569 +#else
570 + unsigned char buf[4];
571 + fread(buf, 1, 4, fp);
572 + mem_to_int(dest, buf);
573 +#endif
574 +}
575 +
576 +static void fwrite_int(const int *src, FILE *fp)
577 +{
578 +#if __BYTE_ORDER == __LITTLE_ENDIAN
579 + fwrite(src, 4, 1, fp);
580 +#else
581 + unsigned char buf[4];
582 + buf[0] = *src;
583 + buf[1] = *src >> 8;
584 + buf[2] = *src >> 16;
585 + buf[3] = *src >> 24;
586 + fwrite(buf, 1, 4, fp);
587 +#endif
588 +}
589
590 // loads one splendind map from disk
591 Tmap *load_map(char *fname) {
592 @@ -93,7 +128,19 @@
593 }
594
595 // read datastruct
596 - fread(m, sizeof(Tmap), 1, fp);
597 + // a mapfile contain a raw dump of the Tmap struct made on an i386
598 + // the code below reads these struct dumps in an arch neutral manner
599 + // Note this dumps contains pointers, these are not used because these
600 + // ofcourse point to some no longer valid address.
601 + fread(m, 64, 1, fp); // first 64 bytes data
602 + fread_int(&(m->width), fp);
603 + fread_int(&(m->height), fp);
604 + fread(header, 4, 1, fp); // skip the first pointer
605 + fread_int(&(m->offset_x), fp);
606 + fread_int(&(m->offset_y), fp);
607 + fread(header, 4, 1, fp); // skip the second pointer
608 + fread_int(&(m->start_x), fp);
609 + fread_int(&(m->start_y), fp);
610
611 // read map data
612 m->dat = malloc(m->width * m->height * sizeof(Tmappos));
613 @@ -116,8 +163,8 @@
614 // loads one splendind map from memory
615 Tmap *load_map_from_memory(void *mem) {
616 Tmap *m;
617 - char header[6];
618 - char *c = (char *)mem;
619 + unsigned char header[6];
620 + unsigned char *c = (unsigned char *)mem;
621
622
623 // does the header match?
624 @@ -137,9 +184,19 @@
625 }
626
627 // read datastruct
628 - // fread(m, sizeof(Tmap), 1, fp);
629 - memcpy(m, c, sizeof(Tmap));
630 - c += sizeof(Tmap);
631 + // a mapfile contain a raw dump of the Tmap struct made on an i386
632 + // the code below reads these struct dumps in an arch neutral manner
633 + // Note this dumps contains pointers, these are not used because these
634 + // ofcourse point to some no longer valid address.
635 + memcpy(m, c, 64); c += 64; // first 64 bytes data
636 + mem_to_int(&(m->width), c); c += 4;
637 + mem_to_int(&(m->height), c); c += 4;
638 + c += 4; // skip the first pointer
639 + mem_to_int(&(m->offset_x), c); c += 4;
640 + mem_to_int(&(m->offset_y), c); c += 4;
641 + c += 4; // skip the second pointer
642 + mem_to_int(&(m->start_x), c); c+= 4;
643 + mem_to_int(&(m->start_y), c); c+= 4;
644
645 // read map data
646 m->dat = malloc(m->width * m->height * sizeof(Tmappos));
647 @@ -174,7 +231,18 @@
648 fwrite(header, 6, 1, fp);
649
650 // write datastruct
651 - fwrite(m, sizeof(Tmap), 1, fp);
652 + // a mapfile should contain a raw dump of the Tmap struct as made on an
653 + // i386 the code below writes a struct dump as an i386 in an arch
654 + // neutral manner
655 + fwrite(m, 64, 1, fp); // first 64 bytes data
656 + fwrite_int(&(m->width), fp);
657 + fwrite_int(&(m->height), fp);
658 + fwrite(header, 4, 1, fp); // skip the first pointer
659 + fwrite_int(&(m->offset_x), fp);
660 + fwrite_int(&(m->offset_y), fp);
661 + fwrite(header, 4, 1, fp); // skip the second pointer
662 + fwrite_int(&(m->start_x), fp);
663 + fwrite_int(&(m->start_y), fp);
664
665 // write map data
666 fwrite(m->dat, sizeof(Tmappos), m->width * m->height, fp);
667 @@ -409,7 +477,7 @@
668 }
669
670 if (mask == 5 && oy > 31 - ox) return mask; // 45 degree slope /
671 - if (mask == 6 && oy > ox) return mask; // 45 degree slope \
672 + if (mask == 6 && oy > ox) return mask; // 45 degree slope \ .
673
674 // the not so simple ones
675 if (mask == 3 && oy > 31 - ox / 2) return mask; // 22 degree slope / (low)
676 Index: alex4-1.1/src/shooter.h
677 ===================================================================
678 --- alex4-1.1.orig/src/shooter.h 2008-01-26 21:33:49.000000000 +0100
679 +++ alex4-1.1/src/shooter.h 2008-01-26 21:34:05.000000000 +0100
680 @@ -83,8 +83,8 @@
681 int difficulty;
682
683 // player related
684 - long unsigned int score;
685 - long unsigned int show_score;
686 + unsigned int score;
687 + unsigned int show_score;
688 int lives;
689 int power_gauge;
690 int power_level;
691 @@ -118,4 +118,4 @@
692 int start_shooter(Tcontrol *c, int with_sound);
693
694
695 -#endif
696 \ No newline at end of file
697 +#endif
698 Index: alex4-1.1/src/timer.h
699 ===================================================================
700 --- alex4-1.1.orig/src/timer.h 2008-01-26 21:33:49.000000000 +0100
701 +++ alex4-1.1/src/timer.h 2008-01-26 21:34:05.000000000 +0100
702 @@ -37,4 +37,4 @@
703 void fps_counter(void);
704 void cycle_counter(void);
705
706 -#endif
707 \ No newline at end of file
708 +#endif
709 Index: alex4-1.1/src/main.h
710 ===================================================================
711 --- alex4-1.1.orig/src/main.h 2008-01-26 21:33:49.000000000 +0100
712 +++ alex4-1.1/src/main.h 2008-01-26 21:34:05.000000000 +0100
713 @@ -93,5 +93,8 @@
714 #define check_bb_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
715 ((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) ))
716
717 +#ifndef DATADIR
718 +#define DATADIR "data/"
719 +#endif
720
721 -#endif
722 \ No newline at end of file
723 +#endif
724 Index: alex4-1.1/src/script.h
725 ===================================================================
726 --- alex4-1.1.orig/src/script.h 2008-01-26 21:33:49.000000000 +0100
727 +++ alex4-1.1/src/script.h 2008-01-26 21:34:05.000000000 +0100
728 @@ -51,4 +51,4 @@
729
730
731
732 -#endif
733 \ No newline at end of file
734 +#endif
735 Index: alex4-1.1/src/edit.h
736 ===================================================================
737 --- alex4-1.1.orig/src/edit.h 2008-01-26 21:33:49.000000000 +0100
738 +++ alex4-1.1/src/edit.h 2008-01-26 21:34:05.000000000 +0100
739 @@ -37,4 +37,4 @@
740 void draw_edit_mode(BITMAP *bmp, Tmap *map, int mx, int my);
741 void update_edit_mode(Tmap *map, BITMAP *bmp, int mx, int my, int mb);
742
743 -#endif
744 \ No newline at end of file
745 +#endif
746 Index: alex4-1.1/src/token.c
747 ===================================================================
748 --- alex4-1.1.orig/src/token.c 2008-01-26 21:33:49.000000000 +0100
749 +++ alex4-1.1/src/token.c 2008-01-26 21:34:05.000000000 +0100
750 @@ -67,7 +67,7 @@
751
752 // tokenizes the string str
753 Ttoken *tokenize(char *str) {
754 - Ttoken *tok_list, *tok_tmp;
755 + Ttoken *tok_list, *tok_tmp = NULL;
756 char word[256];
757 int a, b, c;
758 int i = 0;
759 Index: alex4-1.1/src/hisc.h
760 ===================================================================
761 --- alex4-1.1.orig/src/hisc.h 2008-01-26 21:33:49.000000000 +0100
762 +++ alex4-1.1/src/hisc.h 2008-01-26 21:34:05.000000000 +0100
763 @@ -48,4 +48,4 @@
764 void draw_hisc_post(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
765 void draw_hisc_table(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
766
767 -#endif
768 \ No newline at end of file
769 +#endif
770 Index: alex4-1.1/src/options.h
771 ===================================================================
772 --- alex4-1.1.orig/src/options.h 2008-01-26 21:33:49.000000000 +0100
773 +++ alex4-1.1/src/options.h 2008-01-26 21:34:05.000000000 +0100
774 @@ -43,4 +43,4 @@
775 void load_options(Toptions *o, PACKFILE *fp);
776 void reset_options(Toptions *o);
777
778 -#endif
779 \ No newline at end of file
780 +#endif
781 Index: alex4-1.1/src/timer.c
782 ===================================================================
783 --- alex4-1.1.orig/src/timer.c 2008-01-26 21:33:49.000000000 +0100
784 +++ alex4-1.1/src/timer.c 2008-01-26 21:34:05.000000000 +0100
785 @@ -60,4 +60,4 @@
786 game_count ++;
787
788 return TRUE;
789 -}
790 \ No newline at end of file
791 +}
792 Index: alex4-1.1/src/actor.h
793 ===================================================================
794 --- alex4-1.1.orig/src/actor.h 2008-01-26 21:33:49.000000000 +0100
795 +++ alex4-1.1/src/actor.h 2008-01-26 21:34:05.000000000 +0100
796 @@ -91,4 +91,4 @@
797 void kill_actor(Tactor *a);
798
799
800 -#endif
801 \ No newline at end of file
802 +#endif
803 Index: alex4-1.1/src/bullet.h
804 ===================================================================
805 --- alex4-1.1.orig/src/bullet.h 2008-01-26 21:33:49.000000000 +0100
806 +++ alex4-1.1/src/bullet.h 2008-01-26 21:34:05.000000000 +0100
807 @@ -52,4 +52,4 @@
808 void update_bullet(Tbullet *b);
809 void update_bullet_with_map(Tbullet *b, Tmap *m);
810
811 -#endif
812 \ No newline at end of file
813 +#endif
0 Hans de Goede's patch for Fedora.
1
2 --- a/src/main.c
3 +++ b/src/main.c
4 @@ -38,6 +38,7 @@
5 #include "main.h"
6 #include "edit.h"
7 #include "shooter.h"
8 +#include "unix.h"
9
10 #include "../data/data.h"
11
12 @@ -66,7 +67,6 @@
13 Tscroller hscroll;
14 Thisc *hisc_table;
15 Thisc *hisc_table_space;
16 -char working_directory[1024];
17
18 // the map
19 Tmap *map = NULL;
20 @@ -126,6 +126,7 @@
21 int playing_original_game = 1;
22 int init_ok = 0;
23
24 +static FILE* log_fp = NULL;
25
26
27 // // // // // // // // // // // // // // // // // // // // //
28 @@ -154,20 +155,18 @@
29 // loggs the text to the text file
30 void log2file(char *format, ...) {
31 va_list ptr; /* get an arg pointer */
32 - FILE *fp;
33
34 - fp = fopen("log.txt", "at");
35 - if (fp) {
36 + if (log_fp) {
37 /* initialize ptr to point to the first argument after the format string */
38 va_start(ptr, format);
39
40 /* Write to logfile. */
41 - vfprintf(fp, format, ptr); // Write passed text.
42 - fprintf(fp, "\n"); // New line..
43 + vfprintf(log_fp, format, ptr); // Write passed text.
44 + fprintf(log_fp, "\n"); // New line..
45
46 va_end(ptr);
47
48 - fclose(fp);
49 + fflush(log_fp);
50 }
51
52 }
53 @@ -618,6 +617,10 @@
54 BITMAP *bmp;
55 int i;
56 int w, h;
57 +#ifdef __unix__
58 + char filename[512];
59 + char *homedir = get_homedir();
60 +#endif
61
62 log2file("\nInit routines:");
63
64 @@ -625,7 +628,13 @@
65 log2file(" initializing allegro");
66 text_mode(-1);
67 garble_string(init_string, 53);
68 +#ifdef __unix__
69 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
70 + homedir? homedir:".");
71 + override_config_file(filename);
72 +#else
73 set_config_file("alex4.ini");
74 +#endif
75 set_window_close_button(FALSE);
76
77 // install timers
78 @@ -695,6 +704,7 @@
79 textout_centre(swap_screen, font, "loading...", 320, 200, 1);
80 blit_to_screen(swap_screen);
81
82 +#ifndef __unix__
83 // set switch modes and callbacks
84 if (set_display_switch_mode(SWITCH_PAUSE) < 0)
85 log2file(" * display switch mode failed");
86 @@ -702,6 +712,7 @@
87 log2file(" * display switch in failed");
88 if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
89 log2file(" * display switch out failed");
90 +#endif
91
92
93 // set win title (no! really???)
94 @@ -718,7 +729,7 @@
95 // load data
96 log2file(" loading data");
97 packfile_password(init_string);
98 - data = load_datafile("data/data.dat");
99 + data = load_datafile(DATADIR "data.dat");
100 packfile_password(NULL);
101 if (data == NULL) {
102 log2file(" *** failed");
103 @@ -728,7 +739,13 @@
104
105 // load options
106 log2file(" loading options");
107 +#ifdef __unix__
108 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
109 + homedir? homedir:".");
110 + pf = pack_fopen(filename, "rp");
111 +#else
112 pf = pack_fopen("alex4.sav", "rp");
113 +#endif
114 if (pf) {
115 load_options(&options, pf);
116 pack_fclose(pf);
117 @@ -740,7 +757,13 @@
118
119 // loading highscores
120 log2file(" loading hiscores");
121 +#ifdef __unix__
122 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
123 + homedir? homedir:".");
124 + pf = pack_fopen(filename, "rp");
125 +#else
126 pf = pack_fopen("alex4.hi", "rp");
127 +#endif
128 if (pf) {
129 load_hisc_table(hisc_table, pf);
130 load_hisc_table(hisc_table_space, pf);
131 @@ -776,7 +799,7 @@
132 log2file(" loading original maps");
133 packfile_password(init_string);
134 num_levels = -1; // skip end object when counting
135 - maps = load_datafile_callback("data/maps.dat", count_maps_callback);
136 + maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
137 packfile_password(NULL);
138 if (maps == NULL) {
139 log2file(" *** failed");
140 @@ -835,11 +858,12 @@
141 // install sound
142 log2file(" installing sound");
143 set_volume_per_voice(0);
144 - switch(get_config_int("sound", "sound_device", 0)) {
145 + switch(get_config_int("sound", "sound_device", 1)) {
146 case 1:
147 i = DIGI_AUTODETECT;
148 log2file(" DIGI_AUTODETECT selected (%d)", i);
149 break;
150 +#ifdef ALLEGRO_WINDOWS
151 case 2:
152 i = DIGI_DIRECTX(0);
153 log2file(" DIGI_DIRECTX(0) selected (%d)", i);
154 @@ -848,6 +872,20 @@
155 i = DIGI_DIRECTAMX(0);
156 log2file(" DIGI_DIRECTAMX(0) selected (%d)", i);
157 break;
158 +#elif defined ALLEGRO_UNIX
159 +#ifdef DIGI_OSS
160 + case 2:
161 + i = DIGI_OSS;
162 + log2file(" DIGI_OSS selected (%d)", i);
163 + break;
164 +#endif
165 +#ifdef DIGI_ALSA
166 + case 3:
167 + i = DIGI_ALSA;
168 + log2file(" DIGI_ALSA selected (%d)", i);
169 + break;
170 +#endif
171 +#endif
172 default:
173 i = -770405; // dummy number
174 got_sound = 0;
175 @@ -870,9 +908,9 @@
176 if (get_config_int("sound", "use_sound_datafile", 1)) {
177 log2file(" loading sound datafile");
178 packfile_password(init_string);
179 - sfx_data = load_datafile("data/sfx_44.dat");
180 + sfx_data = load_datafile(DATADIR "sfx_44.dat");
181 if (sfx_data == NULL) {
182 - sfx_data = load_datafile("data/sfx_22.dat");
183 + sfx_data = load_datafile(DATADIR "sfx_22.dat");
184 log2file(" sfx_44.dat not found");
185 s = 0;
186 }
187 @@ -971,6 +1009,10 @@
188 void uninit_game() {
189 int i;
190 PACKFILE *pf;
191 +#ifdef __unix__
192 + char filename[512];
193 + char *homedir = get_homedir();
194 +#endif
195
196 log2file("\nExit routines:");
197
198 @@ -989,14 +1031,26 @@
199 // only save if everything was inited ok!
200 if (init_ok) {
201 log2file(" saving options");
202 +#ifdef __unix__
203 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
204 + homedir? homedir:".");
205 + pf = pack_fopen(filename, "wp");
206 +#else
207 pf = pack_fopen("alex4.sav", "wp");
208 +#endif
209 if (pf) {
210 save_options(&options, pf);
211 pack_fclose(pf);
212 }
213
214 log2file(" saving highscores");
215 +#ifdef __unix__
216 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
217 + homedir? homedir:".");
218 + pf = pack_fopen(filename, "wp");
219 +#else
220 pf = pack_fopen("alex4.hi", "wp");
221 +#endif
222 if (pf) {
223 save_hisc_table(hisc_table, pf);
224 save_hisc_table(hisc_table_space, pf);
225 @@ -1289,7 +1343,7 @@
226 // poll music machine
227 if (got_sound) al_poll_duh(dp);
228
229 - if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
230 + if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
231 mode = 2;
232 }
233
234 @@ -1343,7 +1397,7 @@
235 if (space) {
236 // get space bg
237 packfile_password(init_string);
238 - df = load_datafile_object("data/a45.dat", "BG1");
239 + df = load_datafile_object(DATADIR "a45.dat", "BG1");
240 packfile_password(NULL);
241 if (df != NULL) {
242 bg = df->dat;
243 @@ -2149,7 +2203,7 @@
244
245 // calculates camera pos for map m considering player p
246 void calculate_camera_pos(Tplayer *p, Tmap *m) {
247 - static camera_type = 1;
248 + static int camera_type = 1;
249
250 if (p->actor->status == AC_BALL) {
251 camera_type = 2;
252 @@ -2841,6 +2895,10 @@
253 }
254 else {
255 PACKFILE *pf;
256 +#ifdef __unix__
257 + char filename[512];
258 + char *homedir = get_homedir();
259 +#endif
260 log2file(" level complete");
261 if (got_sound) stop_music();
262 if (level < MAX_LEVELS && playing_original_game) {
263 @@ -2875,7 +2933,14 @@
264
265 // save options
266 log2file(" saving options");
267 +#ifdef __unix__
268 + snprintf(filename, sizeof(filename),
269 + "%s/.alex4/alex4.sav",
270 + homedir? homedir:".");
271 + pf = pack_fopen(filename, "wp");
272 +#else
273 pf = pack_fopen("alex4.sav", "wp");
274 +#endif
275 if (pf) {
276 save_options(&options, pf);
277 pack_fclose(pf);
278 @@ -2969,24 +3034,36 @@
279
280 // main
281 int main(int argc, char **argv) {
282 - FILE *fp;
283 int i;
284 char full_path[1024];
285 +#ifndef __unix__
286 + char working_directory[1024];
287 +#else
288 + char *homedir = get_homedir();
289 +#endif
290
291 // init allegro
292 allegro_init();
293
294 +#ifdef __unix__
295 + // start logfile
296 + snprintf(full_path, sizeof(full_path), "%s/.alex4",
297 + homedir? homedir:".");
298 + check_and_create_dir(full_path);
299 + snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
300 + homedir? homedir:".");
301 + log_fp = fopen(full_path, "wt");
302 +#else
303 // get working directory
304 get_executable_name(full_path, 1024);
305 replace_filename(working_directory, full_path, "", 1024);
306 chdir(working_directory);
307
308 -
309 // start logfile
310 - fp = fopen("log.txt", "wt");
311 - if (fp) {
312 - fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
313 - fclose(fp);
314 + log_fp = fopen("log.txt", "wt");
315 +#endif
316 + if (log_fp) {
317 + fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
318 }
319
320 // log program arguments
321 @@ -2994,7 +3071,9 @@
322 for(i = 0; i < argc; i ++) {
323 log2file(" %s", argv[i]);
324 }
325 +#ifndef __unix__
326 log2file("Working directory is:\n %s", working_directory);
327 +#endif
328
329 // test wether to play real game
330 // or custom levels
331 @@ -3022,6 +3101,8 @@
332 uninit_game();
333 allegro_exit();
334 log2file("\nDone...\n");
335 + if (log_fp)
336 + fclose(log_fp);
337
338 return 0;
339 } END_OF_MAIN();
340 --- a/src/player.h
341 +++ b/src/player.h
342 @@ -60,4 +60,4 @@
343 void wound_player(Tplayer *p);
344 void kill_player(Tplayer *p);
345
346 -#endif
347 \ No newline at end of file
348 +#endif
349 --- a/src/map.h
350 +++ b/src/map.h
351 @@ -111,4 +111,4 @@
352
353
354
355 -#endif
356 \ No newline at end of file
357 +#endif
358 --- /dev/null
359 +++ b/src/unix.c
360 @@ -0,0 +1,87 @@
361 +#ifdef __unix__
362 +#include <stdio.h>
363 +#include <stdlib.h>
364 +#include <unistd.h>
365 +#include <pwd.h>
366 +#include <errno.h>
367 +#include <sys/types.h>
368 +#include <sys/stat.h>
369 +#if defined(__DECC) && defined(VMS)
370 +#include <unixlib.h>
371 +static char *vms_to_unix_buffer = NULL;
372 +static int convert_vms_to_unix(char *vms_dir_name)
373 +{
374 + vms_to_unix_buffer = vms_dir_name;
375 +}
376 +#endif
377 +
378 +char *get_homedir(void)
379 +{
380 + struct passwd *pw;
381 + char *home;
382 +
383 + home = getenv("HOME");
384 + if (home)
385 + return home;
386 +
387 + if (!(pw = getpwuid(getuid())))
388 + {
389 + fprintf(stderr, "Who are you? Not found in passwd database!!\n");
390 + return NULL;
391 + }
392 +
393 +#if defined(__DECC) && defined(VMS)
394 + /* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
395 + Format. */
396 + decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
397 + return vms_to_unix_buffer;
398 +#else
399 + return pw->pw_dir;
400 +#endif
401 +}
402 +//-----------------------------------------------------------------------------
403 +int check_and_create_dir(const char *name)
404 +{
405 + struct stat stat_buffer;
406 +
407 + if (stat(name, &stat_buffer))
408 + {
409 + /* error check if it doesn't exist or something else is wrong */
410 + if (errno == ENOENT)
411 + {
412 + /* doesn't exist letts create it ;) */
413 +#ifdef BSD43
414 + if (mkdir(name, 0775))
415 +#else
416 + if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
417 +#endif
418 + {
419 + fprintf(stderr, "Error creating dir %s", name);
420 + perror(" ");
421 + return -1;
422 + }
423 + }
424 + else
425 + {
426 + /* something else went wrong yell about it */
427 + fprintf(stderr, "Error opening %s", name);
428 + perror(" ");
429 + return -1;
430 + }
431 + }
432 + else
433 + {
434 + /* file exists check it's a dir otherwise yell about it */
435 +#ifdef BSD43
436 + if (!(S_IFDIR & stat_buffer.st_mode))
437 +#else
438 + if (!S_ISDIR(stat_buffer.st_mode))
439 +#endif
440 + {
441 + fprintf(stderr,"Error %s exists but isn't a dir\n", name);
442 + return -1;
443 + }
444 + }
445 + return 0;
446 +}
447 +#endif
448 --- /dev/null
449 +++ b/src/Makefile
450 @@ -0,0 +1,24 @@
451 +PREFIX = /usr/local
452 +DATADIR = $(PREFIX)/share/$(TARGET)
453 +CFLAGS = -g -Wall -Wno-deprecated-declarations -O2
454 +LDFLAGS = `allegro-config --libs` -laldmb -ldumb
455 +DEFINES = -DDATADIR=\"$(DATADIR)/\"
456 +OBJS = actor.o edit.o map.o player.o shooter.o unix.o \
457 + bullet.o hisc.o options.o script.o timer.o \
458 + control.o main.o particle.o scroller.o token.o
459 +TARGET = alex4
460 +
461 +$(TARGET): $(OBJS)
462 + $(CC) $(LDFLAGS) -o $@ $^
463 +
464 +%.o: %.c
465 + $(CC) $(CFLAGS) $(DEFINES) -o $@ -c $<
466 +
467 +install: $(TARGET)
468 + mkdir -p $(PREFIX)/bin
469 + mkdir -p $(DATADIR)
470 + install -p -m 755 $(TARGET) $(PREFIX)/bin
471 + install -p -m 644 ../data/*.dat $(DATADIR)
472 +
473 +clean:
474 + rm -f $(OBJS) $(TARGET) *~
475 --- a/src/token.h
476 +++ b/src/token.h
477 @@ -41,4 +41,4 @@
478 Ttoken *tokenize(char *str);
479
480
481 -#endif
482 \ No newline at end of file
483 +#endif
484 --- a/src/shooter.c
485 +++ b/src/shooter.c
486 @@ -1372,7 +1372,7 @@
487 // load data
488 log2file(" loading shooter data");
489 packfile_password(get_init_string());
490 - s_data = load_datafile("data/a45.dat");
491 + s_data = load_datafile(DATADIR "a45.dat");
492 if (!s_data) {
493 log2file(" *** failed");
494 return -1;
495 --- a/src/particle.h
496 +++ b/src/particle.h
497 @@ -54,4 +54,4 @@
498 void update_particle_with_map(Tparticle *p, Tmap *m);
499 void create_burst(Tparticle *ps, int x, int y, int spread, int num, int life, int bmp);
500
501 -#endif
502 \ No newline at end of file
503 +#endif
504 --- /dev/null
505 +++ b/src/unix.h
506 @@ -0,0 +1,6 @@
507 +#ifdef __unix__
508 +
509 +char *get_homedir();
510 +int check_and_create_dir(const char *name);
511 +
512 +#endif
513 --- a/src/scroller.h
514 +++ b/src/scroller.h
515 @@ -51,4 +51,4 @@
516
517
518
519 -#endif
520 \ No newline at end of file
521 +#endif
522 --- a/src/map.c
523 +++ b/src/map.c
524 @@ -24,6 +24,7 @@
525 #include <stdlib.h>
526 #include <stdio.h>
527 #include <string.h>
528 +#include <endian.h>
529 #include "allegro.h"
530 #include "map.h"
531 #include "timer.h"
532 @@ -64,7 +65,41 @@
533
534 return m;
535 }
536 -
537 +
538 +static void mem_to_int(int *dest, unsigned char *mem)
539 +{
540 +#if __BYTE_ORDER == __LITTLE_ENDIAN
541 + memcpy(dest, mem, 4);
542 +#else
543 + *dest = mem[0] | (((int)mem[1]) << 8) | (((int)mem[2]) << 16) |
544 + (((int)mem[3]) << 24);
545 +#endif
546 +}
547 +
548 +static void fread_int(int *dest, FILE *fp)
549 +{
550 +#if __BYTE_ORDER == __LITTLE_ENDIAN
551 + fread(dest, 4, 1, fp);
552 +#else
553 + unsigned char buf[4];
554 + fread(buf, 1, 4, fp);
555 + mem_to_int(dest, buf);
556 +#endif
557 +}
558 +
559 +static void fwrite_int(const int *src, FILE *fp)
560 +{
561 +#if __BYTE_ORDER == __LITTLE_ENDIAN
562 + fwrite(src, 4, 1, fp);
563 +#else
564 + unsigned char buf[4];
565 + buf[0] = *src;
566 + buf[1] = *src >> 8;
567 + buf[2] = *src >> 16;
568 + buf[3] = *src >> 24;
569 + fwrite(buf, 1, 4, fp);
570 +#endif
571 +}
572
573 // loads one splendind map from disk
574 Tmap *load_map(char *fname) {
575 @@ -93,7 +128,19 @@
576 }
577
578 // read datastruct
579 - fread(m, sizeof(Tmap), 1, fp);
580 + // a mapfile contain a raw dump of the Tmap struct made on an i386
581 + // the code below reads these struct dumps in an arch neutral manner
582 + // Note this dumps contains pointers, these are not used because these
583 + // ofcourse point to some no longer valid address.
584 + fread(m, 64, 1, fp); // first 64 bytes data
585 + fread_int(&(m->width), fp);
586 + fread_int(&(m->height), fp);
587 + fread(header, 4, 1, fp); // skip the first pointer
588 + fread_int(&(m->offset_x), fp);
589 + fread_int(&(m->offset_y), fp);
590 + fread(header, 4, 1, fp); // skip the second pointer
591 + fread_int(&(m->start_x), fp);
592 + fread_int(&(m->start_y), fp);
593
594 // read map data
595 m->dat = malloc(m->width * m->height * sizeof(Tmappos));
596 @@ -116,8 +163,8 @@
597 // loads one splendind map from memory
598 Tmap *load_map_from_memory(void *mem) {
599 Tmap *m;
600 - char header[6];
601 - char *c = (char *)mem;
602 + unsigned char header[6];
603 + unsigned char *c = (unsigned char *)mem;
604
605
606 // does the header match?
607 @@ -137,9 +184,19 @@
608 }
609
610 // read datastruct
611 - // fread(m, sizeof(Tmap), 1, fp);
612 - memcpy(m, c, sizeof(Tmap));
613 - c += sizeof(Tmap);
614 + // a mapfile contain a raw dump of the Tmap struct made on an i386
615 + // the code below reads these struct dumps in an arch neutral manner
616 + // Note this dumps contains pointers, these are not used because these
617 + // ofcourse point to some no longer valid address.
618 + memcpy(m, c, 64); c += 64; // first 64 bytes data
619 + mem_to_int(&(m->width), c); c += 4;
620 + mem_to_int(&(m->height), c); c += 4;
621 + c += 4; // skip the first pointer
622 + mem_to_int(&(m->offset_x), c); c += 4;
623 + mem_to_int(&(m->offset_y), c); c += 4;
624 + c += 4; // skip the second pointer
625 + mem_to_int(&(m->start_x), c); c+= 4;
626 + mem_to_int(&(m->start_y), c); c+= 4;
627
628 // read map data
629 m->dat = malloc(m->width * m->height * sizeof(Tmappos));
630 @@ -174,7 +231,18 @@
631 fwrite(header, 6, 1, fp);
632
633 // write datastruct
634 - fwrite(m, sizeof(Tmap), 1, fp);
635 + // a mapfile should contain a raw dump of the Tmap struct as made on an
636 + // i386 the code below writes a struct dump as an i386 in an arch
637 + // neutral manner
638 + fwrite(m, 64, 1, fp); // first 64 bytes data
639 + fwrite_int(&(m->width), fp);
640 + fwrite_int(&(m->height), fp);
641 + fwrite(header, 4, 1, fp); // skip the first pointer
642 + fwrite_int(&(m->offset_x), fp);
643 + fwrite_int(&(m->offset_y), fp);
644 + fwrite(header, 4, 1, fp); // skip the second pointer
645 + fwrite_int(&(m->start_x), fp);
646 + fwrite_int(&(m->start_y), fp);
647
648 // write map data
649 fwrite(m->dat, sizeof(Tmappos), m->width * m->height, fp);
650 @@ -409,7 +477,7 @@
651 }
652
653 if (mask == 5 && oy > 31 - ox) return mask; // 45 degree slope /
654 - if (mask == 6 && oy > ox) return mask; // 45 degree slope \
655 + if (mask == 6 && oy > ox) return mask; // 45 degree slope \ .
656
657 // the not so simple ones
658 if (mask == 3 && oy > 31 - ox / 2) return mask; // 22 degree slope / (low)
659 --- a/src/shooter.h
660 +++ b/src/shooter.h
661 @@ -83,8 +83,8 @@
662 int difficulty;
663
664 // player related
665 - long unsigned int score;
666 - long unsigned int show_score;
667 + unsigned int score;
668 + unsigned int show_score;
669 int lives;
670 int power_gauge;
671 int power_level;
672 @@ -118,4 +118,4 @@
673 int start_shooter(Tcontrol *c, int with_sound);
674
675
676 -#endif
677 \ No newline at end of file
678 +#endif
679 --- a/src/timer.h
680 +++ b/src/timer.h
681 @@ -37,4 +37,4 @@
682 void fps_counter(void);
683 void cycle_counter(void);
684
685 -#endif
686 \ No newline at end of file
687 +#endif
688 --- a/src/main.h
689 +++ b/src/main.h
690 @@ -93,5 +93,8 @@
691 #define check_bb_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
692 ((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) ))
693
694 +#ifndef DATADIR
695 +#define DATADIR "data/"
696 +#endif
697
698 -#endif
699 \ No newline at end of file
700 +#endif
701 --- a/src/script.h
702 +++ b/src/script.h
703 @@ -51,4 +51,4 @@
704
705
706
707 -#endif
708 \ No newline at end of file
709 +#endif
710 --- a/src/edit.h
711 +++ b/src/edit.h
712 @@ -37,4 +37,4 @@
713 void draw_edit_mode(BITMAP *bmp, Tmap *map, int mx, int my);
714 void update_edit_mode(Tmap *map, BITMAP *bmp, int mx, int my, int mb);
715
716 -#endif
717 \ No newline at end of file
718 +#endif
719 --- a/src/token.c
720 +++ b/src/token.c
721 @@ -67,7 +67,7 @@
722
723 // tokenizes the string str
724 Ttoken *tokenize(char *str) {
725 - Ttoken *tok_list, *tok_tmp;
726 + Ttoken *tok_list, *tok_tmp = NULL;
727 char word[256];
728 int a, b, c;
729 int i = 0;
730 --- a/src/hisc.h
731 +++ b/src/hisc.h
732 @@ -48,4 +48,4 @@
733 void draw_hisc_post(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
734 void draw_hisc_table(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
735
736 -#endif
737 \ No newline at end of file
738 +#endif
739 --- a/src/options.h
740 +++ b/src/options.h
741 @@ -43,4 +43,4 @@
742 void load_options(Toptions *o, PACKFILE *fp);
743 void reset_options(Toptions *o);
744
745 -#endif
746 \ No newline at end of file
747 +#endif
748 --- a/src/timer.c
749 +++ b/src/timer.c
750 @@ -60,4 +60,4 @@
751 game_count ++;
752
753 return TRUE;
754 -}
755 \ No newline at end of file
756 +}
757 --- a/src/actor.h
758 +++ b/src/actor.h
759 @@ -91,4 +91,4 @@
760 void kill_actor(Tactor *a);
761
762
763 -#endif
764 \ No newline at end of file
765 +#endif
766 --- a/src/bullet.h
767 +++ b/src/bullet.h
768 @@ -52,4 +52,4 @@
769 void update_bullet(Tbullet *b);
770 void update_bullet_with_map(Tbullet *b, Tmap *m);
771
772 -#endif
773 \ No newline at end of file
774 +#endif