MCPcopy Create free account
hub / github.com/NetHack/NetHack / tty_add_menu

Function tty_add_menu

win/tty/wintty.c:2558–2623  ·  view source on GitHub ↗

ARGSUSED*/ * Add a menu item to the beginning of the menu list. This list is reversed * later. */

Source from the content-addressed store, hash-verified

2556 * later.
2557 */
2558void
2559tty_add_menu(
2560 winid window, /* window to use, must be of type NHW_MENU */
2561 const glyph_info *glyphinfo, /* glyph info with glyph to
2562 * display with item */
2563 const anything *identifier, /* what to return if selected */
2564 char ch, /* selector letter (0 = pick our own) */
2565 char gch, /* group accelerator (0 = no group) */
2566 int attr, /* attribute for string (like tty_putstr()) */
2567 int clr, /* color for string */
2568 const char *str, /* menu string */
2569 unsigned int itemflags) /* itemflags such as MENU_ITEMFLAGS_SELECTED */
2570{
2571 boolean preselected = ((itemflags & MENU_ITEMFLAGS_SELECTED) != 0);
2572 struct WinDesc *cw = 0;
2573 tty_menu_item *item;
2574 const char *newstr;
2575 char buf[4 + BUFSZ];
2576
2577 HUPSKIP();
2578 if (str == (const char *) 0)
2579 return;
2580
2581 if (window == WIN_ERR
2582 || (cw = wins[window]) == (struct WinDesc *) 0
2583 || cw->type != NHW_MENU)
2584 ttywindowpanic();
2585
2586#ifdef TTY_PERM_INVENT
2587 if (cw->mbehavior == MENU_BEHAVE_PERMINV) {
2588 ttyinv_add_menu(window, cw, ch, attr, clr, str);
2589 return;
2590 }
2591#endif
2592
2593 cw->nitems++;
2594 if (identifier->a_void) {
2595 int len = (int) strlen(str);
2596
2597 if (len >= BUFSZ) {
2598 /* We *think* everything's coming in off at most BUFSZ bufs... */
2599 impossible("Menu item too long (%d).", len);
2600 len = BUFSZ - 1;
2601 }
2602 Sprintf(buf, "%c - ", ch ? ch : '?');
2603 (void) strncpy(buf + 4, str, len);
2604 buf[4 + len] = '\0';
2605 newstr = buf;
2606 } else
2607 newstr = str;
2608
2609 item = (tty_menu_item *) alloc(sizeof *item);
2610 item->identifier = *identifier;
2611 item->count = -1L;
2612 item->selected = preselected;
2613 item->itemflags = itemflags;
2614 item->selector = ch;
2615 item->gselector = gch;

Callers 1

tty_end_menuFunction · 0.85

Calls 4

ttyinv_add_menuFunction · 0.85
dupstrFunction · 0.85
impossibleFunction · 0.50
allocFunction · 0.50

Tested by

no test coverage detected