From e663d12ea58746c210fe087874be89346d953cde Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 24 Mar 2004 14:35:11 +0000 Subject: [PATCH] - commited Michael George's config-file patch SVN-Revision: 332 --- src/Makefile.am | 2 ++ src/globals.h | 3 ++- src/high_scores.cpp | 47 ++++++++--------------------------------------- src/high_scores.h | 6 +++++- src/setup.cpp | 51 ++++++++++++++++++++++++++++++++++++--------------- src/setup.h | 1 + src/sound.cpp | 6 +++--- src/sound.h | 6 +++--- src/supertux.cpp | 2 +- src/worldmap.cpp | 4 ++-- 10 files changed, 63 insertions(+), 65 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 7e5fea56a..c43677857 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,8 @@ supertux_SOURCES = \ bitmask.h \ button.cpp \ button.h \ + configfile.h \ + configfile.cpp \ collision.cpp \ collision.h \ defines.h \ diff --git a/src/globals.h b/src/globals.h index c476a3cdc..9528e9440 100644 --- a/src/globals.h +++ b/src/globals.h @@ -36,7 +36,8 @@ extern char* level_startup_file; extern bool launch_worldmap_mode; /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ -extern char *st_dir, *st_save_dir; +extern char* st_dir; +extern char* st_save_dir; extern SDL_Joystick * js; diff --git a/src/high_scores.cpp b/src/high_scores.cpp index d2e71020c..9d6e2f1f0 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -15,47 +15,16 @@ #include "menu.h" #include "screen.h" #include "texture.h" +#include "setup.h" -int hs_score; -char hs_name[62]; /* highscores global variables*/ - -FILE * opendata(char * mode) -{ - char * filename = NULL; - FILE * fi; - - - filename = (char *) malloc(sizeof(char) * (strlen(st_dir) + - strlen("/st_highscore.dat") + 1)); - - strcpy(filename, st_dir); - /* Open the high score file: */ - -#ifndef WIN32 - strcat(filename, "/highscore"); +#ifdef WIN32 +const char * highscore_filename = "/st_highscore.dat"; #else - strcat(filename, "/st_highscore.dat"); +const char * highscore_filename = "/highscore"; #endif - - /* Try opening the file: */ - - fi = fopen(filename, mode); - free( filename ); - - if (fi == NULL) - { - fprintf(stderr, "Warning: Unable to open the high score file "); - - if (strcmp(mode, "r") == 0) - fprintf(stderr, "for read!!!\n"); - else if (strcmp(mode, "w") == 0) - fprintf(stderr, "for write!!!\n"); - - } - - return(fi); -} +int hs_score; +char hs_name[62]; /* highscores global variables*/ /* Load data from high score file: */ @@ -72,7 +41,7 @@ void load_hs(void) /* Try to open file: */ - fi = opendata("r"); + fi = opendata(highscore_filename, "r"); if (fi != NULL) { do @@ -162,7 +131,7 @@ void save_hs(int score) /* Try to open file: */ - fi = opendata("w"); + fi = opendata(highscore_filename, "w"); if (fi != NULL) { fprintf(fi, "# Supertux highscore file\n\n"); diff --git a/src/high_scores.h b/src/high_scores.h index d5dd38d68..1260d4088 100644 --- a/src/high_scores.h +++ b/src/high_scores.h @@ -5,6 +5,9 @@ */ +#ifndef SUPERTUX_HIGH_SCORES_H +#define SUPERTUX_HIGH_SCORES_H + #include extern int hs_score; @@ -12,4 +15,5 @@ extern char hs_name[62]; /* highscores global variables*/ void save_hs(int score); void load_hs(); -FILE * opendata(char * mode); + +#endif diff --git a/src/setup.cpp b/src/setup.cpp index d1ccad6d6..82326c870 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -37,6 +37,7 @@ #include "texture.h" #include "menu.h" #include "gameloop.h" +#include "configfile.h" #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) @@ -102,6 +103,36 @@ int fcreatedir(const char* relative_dir) } } +FILE * opendata(const char * rel_filename, const char * mode) +{ + char * filename = NULL; + FILE * fi; + + filename = (char *) malloc(sizeof(char) * (strlen(st_dir) + + strlen(rel_filename) + 1)); + + strcpy(filename, st_dir); + /* Open the high score file: */ + + strcat(filename, rel_filename); + + /* Try opening the file: */ + fi = fopen(filename, mode); + + if (fi == NULL) + { + fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename); + + if (strcmp(mode, "r") == 0) + fprintf(stderr, "for read!!!\n"); + else if (strcmp(mode, "w") == 0) + fprintf(stderr, "for write!!!\n"); + } + free( filename ); + + return(fi); +} + /* Get all names of sub-directories in a certain directory. */ /* Returns the number of sub-directories found. */ /* Note: The user has to free the allocated space. */ @@ -310,7 +341,7 @@ void st_directory_setup(void) } } #else - datadir = DATA_PREFIX; + datadir = DATA_PREFIX; #endif } printf("Datadir: %s\n", datadir.c_str()); @@ -781,16 +812,16 @@ void st_shutdown(void) { close_audio(); SDL_Quit(); + saveconfig(); } - /* --- ABORT! --- */ void st_abort(const std::string& reason, const std::string& details) { fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str()); st_shutdown(); - exit(1); + abort(); } @@ -841,17 +872,7 @@ void parseargs(int argc, char * argv[]) { int i; - /* Set defaults: */ - - - debug_mode = false; - use_fullscreen = false; - show_fps = false; - use_gl = false; - - use_sound = true; - use_music = true; - audio_device = true; + loadconfig(); /* Parse arguments: */ @@ -927,7 +948,7 @@ void parseargs(int argc, char * argv[]) } else if (strcmp(argv[i], "--help") == 0) - { /* Show help: */ + { /* Show help: */ puts("Super Tux " VERSION "\n" " Please see the file \"README.txt\" for more details.\n"); printf("Usage: %s [OPTIONS] FILENAME\n\n", argv[0]); diff --git a/src/setup.h b/src/setup.h index 3686d3fe5..a688ccc19 100644 --- a/src/setup.h +++ b/src/setup.h @@ -20,6 +20,7 @@ int faccessible(const char *filename); int fcreatedir(const char* relative_dir); int fwriteable(const char *filename); +FILE * opendata(const char * filename, const char * mode); string_list_type dsubdirs(const char *rel_path, const char* expected_file); string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str); void free_strings(char **strings, int num); diff --git a/src/sound.cpp b/src/sound.cpp index 173e30809..30a49a560 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -16,9 +16,9 @@ #include "setup.h" /*global variable*/ -int use_sound; /* handle sound on/off menu and command-line option */ -int use_music; /* handle music on/off menu and command-line option */ -int audio_device; /* != 0: available and initialized */ +bool use_sound; /* handle sound on/off menu and command-line option */ +bool use_music; /* handle music on/off menu and command-line option */ +bool audio_device; /* != 0: available and initialized */ int current_music; char * soundfilenames[NUM_SOUNDS] = { diff --git a/src/sound.h b/src/sound.h index 1a867b2f6..a7663e220 100644 --- a/src/sound.h +++ b/src/sound.h @@ -22,9 +22,9 @@ #define SOUND_RESERVED_CHANNELS 2 /*global variable*/ -extern int use_sound; /* handle sound on/off menu and command-line option */ -extern int use_music; /* handle music on/off menu and command-line option */ -extern int audio_device; /* != 0: available and initialized */ +extern bool use_sound; /* handle sound on/off menu and command-line option */ +extern bool use_music; /* handle music on/off menu and command-line option */ +extern bool audio_device; /* != 0: available and initialized */ /* enum of different internal music types */ enum Music_Type { diff --git a/src/supertux.cpp b/src/supertux.cpp index dd105e832..26da3cfe0 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -19,9 +19,9 @@ int main(int argc, char * argv[]) { int done; + st_directory_setup(); parseargs(argc, argv); - st_directory_setup(); st_audio_setup(); st_video_setup(); st_joystick_setup(); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 07bdd8de4..d56af648c 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -1,7 +1,7 @@ // $Id$ // -// Pingus - A free Lemmings clone -// Copyright (C) 2002 Ingo Ruhnke +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Ingo Ruhnke // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License -- 2.11.0