Package-Name: rRootage
Gentoo-Package: games/action/rrootage
Requires: SDL SDL_mixer libbulletml
Homepage: http://www.asahi-net.or.jp/~cs8k-cyu/windows/rr.html
#Source: http://www.asahi-net.or.jp/~cs8k-cyu/windows/rr.html/(rr(\d+)_(\d+)\.zip)/[\0-\377]*?rr(\d+)_(\d+).zip $1.$2
Source: sourceforge:///rrootage/rRootage-(\d+(.\d+)+\w*).tar.gz $1
Zap-Before-Install: 1
Old-Repack:
	unzip "$(SOURCE)"
	test -d rRootage-"$(VERSION)" || mv rr* rRootage-"$(VERSION)"
	rm -f rRootage-"$(VERSION)"/{*.dll,*.exe,*.bat}
Repack:
	tar xzvfp "$(SOURCE)"
Compile:
	cp -pf readme.txt readme_e.txt "$(PREFIX)/"
	$(MAKE) -C src PROG='$$(NAME)' MORE_CFLAGS='-O3 $(GCC_OPT_FLAGS) -Wall -DDATAPREFIX=\"$(PREFIX)/share/games/rRootage\"' CPPFLAGS='$$(CFLAGS) -I/usr/include/bulletml '"`sdl-config --cflags`" LDFLAGS="-lGL -lGLU `sdl-config --libs` -lSDL_mixer -lbulletml"
	rm -rf "$(PREFIX)"/{bin,share}
	mkdir -p "$(PREFIX)"/{bin,share/games/rRootage}
	cp -p src/rr "$(PREFIX)"/bin/
	cp -a images morph morph_heavy normal psy reversible simple sounds "$(PREFIX)"/share/games/rRootage/
Install:
	$(MAKE) instbin BIN=rr
Patch: <<EOT
diff -ur ../rRootage-0.23-orig/src/Makefile src/Makefile
--- ../rRootage-0.23-orig/src/Makefile	2003-08-10 12:21:28 +0900
+++ src/Makefile	2005-07-07 06:31:11 +0900
@@ -21,11 +21,10 @@
 	foe.$(O) foecommand.$(O) barragemanager.$(O) boss.$(O) ship.$(O) laser.$(O) \
 	frag.$(O) background.$(O) letterrender.$(O) shot.$(O) \
 	screen.$(O) vector.$(O) degutil.$(O) rand.$(O) mt19937int.$(O) \
-	soundmanager.$(O) attractmanager.$(O) \
-	$(NAME)_res.$(O)
+	soundmanager.$(O) attractmanager.$(O)
 
 $(PROG): $(OBJS) 
-	$(CC) $(CFLAGS) -o $(PROG) $(OBJS) $(LDFLAGS)
+	$(CXX) $(CFLAGS) -o $(PROG) $(OBJS) $(LDFLAGS)
 
 $(NAME)_res.o: $(NAME).rc
 	windres -i $(NAME).rc -o $(NAME)_res.o
diff -ur ../rRootage-0.23-orig/src/attractmanager.c src/attractmanager.c
--- ../rRootage-0.23-orig/src/attractmanager.c	2003-04-26 12:24:16 +0900
+++ src/attractmanager.c	2005-07-07 06:13:06 +0900
@@ -34,7 +34,7 @@
 
 static HiScore hiScore;
 
