From 8710c2c29ab4236aed9d68b36959d24970382e60 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 8 Apr 2018 17:04:24 -0700 Subject: [PATCH] minor fix for #annotate Some github feedback pointed out that getting annotation input from the player behaved differently from similar input for naming of monsters and objects. The complaint stated that hitting without supplying any input removed the old annotation, where other naming would leave the old name intact. 3.6.0 did misbehave that way; current code does too if EDIT_GETLIN is disabled but behaves as desired when it's enabled. (There's nothing that I can spot in donamelevel() to explain why. I'm confused. Is tty_getlin() returning the default answer instead of empty if that default text is deleted at the prompt and no new text entered prior to ?) Make donamelevel() work like mon/obj naming. Empty input leaves existing annotation, if any, intact. --- doc/fixes36.1 | 2 ++ src/dungeon.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 24edd3550..f30c4e0aa 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -537,6 +537,8 @@ gas spore explosion killing a gas spore which triggers a recursive explosion they were both "gas spore's explosion" it wouldn't be noticeable (see corresponding post-3.6.0 entry for more...) wizard mode 'sanity_check' gave spurious "mon not on map" warnings when mounted +at the prompt for entering a level annotation, responding with + erroneously removed old annotation; use to do that Fixes to Post-3.6.0 Problems that Were Exposed Via git Repository diff --git a/src/dungeon.c b/src/dungeon.c index 2f7b42a64..87ae052b8 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dungeon.c $NHDT-Date: 1517912411 2018/02/06 10:20:11 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.83 $ */ +/* NetHack 3.6 dungeon.c $NHDT-Date: 1523232258 2018/04/09 00:04:18 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.86 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2034,27 +2034,33 @@ int donamelevel() { mapseen *mptr; - char nbuf[BUFSZ] = DUMMY; /* Buffer for response */ + char nbuf[BUFSZ]; /* Buffer for response */ if (!(mptr = find_mapseen(&u.uz))) return 0; + nbuf[0] = '\0'; #ifdef EDIT_GETLIN if (mptr->custom) { (void) strncpy(nbuf, mptr->custom, BUFSZ); - nbuf[BUFSZ-1] = '\0'; + nbuf[BUFSZ - 1] = '\0'; } #else if (mptr->custom) { char tmpbuf[BUFSZ]; + Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", mptr->custom, - strlen(mptr->custom) > 30 ? "..." : ""); + (strlen(mptr->custom) > 30) ? "..." : ""); getlin(tmpbuf, nbuf); } else #endif getlin("What do you want to call this dungeon level?", nbuf); - if (index(nbuf, '\033')) + + /* empty input or ESC means don't add or change annotation; + space-only means discard current annotation without adding new one */ + if (!*nbuf || *nbuf == '\033') return 0; + /* strip leading and trailing spaces, compress out consecutive spaces */ (void) mungspaces(nbuf); /* discard old annotation, if any */ @@ -2063,7 +2069,8 @@ donamelevel() mptr->custom = (char *) 0; mptr->custom_lth = 0; } - /* add new annotation, unless it's empty or a single space */ + /* add new annotation, unless it's all spaces (which will be an + empty string after mungspaces() above) */ if (*nbuf && strcmp(nbuf, " ")) { mptr->custom = dupstr(nbuf); mptr->custom_lth = strlen(mptr->custom);