Move LibraryFileName to iolib.c, where it belongs
This commit is contained in:
parent
06bf31c32b
commit
e3ba66b328
8 changed files with 106 additions and 108 deletions
src
include
stratagus
ui
video
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "freecraft.h"
|
||||
#include "iolib.h"
|
||||
|
||||
#ifdef USE_CCL
|
||||
|
||||
|
|
|
@ -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\
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue