From 09c15f206edac18bd2158c189c821b9ba85d3939 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 22 Mar 2023 16:06:18 +0000 Subject: New shared function, getenv_bool() This provides a standard way to get a boolean from an environment variable. It treats the variable as true iff its value begins with 'y' or 'Y', like most of the current implementations. The function takes a default value which it returns if the environment variable is undefined. This replaces the various ad-hoc tests of environment variable scattered around and mostly doesn't change their behaviour. The exceptions are TOWERS_2D in Towers and DEBUG_PUZZLES in the Windows front end. Both of those were treated as true if they were defined at all, but now follow the same rules as other boolean environment variables. --- range.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'range.c') diff --git a/range.c b/range.c index c360b75..0887f9a 100644 --- a/range.c +++ b/range.c @@ -1324,10 +1324,8 @@ static char *interpret_move(const game_state *state, game_ui *ui, */ { static int swap_buttons = -1; - if (swap_buttons < 0) { - char *env = getenv("RANGE_SWAP_BUTTONS"); - swap_buttons = (env && (env[0] == 'y' || env[0] == 'Y')); - } + if (swap_buttons < 0) + swap_buttons = getenv_bool("RANGE_SWAP_BUTTONS", false); if (swap_buttons) { if (button == LEFT_BUTTON) button = RIGHT_BUTTON; -- cgit v1.1