From e3ba66b3280595cc26ba2032b423fb34223e3da4 Mon Sep 17 00:00:00 2001
From: ariclone <>
Date: Sat, 3 Jun 2000 12:43:41 +0000
Subject: [PATCH] Move LibraryFileName to iolib.c, where it belongs

---
 src/include/Makefile        |  2 +-
 src/include/freecraft.h     |  3 --
 src/include/iolib.h         |  4 ++
 src/stratagus/iolib.cpp     | 88 +++++++++++++++++++++++++++++++++++++
 src/stratagus/script.cpp    |  1 +
 src/stratagus/stratagus.cpp | 10 ++---
 src/ui/menus.cpp            | 18 +++-----
 src/video/graphic.cpp       | 88 +------------------------------------
 8 files changed, 106 insertions(+), 108 deletions(-)

diff --git a/src/include/Makefile b/src/include/Makefile
index 4087aa054..bfeaa0383 100644
--- a/src/include/Makefile
+++ b/src/include/Makefile
@@ -30,7 +30,7 @@ HDRS	= actions.h ai.h ccl.h freecraft.h construct.h cursor.h font.h icons.h \
 	  pud.h tileset.h unit.h unittype.h upgrade.h upgrade_structs.h \
 	  ccl_sound.h sound.h sound_id.h unitsound.h wav.h sound_server.h \
 	  video.h new_video.h network.h goal.h ui.h button.h menus.h \
-	  siod.h siodp.h compression.h depend.h myendian.h rdtsc.h \
+	  siod.h siodp.h iolib.h depend.h myendian.h rdtsc.h \
 	  etlib/generic.h etlib/xmalloc.h etlib/hash.h etlib/dllist.h
 
 all:
diff --git a/src/include/freecraft.h b/src/include/freecraft.h
index 321a5dc7d..48c0c52d5 100644
--- a/src/include/freecraft.h
+++ b/src/include/freecraft.h
@@ -310,9 +310,6 @@ extern void GameMainLoop(void);		/// game main loop
 extern char* strdcat(const char* l, const char* r);
      /// strdup + strcat + strcat
 extern char* strdcat3(const char* l, const char *m, const char* r);
