From 7fac45d848b5bc58efac9fc8692a417dd73218dd Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Fri, 29 Dec 2017 17:38:08 -0500 Subject: [PATCH] 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. --- urogue/options.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/urogue/options.c b/urogue/options.c index 64b9864..2aa3f7b 100644 --- a/urogue/options.c +++ b/urogue/options.c @@ -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; +}