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. --- cube.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'cube.c') diff --git a/cube.c b/cube.c index a30dc10..249d1ba 100644 --- a/cube.c +++ b/cube.c @@ -489,25 +489,21 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Type of solid"; ret[0].type = C_CHOICES; - ret[0].sval = ":Tetrahedron:Cube:Octahedron:Icosahedron"; - ret[0].ival = params->solid; + ret[0].u.choices.choicenames = ":Tetrahedron:Cube:Octahedron:Icosahedron"; + ret[0].u.choices.selected = params->solid; ret[1].name = "Width / top"; ret[1].type = C_STRING; sprintf(buf, "%d", params->d1); - ret[1].sval = dupstr(buf); - ret[1].ival = 0; + ret[1].u.string.sval = dupstr(buf); ret[2].name = "Height / bottom"; ret[2].type = C_STRING; sprintf(buf, "%d", params->d2); - ret[2].sval = dupstr(buf); - ret[2].ival = 0; + ret[2].u.string.sval = dupstr(buf); ret[3].name = NULL; ret[3].type = C_END; - ret[3].sval = NULL; - ret[3].ival = 0; return ret; } @@ -516,9 +512,9 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->solid = cfg[0].ival; - ret->d1 = atoi(cfg[1].sval); - ret->d2 = atoi(cfg[2].sval); + ret->solid = cfg[0].u.choices.selected; + ret->d1 = atoi(cfg[1].u.string.sval); + ret->d2 = atoi(cfg[2].u.string.sval); return ret; } -- cgit v1.1