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

Function doname_base

src/objnam.c:1222–1751  ·  view source on GitHub ↗

core of doname() */

Source from the content-addressed store, hash-verified

1220
1221/* core of doname() */
1222staticfn char *
1223doname_base(
1224 struct obj *obj, /* object to format */
1225 unsigned doname_flags) /* special case requests */
1226{
1227 boolean ispoisoned = FALSE,
1228 with_price = (doname_flags & DONAME_WITH_PRICE) != 0,
1229 vague_quan = (doname_flags & DONAME_VAGUE_QUAN) != 0,
1230 for_menu = (doname_flags & DONAME_FOR_MENU) != 0;
1231 boolean known, dknown, cknown, bknown, lknown,
1232 fake_arti, force_the;
1233 char prefix[PREFIX];
1234 char tmpbuf[PREFIX + 1]; /* for when we have to add something at
1235 * the start of prefix instead of the
1236 * end (Strcat is used on the end) */
1237 const char *aname = 0;
1238 int omndx = obj->corpsenm;
1239 char *bp;
1240 char *bp_eos, *bp_end;
1241 size_t bpspaceleft;
1242
1243 /* 'bp' will be within an obuf[] rather than at the start of one,
1244 usually (but not always) pointing at &obuf[PREFIX];
1245 gx.xnamep always points to the start of that buffer;
1246 'bp_eos' and 'bpspaceleft' are used and updated by Concat*() macros */
1247 bp = xname(obj);
1248 bp_end = gx.xnamep + BUFSZ - 1;
1249 bp_eos = eos(bp);
1250 assert(bp_end >= bp_eos); /* ok provided xname() bounds checking works */
1251 /* size_t cast: convert signed ptrdiff_t to unsigned size_t */
1252 bpspaceleft = (size_t) (bp_end - bp_eos);
1253
1254 if (iflags.override_ID) {
1255 known = dknown = cknown = bknown = lknown = TRUE;
1256 } else {
1257 known = obj->known;
1258 dknown = obj->dknown;
1259 cknown = obj->cknown;
1260 bknown = obj->bknown;
1261 lknown = obj->lknown;
1262 }
1263
1264 /* When using xname, we want "poisoned arrow", and when using
1265 * doname, we want "poisoned +0 arrow". This kludge is about the only
1266 * way to do it, at least until someone overhauls xname() and doname(),
1267 * combining both into one function taking a parameter.
1268 */
1269 /* must check opoisoned--someone can have a weirdly-named fruit */
1270 if (!strncmp(bp, "poisoned ", 9) && obj->opoisoned) {
1271 bp += 9; /* doesn't affect bp_eos or bpspaceleft */
1272 ispoisoned = TRUE;
1273 }
1274
1275 /* fruits are allowed to be given artifact names; when that happens,
1276 format the name like the corresponding artifact, which may or may not
1277 want "the" prefix and when it doesn't, avoid "a"/"an" prefix too */
1278 fake_arti = (obj->otyp == SLIME_MOLD
1279 && (aname = artifact_name(bp, (short *) 0, FALSE)) != 0);

Callers 4

donameFunction · 0.85
doname_with_priceFunction · 0.85
doname_vague_quanFunction · 0.85
paydonameFunction · 0.85

Calls 15

xnameFunction · 0.85
eosFunction · 0.85
artifact_nameFunction · 0.85
obj_is_pnameFunction · 0.85
the_unique_objFunction · 0.85
count_contentsFunction · 0.85
doffingFunction · 0.85
donningFunction · 0.85
artifact_lightFunction · 0.85
arti_light_descriptionFunction · 0.85
add_erosion_wordsFunction · 0.85
find_midFunction · 0.85

Tested by

no test coverage detected