diff options
| -rw-r--r-- | emcc.c | 6 | ||||
| -rw-r--r-- | fifteen.c | 6 | ||||
| -rw-r--r-- | lightup.c | 7 | ||||
| -rw-r--r-- | loopy.c | 7 | ||||
| -rw-r--r-- | misc.c | 8 | ||||
| -rw-r--r-- | pearl.c | 3 | ||||
| -rw-r--r-- | puzzles.h | 2 | ||||
| -rw-r--r-- | range.c | 6 | ||||
| -rw-r--r-- | signpost.c | 6 | ||||
| -rw-r--r-- | slant.c | 6 | ||||
| -rw-r--r-- | towers.c | 2 | ||||
| -rw-r--r-- | windows.c | 2 |
12 files changed, 26 insertions, 35 deletions
@@ -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); @@ -714,10 +714,8 @@ static char *interpret_move(const game_state *state, game_ui *ui, return NULL; /* out of bounds */ } else if (IS_CURSOR_MOVE(button)) { static int invert_cursor = -1; - if (invert_cursor == -1) { - char *env = getenv("FIFTEEN_INVERT_CURSOR"); - invert_cursor = (env && (env[0] == 'y' || env[0] == 'Y')); - } + if (invert_cursor == -1) + invert_cursor = getenv_bool("FIFTEEN_INVERT_CURSOR", false); button = flip_cursor(button); /* the default */ if (invert_cursor) button = flip_cursor(button); /* undoes the first flip */ @@ -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, @@ -3292,11 +3292,8 @@ static void game_redraw_line(drawing *dr, game_drawstate *ds, if (line_colour == COL_FAINT) { static int draw_faint_lines = -1; - if (draw_faint_lines < 0) { - char *env = getenv("LOOPY_FAINT_LINES"); - draw_faint_lines = (!env || (env[0] == 'y' || - env[0] == 'Y')); - } + if (draw_faint_lines < 0) + draw_faint_lines = getenv_bool("LOOPY_FAINT_LINES", true); if (draw_faint_lines) draw_line(dr, x1, y1, x2, y2, line_colour); } else { @@ -198,6 +198,14 @@ char *fgetline(FILE *fp) return ret; } +bool getenv_bool(const char *name, bool dflt) +{ + char *env = getenv(name); + if (env == NULL) return dflt; + if (env[0] == 'y' || env[0] == 'Y') return true; + return false; +} + /* Utility functions for colour manipulation. */ static float colour_distance(const float a[3], const float b[3]) @@ -1929,8 +1929,7 @@ static int get_gui_style(void) static int gui_style = -1; if (gui_style == -1) { - char *env = getenv("PEARL_GUI_LOOPY"); - if (env && (env[0] == 'y' || env[0] == 'Y')) + if (getenv_bool("PEARL_GUI_LOOPY", false)) gui_style = GUI_LOOPY; else gui_style = GUI_MASYU; @@ -377,6 +377,8 @@ char *fgetline(FILE *fp); char *bin2hex(const unsigned char *in, int inlen); unsigned char *hex2bin(const char *in, int outlen); +bool getenv_bool(const char *name, bool dflt); + /* Mixes two colours in specified proportions. */ void colour_mix(const float src1[3], const float src2[3], float p, float dst[3]); @@ -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; @@ -2161,10 +2161,8 @@ static void game_redraw(drawing *dr, game_drawstate *ds, * yourself which is more brain-twisting :-) */ static int gear_mode = -1; - if (gear_mode < 0) { - char *env = getenv("SIGNPOST_GEARS"); - gear_mode = (env && (env[0] == 'y' || env[0] == 'Y')); - } + if (gear_mode < 0) + gear_mode = getenv_bool("SIGNPOST_GEARS", false); if (gear_mode) sign = 1 - 2 * ((x ^ y) & 1); else @@ -1681,10 +1681,8 @@ static char *interpret_move(const game_state *state, game_ui *ui, */ { static int swap_buttons = -1; - if (swap_buttons < 0) { - char *env = getenv("SLANT_SWAP_BUTTONS"); - swap_buttons = (env && (env[0] == 'y' || env[0] == 'Y')); - } + if (swap_buttons < 0) + swap_buttons = getenv_bool("SLANT_SWAP_BUTTONS", false); if (swap_buttons) { if (button == LEFT_BUTTON) button = RIGHT_BUTTON; @@ -1636,7 +1636,7 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state) int i; ds->tilesize = 0; - ds->three_d = !getenv("TOWERS_2D"); + ds->three_d = !getenv_bool("TOWERS_2D", false); ds->tiles = snewn((w+2)*(w+2), long); ds->drawn = snewn((w+2)*(w+2)*4, long); for (i = 0; i < (w+2)*(w+2)*4; i++) @@ -104,7 +104,7 @@ void debug_printf(const char *fmt, ...) static int debugging = -1; if (debugging == -1) - debugging = getenv("DEBUG_PUZZLES") ? 1 : 0; + debugging = getenv_bool("DEBUG_PUZZLES", false); if (debugging) { va_start(ap, fmt); |