dumb interface: add -R option to immediately load a saved game.
authorDavid Griffith <dave@661.org>
Thu, 16 Feb 2017 09:33:44 +0000 (01:33 -0800)
committerDavid Griffith <dave@661.org>
Thu, 16 Feb 2017 09:33:44 +0000 (01:33 -0800)
src/common/frotz.h
src/dumb/dumb_init.c
src/dumb/dumb_input.c

index 1fa208b65e5512f82041c37215d64bd99b999c37..c377b16c5116f29e3ca8ca9bf49b166fdad1c287 100644 (file)
@@ -16,6 +16,9 @@
 #ifndef __UNIX_PORT_FILE
 #include <signal.h>
 typedef int bool;
+#endif /* __UNIX_PORT_FILE */
+
+#include <stdio.h>
 
 #ifndef TRUE
 #define TRUE 1
@@ -25,12 +28,6 @@ typedef int bool;
 #define FALSE 0
 #endif
 
-#endif /* __UNIX_PORT_FILE */
-
-
-#include <stdio.h>
-
-
 /* typedef unsigned short zbyte; */
 typedef unsigned char zbyte;
 typedef unsigned short zword;
index 0a0ec623b32063d69322b4f04e2dab895bb052f6..5ac463ac61c6ee4b62ea0ebea4e1146c66f84ad3 100644 (file)
@@ -16,16 +16,15 @@ An interpreter for all Infocom and other Z-Machine games.\n\
 Complies with standard 1.0 of Graham Nelson's specification.\n\
 \n\
 Syntax: dfrotz [options] story-file\n\
-  -a   watch attribute setting \t  R xxx  do runtime setting \\xxx\n\
+  -a   watch attribute setting \t -r xxx  do runtime setting \\xxx\n\
   -A   watch attribute testing \t    before starting (can be used repeatedly)\n\
-  -h # screen height           \t -s # random number seed value\n\
-  -i   ignore fatal errors     \t -S # transcript width\n\
-  -I # interpreter number      \t -t   set Tandy bit\n\
-  -o   watch object movement   \t -u # slots for multiple undo\n\
-  -O   watch object locating   \t -w # screen width\n\
-  -p   plain ASCII output only \t -x   expand abbreviations g/x/z\n\
-  -P   alter piracy opcode"
-
+  -h # screen height           \t -R <filename> load this save file\n\
+  -i   ignore fatal errors     \t -s # random number seed value\n\
+  -I # interpreter number      \t -S # transcript width\n\
+  -o   watch object movement   \t -t   set Tandy bit\n\
+  -O   watch object locating   \t -u # slots for multiple undo\n\
+  -p   plain ASCII output only \t -w # screen width\n\
+  -P   alter piracy opcode     \t -x   expand abbreviations g/x/z"
 
 /* A unix-like getopt, but with the names changed to avoid any problems.  */
 static int zoptind = 1;
@@ -79,7 +78,7 @@ void os_process_arguments(int argc, char *argv[])
     do_more_prompts = TRUE;
     /* Parse the options */
     do {
-       c = zgetopt(argc, argv, "aAh:iI:moOpPs:R:S:tu:w:xZ:");
+       c = zgetopt(argc, argv, "aAh:iI:moOpPs:r:R:S:tu:w:xZ:");
        switch(c) {
          case 'a': f_setup.attribute_assignment = 1; break;
          case 'A': f_setup.attribute_testing = 1; break;
@@ -91,7 +90,10 @@ void os_process_arguments(int argc, char *argv[])
          case 'O': f_setup.object_locating = 1; break;
          case 'P': f_setup.piracy = 1; break;
        case 'p': plain_ascii = 1; break;
-       case 'R': dumb_handle_setting(zoptarg, FALSE, TRUE); break;
+       case 'R': f_setup.restore_mode = 1;
+                 f_setup.tmp_save_name = my_strdup(zoptarg);
+                 break;
+       case 'r': dumb_handle_setting(zoptarg, FALSE, TRUE); break;
        case 's': user_random_seed = atoi(zoptarg); break;
          case 'S': f_setup.script_cols = atoi(zoptarg); break;
        case 't': user_tandy_bit = 1; break;
@@ -130,9 +132,16 @@ void os_process_arguments(int argc, char *argv[])
     p = strrchr(f_setup.story_name, '.');
     *p = '\0'; /* extension removed */
 
-    f_setup.save_name = malloc(strlen(f_setup.story_name) * sizeof(char) + 5);
-    strncpy(f_setup.save_name, f_setup.story_name, strlen(f_setup.story_name));
-    strncat(f_setup.save_name, EXT_SAVE, strlen(EXT_SAVE));
+
+    if (!f_setup.restore_mode) {
+      f_setup.save_name = malloc(strlen(f_setup.story_name) * sizeof(char) + 5);
+      strncpy(f_setup.save_name, f_setup.story_name, strlen(f_setup.story_name));
+      strncat(f_setup.save_name, EXT_SAVE, strlen(EXT_SAVE));
+    } else { /* Set our auto load save as the name save */
+      f_setup.save_name = malloc(strlen(f_setup.tmp_save_name) * sizeof(char) + 5);
+      strncpy(f_setup.save_name, f_setup.tmp_save_name, strlen(f_setup.tmp_save_name));
+      free(f_setup.tmp_save_name);
+    }
 
     f_setup.script_name = malloc(strlen(f_setup.story_name) * sizeof(char) + 5);
     strncpy(f_setup.script_name, f_setup.story_name, strlen(f_setup.story_name));
index 2593bcfd9bd064d7b93e8fb492688c7b42dabe47..32c1c67c1f49d764145a86f411e052a89d269a23 100644 (file)
@@ -390,11 +390,19 @@ int os_read_file_name (char *file_name, const char *default_name, int flag)
   char buf[INPUT_BUFFER_SIZE], prompt[INPUT_BUFFER_SIZE];
   FILE *fp;
 
-  sprintf(prompt, "Please enter a filename [%s]: ", default_name);
-  dumb_read_misc_line(buf, prompt);
-  if (strlen(buf) > MAX_FILE_NAME) {
-    printf("Filename too long\n");
-    return FALSE;
+  /* If we're restoring a game before the interpreter starts,
+   * our filename is already provided.  Just go ahead silently.
+   */
+  if (f_setup.restore_mode) {
+    strcpy(file_name, default_name);
+    return TRUE;
+  } else {
+    sprintf(prompt, "Please enter a filename [%s]: ", default_name);
+    dumb_read_misc_line(buf, prompt);
+    if (strlen(buf) > MAX_FILE_NAME) {
+      printf("Filename too long\n");
+      return FALSE;
+    }
   }
 
   strcpy (file_name, buf[0] ? buf : default_name);