From de67801b0fd3dfa11777c1ef86cd617baf376b7b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 1 Oct 2017 13:38:35 +0100 Subject: Use a proper union in struct config_item. This allows me to use different types for the mutable, dynamically allocated string value in a C_STRING control and the fixed constant list of option names in a C_CHOICES. --- twiddle.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'twiddle.c') diff --git a/twiddle.c b/twiddle.c index f52e999..70f768d 100644 --- a/twiddle.c +++ b/twiddle.c @@ -156,41 +156,33 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Width"; ret[0].type = C_STRING; sprintf(buf, "%d", params->w); - ret[0].sval = dupstr(buf); - ret[0].ival = 0; + ret[0].u.string.sval = dupstr(buf); ret[1].name = "Height"; ret[1].type = C_STRING; sprintf(buf, "%d", params->h); - ret[1].sval = dupstr(buf); - ret[1].ival = 0; + ret[1].u.string.sval = dupstr(buf); ret[2].name = "Rotating block size"; ret[2].type = C_STRING; sprintf(buf, "%d", params->n); - ret[2].sval = dupstr(buf); - ret[2].ival = 0; + ret[2].u.string.sval = dupstr(buf); ret[3].name = "One number per row"; ret[3].type = C_BOOLEAN; - ret[3].sval = NULL; - ret[3].ival = params->rowsonly; + ret[3].u.boolean.bval = params->rowsonly; ret[4].name = "Orientation matters"; ret[4].type = C_BOOLEAN; - ret[4].sval = NULL; - ret[4].ival = params->orientable; + ret[4].u.boolean.bval = params->orientable; ret[5].name = "Number of shuffling moves"; ret[5].type = C_STRING; sprintf(buf, "%d", params->movetarget); - ret[5].sval = dupstr(buf); - ret[5].ival = 0; + ret[5].u.string.sval = dupstr(buf); ret[6].name = NULL; ret[6].type = C_END; - ret[6].sval = NULL; - ret[6].ival = 0; return ret; } @@ -199,12 +191,12 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->w = atoi(cfg[0].sval); - ret->h = atoi(cfg[1].sval); - ret->n = atoi(cfg[2].sval); - ret->rowsonly = cfg[3].ival; - ret->orientable = cfg[4].ival; - ret->movetarget = atoi(cfg[5].sval); + ret->w = atoi(cfg[0].u.string.sval); + ret->h = atoi(cfg[1].u.string.sval); + ret->n = atoi(cfg[2].u.string.sval); + ret->rowsonly = cfg[3].u.boolean.bval; + ret->orientable = cfg[4].u.boolean.bval; + ret->movetarget = atoi(cfg[5].u.string.sval); return ret; } -- cgit v1.1