Skip to content

Commit

Permalink
Cleanup of code for the new option to immediately load a saved game.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGriffith committed Jan 22, 2016
1 parent f7ad62f commit 2b78726
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/common/fastmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/common/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
32 changes: 15 additions & 17 deletions src/curses/ux_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> 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];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions src/curses/ux_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit 2b78726

Please sign in to comment.