get a name for a monster or an object from player; truncate if longer than PL_PSIZ, then return it */
| 102 | /* get a name for a monster or an object from player; |
| 103 | truncate if longer than PL_PSIZ, then return it */ |
| 104 | staticfn char * |
| 105 | name_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 */ |
no test coverage detected