MCPcopy Create free account
hub / github.com/NetHack/NetHack / name_from_player

Function name_from_player

src/do_name.c:104–128  ·  view source on GitHub ↗

get a name for a monster or an object from player; truncate if longer than PL_PSIZ, then return it */

Source from the content-addressed store, hash-verified

102/* get a name for a monster or an object from player;
103 truncate if longer than PL_PSIZ, then return it */
104staticfn char *
105name_from_player(
106 char *outbuf, /* output buffer, assumed to be at least BUFSZ long;
107 * anything longer than PL_PSIZ will be truncated */
108 const char *prompt,
109 const char *defres) /* only used if EDIT_GETLIN is enabled; only useful
110 * if windowport xxx's xxx_getlin() supports that */
111{
112 outbuf[0] = '\0';
113#ifdef EDIT_GETLIN
114 if (defres && *defres)
115 Strcpy(outbuf, defres); /* default response from getlin() */
116#else
117 nhUse(defres);
118#endif
119 getlin(prompt, outbuf);
120 if (!*outbuf || *outbuf == '\033')
121 return NULL;
122
123 /* strip leading and trailing spaces, condense internal sequences */
124 (void) mungspaces(outbuf);
125 if (strlen(outbuf) >= PL_PSIZ)
126 outbuf[PL_PSIZ - 1] = '\0';
127 return outbuf;
128}
129
130/* historical note: this returns a monster pointer because it used to
131 allocate a new bigger block of memory to hold the monster and its name */

Callers 3

do_mgivennameFunction · 0.85
do_onameFunction · 0.85
docallFunction · 0.85

Calls 2

getlinFunction · 0.85
mungspacesFunction · 0.85

Tested by

no test coverage detected