-#define PREF_FILE "rr.prf"
+#define PREF_FILE ".rr.prf"
 #define DEFAULT_HISCORE 100000
 
 static void initHiScore() {
@@ -62,7 +62,11 @@
   FILE *fp;
   int i, j;
   int version;
-  if ( NULL == (fp = fopen(PREF_FILE,"rb")) ) {
+  char *home, pref_file[4096];
+  home = getenv("HOME");
+  snprintf(pref_file, sizeof(pref_file), "%s%s.rr.prf",
+           home ? home : "", home ? "/" : "");
+  if ( NULL == (fp = fopen(pref_file,"rb")) ) {
     initHiScore();
     return;
   }
@@ -86,7 +90,10 @@
 void savePreference() {
   FILE *fp;
   int i, j;
-  if ( NULL == (fp = fopen(PREF_FILE,"wb")) ) return;
+  char *home, pref_file[4096];
+  home = getenv("HOME");
+  snprintf(pref_file, "%s%s.rr.prf", home ? home : "", home ? "/" : "");
+  if ( NULL == (fp = fopen(pref_file,"wb")) ) return;
   putw(VERSION_NUM, fp);
   for ( j=0 ; j<MODE_NUM ; j++ ) {
     for ( i=0 ; i<STAGE_NUM ; i++ ) {
diff -ur ../rRootage-0.23-orig/src/barragemanager.cc src/barragemanager.cc
--- ../rRootage-0.23-orig/src/barragemanager.cc	2003-04-26 12:24:16 +0900
+++ src/barragemanager.cc	2005-07-07 06:29:24 +0900
@@ -26,20 +26,23 @@
   "normal", "reversible", "morph", "simple", "morph_heavy", "psy",
 };
 
-static int readBulletMLFiles(const char *dirPath, Barrage brg[]) {
+static int readBulletMLFiles(const char *dirName, Barrage brg[]) {
   DIR *dp;
   struct dirent *dir;
   int i = 0;
-  char fileName[256];
+  char fileName[4096], dirPath[4096];
+#ifdef DATAPREFIX
+  snprintf(dirPath, sizeof(dirPath), "%s/%s", DATAPREFIX, dirName);
+#else
+  dirPath = (char *)dirName;
+#endif
   if ( (dp = opendir(dirPath)) == NULL ) {
     fprintf(stderr, "Can't open directory: %s\n", dirPath);
     exit(1);
   }
   while ((dir = readdir(dp)) != NULL) {
     if ( strcmp(strrchr(dir->d_name, '.'), ".xml") != 0 ) continue; // Read .xml files.
-    strcpy(fileName, dirPath);
-    strcat(fileName, "/");
-    strncat(fileName, dir->d_name, sizeof(fileName)-strlen(fileName)-1);
+    snprintf(fileName, sizeof(fileName), "%s/%s", dirPath, dir->d_name);
     brg[i].bulletml = new BulletMLParserTinyXML(fileName);
     brg[i].bulletml->build(); i++;
     printf("%s\n", fileName);
diff -ur ../rRootage-0.23-orig/src/screen.c src/screen.c
--- ../rRootage-0.23-orig/src/screen.c	2003-08-10 12:21:28 +0900
+++ src/screen.c	2005-07-07 06:20:07 +0900
@@ -25,6 +25,12 @@
 #include "letterrender.h"
 #include "boss_mtd.h"
 
+#ifdef DATAPREFIX
+# define IMAGEPREFIX DATAPREFIX"/images/"
+#else
+# define IMAGEPREFIX "images/"
+#endif
+
 #define FAR_PLANE 720
 
 #define SCREEN_WIDTH 640
@@ -72,8 +78,8 @@
 void loadGLTexture(char *fileName, GLuint *texture) {
   SDL_Surface *surface;
 
-  char name[32];
-  strcpy(name, "images/");
+  char name[4096];
+  strcpy(name, IMAGEPREFIX);
   strcat(name, fileName);
   surface = SDL_LoadBMP(name);
   if ( !surface ) {
diff -ur ../rRootage-0.23-orig/src/soundmanager.c src/soundmanager.c
--- ../rRootage-0.23-orig/src/soundmanager.c	2003-04-26 12:24:16 +0900
+++ src/soundmanager.c	2005-07-07 06:19:53 +0900
@@ -20,6 +20,12 @@
 
 static int useAudio = 0;
 
+#ifdef DATAPREFIX
+# define SOUNDPREFIX DATAPREFIX"/sounds/"
+#else
+# define SOUNDPREFIX "sounds/"
+#endif
+
 #define MUSIC_NUM 3
 
 static char *musicFileName[MUSIC_NUM] = {
@@ -69,11 +75,10 @@
 
 static void loadSounds() {
   int i;
-  char name[32];
+  char name[4096];
 
   for ( i=0 ; i<MUSIC_NUM ; i++ ) {
-    strcpy(name, "sounds/");
-    strcat(name, musicFileName[i]);
+    snprintf(name, sizeof(name), "%s/%s", SOUNDPREFIX, musicFileName[i]);
     if ( NULL == (music[i] = Mix_LoadMUS(name)) ) {
       fprintf(stderr, "Couldn't load: %s\n", name);
       useAudio = 0;
@@ -81,8 +86,7 @@
     }
   }
   for ( i=0 ; i<CHUNK_NUM ; i++ ) {
-    strcpy(name, "sounds/");
-    strcat(name, chunkFileName[i]);
+    snprintf(name, sizeof(name), "%s/%s", SOUNDPREFIX, chunkFileName[i]);
     if ( NULL == (chunk[i] = Mix_LoadWAV(name)) ) {
       fprintf(stderr, "Couldn't load: %s\n", name);
       useAudio = 0;
EOT

/pkg/rRootage/
/usr/bin/rr