- 
-    /// Build libary path name
-extern char* LibraryFileName(const char* file,char* buffer);
 
 /*============================================================================
 ==	Misc
diff --git a/src/include/iolib.h b/src/include/iolib.h
index f7a46920a..365f72424 100644
--- a/src/include/iolib.h
+++ b/src/include/iolib.h
@@ -79,8 +79,12 @@ extern int CLclose(CLFile *file);			  ///  Library file close
 extern int CLread(CLFile *file, void *buf, size_t len);	  ///  Library file read
 extern int CLseek(CLFile *file, long offset, int whence); ///  Library file seek
 
+
 #endif	// USE_ZLIB || USE_BZ2LIB
 
+    /// Build libary path name
+extern char* LibraryFileName(const char* file,char* buffer);
+
 //@}
 
 #endif	// !__IOLIB_H__
diff --git a/src/stratagus/iolib.cpp b/src/stratagus/iolib.cpp
index c7fdcc5a0..b292cb701 100644
--- a/src/stratagus/iolib.cpp
+++ b/src/stratagus/iolib.cpp
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
 
 #include "freecraft.h"
@@ -264,4 +265,91 @@ global int CLseek(CLFile *file, long offset, int whence)
 
 #endif	// USE_ZLIB || USE_BZ2LIB
 
+/**
+**	Generate a filename into library.
+**
+**	Try current directory, user home directory, global directory.
+**
+**	FIXME: I want also support files stored into tar/zip archives.
+**
+**	@param file	Filename to open.
+**	@param buffer	Allocated buffer for generated filename.
+**
+**	@return		Pointer to buffer.
+*/
+global char* LibraryFileName(const char* file,char* buffer)
+{
+    //
+    //	Absolute path or in current directory.
+    //
+    strcpy(buffer,file);
+    if( *buffer=='/' || !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#ifdef USE_ZLIB		// gzip or bzip2 in current directory
+    sprintf(buffer,"%s.gz",file);
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#endif
+#ifdef USE_BZ2LIB
+    sprintf(buffer,"%s.bz2",file);
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#endif
+
+    //
+    //	In user home directory
+    //
+    sprintf(buffer,"%s/%s/%s",getenv("HOME"),FREECRAFT_HOME_PATH,file);
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#ifdef USE_ZLIB		// gzip or bzip2 in user home directory
+    strcat(buffer,".gz");
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#endif
+#ifdef USE_BZ2LIB
+#ifndef USE_ZLIB
+    strcat(buffer,".bz2");
+#else
+    sprintf(buffer,"%s/%s/%s.bz2",getenv("HOME"),FREECRAFT_HOME_PATH,file);
+#endif
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#endif
+
+    //
+    //	In global shared directory
+    //
+    sprintf(buffer,"%s/%s",FreeCraftLibPath,file);
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#ifdef USE_ZLIB		// gzip or bzip2 in global shared directory
+    strcat(buffer,".gz");
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#endif
+#ifdef USE_BZ2LIB
+#ifndef USE_ZLIB
+    strcat(buffer,".bz2");
+#else
+    sprintf(buffer,"%s/%s.bz2",FreeCraftLibPath,file);
+#endif
+    if( !access(buffer,R_OK) ) {
+	return buffer;
+    }
+#endif
+    DebugLevel0(__FUNCTION__": File `%s' not found\n",file);
+
+    strcpy(buffer,file);
+    return buffer;
+}
+
 //@}
diff --git a/src/stratagus/script.cpp b/src/stratagus/script.cpp
index 51d91a298..5f65a53da 100644
--- a/src/stratagus/script.cpp
+++ b/src/stratagus/script.cpp
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 
 #include "freecraft.h"
+#include "iolib.h" 
 
 #ifdef USE_CCL
 
diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp
index 63fd23562..0e94f7331 100644
--- a/src/stratagus/stratagus.cpp
+++ b/src/stratagus/stratagus.cpp
@@ -431,9 +431,9 @@ global int main1(int argc __attribute__ ((unused)),
     }
     // FIXME: more races supported
 
-    printf("%s\n  written by Lutz Sammer, Fabrice Rossi, Vladi Shabanski, Patrice Fortier,\n  Jon Gabrielson and others."
+    printf("%s\n  written by Lutz Sammer, Fabrice Rossi, Vladi Shabanski, Patrice Fortier,\n  Jon Gabrielson, Andreas Arens and others."
 #ifdef USE_CCL2
-    " SIOD Copyright by George J. Carrette."
+    "\n  SIOD Copyright by George J. Carrette."
 #endif
     "\nCompile options "
 #ifdef USE_CCL
@@ -519,12 +519,12 @@ global volatile void Exit(int err)
 */
 local void Usage(void)
 {
-    printf("%s\n  written by Lutz Sammer, Fabrice Rossi, Vladi Shabanski, Patrice Fortier,\n  Jon Gabrielson and others."
+    printf("%s\n  written by Lutz Sammer, Fabrice Rossi, Vladi Shabanski, Patrice Fortier,\n  Jon Gabrielson, Andreas Arens and others."
 #ifdef USE_CCL2
-    " SIOD Copyright by George J. Carrette."
+    "\n  SIOD Copyright by George J. Carrette."
 #endif
 "\n\nUsage: freecraft [OPTIONS] [map.pud|map.pud.gz|map.cm|map.cm.gz]\n\
-\t-d datapath\tpath to clone data\n\
+\t-d datapath\tpath to freecraft data\n\
 \t-c file.ccl\tccl start file\n\
 \t-f factor\tComputer units cost factor\n\
 \t-h\t\tHelp shows this page\n\
diff --git a/src/ui/menus.cpp b/src/ui/menus.cpp
index 16de66ff3..3a2a2a300 100644
--- a/src/ui/menus.cpp
+++ b/src/ui/menus.cpp
@@ -38,7 +38,7 @@
 #include "new_video.h"
 
 #ifndef NEW_VIDEO
-#error ONLY WORKS WITH NEW VIDEO!
+//#error ONLY WORKS WITH NEW VIDEO!
 #endif
 
 /*----------------------------------------------------------------------------
@@ -762,35 +762,29 @@ global void ProcessMenu(int MenuId, int Loop)
     MenuButtonCurSel = -1;
     for (i = 0; i < menu->nitems; ++i) {
 	mi = menu->items + i;
-	// FIXME: Maybe activate if mouse-pointer is over it right now?
 	switch (mi->mitype) {
 	    case MI_TYPE_BUTTON:
+	    case MI_TYPE_PULLDOWN:
+	    case MI_TYPE_LISTBOX:
 		mi->flags &= ~(MenuButtonClicked|MenuButtonActive|MenuButtonSelected);
+		// FIXME: Maybe activate if mouse-pointer is over it right now?
 		if (i == menu->defsel) {
 		    mi->flags |= MenuButtonSelected;
 		    MenuButtonCurSel = i;
 		}
 		break;
+	}
+	switch (mi->mitype) {
 	    case MI_TYPE_PULLDOWN:
-		mi->flags &= ~(MenuButtonClicked|MenuButtonActive|MenuButtonSelected);
 		mi->d.pulldown.cursel = 0;
 		if (mi->d.pulldown.defopt != -1)
 		    mi->d.pulldown.curopt = mi->d.pulldown.defopt;
-		if (i == menu->defsel) {
-		    mi->flags |= MenuButtonSelected;
-		    MenuButtonCurSel = i;
-		}
 		break;
 	    case MI_TYPE_LISTBOX:
-		mi->flags &= ~(MenuButtonClicked|MenuButtonActive|MenuButtonSelected);
 		mi->d.listbox.cursel = 0;
 		mi->d.listbox.startline = 0;
 		if (mi->d.listbox.defopt != -1)
 		    mi->d.listbox.curopt = mi->d.listbox.defopt;
-		if (i == menu->defsel) {
-		    mi->flags |= MenuButtonSelected;
-		    MenuButtonCurSel = i;
-		}
 		break;
 	    default:
 		break;
diff --git a/src/video/graphic.cpp b/src/video/graphic.cpp
index 48bb62009..098ffa7c6 100644
--- a/src/video/graphic.cpp
+++ b/src/video/graphic.cpp
@@ -28,6 +28,7 @@
 
 #include "freecraft.h"
 #include "video.h"
+#include "iolib.h"
 
 /*----------------------------------------------------------------------------
 --	Declarations
@@ -453,93 +454,6 @@ global Graphic* NewGraphic(
     return MakeGraphic(depth,width,height,data,size);
 }
 
-/**
-**	Generate a filename into library.
-**
-**	Try current directory, user home directory, global directory.
-**
-**	FIXME: I want also support files stored into tar/zip archives.
-**
-**	@param file	Filename to open.
-**	@param buffer	Allocated buffer for generated filename.
-**
-**	@return		Pointer to buffer.
-*/
-global char* LibraryFileName(const char* file,char* buffer)
-{
-    //
-    //	Absolute path or in current directory.
-    //
-    strcpy(buffer,file);
-    if( *buffer=='/' || !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#ifdef USE_ZLIB		// gzip or bzip2 in current directory
-    sprintf(buffer,"%s.gz",file);
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#endif
-#ifdef USE_BZ2LIB
-    sprintf(buffer,"%s.bz2",file);
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#endif
-
-    //
-    //	In user home directory
-    //
-    sprintf(buffer,"%s/%s/%s",getenv("HOME"),FREECRAFT_HOME_PATH,file);
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#ifdef USE_ZLIB		// gzip or bzip2 in user home directory
-    strcat(buffer,".gz");
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#endif
-#ifdef USE_BZ2LIB
-#ifndef USE_ZLIB
-    strcat(buffer,".bz2");
-#else
-    sprintf(buffer,"%s/%s/%s.bz2",getenv("HOME"),FREECRAFT_HOME_PATH,file);
-#endif
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#endif
-
-    //
-    //	In global shared directory
-    //
-    sprintf(buffer,"%s/%s",FreeCraftLibPath,file);
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#ifdef USE_ZLIB		// gzip or bzip2 in global shared directory
-    strcat(buffer,".gz");
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#endif
-#ifdef USE_BZ2LIB
-#ifndef USE_ZLIB
-    strcat(buffer,".bz2");
-#else
-    sprintf(buffer,"%s/%s.bz2",FreeCraftLibPath,file);
-#endif
-    if( !access(buffer,R_OK) ) {
-	return buffer;
-    }
-#endif
-    DebugLevel0(__FUNCTION__": File `%s' not found\n",file);
-
-    strcpy(buffer,file);
-    return buffer;
-}
-
 /**
 **	creates a checksum used to compare palettes.
 **	JOSH: change the method if you have better ideas.