diff options
-rw-r--r-- | src/dirs.c | 56 | ||||
-rw-r--r-- | src/dirs.h (renamed from src/main.h) | 7 | ||||
-rw-r--r-- | src/help.c | 2 | ||||
-rw-r--r-- | src/local.mk | 3 | ||||
-rw-r--r-- | src/main-menu.c | 2 | ||||
-rw-r--r-- | src/main.c | 39 |
6 files changed, 66 insertions, 43 deletions
diff --git a/src/dirs.c b/src/dirs.c new file mode 100644 index 0000000..7d3f6ee --- /dev/null +++ b/src/dirs.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2021 P. J. McDermott + * + * This file is part of Dodge Balls + * + * Dodge Balls is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Dodge Balls is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Dodge Balls. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <libgen.h> +#include <stdlib.h> +#include <string.h> +#include "dirs.h" + +static const char *_db_games_dir; +static const char *_db_fonts_dir; + +void +db_find_dirs(char *program_name) +{ + char *program_dir; + + program_dir = realpath(dirname(program_name), NULL); + if (strcmp(program_dir, ABS_BUILDDIR) == 0) { + /* Running in place */ + _db_games_dir = ABS_BUILDDIR "/games"; + _db_fonts_dir = ABS_BUILDDIR "/fonts"; + } else { + /* Running from installation */ + _db_games_dir = GAMESDIR; + _db_fonts_dir = FONTSDIR; + } + free(program_dir); +} + +const char * +db_get_games_dir(void) +{ + return _db_games_dir; +} + +const char * +db_get_fonts_dir(void) +{ + return _db_fonts_dir; +} @@ -17,10 +17,11 @@ * along with Dodge Balls. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef DB_MAIN_H_ -#define DB_MAIN_H_ +#ifndef DB_DIRS_H_ +#define DB_DIRS_H_ +void db_find_dirs(char *program_name); const char *db_get_games_dir(void) __attribute__((__pure__)); const char *db_get_fonts_dir(void) __attribute__((__pure__)); -#endif /* DB_MAIN_H_ */ +#endif /* DB_DIRS_H_ */ @@ -22,8 +22,8 @@ #include <config.h> #include "collision.h" #include "defs.h" +#include "dirs.h" #include "help.h" -#include "main.h" #include "output.h" #include "util.h" diff --git a/src/local.mk b/src/local.mk index 34594ab..7bc031d 100644 --- a/src/local.mk +++ b/src/local.mk @@ -2,6 +2,8 @@ dodge_balls_SOURCES += \ %reldir%/collision.c \ %reldir%/collision.h \ %reldir%/defs.h \ + %reldir%/dirs.c \ + %reldir%/dirs.h \ %reldir%/game.c \ %reldir%/game.h \ %reldir%/help.c \ @@ -11,7 +13,6 @@ dodge_balls_SOURCES += \ %reldir%/main-menu.c \ %reldir%/main-menu.h \ %reldir%/main.c \ - %reldir%/main.h \ %reldir%/output.c \ %reldir%/output.h \ %reldir%/util.c \ diff --git a/src/main-menu.c b/src/main-menu.c index 74f8bff..f1f05c3 100644 --- a/src/main-menu.c +++ b/src/main-menu.c @@ -22,10 +22,10 @@ #include <stdlib.h> #include "collision.h" #include "defs.h" +#include "dirs.h" #include "game.h" #include "help.h" #include "main-menu.h" -#include "main.h" #include "output.h" #include "util.h" @@ -19,38 +19,15 @@ #include <SDL.h> #include <SDL_ttf.h> -#include <libgen.h> -#include <stdio.h> #include <stdlib.h> -#include <string.h> #include "defs.h" -#include "main.h" +#include "dirs.h" #include "main-menu.h" #include "output.h" -static const char *_db_games_dir; -static const char *_db_fonts_dir; static SDL_Window *_db_window; static SDL_Renderer *_db_renderer; -static void -_db_find_dirs(char *program_name) -{ - char *program_dir; - - program_dir = realpath(dirname(program_name), NULL); - if (strcmp(program_dir, ABS_BUILDDIR) == 0) { - /* Running in place */ - _db_games_dir = ABS_BUILDDIR "/games"; - _db_fonts_dir = ABS_BUILDDIR "/fonts"; - } else { - /* Running from installation */ - _db_games_dir = GAMESDIR; - _db_fonts_dir = FONTSDIR; - } - free(program_dir); -} - static int _db_init(void) { @@ -97,23 +74,11 @@ _db_quit(void) SDL_Quit(); } -const char * -db_get_games_dir(void) -{ - return _db_games_dir; -} - -const char * -db_get_fonts_dir(void) -{ - return _db_fonts_dir; -} - int main(int argc __attribute__((__unused__)), char *argv[]) { /* Find data directories */ - _db_find_dirs(argv[0]); + db_find_dirs(argv[0]); /* Initialize SDL libraries */ if (_db_init() < 0) { |