From: David Griffith Date: Thu, 16 Feb 2017 09:33:44 +0000 (-0800) Subject: dumb interface: add -R option to immediately load a saved game. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=c472ec22c189aae93644cf30bd37fd5c495f6ba3;p=liskon_frotz.git dumb interface: add -R option to immediately load a saved game. --- diff --git a/src/common/frotz.h b/src/common/frotz.h index 1fa208b..c377b16 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -16,6 +16,9 @@ #ifndef __UNIX_PORT_FILE #include typedef int bool; +#endif /* __UNIX_PORT_FILE */ + +#include #ifndef TRUE #define TRUE 1 @@ -25,12 +28,6 @@ typedef int bool; #define FALSE 0 #endif -#endif /* __UNIX_PORT_FILE */ - - -#include - - /* typedef unsigned short zbyte; */ typedef unsigned char zbyte; typedef unsigned short zword; diff --git a/src/dumb/dumb_init.c b/src/dumb/dumb_init.c index 0a0ec62..5ac463a 100644 --- a/src/dumb/dumb_init.c +++ b/src/dumb/dumb_init.c @@ -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 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)); diff --git a/src/dumb/dumb_input.c b/src/dumb/dumb_input.c index 2593bcf..32c1c67 100644 --- a/src/dumb/dumb_input.c +++ b/src/dumb/dumb_input.c @@ -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);