From 4415eb0e9e499d03c94d82032a76e7b235fa255b Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 4 Feb 2023 12:19:57 +0800 Subject: [PATCH] Genericize config paths Use CMake definitions to specify config paths and filenames. --- CMakeLists.txt | 2 ++ src/packages/game/IZ_app.c | 3 +-- src/packages/game/IZ_app_config.c | 2 +- src/packages/game/input/input.test.c | 28 +++++++++++++------------- src/packages/game/output/output.test.c | 2 +- src/packages/server/IZ_app.c | 2 +- src/packages/server/IZ_app_config.c | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 600ce4f..d45e443 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ add_definitions( -DIZ_PLAYERS=1 #-DIZ_LOG_DATE_FUNCTION=IZ_TimerElapsed -DIZ_LOG_DATE_FUNCTION=IZ_TimerNow + -DIZ_CONFIG_GAME_PATH="config-game.ini" + -DIZ_CONFIG_SERVER_PATH="config-server.ini" ) if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") diff --git a/src/packages/game/IZ_app.c b/src/packages/game/IZ_app.c index 994c3a2..54be353 100644 --- a/src/packages/game/IZ_app.c +++ b/src/packages/game/IZ_app.c @@ -84,12 +84,11 @@ void IZ_AppPrintHelpOptions() { "\n" "Options:\n" "\n" - " -c Specifies the path to the config file. (default: \"./config-game.ini\")\n" + " -c Specifies the path to the config file. (default: \"./" IZ_CONFIG_GAME_PATH "\")\n" " -f Specifies the frames per second. (default: 30)\n" " -h Displays this help screen.\n" " -i Specifies the interval of sending packets (default: 200)\n" " in milliseconds.\n" - ); } diff --git a/src/packages/game/IZ_app_config.c b/src/packages/game/IZ_app_config.c index d879e18..356972e 100644 --- a/src/packages/game/IZ_app_config.c +++ b/src/packages/game/IZ_app_config.c @@ -8,5 +8,5 @@ void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) { #endif IZ_memcpy(config_path, string_size, config_path_dir, 128); - IZ_strcat(config_path, string_size, "config-game.ini"); + IZ_strcat(config_path, string_size, IZ_CONFIG_GAME_PATH); } diff --git a/src/packages/game/input/input.test.c b/src/packages/game/input/input.test.c index 9af2a05..f7cea48 100644 --- a/src/packages/game/input/input.test.c +++ b/src/packages/game/input/input.test.c @@ -42,7 +42,7 @@ spec("input") { } it("sets initial state") { - IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL); + IZ_JoystickInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); // check(mock_is_called(IZ_memcpy), "Initial state not loaded."); check(mock_is_called(SDL_NumJoysticks), "Connected joysticks not checked."); @@ -51,7 +51,7 @@ spec("input") { it("calls load method") { mock_set_expected_calls(ini_getl, ((IZ_CONTROLS - 4) + 2) * IZ_PLAYERS); - IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL); + IZ_JoystickInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl), @@ -64,7 +64,7 @@ spec("input") { it("calls save method") { mock_set_expected_calls(ini_putl, ((IZ_CONTROLS - 4) + 2) * IZ_PLAYERS); - IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL); + IZ_JoystickInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), @@ -77,7 +77,7 @@ spec("input") { it("opens device handles") { mock_set_expected_calls(SDL_JoystickOpen, MOCK_OPEN_JOYSTICKS); - IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL); + IZ_JoystickInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(SDL_JoystickOpen) == mock_get_actual_calls(SDL_JoystickOpen), @@ -352,7 +352,7 @@ spec("input") { it("calls save method") { mock_set_expected_calls(ini_putl, ((IZ_CONTROLS - 4) + 2) * IZ_PLAYERS); - IZ_JoystickSaveConfig(&state, "config-game.ini"); + IZ_JoystickSaveConfig(&state, IZ_CONFIG_GAME_PATH); check( mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), @@ -417,7 +417,7 @@ spec("input") { } it("sets initial state") { - IZ_KeyboardInitialize(&state, "config-game.ini", 0, NULL); + IZ_KeyboardInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); // check(mock_is_called(IZ_memcpy), "Initial state not loaded."); } @@ -425,7 +425,7 @@ spec("input") { it("calls load method") { mock_set_expected_calls(ini_gets, IZ_CONTROLS * IZ_PLAYERS); - IZ_KeyboardInitialize(&state, "config-game.ini", 0, NULL); + IZ_KeyboardInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(ini_gets) == mock_get_actual_calls(ini_gets), @@ -438,7 +438,7 @@ spec("input") { it("calls save method") { mock_set_expected_calls(ini_puts, IZ_CONTROLS * IZ_PLAYERS); - IZ_KeyboardInitialize(&state, "config-game.ini", 0, NULL); + IZ_KeyboardInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts), @@ -505,7 +505,7 @@ spec("input") { it("calls save method") { mock_set_expected_calls(ini_puts, IZ_CONTROLS * IZ_PLAYERS); - IZ_KeyboardSaveConfig("config-game.ini", &state); + IZ_KeyboardSaveConfig(IZ_CONFIG_GAME_PATH, &state); check( mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts), @@ -550,7 +550,7 @@ spec("input") { } it("sets initial state") { - IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL); + IZ_MIDIInputInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); // check(mock_is_called(IZ_memcpy), "Initial state not loaded."); check(mock_is_called(Pm_CountDevices), "Connected MIDI devices not checked."); @@ -560,7 +560,7 @@ spec("input") { mock_set_expected_calls(ini_gets, IZ_CONTROLS * IZ_PLAYERS); mock_set_expected_calls(ini_getl, 2 * IZ_PLAYERS); - IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL); + IZ_MIDIInputInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(ini_gets) == mock_get_actual_calls(ini_gets), @@ -581,7 +581,7 @@ spec("input") { mock_set_expected_calls(ini_puts, IZ_CONTROLS * IZ_PLAYERS); mock_set_expected_calls(ini_putl, 2 * IZ_PLAYERS); - IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL); + IZ_MIDIInputInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts), @@ -601,7 +601,7 @@ spec("input") { it("opens device handles") { mock_set_expected_calls(Pm_OpenInput, MOCK_OPEN_JOYSTICKS); - IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL); + IZ_MIDIInputInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL); check( mock_get_expected_calls(Pm_OpenInput) == mock_get_actual_calls(Pm_OpenInput), @@ -627,7 +627,7 @@ spec("input") { mock_set_expected_calls(ini_puts, IZ_CONTROLS * IZ_PLAYERS); mock_set_expected_calls(ini_putl, 2 * IZ_PLAYERS); - IZ_MIDIInputSaveConfig("config-game.ini", &state); + IZ_MIDIInputSaveConfig(IZ_CONFIG_GAME_PATH, &state); check( mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts), diff --git a/src/packages/game/output/output.test.c b/src/packages/game/output/output.test.c index dfc68cc..12e29f1 100644 --- a/src/packages/game/output/output.test.c +++ b/src/packages/game/output/output.test.c @@ -44,7 +44,7 @@ spec("output") { it("calls save method") { mock_set_expected_calls(ini_putl, 3); - IZ_VideoSaveConfig(&state, "config-game.ini"); + IZ_VideoSaveConfig(&state, IZ_CONFIG_GAME_PATH); check( mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), diff --git a/src/packages/server/IZ_app.c b/src/packages/server/IZ_app.c index e030939..7b7290c 100644 --- a/src/packages/server/IZ_app.c +++ b/src/packages/server/IZ_app.c @@ -49,7 +49,7 @@ void IZ_AppPrintHelpOptions() { "\n" "Options:\n" "\n" - " -c Specifies the path to the config file. (default: \"./config-server.ini\")\n" + " -c Specifies the path to the config file. (default: \"./" IZ_CONFIG_SERVER_PATH "\")\n" " -d Specifies the path to the database. (default: \"./db.sqlite\")\n" " -h Displays this help screen.\n" " -m Specifies the message of the day. (default: \"\")\n" diff --git a/src/packages/server/IZ_app_config.c b/src/packages/server/IZ_app_config.c index 44924d5..8df3140 100644 --- a/src/packages/server/IZ_app_config.c +++ b/src/packages/server/IZ_app_config.c @@ -8,5 +8,5 @@ void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) { #endif IZ_memcpy(config_path, string_size, config_path_dir, 128); - IZ_strcat(config_path, string_size, "config-server.ini"); + IZ_strcat(config_path, string_size, IZ_CONFIG_SERVER_PATH); }