core of doname() */
| 1220 | |
| 1221 | /* core of doname() */ |
| 1222 | staticfn char * |
| 1223 | doname_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); |
no test coverage detected