ref: 4da39de2829b9021e8a14f9309892b02580f3682
parent: 0a798c7484786abcd4b187f94b3734823ca1204e
author: Simon Tatham <anakin@pobox.com>
date: Sun Jul 24 06:05:11 EDT 2005
(GTK only so far) Allow the argument passed to a game binary to be either a game ID or a save file name. (The former takes priority, because you can usually find a synonym for the latter, such as by prepending `./' or `$PWD/'.) [originally from svn r6135]
--- a/gtk.c
+++ b/gtk.c
@@ -1373,7 +1373,7 @@
gtk_widget_show(menuitem);
}
-static frontend *new_window(char *game_id, char **error)
+static frontend *new_window(char *arg, char **error)
{
frontend *fe;
GtkBox *vbox;
@@ -1387,15 +1387,36 @@
fe->me = midend_new(fe, &thegame);
- if (game_id) {
- *error = midend_game_id(fe->me, game_id);
- if (*error) {
- midend_free(fe->me);
- sfree(fe);
- return NULL;
+ if (arg) {
+ char *err;
+ /*
+ * Try treating the argument as a game ID.
+ */
+ err = midend_game_id(fe->me, arg);
+ if (!err) {
+ /*
+ * It's a valid game ID.
+ */
+ midend_new_game(fe->me);
+ } else {
+ FILE *fp = fopen(arg, "r");
+ if (!fp) {
+ err = "Supplied argument is neither a game ID nor a save file";
+ } else {
+ err = midend_deserialise(fe->me, savefile_read, fp);
+ fclose(fp);
+ }
}
+ if (err) {
+ *error = err;
+ midend_free(fe->me);
+ sfree(fe);
+ return NULL;
+ }
+
+ } else {
+ midend_new_game(fe->me);
}
- midend_new_game(fe->me);
fe->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(fe->window), thegame.name);