UltraRogue: fix changing the score option.

Changing the score file now works again, if use_savedir is not set.  If
it is, an error message is shown.
This commit is contained in:
John "Elwin" Edwards 2017-12-29 17:38:08 -05:00
parent 61e05e655c
commit 7fac45d848

View file

@ -24,6 +24,7 @@
#define EQSTR(a, b, c) (strncmp(a, b, c) == 0)
int get_restr(opt_arg *opt, WINDOW *win);
int get_score(opt_arg *opt, WINDOW *win);
/* description of an option and what to do with it */
static OPTION optlist[] =
@ -35,7 +36,7 @@ static OPTION optlist[] =
{"name", "Name (name): ", &whoami, put_str, get_restr},
{"fruit", "Fruit (fruit): ", &fruit, put_str, get_str},
{"file", "Save file (file): ", &file_name, put_str, get_restr},
{"score", "Score file (score): ", &score_file, put_str, get_restr},
{"score", "Score file (score): ", &score_file, put_str, get_score},
{"class", "Character class (class): ",&char_type, put_abil, get_abil}
};
@ -583,3 +584,24 @@ get_restr(opt_arg *opt, WINDOW *win)
return(NORM);
}
int
get_score(opt_arg *opt, WINDOW *win)
{
char old_score_file[2*LINELEN];
int status;
if (use_savedir)
return get_restr(opt, win);
strncpy(old_score_file, opt->str, 2*LINELEN);
old_score_file[2*LINELEN - 1] = '\0';
status = get_str(opt, win);
if (status == NORM && strcmp(old_score_file, opt->str)) {
fclose(fd_score);
fd_score = fopen(score_file, "r+");
if (fd_score == NULL)
fd_score = fopen(score_file, "a+");
}
return status;
}