]> granicus.if.org Git - nethack/commitdiff
\#saveoptions fix
authorPatR <rankin@nethack.org>
Thu, 13 Oct 2022 20:19:58 +0000 (13:19 -0700)
committernhmall <nhmall@nethack.org>
Sat, 15 Oct 2022 16:28:53 +0000 (12:28 -0400)
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
src/files.c
src/options.c

index bea0aa0bc0403174f9e09102c4786fdd5f99bf09..f9c08a7eebe808ac181183ee35b4358e9c877126 100644 (file)
@@ -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
index 205cca5e642ab63e97fb68aa89150fe274d052a9..7642c3a8e3d954a1bc71a2927ad27a576c5f59d3 100644 (file)
@@ -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;
 }
index a75ba3115cd23c11064bf092785afa940c144c9e..ab5a4b2b52e4332bc813cf92948d0b0413e73384 100644 (file)
@@ -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;