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

Function query_annotation

src/dungeon.c:2499–2567  ·  view source on GitHub ↗

ask user to annotate level lev. if lev is NULL, uses current level. */

Source from the content-addressed store, hash-verified

2497/* ask user to annotate level lev.
2498 if lev is NULL, uses current level. */
2499staticfn void
2500query_annotation(d_level *lev)
2501{
2502 mapseen *mptr;
2503 char nbuf[BUFSZ]; /* Buffer for response */
2504
2505 if (!(mptr = find_mapseen(lev ? lev : &u.uz)))
2506 return;
2507
2508 nbuf[0] = '\0';
2509#ifdef EDIT_GETLIN
2510 if (mptr->custom) {
2511 (void) strncpy(nbuf, mptr->custom, BUFSZ);
2512 nbuf[BUFSZ - 1] = '\0';
2513 }
2514#else
2515 if (mptr->custom) {
2516 char tmpbuf[BUFSZ];
2517
2518 Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", mptr->custom,
2519 (strlen(mptr->custom) > 30) ? "..." : "");
2520 getlin(tmpbuf, nbuf);
2521 } else
2522#endif
2523 {
2524 char qbuf[QBUFSZ], lbuf[QBUFSZ]; /* level description */
2525
2526 if (!lev || on_level(&u.uz, lev)) {
2527 Strcpy(lbuf, "this dungeon level");
2528 } else {
2529 int dflgs = (lev->dnum == u.uz.dnum) ? 0 : 2;
2530 d_level save_uz = u.uz;
2531
2532 u.uz = *lev;
2533 (void) describe_level(lbuf, dflgs);
2534 u.uz = save_uz;
2535
2536 (void) strsubst(lbuf, "Dlvl:", "level ");
2537 /* even though we've told describe_level() not to append
2538 a trailing space (by not including '1' in dflgs), the
2539 level number is formatted with %-2d so single digit
2540 values will end up with one anyway; remove it */
2541 (void) trimspaces(lbuf);
2542 }
2543 Snprintf(qbuf, sizeof qbuf, "What do you want to call %s?", lbuf);
2544 getlin(qbuf, nbuf);
2545 }
2546
2547 /* empty input or ESC means don't add or change annotation;
2548 space-only means discard current annotation without adding new one */
2549 if (!*nbuf || *nbuf == '\033')
2550 return;
2551 /* strip leading and trailing spaces, compress out consecutive spaces */
2552 (void) mungspaces(nbuf);
2553
2554 /* discard old annotation, if any */
2555 if (mptr->custom) {
2556 free((genericptr_t) mptr->custom);

Callers 2

donamelevelFunction · 0.85
show_overviewFunction · 0.85

Calls 8

find_mapseenFunction · 0.85
getlinFunction · 0.85
on_levelFunction · 0.85
describe_levelFunction · 0.85
strsubstFunction · 0.85
trimspacesFunction · 0.85
mungspacesFunction · 0.85
dupstrFunction · 0.85

Tested by

no test coverage detected