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. --- emcc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'emcc.c') diff --git a/emcc.c b/emcc.c index eedfc35..31aedbd 100644 --- a/emcc.c +++ b/emcc.c @@ -987,7 +987,6 @@ int main(int argc, char **argv) */ { struct preset_menu *menu = midend_get_presets(me, &npresets); - char *env; bool may_configure = false; presets = snewn(npresets, game_params *); for (i = 0; i < npresets; i++) @@ -999,10 +998,7 @@ int main(int argc, char **argv) * Crude hack to allow the "Custom..." item to be hidden on * KaiOS, where dialogs don't yet work. */ - env = getenv("PUZZLES_ALLOW_CUSTOM"); - - if (thegame.can_configure && - (!env || env[0] == 'y' || env[0] == 'Y')) + if (thegame.can_configure && getenv_bool("PUZZLES_ALLOW_CUSTOM", true)) may_configure = true; if (may_configure) js_add_preset(0, "Custom...", -1); -- cgit v1.1