From: David Griffith Date: Fri, 22 Jan 2016 03:58:19 +0000 (-0800) Subject: Cleanup of code for the new option to immediately load a saved game. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=2b78726ae2ee04d13e36779df7ca5d851cc2fef8;p=liskon_frotz.git Cleanup of code for the new option to immediately load a saved game. --- diff --git a/ChangeLog b/ChangeLog index a7767b1..1aeb68d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ Summary of changes between Frotz 2.44 and Frotz 2.45: ===================================================== -Frotz 2.45 was released on Wednesday, January 20, 2016. +Frotz 2.45 was released on ???? NEW FEATURE diff --git a/src/common/fastmem.c b/src/common/fastmem.c index 0796403..75b042d 100644 --- a/src/common/fastmem.c +++ b/src/common/fastmem.c @@ -770,6 +770,9 @@ void z_restore (void) finished: + if (gfp == NULL && f_setup.restore_mode) + os_fatal ("Error reading save file"); + if (h_version <= V3) branch (success); else diff --git a/src/common/process.c b/src/common/process.c index 6944ce3..c542b13 100644 --- a/src/common/process.c +++ b/src/common/process.c @@ -255,12 +255,11 @@ static void load_all_operands (zbyte specifier) */ void interpret (void) { -/*before we start lets load a save if one was given from the command line*/ - if(f_setup.restore_mode==1) - { - z_restore(); - f_setup.restore_mode=0; - } + /* If we got a save file on the command line, use it now. */ + if(f_setup.restore_mode==1) { + z_restore(); + f_setup.restore_mode=0; + } do { diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 4887bed..4d69ad8 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -72,14 +72,14 @@ Syntax: frotz [options] story-file\n\ -b # background color \t -P alter piracy opcode\n\ -c # context lines \t -q quiet (disable sound effects)\n\ -d disable color \t -r # right margin\n\ - -e enable sound \t -R load a save file directly from command line\n\ + -e enable sound \t -R load this save file\n\ -f # foreground color \t -s # random number seed value\n\ -F Force color mode \t -S # transcript width\n\ -h # screen height \t -t set Tandy bit\n\ -i ignore fatal errors \t -u # slots for multiple undo\n\ -l # left margin \t -w # screen width\n\ -o watch object movement \t -x expand abbreviations g/x/z\n" - + /* char stripped_story_name[FILENAME_MAX+1]; char semi_stripped_story_name[FILENAME_MAX+1]; @@ -207,8 +207,6 @@ void os_process_arguments (int argc, char *argv[]) getconfig(configfile); /* we're not concerned if this fails */ } - f_setup.tmp_save_name = malloc(FILENAME_MAX * sizeof(char)); /*needs to be initialized before we get to parsing our options*/ - /* Parse the options */ do { @@ -246,7 +244,10 @@ void os_process_arguments (int argc, char *argv[]) case 'P': f_setup.piracy = 1; break; case 'q': f_setup.sound = 0; break; case 'r': f_setup.right_margin = atoi(optarg); break; - case 'R': f_setup.restore_mode = 1; strcpy(f_setup.tmp_save_name, optarg); break; + case 'R': f_setup.restore_mode = 1; + f_setup.tmp_save_name = malloc(FILENAME_MAX * sizeof(char) + 1); + strncpy(f_setup.tmp_save_name, optarg, FILENAME_MAX); + break; case 's': u_setup.random_seed = atoi(optarg); break; case 'S': f_setup.script_cols = atoi(optarg); break; case 't': u_setup.tandy_bit = 1; break; @@ -343,22 +344,19 @@ void os_process_arguments (int argc, char *argv[]) strncpy(f_setup.command_name, f_setup.story_name, strlen(f_setup.story_name)); strncat(f_setup.command_name, EXT_COMMAND, strlen(EXT_COMMAND)); - - 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.aux_name = malloc(strlen(f_setup.story_name) * sizeof(char) + 5); strncpy(f_setup.aux_name, f_setup.story_name, strlen(f_setup.story_name)); strncat(f_setup.aux_name, EXT_AUX, strlen(EXT_AUX)); - - /*Set our auto load save as the name_save*/ - if(f_setup.restore_mode == 1) - { - char * delete_me = f_setup.save_name; - f_setup.save_name=f_setup.tmp_save_name; - free(delete_me); - } switch (ux_init_blorb()) { case bb_err_Format: diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index fd91c81..ee91011 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -640,16 +640,18 @@ int os_read_file_name (char *file_name, const char *default_name, int flag) istream_replay = 0; ostream_record = 0; - if(f_setup.restore_mode==0) - { - print_string ("Enter a file name.\nDefault is \""); - print_string (default_name); - print_string ("\": "); - read_string (FILENAME_MAX, (zchar *)file_name); - } - else - file_name[0]=0;//set to zero because we are not taking user input + /* If we're restoring a game before the interpreter starts, + * our filename is already provided. Just go ahead silently. + */ + if (f_setup.restore_mode) { + file_name[0]=0; + } else { + print_string ("Enter a file name.\nDefault is \""); + print_string (default_name); + print_string ("\": "); + read_string (FILENAME_MAX, (zchar *)file_name); + } /* Use the default name if nothing was typed */