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.
This commit is contained in:
Simon Tatham
2017-10-01 13:38:35 +01:00
parent eeb2db283d
commit de67801b0f
51 changed files with 528 additions and 643 deletions

12
range.c
View File

@ -170,18 +170,14 @@ static config_item *game_configure(const game_params *params)
ret[0].name = "Width";
ret[0].type = C_STRING;
ret[0].sval = nfmtstr(10, "%d", params->w);
ret[0].ival = 0;
ret[0].u.string.sval = nfmtstr(10, "%d", params->w);
ret[1].name = "Height";
ret[1].type = C_STRING;
ret[1].sval = nfmtstr(10, "%d", params->h);
ret[1].ival = 0;
ret[1].u.string.sval = nfmtstr(10, "%d", params->h);
ret[2].name = NULL;
ret[2].type = C_END;
ret[2].sval = NULL;
ret[2].ival = 0;
return ret;
}
@ -189,8 +185,8 @@ static config_item *game_configure(const game_params *params)
static game_params *custom_params(const config_item *configuration)
{
game_params *ret = snew(game_params);
ret->w = atoi(configuration[0].sval);
ret->h = atoi(configuration[1].sval);
ret->w = atoi(configuration[0].u.string.sval);
ret->h = atoi(configuration[1].u.string.sval);
return ret;
}