MCPcopy Index your code
hub / github.com/NetHack/NetHack / just_an

Function just_an

src/objnam.c:2108–2142  ·  view source on GitHub ↗

pick "", "a ", or "an " as article for 'str'; used by an() and doname() */

Source from the content-addressed store, hash-verified

2106
2107/* pick "", "a ", or "an " as article for 'str'; used by an() and doname() */
2108char *
2109just_an(char *outbuf, const char *str)
2110{
2111 char c0;
2112
2113 *outbuf = '\0';
2114 c0 = lowc(*str);
2115 if (!str[1] || str[1] == ' ') {
2116 /* single letter; might be used for named fruit or a musical note */
2117 Strcpy(outbuf, strchr("aefhilmnosx", c0) ? "an " : "a ");
2118 } else if (!strncmpi(str, "the ", 4)
2119 /* these probably shouldn't be handled here because doing so
2120 impacts inventory when using them for named fruit */
2121 || !strcmpi(str, "molten lava")
2122 || !strcmpi(str, "iron bars")
2123 || !strcmpi(str, "ice")
2124 ) {
2125 ; /* no article */
2126 } else {
2127 /* normal case is "an <vowel>" or "a <consonant>" */
2128 if ((strchr(vowels, c0) /* some exceptions warranting "a <vowel>" */
2129 /* 'wun' initial sound */
2130 && (strncmpi(str, "one", 3) || (str[3] && !strchr("-_ ", str[3])))
2131 /* long 'u' initial sound */
2132 && strncmpi(str, "eu", 2) /* "eucalyptus leaf" */
2133 && strncmpi(str, "uke", 3) && strncmpi(str, "ukulele", 7)
2134 && strncmpi(str, "unicorn", 7) && strncmpi(str, "uranium", 7)
2135 && strncmpi(str, "useful", 6)) /* "useful tool" */
2136 || (c0 == 'x' && !strchr(vowels, lowc(str[1]))))
2137 Strcpy(outbuf, "an ");
2138 else
2139 Strcpy(outbuf, "a ");
2140 }
2141 return outbuf;
2142}
2143
2144char *
2145an(const char *str)

Callers 8

do_name.cFile · 0.85
xname_flagsFunction · 0.85
doname_baseFunction · 0.85
anFunction · 0.85
domove_swap_with_petFunction · 0.85
trapnoteFunction · 0.85
background_enlightenmentFunction · 0.85
priestnameFunction · 0.85

Calls 2

lowcFunction · 0.70
strncmpiFunction · 0.70

Tested by

no test coverage detected