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

Function the

src/objnam.c:2170–2231  ·  view source on GitHub ↗

* Prepend "the" if necessary; assumes str is a subject derived from xname. * Use type_is_pname() for monster names, not the(). the() is idempotent. */

Source from the content-addressed store, hash-verified

2168 * Use type_is_pname() for monster names, not the(). the() is idempotent.
2169 */
2170char *
2171the(const char *str)
2172{
2173 const char *aname;
2174 char *buf = nextobuf();
2175 boolean insert_the = FALSE;
2176
2177 if (!str || !*str) {
2178 impossible("Alphabet soup: 'the(%s)'.", str ? "\"\"" : "<null>");
2179 return strcpy(buf, "the []");
2180 }
2181 if (!strncmpi(str, "the ", 4)) {
2182 buf[0] = lowc(*str);
2183 Strcpy(&buf[1], str + 1);
2184 return buf;
2185 } else if (*str < 'A' || *str > 'Z'
2186 /* some capitalized monster names want "the", others don't */
2187 || CapitalMon(str)
2188 /* treat named fruit as not a proper name, even if player
2189 has assigned a capitalized proper name as his/her fruit,
2190 unless it matches an artifact name */
2191 || (fruit_from_name(str, TRUE, (int *) 0)
2192 && ((aname = artifact_name(str, (short *) 0, FALSE)) == 0
2193 || strncmpi(aname, "the ", 4) == 0))) {
2194 /* not a proper name, needs an article */
2195 insert_the = TRUE;
2196 } else {
2197 /* Probably a proper name, might not need an article */
2198 char *named, *called;
2199 const char *tmp;
2200 int l;
2201
2202 /* some objects have capitalized adjectives in their names */
2203 if (((tmp = strrchr(str, ' ')) != 0 || (tmp = strrchr(str, '-')) != 0)
2204 && (tmp[1] < 'A' || tmp[1] > 'Z')) {
2205 /* insert "the" unless we have an apostrophe (where we assume
2206 we're dealing with "Unique's corpse" when "Unique" wasn't
2207 caught by CapitalMon() above) */
2208 insert_the = !strchr(str, '\'');
2209 } else if (tmp && strchr(str, ' ') < tmp) { /* has spaces */
2210 /* it needs an article if the name contains "of" */
2211 tmp = strstri(str, " of ");
2212 named = strstri(str, " named ");
2213 called = strstri(str, " called ");
2214 if (called && (!named || called < named))
2215 named = called;
2216
2217 if (tmp && (!named || tmp < named)) /* found an "of" */
2218 insert_the = TRUE;
2219 /* stupid special case: lacks "of" but needs "the" */
2220 else if (!named && (l = Strlen(str)) >= 31
2221 && !strcmp(&str[l - 31],
2222 "Platinum Yendorian Express Card"))
2223 insert_the = TRUE;
2224 }
2225 }
2226 if (insert_the)
2227 Strcpy(buf, "the ");

Callers 15

finish_questFunction · 0.85
fix_ghostly_objFunction · 0.85
container_contentsFunction · 0.85
dositFunction · 0.85
convert_argFunction · 0.85
potion_dipFunction · 0.85
itemactionsFunction · 0.85
use_crystal_ballFunction · 0.85
on_msgFunction · 0.85
select_offFunction · 0.85
hmon_hitmon_misc_objFunction · 0.85

Calls 9

nextobufFunction · 0.85
CapitalMonFunction · 0.85
fruit_from_nameFunction · 0.85
artifact_nameFunction · 0.85
strrchrFunction · 0.85
strstriFunction · 0.85
impossibleFunction · 0.70
strncmpiFunction · 0.70
lowcFunction · 0.70

Tested by

no test coverage detected