format a container name for cinventory_display(), inserting "trapped" if that's appropriate */
| 5388 | /* format a container name for cinventory_display(), inserting "trapped" |
| 5389 | if that's appropriate */ |
| 5390 | staticfn char * |
| 5391 | cinv_doname(struct obj *obj) |
| 5392 | { |
| 5393 | char *result = doname(obj); |
| 5394 | |
| 5395 | /* |
| 5396 | * If obj->tknown ever gets implemented, doname() will handle this. |
| 5397 | * Assumes that probing reveals the trap prior to calling us. Since |
| 5398 | * we lack that flag, hero forgets about it as soon as we're done.... |
| 5399 | */ |
| 5400 | |
| 5401 | /* 'result' is an obuf[] but might point into the middle (&buf[PREFIX]) |
| 5402 | rather than the beginning and we don't have access to that; |
| 5403 | assume that there is at least QBUFSZ available when reusing it */ |
| 5404 | if (obj->otrapped && strlen(result) + sizeof "trapped " <= QBUFSZ) { |
| 5405 | /* obj->lknown has been set before calling us so either "locked" or |
| 5406 | "unlocked" should always be present (for a trapped container) */ |
| 5407 | char *p = strstri(result, " locked"), |
| 5408 | *q = strstri(result, " unlocked"); |
| 5409 | |
| 5410 | if (p && (!q || p < q)) |
| 5411 | (void) strsubst(p, " locked ", " trapped locked "); |
| 5412 | else if (q) |
| 5413 | (void) strsubst(q, " unlocked ", " trapped unlocked "); |
| 5414 | /* might need to change "an" to "a"; when no BUC is present, |
| 5415 | "an unlocked" yielded "an trapped unlocked" above */ |
| 5416 | (void) strsubst(result, "an trapped ", "a trapped "); |
| 5417 | } |
| 5418 | return result; |
| 5419 | } |
| 5420 | |
| 5421 | /* used by safe_qbuf() if the full doname() result is too long */ |
| 5422 | staticfn char * |