#!/bin/sh
# This is a shell archive
echo x alex4
mkdir -p alex4 > /dev/null 2>&1
echo x alex4/pkg-descr
sed 's/^X//' > alex4/pkg-descr << 'SHAR_END'
XIn the latest installment of the series Alex travels through the jungle
Xin search of his kidnapped girlfriend. Plenty of classic platforming
Xin four nice colors guaranteed! 
X
XWWW: http://allegator.sourceforge.net/
SHAR_END
echo x alex4/distinfo
sed 's/^X//' > alex4/distinfo << 'SHAR_END'
XSHA256 (alex4src_data.zip) = d266d7fba64fbfedf13240d3d0eb21b8bacbedeaa5f22b26a27d472c8d23f103
XSIZE (alex4src_data.zip) = 664561
XSHA256 (alex4.png) = 236a8d163ee8aa94073aa1ec969a85e887b3c70fefbcd03b1f41b93b09fa32c6
XSIZE (alex4.png) = 283
SHAR_END
echo x alex4/Makefile
sed 's/^X//' > alex4/Makefile << 'SHAR_END'
X# Created by: Nikolai Lifanov <lifanov@mail.lifanov.com>
X# $FreeBSD$
X
XPORTNAME=	alex4
XPORTVERSION=	1.1
XCATEGORIES=	games
XMASTER_SITES=	SF/allegator/Alex4/source%20and%20data/ \
X		SF/lifanov-ports-distfiles/games/${PORTNAME}/:icons
XDISTFILES=	alex4src_data.zip ${PORTNAME}.png:icons
XEXTRACT_ONLY=	alex4src_data.zip
X
XMAINTAINER=	lifanov@mail.lifanov.com
XCOMMENT=	Classic platformer with Alex the Allegator
X
XLICENSE=	GPLv2
XLICENSE_FILE=	${WRKSRC}/license.txt
X
XBUILD_DEPENDS=	${LOCALBASE}/lib/libaldmb.a:audio/dumb-allegro
XLIB_DEPENDS=	liballeg.so:devel/allegro
X
XDESKTOP_ENTRIES="Alex the Allegator 4" "" "${PORTNAME}" \
X		"${PORTNAME}" "Game;ActionGame;" ""
X
XWRKSRC=		 ${WRKDIR}/alex4src/src
X
XMAKE_JOBS_UNSAFE=yes
X
XUSES=	dos2unix gmake zip
X
Xpost-patch:
X	@${REINPLACE_CMD} \
X		-e 's,%%STAGEDIR%%,${STAGEDIR},g' \
X		-e 's,%%DATADIR%%,${DATADIR},g' \
X			${WRKSRC}/Makefile
X
Xpre-install:
X	${STRIP_CMD} ${WRKSRC}/alex4
X	${INSTALL_DATA} ${_DISTDIR}${PORTNAME}.png \
X		${STAGEDIR}${PREFIX}/share/pixmaps
X
X.include <bsd.port.mk>
SHAR_END
echo x alex4/files
mkdir -p alex4/files > /dev/null 2>&1
echo x alex4/pkg-plist
sed 's/^X//' > alex4/pkg-plist << 'SHAR_END'
Xbin/alex4
Xshare/pixmaps/alex4.png
X%%DATADIR%%/a45.dat
X%%DATADIR%%/data.dat
X%%DATADIR%%/maps.dat
X%%DATADIR%%/sfx_22.dat
SHAR_END
echo x alex4/files/patch-main.h
sed 's/^X//' > alex4/files/patch-main.h << 'SHAR_END'
X--- main.h.orig	2016-06-14 13:49:42.882747000 -0400
X+++ main.h
X@@ -93,5 +93,8 @@
X #define check_bb_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
X                                                         ((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) ))
X 
X+#ifndef DATADIR
X+#define DATADIR "data/"
X+#endif
X 
X #endif
SHAR_END
echo x alex4/files/patch-map.c
sed 's/^X//' > alex4/files/patch-map.c << 'SHAR_END'
X--- map.c.orig	2016-06-14 16:25:53 UTC
X+++ map.c
X@@ -24,6 +24,7 @@
X #include <stdlib.h>
X #include <stdio.h>
X #include <string.h>
X+#include <machine/endian.h>
X #include "allegro.h"
X #include "map.h"
X #include "timer.h"
X@@ -64,7 +65,41 @@ Tmap *create_map(int w, int h) {
X 
X 	return m;
X }
X-	
X+
X+static void mem_to_int(int *dest, unsigned char *mem)
X+{
X+#if __BYTE_ORDER == __LITTLE_ENDIAN
X+	memcpy(dest, mem, 4);
X+#else
X+	*dest = mem[0] | (((int)mem[1]) << 8) | (((int)mem[2]) << 16) |
X+		(((int)mem[3]) << 24);
X+#endif
X+}
X+
X+static void fread_int(int *dest, FILE *fp)
X+{
X+#if __BYTE_ORDER == __LITTLE_ENDIAN
X+	fread(dest, 4, 1, fp);
X+#else
X+	unsigned char buf[4];
X+	fread(buf, 1, 4, fp);
X+	mem_to_int(dest, buf);
X+#endif
X+}
X+
X+static void fwrite_int(const int *src, FILE *fp)
X+{
X+#if __BYTE_ORDER == __LITTLE_ENDIAN
X+	fwrite(src, 4, 1, fp);
X+#else
X+	unsigned char buf[4];
X+	buf[0] = *src;
X+	buf[1] = *src >> 8;
X+	buf[2] = *src >> 16;
X+	buf[3] = *src >> 24;
X+	fwrite(buf, 1, 4, fp);
X+#endif
X+}
X 
X // loads one splendind map from disk
X Tmap *load_map(char *fname) {
X@@ -93,7 +128,19 @@ Tmap *load_map(char *fname) {
X 	}
X 	
X 	// read datastruct
X-	fread(m, sizeof(Tmap), 1, fp);
X+	// a mapfile contain a raw dump of the Tmap struct made on an i386
X+	// the code below reads these struct dumps in an arch neutral manner
X+	// Note this dumps contains pointers, these are not used because these
X+	// ofcourse point to some no longer valid address.
X+	fread(m, 64, 1, fp);             // first 64 bytes data
X+	fread_int(&(m->width), fp);
X+	fread_int(&(m->height), fp);
X+	fread(header, 4, 1, fp);         // skip the first pointer
X+	fread_int(&(m->offset_x), fp);
X+	fread_int(&(m->offset_y), fp);
X+	fread(header, 4, 1, fp);         // skip the second pointer
X+	fread_int(&(m->start_x), fp);
X+	fread_int(&(m->start_y), fp);
X 
X 	// read map data
X 	m->dat = malloc(m->width * m->height * sizeof(Tmappos));
X@@ -116,8 +163,8 @@ Tmap *load_map(char *fname) {
X // loads one splendind map from memory
X Tmap *load_map_from_memory(void *mem) {
X 	Tmap *m;
X-	char header[6];
X-    char *c = (char *)mem;
X+	unsigned char header[6];
X+	unsigned char *c = (unsigned char *)mem;
X 
X 	
X 	// does the header match?
X@@ -137,9 +184,19 @@ Tmap *load_map_from_memory(void *mem) {
X 	}
X 	
X 	// read datastruct
X-	// fread(m, sizeof(Tmap), 1, fp);
X-	memcpy(m, c, sizeof(Tmap));
X-    c += sizeof(Tmap);
X+	// a mapfile contain a raw dump of the Tmap struct made on an i386
X+	// the code below reads these struct dumps in an arch neutral manner
X+	// Note this dumps contains pointers, these are not used because these
X+	// ofcourse point to some no longer valid address.
X+	memcpy(m, c, 64); c += 64;             // first 64 bytes data
X+	mem_to_int(&(m->width), c);  c += 4;
X+	mem_to_int(&(m->height), c); c += 4;
X+	c += 4;	                               // skip the first pointer
X+	mem_to_int(&(m->offset_x), c); c += 4;
X+	mem_to_int(&(m->offset_y), c); c += 4;
X+	c += 4;                                // skip the second pointer
X+	mem_to_int(&(m->start_x), c); c+= 4;
X+	mem_to_int(&(m->start_y), c); c+= 4;
X 
X 	// read map data
X 	m->dat = malloc(m->width * m->height * sizeof(Tmappos));
X@@ -174,7 +231,18 @@ int save_map(Tmap *m, char *fname) {
X 	fwrite(header, 6, 1, fp);
X 
X 	// write datastruct
X-	fwrite(m, sizeof(Tmap), 1, fp);
X+	// a mapfile should contain a raw dump of the Tmap struct as made on an
X+	// i386 the code below writes a struct dump as an i386 in an arch
X+	// neutral manner
X+	fwrite(m, 64, 1, fp);             // first 64 bytes data
X+	fwrite_int(&(m->width), fp);
X+	fwrite_int(&(m->height), fp);
X+	fwrite(header, 4, 1, fp);         // skip the first pointer
X+	fwrite_int(&(m->offset_x), fp);
X+	fwrite_int(&(m->offset_y), fp);
X+	fwrite(header, 4, 1, fp);         // skip the second pointer
X+	fwrite_int(&(m->start_x), fp);
X+	fwrite_int(&(m->start_y), fp);
X 
X 	// write map data
X 	fwrite(m->dat, sizeof(Tmappos), m->width * m->height, fp);
X@@ -409,7 +477,7 @@ int is_ground(Tmap *sm , int x, int y) {
X 	}
X 
X 	if (mask == 5 && oy > 31 - ox) return mask; // 45 degree slope / 
X-	if (mask == 6 && oy > ox) return mask;		// 45 degree slope \
X+	if (mask == 6 && oy > ox) return mask;		// 45 degree slope \ .
X 
X 	// the not so simple ones
X 	if (mask == 3 && oy > 31 - ox / 2) return mask;	// 22 degree slope / (low)
SHAR_END
echo x alex4/files/patch-shooter.h
sed 's/^X//' > alex4/files/patch-shooter.h << 'SHAR_END'
X--- shooter.h.orig	2016-06-14 16:25:53 UTC
X+++ shooter.h
X@@ -83,8 +83,8 @@ typedef struct {
X 	int difficulty;
X 
X 	// player related
X-	long unsigned int score;
X-	long unsigned int show_score;
X+	unsigned int score;
X+	unsigned int show_score;
X 	int lives;
X 	int power_gauge;
X 	int power_level;
X@@ -118,4 +118,4 @@ typedef struct {
X int start_shooter(Tcontrol *c, int with_sound);
X 
X 
X-#endif
X\ No newline at end of file
X+#endif
SHAR_END
echo x alex4/files/patch-token.c
sed 's/^X//' > alex4/files/patch-token.c << 'SHAR_END'
X--- token.c.orig	2016-06-14 16:25:53 UTC
X+++ token.c
X@@ -67,7 +67,7 @@ void insert_token(Ttoken *list, Ttoken *
X 
X // tokenizes the string str
X Ttoken *tokenize(char *str) {
X-    Ttoken *tok_list, *tok_tmp;
X+    Ttoken *tok_list, *tok_tmp = NULL;
X     char word[256];
X     int a, b, c;
X     int i = 0;
SHAR_END
echo x alex4/files/patch-unix.h
sed 's/^X//' > alex4/files/patch-unix.h << 'SHAR_END'
X--- unix.h.orig	2016-06-14 16:25:53 UTC
X+++ unix.h
X@@ -0,0 +1,6 @@
X+#ifdef __unix__
X+
X+char *get_homedir();
X+int check_and_create_dir(const char *name);
X+
X+#endif
SHAR_END
echo x alex4/files/patch-shooter.c
sed 's/^X//' > alex4/files/patch-shooter.c << 'SHAR_END'
X--- shooter.c.orig	2016-06-14 16:25:53 UTC
X+++ shooter.c
X@@ -1372,7 +1372,7 @@ int s_init_shooter() {
X 	// load data
X 	log2file(" loading shooter data");
X 	packfile_password(get_init_string());
X-	s_data = load_datafile("data/a45.dat");
X+	s_data = load_datafile(DATADIR "a45.dat");
X 	if (!s_data) {
X 		log2file(" *** failed");
X 		return -1;
SHAR_END
echo x alex4/files/patch-main.c
sed 's/^X//' > alex4/files/patch-main.c << 'SHAR_END'
X--- main.c.orig	2016-06-14 16:25:53 UTC
X+++ main.c
X@@ -38,6 +38,7 @@
X #include "main.h"
X #include "edit.h"
X #include "shooter.h"
X+#include "unix.h"
X 
X #include "../data/data.h"
X 
X@@ -66,7 +67,6 @@ PALETTE org_pal;
X Tscroller hscroll;
X Thisc *hisc_table;
X Thisc *hisc_table_space;
X-char working_directory[1024];
X 
X // the map
X Tmap *map = NULL;
X@@ -126,6 +126,7 @@ int menu_choice = 1;
X int playing_original_game = 1;
X int init_ok = 0;
X 
X+static FILE* log_fp = NULL;
X 
X 
X // // // // // // // // // // // // // // // // // // // // // 
X@@ -154,20 +155,18 @@ char *get_init_string() {
X // loggs the text to the text file
X void log2file(char *format, ...) {
X 	va_list ptr; /* get an arg pointer */
X- 	FILE *fp;
X 	
X-	fp = fopen("log.txt", "at");
X-	if (fp) {
X+	if (log_fp) {
X 		/* initialize ptr to point to the first argument after the format string */
X 		va_start(ptr, format);
X  
X 		/* Write to logfile. */
X-		vfprintf(fp, format, ptr); // Write passed text.
X-		fprintf(fp, "\n"); // New line..
X+		vfprintf(log_fp, format, ptr); // Write passed text.
X+		fprintf(log_fp, "\n"); // New line..
X  
X 		va_end(ptr);
X  
X-		fclose(fp);
X+		fflush(log_fp);
X 	}
X 
X }
X@@ -618,6 +617,10 @@ int init_game(const char *map_file) {
X 	BITMAP *bmp;
X 	int i;
X 	int w, h;
X+#ifdef __unix__   
X+	char filename[512];
X+	char *homedir = get_homedir();
X+#endif 	
X 
X 	log2file("\nInit routines:");
X 
X@@ -625,7 +628,13 @@ int init_game(const char *map_file) {
X 	log2file(" initializing allegro");
X 	text_mode(-1);
X 	garble_string(init_string, 53);
X+#ifdef __unix__
X+	snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
X+		homedir? homedir:".");
X+	override_config_file(filename);
X+#else
X 	set_config_file("alex4.ini");
X+#endif
X 	set_window_close_button(FALSE);
X 	
X 	// install timers
X@@ -695,6 +704,7 @@ int init_game(const char *map_file) {
X 	textout_centre(swap_screen, font, "loading...", 320, 200, 1);
X 	blit_to_screen(swap_screen);
X 
X+#ifndef __unix__
X 	// set switch modes and callbacks
X 	if (set_display_switch_mode(SWITCH_PAUSE) < 0)
X 		log2file("  * display switch mode failed");
X@@ -702,6 +712,7 @@ int init_game(const char *map_file) {
X 		log2file("  * display switch in failed");
X 	if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
X 		log2file("  * display switch out failed");
X+#endif
X 
X 
X 	// set win title (no! really???)
X@@ -718,7 +729,7 @@ int init_game(const char *map_file) {
X 	// load data
X 	log2file(" loading data");
X 	packfile_password(init_string);
X-	data = load_datafile("data/data.dat");
X+	data = load_datafile(DATADIR "data.dat");
X 	packfile_password(NULL);
X 	if (data == NULL) {
X     	log2file("  *** failed");
X@@ -728,7 +739,13 @@ int init_game(const char *map_file) {
X 
X 	// load options
X 	log2file(" loading options");
X+#ifdef __unix__
X+	snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
X+		homedir? homedir:".");
X+	pf = pack_fopen(filename, "rp");
X+#else
X 	pf = pack_fopen("alex4.sav", "rp");
X+#endif
X 	if (pf) {
X 		load_options(&options, pf);
X 		pack_fclose(pf);
X@@ -740,7 +757,13 @@ int init_game(const char *map_file) {
X 
X 	// loading highscores
X 	log2file(" loading hiscores");
X+#ifdef __unix__
X+	snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
X+		homedir? homedir:".");
X+	pf = pack_fopen(filename, "rp");
X+#else
X 	pf = pack_fopen("alex4.hi", "rp");
X+#endif
X 	if (pf) {
X 		load_hisc_table(hisc_table, pf);
X 		load_hisc_table(hisc_table_space, pf);
X@@ -776,7 +799,7 @@ int init_game(const char *map_file) {
X 		log2file(" loading original maps");
X 		packfile_password(init_string);
X 		num_levels = -1;  // skip end object when counting
X-		maps = load_datafile_callback("data/maps.dat", count_maps_callback);
X+		maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
X 		packfile_password(NULL);
X 		if (maps == NULL) {
X 	    	log2file("  *** failed");
X@@ -835,11 +858,12 @@ int init_game(const char *map_file) {
X 	// install sound
X 	log2file(" installing sound");
X    	set_volume_per_voice(0);
X-	switch(get_config_int("sound", "sound_device", 0)) {
X+	switch(get_config_int("sound", "sound_device", 1)) {
X 		case 1:
X 			i = DIGI_AUTODETECT;
X 			log2file("  DIGI_AUTODETECT selected (%d)", i);
X 			break;
X+#ifdef ALLEGRO_WINDOWS
X 		case 2:
X 			i = DIGI_DIRECTX(0);
X 			log2file("  DIGI_DIRECTX(0) selected (%d)", i);
X@@ -848,6 +872,20 @@ int init_game(const char *map_file) {
X 			i = DIGI_DIRECTAMX(0);
X 			log2file("  DIGI_DIRECTAMX(0) selected (%d)", i);
X 			break;
X+#elif defined ALLEGRO_UNIX
X+#ifdef DIGI_OSS
X+		case 2:
X+			i = DIGI_OSS;
X+			log2file("  DIGI_OSS selected (%d)", i);
X+			break;
X+#endif
X+#ifdef DIGI_ALSA
X+		case 3:
X+			i = DIGI_ALSA;
X+			log2file("  DIGI_ALSA selected (%d)", i);
X+			break;
X+#endif
X+#endif
X 		default:
X 			i = -770405;	// dummy number
X 			got_sound = 0;
X@@ -870,9 +908,9 @@ int init_game(const char *map_file) {
X 		if (get_config_int("sound", "use_sound_datafile", 1)) {
X 			log2file(" loading sound datafile");
X 			packfile_password(init_string);
X-			sfx_data = load_datafile("data/sfx_44.dat");
X+			sfx_data = load_datafile(DATADIR "sfx_44.dat");
X 			if (sfx_data == NULL) {
X-				sfx_data = load_datafile("data/sfx_22.dat");
X+				sfx_data = load_datafile(DATADIR "sfx_22.dat");
X 				log2file("  sfx_44.dat not found");
X 				s = 0;
X 			}
X@@ -971,6 +1009,10 @@ int init_game(const char *map_file) {
X void uninit_game() {
X 	int i;
X 	PACKFILE *pf;
X+#ifdef __unix__   
X+	char filename[512];
X+	char *homedir = get_homedir();
X+#endif 	
X 
X 	log2file("\nExit routines:");
X 
X@@ -989,14 +1031,26 @@ void uninit_game() {
X 	// only save if everything was inited ok!
X 	if (init_ok) {
X 		log2file(" saving options");
X+#ifdef __unix__
X+		snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
X+			homedir? homedir:".");
X+		pf = pack_fopen(filename, "wp");
X+#else
X 		pf = pack_fopen("alex4.sav", "wp");
X+#endif
X 		if (pf) {
X 			save_options(&options, pf);
X 			pack_fclose(pf);
X 		}
X 		
X 		log2file(" saving highscores");
X+#ifdef __unix__
X+		snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
X+			homedir? homedir:".");
X+		pf = pack_fopen(filename, "wp");
X+#else
X 		pf = pack_fopen("alex4.hi", "wp");
X+#endif
X 		if (pf) {
X 			save_hisc_table(hisc_table, pf);
X 			save_hisc_table(hisc_table_space, pf);
X@@ -1289,7 +1343,7 @@ void show_cutscene(int level) {
X 			// poll music machine
X 			if (got_sound) al_poll_duh(dp);
X 
X-			if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
X+			if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
X 				mode = 2;
X 			}
X 			
X@@ -1343,7 +1397,7 @@ void show_scores(int space, Thisc *table
X 	if (space) {
X 		// get space bg
X 		packfile_password(init_string);
X-		df = load_datafile_object("data/a45.dat", "BG1");
X+		df = load_datafile_object(DATADIR "a45.dat", "BG1");
X 		packfile_password(NULL);
X 		if (df != NULL)	{
X 			bg = df->dat;
X@@ -2149,7 +2203,7 @@ void check_alex_with_enemies() {
X 
X // calculates camera pos for map m considering player p
X void calculate_camera_pos(Tplayer *p, Tmap *m) {
X-	static camera_type = 1;
X+	static int camera_type = 1;
X 
X 	if (p->actor->status == AC_BALL) {
X 		camera_type = 2;
X@@ -2841,6 +2895,10 @@ int do_main_menu() {
X 			}
X 			else {
X 				PACKFILE *pf;
X+#ifdef __unix__   
X+				char filename[512];
X+				char *homedir = get_homedir();
X+#endif 	
X 				log2file(" level complete");
X 				if (got_sound) stop_music();
X 				if (level < MAX_LEVELS && playing_original_game) {
X@@ -2875,7 +2933,14 @@ int do_main_menu() {
X 
X 				// save options
X 				log2file(" saving options");
X+#ifdef __unix__
X+				snprintf(filename, sizeof(filename),
X+					"%s/.alex4/alex4.sav",
X+					homedir? homedir:".");
X+				pf = pack_fopen(filename, "wp");
X+#else
X 				pf = pack_fopen("alex4.sav", "wp");
X+#endif
X 				if (pf) {
X 					save_options(&options, pf);
X 					pack_fclose(pf);
X@@ -2969,24 +3034,36 @@ int do_main_menu() {
X 
X // main
X int main(int argc, char **argv) {   
X-	FILE *fp;
X 	int i;
X 	char full_path[1024];
X+#ifndef __unix__   
X+	char working_directory[1024];
X+#else
X+	char *homedir = get_homedir();
X+#endif
X 
X 	// init allegro
X 	allegro_init();
X 
X+#ifdef __unix__
X+	// start logfile
X+	snprintf(full_path, sizeof(full_path), "%s/.alex4",
X+		homedir? homedir:".");
X+	check_and_create_dir(full_path);
X+	snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
X+		homedir? homedir:".");
X+	log_fp = fopen(full_path, "wt");
X+#else
X 	// get working directory
X 	get_executable_name(full_path, 1024);
X 	replace_filename(working_directory, full_path, "", 1024);
X 	chdir(working_directory);
X 
X-
X 	// start logfile
X-	fp = fopen("log.txt", "wt");
X-	if (fp) {
X-		fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
X-		fclose(fp);
X+	log_fp = fopen("log.txt", "wt");
X+#endif
X+	if (log_fp) {
X+		fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
X 	}
X 
X 	// log program arguments
X@@ -2994,7 +3071,9 @@ int main(int argc, char **argv) {   
X 	for(i = 0; i < argc; i ++) {
X 		log2file("   %s", argv[i]);
X 	}
X+#ifndef __unix__
X 	log2file("Working directory is:\n   %s", working_directory);
X+#endif
X 
X 	// test wether to play real game
X 	// or custom levels
X@@ -3022,6 +3101,8 @@ int main(int argc, char **argv) {   
X 	uninit_game();
X 	allegro_exit();
X 	log2file("\nDone...\n");
X+	if (log_fp)
X+		fclose(log_fp);
X 
X 	return 0;
X } END_OF_MAIN(); 
SHAR_END
echo x alex4/files/patch-unix.c
sed 's/^X//' > alex4/files/patch-unix.c << 'SHAR_END'
X--- unix.c.orig	2016-06-14 16:25:53 UTC
X+++ unix.c
X@@ -0,0 +1,87 @@
X+#ifdef __unix__
X+#include <stdio.h>
X+#include <stdlib.h>
X+#include <unistd.h>
X+#include <pwd.h>
X+#include <errno.h>
X+#include <sys/types.h>
X+#include <sys/stat.h>
X+#if defined(__DECC) && defined(VMS)
X+#include <unixlib.h>
X+static char *vms_to_unix_buffer = NULL;
X+static int convert_vms_to_unix(char *vms_dir_name)
X+{
X+	vms_to_unix_buffer = vms_dir_name;
X+}
X+#endif
X+
X+char *get_homedir(void)
X+{
X+	struct passwd *pw;
X+	char *home;
X+
X+	home = getenv("HOME");
X+	if (home)
X+		return home;
X+
X+	if (!(pw = getpwuid(getuid())))
X+	{
X+		fprintf(stderr, "Who are you? Not found in passwd database!!\n");
X+		return NULL;
X+	}
X+
X+#if defined(__DECC) && defined(VMS)
X+	/* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
X+	   Format. */
X+	decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
X+	return vms_to_unix_buffer;
X+#else
X+	return pw->pw_dir;
X+#endif
X+}
X+//-----------------------------------------------------------------------------
X+int check_and_create_dir(const char *name)
X+{
X+	struct stat stat_buffer;
X+
X+	if (stat(name, &stat_buffer))
X+	{
X+		/* error check if it doesn't exist or something else is wrong */
X+		if (errno == ENOENT)
X+		{
X+			/* doesn't exist letts create it ;) */
X+#ifdef BSD43
X+			if (mkdir(name, 0775))
X+#else
X+				if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
X+#endif
X+				{
X+					fprintf(stderr, "Error creating dir %s", name);
X+					perror(" ");
X+					return -1;
X+				}
X+		}
X+		else
X+		{
X+			/* something else went wrong yell about it */
X+			fprintf(stderr, "Error opening %s", name);
X+			perror(" ");
X+			return -1;
X+		}
X+	}
X+	else
X+	{
X+		/* file exists check it's a dir otherwise yell about it */
X+#ifdef BSD43
X+		if (!(S_IFDIR & stat_buffer.st_mode))
X+#else
X+			if (!S_ISDIR(stat_buffer.st_mode))
X+#endif
X+			{
X+				fprintf(stderr,"Error %s exists but isn't a dir\n", name);
X+				return -1;
X+			}
X+	}
X+	return 0;
X+}
X+#endif
SHAR_END
echo x alex4/files/patch-Makefile
sed 's/^X//' > alex4/files/patch-Makefile << 'SHAR_END'
X--- Makefile.orig	2016-06-14 16:25:53 UTC
X+++ Makefile
X@@ -0,0 +1,23 @@
X+CFLAGS += `allegro-config --cflags`
X+LIBS = -laldmb -ldumb `allegro-config --libs` -lm
X+DEFINES = -DDATADIR=\"/usr/local/share/alex4/\"
X+OBJS    =  actor.o    edit.o  map.o       player.o    shooter.o unix.o \
X+           bullet.o   hisc.o  options.o   script.o    timer.o          \
X+           control.o  main.o  particle.o  scroller.o  token.o
X+
X+all: alex4
X+
X+alex4: $(OBJS)
X+	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
X+
X+%.o: %.c
X+	$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -o $@ -c $<
X+
X+install: alex4
X+	mkdir -p /var/poudriere/ports/test/games/alex4/work/stage$(LOCALBASE)/bin
X+	mkdir -p /var/poudriere/ports/test/games/alex4/work/stage/usr/local/share/alex4
X+	install -p -m 755 alex4 /var/poudriere/ports/test/games/alex4/work/stage$(LOCALBASE)/bin
X+	install -p -m 644 ../data/*.dat /var/poudriere/ports/test/games/alex4/work/stage/usr/local/share/alex4
X+
X+clean:
X+	rm -f $(OBJS) $(TARGET) *~
SHAR_END
exit
