Pending 3.7 edition of the naming overflow patch.

Like the 3.6.7 one, the original pieces have been combined into one
commit.  But it is separate from the one added to that version.
This commit is contained in:
PatR
2023-01-27 16:35:35 -08:00
parent 4575d564c7
commit b9bbf0205b
5 changed files with 151 additions and 80 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 do_name.c $NHDT-Date: 1655663780 2022/06/19 18:36:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.254 $ */
/* NetHack 3.7 do_name.c $NHDT-Date: 1672605786 2023/01/01 20:43:06 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.280 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Pasi Kallinen, 2018. */
/* NetHack may be freely redistributed. See license for details. */
@@ -19,6 +19,7 @@ static void gloc_filter_done(void);
static boolean gather_locs_interesting(coordxy, coordxy, int);
static void gather_locs(coord **, int *, int);
static void truncate_to_map(int *, int *, schar, schar);
static char *name_from_player(char *, const char *, const char *);
static void do_mgivenname(void);
static boolean alreadynamed(struct monst *, char *, char *);
static void do_oname(struct obj *);
@@ -1180,6 +1181,34 @@ safe_oname(struct obj *obj)
return "";
}
/* get a name for a monster or an object from player;
truncate if longer than PL_PSIZ, then return it */
static char *
name_from_player(
char *outbuf, /* output buffer, assumed to be at least BUFSZ long;
* anything longer than PL_PSIZ will be truncated */
const char *prompt,
const char *defres) /* only used if EDIT_GETLIN is enabled; only useful
* if windowport xxx's xxx_getlin() supports that */
{
outbuf[0] = '\0';
#ifdef EDIT_GETLIN
if (defres && *defres)
Strcpy(outbuf, defres); /* default response from getlin() */
#else
nhUse(defres);
#endif
getlin(prompt, outbuf);
if (!*outbuf || *outbuf == '\033')
return NULL;
/* strip leading and trailing spaces, condense internal sequences */
(void) mungspaces(outbuf);
if (strlen(outbuf) >= PL_PSIZ)
outbuf[PL_PSIZ - 1] = '\0';
return outbuf;
}
/* historical note: this returns a monster pointer because it used to
allocate a new bigger block of memory to hold the monster and its name */
struct monst *
@@ -1290,17 +1319,10 @@ do_mgivenname(void)
/* special case similar to the one in lookat() */
Sprintf(qbuf, "What do you want to call %s?",
distant_monnam(mtmp, ARTICLE_THE, monnambuf));
buf[0] = '\0';
#ifdef EDIT_GETLIN
/* if there's an existing name, make it be the default answer */
if (has_mgivenname(mtmp))
Strcpy(buf, MGIVENNAME(mtmp));
#endif
getlin(qbuf, buf);
if (!*buf || *buf == '\033')
/* use getlin() to get a name string from the player */
if (!name_from_player(buf, qbuf,
has_mgivenname(mtmp) ? MGIVENNAME(mtmp) : NULL))
return;
/* strip leading and trailing spaces; unnames monster if all spaces */
(void) mungspaces(buf);
/* Unique monsters have their own specific names or titles.
* Shopkeepers, temple priests and other minions use alternate
@@ -1348,17 +1370,9 @@ do_oname(struct obj *obj)
Sprintf(qbuf, "What do you want to name %s ",
is_plural(obj) ? "these" : "this");
(void) safe_qbuf(qbuf, qbuf, "?", obj, xname, simpleonames, "item");
buf[0] = '\0';
#ifdef EDIT_GETLIN
/* if there's an existing name, make it be the default answer */
if (has_oname(obj))
Strcpy(buf, ONAME(obj));
#endif
getlin(qbuf, buf);
if (!*buf || *buf == '\033')
/* use getlin() to get a name string from the player */
if (!name_from_player(buf, qbuf, safe_oname(obj)))
return;
/* strip leading and trailing spaces; unnames item if all spaces */
(void) mungspaces(buf);
/*
* We don't violate illiteracy conduct here, although it is
@@ -1701,14 +1715,8 @@ docall(struct obj *obj)
docall_xname, simpleonames, "thing");
/* pointer to old name */
str1 = &(objects[obj->otyp].oc_uname);
buf[0] = '\0';
#ifdef EDIT_GETLIN
/* if there's an existing name, make it be the default answer */
if (*str1)
Strcpy(buf, *str1);
#endif
getlin(qbuf, buf);
if (!*buf || *buf == '\033')
/* use getlin() to get a name string from the player */
if (!name_from_player(buf, qbuf, *str1))
return;
/* clear old name */