From b0c5479f13c40f0c8e07cc6b679408b56d8891c7 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 19 Mar 2021 19:31:49 -0400 Subject: db_get_*_dir(): Move out of src/main.c --- (limited to 'src') 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 . + */ + +#include +#include +#include +#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; +} diff --git a/src/main.h b/src/dirs.h index c6ce604..5a499de 100644 --- a/src/main.h +++ b/src/dirs.h @@ -17,10 +17,11 @@ * along with Dodge Balls. If not, see . */ -#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_ */ diff --git a/src/help.c b/src/help.c index 3195615..9a4e42d 100644 --- a/src/help.c +++ b/src/help.c @@ -22,8 +22,8 @@ #include #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 #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" diff --git a/src/main.c b/src/main.c index 4b5b25d..aa05340 100644 --- a/src/main.c +++ b/src/main.c @@ -19,38 +19,15 @@ #include #include -#include -#include #include -#include #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) { -- cgit v0.9.1