From cb33b9ecc86cb16965cd90ccc7ce157094c2ff29 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 13 Oct 2022 13:19:58 -0700 Subject: [PATCH] \#saveoptions fix I hadn't ever used #saveoptions before and when I checked to see whether the autounlock:none changes were being handled properly, I discovered that options set via 'm O' weren't being handled at all. This includes some miscellaneous reformatting of things noticed while tracking down the problem. --- doc/fixes3-7-0.txt | 2 ++ src/files.c | 9 ++++++--- src/options.c | 14 +++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index bea0aa0bc..f9c08a7ee 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1410,6 +1410,8 @@ tipping contents of one container directly into another allowed transferring prevent random traps from being created inside the shops in the tourist quest if hero's steed got hit by knockback effect, impossible "no monster to remove" would occur (plus more warnings if 'sanity_check' was On) +the #saveoptions command included options changed via doset_simple() but not + ones changed via full doset() curses: 'msg_window' option wasn't functional for curses unless the binary also included tty support diff --git a/src/files.c b/src/files.c index 205cca5e6..7642c3a8e 100644 --- a/src/files.c +++ b/src/files.c @@ -2000,11 +2000,13 @@ do_write_config_file(void) wait_synch(); pline("Some settings are not saved!"); wait_synch(); - pline("All manual customization and comments are removed from the file!"); + pline( + "All manual customization and comments are removed from the file!"); wait_synch(); } #define overwrite_prompt "Overwrite config file %.*s?" - Sprintf(tmp, overwrite_prompt, (int)(BUFSZ - sizeof overwrite_prompt - 2), configfile); + Sprintf(tmp, overwrite_prompt, + (int) (BUFSZ - sizeof overwrite_prompt - 2), configfile); #undef overwrite_prompt if (!paranoid_query(TRUE, tmp)) return ECMD_OK; @@ -2021,7 +2023,8 @@ do_write_config_file(void) fclose(fp); strbuf_empty(&buf); if (wrote != len) - pline("An error occurred, wrote only partial data (%lu/%lu).", wrote, len); + pline("An error occurred, wrote only partial data (%lu/%lu).", + wrote, len); } return ECMD_OK; } diff --git a/src/options.c b/src/options.c index a75ba3115..ab5a4b2b5 100644 --- a/src/options.c +++ b/src/options.c @@ -4879,8 +4879,8 @@ handler_autounlock(int optidx) free((genericptr_t) window_pick); } else if (n == 0) { /* nothing was picked but menu wasn't cancelled */ /* something that was preselected got unselected, leaving nothing; - treat that as picking 'none' (even though 'none' might be what - got unselected) */ + treat that as picking 'none' (even though 'none' is no longer + among the choices) */ flags.autounlock = 0; } destroy_nhwindow(tmpwin); @@ -5703,8 +5703,8 @@ handler_verbose(int optidx) flags.verbose = !flags.verbose; } else { Sprintf(buf, - "Set verbose_suppressor[%d] (%ld) to what new decimal value ?", - j, verbosity_suppressions[j]); + "Set verbose_suppressor[%d] (%ld) to what new decimal value ?", + j, verbosity_suppressions[j]); abuf[0] = '\0'; getlin(buf, abuf); if (abuf[0] == '\033') @@ -8330,6 +8330,9 @@ doset(void) /* changing options via menu by Per Liboriussen */ reslt = (*allopt[k].optfn)(allopt[k].idx, do_handler, FALSE, empty_optstr, empty_optstr); + /* if player eventually saves options, include this one */ + if (reslt == optn_ok) + opt_set_in_config[k] = TRUE; } else { char abuf[BUFSZ]; @@ -8992,7 +8995,8 @@ all_options_strbuf(strbuf_t *sbuf) - verbose */ buf2 = get_option_value(name, TRUE); if (buf2) { - Sprintf(tmp, "OPTIONS=%s:%s\n", name, buf2); + Snprintf(tmp, sizeof tmp - 1, "OPTIONS=%s:%s", name, buf2); + Strcat(tmp, "\n"); /* guaranteed to fit */ strbuf_append(sbuf, tmp); } break; -- 2.49.0