aboutsummaryrefslogtreecommitdiff
path: root/midend.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-05-19 11:57:09 +0000
committerSimon Tatham <anakin@pobox.com>2004-05-19 11:57:09 +0000
commit350683b25371ec6a7548b2e83b2be15eb629815f (patch)
tree99e1103fd09c1e6ed73df97d33c0ae8c101564f0 /midend.c
parentba076fbdb26149d39e076e161ace330149e71b30 (diff)
downloadpuzzles-350683b25371ec6a7548b2e83b2be15eb629815f.zip
puzzles-350683b25371ec6a7548b2e83b2be15eb629815f.tar.gz
puzzles-350683b25371ec6a7548b2e83b2be15eb629815f.tar.bz2
puzzles-350683b25371ec6a7548b2e83b2be15eb629815f.tar.xz
Introduce routines in each game module to encode a set of game
parameters as a string, and decode it again. This is used in midend.c to prepend the game parameters to the game seed, so that copying out of the Specific box is sufficient to completely specify the game you were playing. Throughout development of these games I have referred to `seed' internally, and `game ID' externally. Now there's a measurable difference between them! :-) [originally from svn r4231]
Diffstat (limited to 'midend.c')
-rw-r--r--midend.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/midend.c b/midend.c
index 63ba193..6a93856 100644
--- a/midend.c
+++ b/midend.c
@@ -333,7 +333,7 @@ int midend_wants_statusbar(midend_data *me)
config_item *midend_get_config(midend_data *me, int which, char **wintitle)
{
- char *titlebuf;
+ char *titlebuf, *parstr;
config_item *ret;
titlebuf = snewn(40 + strlen(game_name), char);
@@ -352,7 +352,15 @@ config_item *midend_get_config(midend_data *me, int which, char **wintitle)
ret[0].type = C_STRING;
ret[0].name = "Game ID";
ret[0].ival = 0;
- ret[0].sval = dupstr(me->seed);
+ /*
+ * The text going in here will be a string encoding of the
+ * parameters, plus a colon, plus the game seed. This is a
+ * full game ID.
+ */
+ parstr = encode_params(me->params);
+ ret[0].sval = snewn(strlen(parstr) + strlen(me->seed) + 2, char);
+ sprintf(ret[0].sval, "%s:%s", parstr, me->seed);
+ sfree(parstr);
ret[1].type = C_END;
ret[1].name = ret[1].sval = NULL;
@@ -367,7 +375,7 @@ config_item *midend_get_config(midend_data *me, int which, char **wintitle)
char *midend_set_config(midend_data *me, int which, config_item *cfg)
{
- char *error;
+ char *error, *p;
game_params *params;
switch (which) {
@@ -385,12 +393,34 @@ char *midend_set_config(midend_data *me, int which, config_item *cfg)
break;
case CFG_SEED:
- error = validate_seed(me->params, cfg[0].sval);
+
+ /*
+ * The game ID will often (in fact, mostly) have a prefix
+ * containing a string-encoded parameter specification
+ * followed by a colon. So first find the colon, and then
+ * split the string up.
+ */
+ p = strchr(cfg[0].sval, ':');
+
+ if (p) {
+ *p++ = '\0'; /* p now points to game seed */
+ params = decode_params(cfg[0].sval);
+ error = validate_params(params);
+ if (error) {
+ free_params(params);
+ return error;
+ }
+ free_params(me->params);
+ me->params = params;
+ } else
+ p = cfg[0].sval;
+
+ error = validate_seed(me->params, p);
if (error)
return error;
sfree(me->seed);
- me->seed = dupstr(cfg[0].sval);
+ me->seed = dupstr(p);
me->fresh_seed = TRUE;
break;