mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
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.
This commit is contained in:
6
emcc.c
6
emcc.c
@ -987,7 +987,6 @@ int main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
struct preset_menu *menu = midend_get_presets(me, &npresets);
|
struct preset_menu *menu = midend_get_presets(me, &npresets);
|
||||||
char *env;
|
|
||||||
bool may_configure = false;
|
bool may_configure = false;
|
||||||
presets = snewn(npresets, game_params *);
|
presets = snewn(npresets, game_params *);
|
||||||
for (i = 0; i < npresets; i++)
|
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
|
* Crude hack to allow the "Custom..." item to be hidden on
|
||||||
* KaiOS, where dialogs don't yet work.
|
* KaiOS, where dialogs don't yet work.
|
||||||
*/
|
*/
|
||||||
env = getenv("PUZZLES_ALLOW_CUSTOM");
|
if (thegame.can_configure && getenv_bool("PUZZLES_ALLOW_CUSTOM", true))
|
||||||
|
|
||||||
if (thegame.can_configure &&
|
|
||||||
(!env || env[0] == 'y' || env[0] == 'Y'))
|
|
||||||
may_configure = true;
|
may_configure = true;
|
||||||
if (may_configure)
|
if (may_configure)
|
||||||
js_add_preset(0, "Custom...", -1);
|
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 */
|
return NULL; /* out of bounds */
|
||||||
} else if (IS_CURSOR_MOVE(button)) {
|
} else if (IS_CURSOR_MOVE(button)) {
|
||||||
static int invert_cursor = -1;
|
static int invert_cursor = -1;
|
||||||
if (invert_cursor == -1) {
|
if (invert_cursor == -1)
|
||||||
char *env = getenv("FIFTEEN_INVERT_CURSOR");
|
invert_cursor = getenv_bool("FIFTEEN_INVERT_CURSOR", false);
|
||||||
invert_cursor = (env && (env[0] == 'y' || env[0] == 'Y'));
|
|
||||||
}
|
|
||||||
button = flip_cursor(button); /* the default */
|
button = flip_cursor(button); /* the default */
|
||||||
if (invert_cursor)
|
if (invert_cursor)
|
||||||
button = flip_cursor(button); /* undoes the first flip */
|
button = flip_cursor(button); /* undoes the first flip */
|
||||||
|
@ -2168,11 +2168,8 @@ static void tile_redraw(drawing *dr, game_drawstate *ds,
|
|||||||
lcol, COL_BLACK);
|
lcol, COL_BLACK);
|
||||||
} else if ((ds_flags & DF_IMPOSSIBLE)) {
|
} else if ((ds_flags & DF_IMPOSSIBLE)) {
|
||||||
static int draw_blobs_when_lit = -1;
|
static int draw_blobs_when_lit = -1;
|
||||||
if (draw_blobs_when_lit < 0) {
|
if (draw_blobs_when_lit < 0)
|
||||||
char *env = getenv("LIGHTUP_LIT_BLOBS");
|
draw_blobs_when_lit = getenv_bool("LIGHTUP_LIT_BLOBS", true);
|
||||||
draw_blobs_when_lit = (!env || (env[0] == 'y' ||
|
|
||||||
env[0] == 'Y'));
|
|
||||||
}
|
|
||||||
if (!(ds_flags & DF_LIT) || draw_blobs_when_lit) {
|
if (!(ds_flags & DF_LIT) || draw_blobs_when_lit) {
|
||||||
int rlen = TILE_SIZE / 4;
|
int rlen = TILE_SIZE / 4;
|
||||||
draw_rect(dr, dx + TILE_SIZE/2 - rlen/2,
|
draw_rect(dr, dx + TILE_SIZE/2 - rlen/2,
|
||||||
|
7
loopy.c
7
loopy.c
@ -3292,11 +3292,8 @@ static void game_redraw_line(drawing *dr, game_drawstate *ds,
|
|||||||
|
|
||||||
if (line_colour == COL_FAINT) {
|
if (line_colour == COL_FAINT) {
|
||||||
static int draw_faint_lines = -1;
|
static int draw_faint_lines = -1;
|
||||||
if (draw_faint_lines < 0) {
|
if (draw_faint_lines < 0)
|
||||||
char *env = getenv("LOOPY_FAINT_LINES");
|
draw_faint_lines = getenv_bool("LOOPY_FAINT_LINES", true);
|
||||||
draw_faint_lines = (!env || (env[0] == 'y' ||
|
|
||||||
env[0] == 'Y'));
|
|
||||||
}
|
|
||||||
if (draw_faint_lines)
|
if (draw_faint_lines)
|
||||||
draw_line(dr, x1, y1, x2, y2, line_colour);
|
draw_line(dr, x1, y1, x2, y2, line_colour);
|
||||||
} else {
|
} else {
|
||||||
|
8
misc.c
8
misc.c
@ -198,6 +198,14 @@ char *fgetline(FILE *fp)
|
|||||||
return ret;
|
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. */
|
/* Utility functions for colour manipulation. */
|
||||||
|
|
||||||
static float colour_distance(const float a[3], const float b[3])
|
static float colour_distance(const float a[3], const float b[3])
|
||||||
|
3
pearl.c
3
pearl.c
@ -1929,8 +1929,7 @@ static int get_gui_style(void)
|
|||||||
static int gui_style = -1;
|
static int gui_style = -1;
|
||||||
|
|
||||||
if (gui_style == -1) {
|
if (gui_style == -1) {
|
||||||
char *env = getenv("PEARL_GUI_LOOPY");
|
if (getenv_bool("PEARL_GUI_LOOPY", false))
|
||||||
if (env && (env[0] == 'y' || env[0] == 'Y'))
|
|
||||||
gui_style = GUI_LOOPY;
|
gui_style = GUI_LOOPY;
|
||||||
else
|
else
|
||||||
gui_style = GUI_MASYU;
|
gui_style = GUI_MASYU;
|
||||||
|
@ -377,6 +377,8 @@ char *fgetline(FILE *fp);
|
|||||||
char *bin2hex(const unsigned char *in, int inlen);
|
char *bin2hex(const unsigned char *in, int inlen);
|
||||||
unsigned char *hex2bin(const char *in, int outlen);
|
unsigned char *hex2bin(const char *in, int outlen);
|
||||||
|
|
||||||
|
bool getenv_bool(const char *name, bool dflt);
|
||||||
|
|
||||||
/* Mixes two colours in specified proportions. */
|
/* Mixes two colours in specified proportions. */
|
||||||
void colour_mix(const float src1[3], const float src2[3], float p,
|
void colour_mix(const float src1[3], const float src2[3], float p,
|
||||||
float dst[3]);
|
float dst[3]);
|
||||||
|
6
range.c
6
range.c
@ -1324,10 +1324,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
static int swap_buttons = -1;
|
static int swap_buttons = -1;
|
||||||
if (swap_buttons < 0) {
|
if (swap_buttons < 0)
|
||||||
char *env = getenv("RANGE_SWAP_BUTTONS");
|
swap_buttons = getenv_bool("RANGE_SWAP_BUTTONS", false);
|
||||||
swap_buttons = (env && (env[0] == 'y' || env[0] == 'Y'));
|
|
||||||
}
|
|
||||||
if (swap_buttons) {
|
if (swap_buttons) {
|
||||||
if (button == LEFT_BUTTON)
|
if (button == LEFT_BUTTON)
|
||||||
button = RIGHT_BUTTON;
|
button = RIGHT_BUTTON;
|
||||||
|
@ -2161,10 +2161,8 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
|||||||
* yourself which is more brain-twisting :-)
|
* yourself which is more brain-twisting :-)
|
||||||
*/
|
*/
|
||||||
static int gear_mode = -1;
|
static int gear_mode = -1;
|
||||||
if (gear_mode < 0) {
|
if (gear_mode < 0)
|
||||||
char *env = getenv("SIGNPOST_GEARS");
|
gear_mode = getenv_bool("SIGNPOST_GEARS", false);
|
||||||
gear_mode = (env && (env[0] == 'y' || env[0] == 'Y'));
|
|
||||||
}
|
|
||||||
if (gear_mode)
|
if (gear_mode)
|
||||||
sign = 1 - 2 * ((x ^ y) & 1);
|
sign = 1 - 2 * ((x ^ y) & 1);
|
||||||
else
|
else
|
||||||
|
6
slant.c
6
slant.c
@ -1681,10 +1681,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
static int swap_buttons = -1;
|
static int swap_buttons = -1;
|
||||||
if (swap_buttons < 0) {
|
if (swap_buttons < 0)
|
||||||
char *env = getenv("SLANT_SWAP_BUTTONS");
|
swap_buttons = getenv_bool("SLANT_SWAP_BUTTONS", false);
|
||||||
swap_buttons = (env && (env[0] == 'y' || env[0] == 'Y'));
|
|
||||||
}
|
|
||||||
if (swap_buttons) {
|
if (swap_buttons) {
|
||||||
if (button == LEFT_BUTTON)
|
if (button == LEFT_BUTTON)
|
||||||
button = RIGHT_BUTTON;
|
button = RIGHT_BUTTON;
|
||||||
|
2
towers.c
2
towers.c
@ -1636,7 +1636,7 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
ds->tilesize = 0;
|
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->tiles = snewn((w+2)*(w+2), long);
|
||||||
ds->drawn = snewn((w+2)*(w+2)*4, long);
|
ds->drawn = snewn((w+2)*(w+2)*4, long);
|
||||||
for (i = 0; i < (w+2)*(w+2)*4; i++)
|
for (i = 0; i < (w+2)*(w+2)*4; i++)
|
||||||
|
@ -104,7 +104,7 @@ void debug_printf(const char *fmt, ...)
|
|||||||
static int debugging = -1;
|
static int debugging = -1;
|
||||||
|
|
||||||
if (debugging == -1)
|
if (debugging == -1)
|
||||||
debugging = getenv("DEBUG_PUZZLES") ? 1 : 0;
|
debugging = getenv_bool("DEBUG_PUZZLES", false);
|
||||||
|
|
||||||
if (debugging) {
|
if (debugging) {
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
Reference in New Issue
Block a user