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. --- lightup.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lightup.c') diff --git a/lightup.c b/lightup.c index 181c502..db9fa2d 100644 --- a/lightup.c +++ b/lightup.c @@ -2168,11 +2168,8 @@ static void tile_redraw(drawing *dr, game_drawstate *ds, lcol, COL_BLACK); } else if ((ds_flags & DF_IMPOSSIBLE)) { static int draw_blobs_when_lit = -1; - if (draw_blobs_when_lit < 0) { - char *env = getenv("LIGHTUP_LIT_BLOBS"); - draw_blobs_when_lit = (!env || (env[0] == 'y' || - env[0] == 'Y')); - } + if (draw_blobs_when_lit < 0) + draw_blobs_when_lit = getenv_bool("LIGHTUP_LIT_BLOBS", true); if (!(ds_flags & DF_LIT) || draw_blobs_when_lit) { int rlen = TILE_SIZE / 4; draw_rect(dr, dx + TILE_SIZE/2 - rlen/2, -- cgit v1.1