diff options
| author | Simon Tatham <anakin@pobox.com> | 2017-10-01 13:38:35 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2017-10-01 16:34:41 +0100 |
| commit | de67801b0fd3dfa11777c1ef86cd617baf376b7b (patch) | |
| tree | f632daee458c8fefcfc90ff809c44672adeedaa4 /unfinished | |
| parent | eeb2db283de9115f7256fa4cc49597d63e06b0ab (diff) | |
| download | puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.zip puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.tar.gz puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.tar.bz2 puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.tar.xz | |
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.
Diffstat (limited to 'unfinished')
| -rw-r--r-- | unfinished/group.c | 18 | ||||
| -rw-r--r-- | unfinished/slide.c | 17 | ||||
| -rw-r--r-- | unfinished/sokoban.c | 12 |
3 files changed, 17 insertions, 30 deletions
diff --git a/unfinished/group.c b/unfinished/group.c index 0d2f915..a9ae704 100644 --- a/unfinished/group.c +++ b/unfinished/group.c @@ -212,23 +212,19 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Grid size"; 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 = "Difficulty"; ret[1].type = C_CHOICES; - ret[1].sval = DIFFCONFIG; - ret[1].ival = params->diff; + ret[1].u.choices.choicenames = DIFFCONFIG; + ret[1].u.choices.selected = params->diff; ret[2].name = "Show identity"; ret[2].type = C_BOOLEAN; - ret[2].sval = NULL; - ret[2].ival = params->id; + ret[2].u.boolean.bval = params->id; ret[3].name = NULL; ret[3].type = C_END; - ret[3].sval = NULL; - ret[3].ival = 0; return ret; } @@ -237,9 +233,9 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->w = atoi(cfg[0].sval); - ret->diff = cfg[1].ival; - ret->id = cfg[2].ival; + ret->w = atoi(cfg[0].u.string.sval); + ret->diff = cfg[1].u.choices.selected; + ret->id = cfg[2].u.boolean.bval; return ret; } diff --git a/unfinished/slide.c b/unfinished/slide.c index 51ac7cb..05a3f8b 100644 --- a/unfinished/slide.c +++ b/unfinished/slide.c @@ -244,25 +244,20 @@ 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 = "Solution length limit"; ret[2].type = C_STRING; sprintf(buf, "%d", params->maxmoves); - 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; } @@ -271,9 +266,9 @@ 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->maxmoves = atoi(cfg[2].sval); + ret->w = atoi(cfg[0].u.string.sval); + ret->h = atoi(cfg[1].u.string.sval); + ret->maxmoves = atoi(cfg[2].u.string.sval); return ret; } diff --git a/unfinished/sokoban.c b/unfinished/sokoban.c index 2f0af35..edd0f28 100644 --- a/unfinished/sokoban.c +++ b/unfinished/sokoban.c @@ -210,19 +210,15 @@ 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 = NULL; ret[2].type = C_END; - ret[2].sval = NULL; - ret[2].ival = 0; return ret; } @@ -231,8 +227,8 @@ 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->w = atoi(cfg[0].u.string.sval); + ret->h = atoi(cfg[1].u.string.sval); return ret; } |