From f7ad62f21569eeea034ec5811bd79f3ca690ae7a Mon Sep 17 00:00:00 2001 From: Michael Anghelone Date: Tue, 19 Jan 2016 22:01:32 -0500 Subject: [PATCH] Added the capability to load a save file as a command line argument. Now you don't need to load the game and issue the restore command to load a file. Everything else still works as one would think. I these changes are only going to effect the curses version for now. I do not have a proper enviroment setup to test out dos. Example: frotz file.zblorb -R save.qzl --- ChangeLog | 10 ++++++++++ src/common/process.c | 6 ++++++ src/common/setup.h | 2 ++ src/curses/ux_init.c | 31 ++++++++++++++++++++++--------- src/curses/ux_input.c | 15 +++++++++------ src/dos/bcinit.c | 1 + src/dumb/dumb_init.c | 1 + src/sdl/sf_resource.c | 1 + 8 files changed, 52 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d3ace7..a7767b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Summary of changes between Frotz 2.44 and Frotz 2.45: +===================================================== + +Frotz 2.45 was released on Wednesday, January 20, 2016. + +NEW FEATURE + +- Added -R option for restoring save file directly from the command line. + + Summary of changes between Frotz 2.43 and Frotz 2.44: ===================================================== diff --git a/src/common/process.c b/src/common/process.c index 9847071..6944ce3 100644 --- a/src/common/process.c +++ b/src/common/process.c @@ -255,6 +255,12 @@ 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; + } do { diff --git a/src/common/setup.h b/src/common/setup.h index 7fe3368..206015d 100644 --- a/src/common/setup.h +++ b/src/common/setup.h @@ -26,9 +26,11 @@ typedef struct frotz_setup_struct { char *script_name; char *command_name; char *save_name; + char *tmp_save_name; char *aux_name; char *story_path; char *zcode_path; + int restore_mode; /* for a save file passed from command line*/ } f_setup_t; extern f_setup_t f_setup; diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 57f154d..4887bed 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 -s # random number seed value\n\ - -f # foreground color \t -S # transcript width\n\ - -F Force color mode \t -t set Tandy bit\n\ - -h # screen height \t -u # slots for multiple undo\n\ - -i ignore fatal errors \t -w # screen width\n\ - -l # left margin \t -x expand abbreviations g/x/z\n\ - -o watch object movement" - + -e enable sound \t -R load a save file directly from command line\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,10 +207,12 @@ 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 { - c = getopt(argc, argv, "aAb:c:def:Fh:il:oOpPqr:s:S:tu:w:xZ:"); + c = getopt(argc, argv, "aAb:c:def:Fh:il:oOpPqrR:s:S:tu:w:xZ:"); switch(c) { case 'a': f_setup.attribute_assignment = 1; break; case 'A': f_setup.attribute_testing = 1; break; @@ -244,6 +246,7 @@ 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 '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; @@ -340,6 +343,7 @@ 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)); @@ -347,6 +351,14 @@ void os_process_arguments (int argc, char *argv[]) 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: @@ -1029,6 +1041,7 @@ void os_init_setup(void) f_setup.script_cols = 80; f_setup.sound = 1; f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE; + f_setup.restore_mode = 0; u_setup.use_blorb = 0; u_setup.exec_in_blorb = 0; diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index a681742..fd91c81 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -633,7 +633,6 @@ zchar os_read_key (int timeout, int cursor) int os_read_file_name (char *file_name, const char *default_name, int flag) { - int saved_replay = istream_replay; int saved_record = ostream_record; @@ -641,12 +640,16 @@ 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 ("\": "); - print_string ("Enter a file name.\nDefault is \""); - print_string (default_name); - print_string ("\": "); - - read_string (FILENAME_MAX, (zchar *)file_name); + read_string (FILENAME_MAX, (zchar *)file_name); + } + else + file_name[0]=0;//set to zero because we are not taking user input /* Use the default name if nothing was typed */ diff --git a/src/dos/bcinit.c b/src/dos/bcinit.c index d6f19cc..a08e03a 100644 --- a/src/dos/bcinit.c +++ b/src/dos/bcinit.c @@ -106,6 +106,7 @@ void os_init_setup(void) f_setup.script_cols = 80; f_setup.sound = 1; f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE; + f_setup.restore_mode = 0; }/* os_init_setup */ diff --git a/src/dumb/dumb_init.c b/src/dumb/dumb_init.c index b3cc7c8..8f65399 100644 --- a/src/dumb/dumb_init.c +++ b/src/dumb/dumb_init.c @@ -211,5 +211,6 @@ void os_init_setup(void) f_setup.script_cols = 80; f_setup.sound = 1; f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE; + f_setup.restore_mode = 0; } diff --git a/src/sdl/sf_resource.c b/src/sdl/sf_resource.c index d723c27..856bd27 100644 --- a/src/sdl/sf_resource.c +++ b/src/sdl/sf_resource.c @@ -1033,5 +1033,6 @@ void os_init_setup(void) f_setup.save_quetzal = 1; f_setup.sound = 1; f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE; + f_setup.restore_mode = 0; } -- 2.34.1