Mercurial > hg > early-roguelike
changeset 293:9dcf3344d3fd
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.
author | John "Elwin" Edwards |
---|---|
date | Fri, 29 Dec 2017 17:38:08 -0500 |
parents | ebf49a933e51 |
children | fe6b7a1a6dfc |
files | urogue/options.c |
diffstat | 1 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/urogue/options.c Fri Dec 29 14:16:24 2017 -0500 +++ b/urogue/options.c Fri Dec 29 17:38:08 2017 -0500 @@ -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 @@ {"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 @@ 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; +}