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

Function Gem_add_menu

outdated/win/gem/wingem.c:745–784  ·  view source on GitHub ↗

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

(window, glyph, identifier, ch, gch, attr, str, itemflags)

Source from the content-addressed store, hash-verified

743 * later.
744 */
745void
746Gem_add_menu(window, glyph, identifier, ch, gch, attr, str, itemflags)
747winid window; /* window to use, must be of type NHW_MENU */
748int glyph; /* glyph to display with item (unused) */
749const anything *identifier; /* what to return if selected */
750char ch; /* keyboard accelerator (0 = pick our own) */
751char gch; /* group accelerator (0 = no group) */
752int attr; /* attribute for string (like Gem_putstr()) */
753const char *str; /* menu string */
754unsigned int itemflags; /* itemflags such as marked as selected */
755{
756 boolean preselected = ((itemflags & MENU_ITEMFLAGS_SELECTED) != 0);
757 Gem_menu_item *G_item;
758 const char *newstr;
759 char buf[QBUFSZ];
760
761 if (str == (const char *) 0)
762 return;
763
764 if (window == WIN_ERR) /* MAR -- test existence */
765 panic(winpanicstr, window);
766
767 if (identifier->a_void)
768 Sprintf(buf, "%c - %s", ch ? ch : '?', str);
769 else
770 Sprintf(buf, "%s", str);
771 newstr = buf;
772
773 G_item = (Gem_menu_item *) alloc(sizeof(Gem_menu_item));
774 G_item->Gmi_identifier = (long) identifier->a_void;
775 G_item->Gmi_glyph = glyph != NO_GLYPH ? glyph2tile[glyph] : NO_GLYPH;
776 G_item->Gmi_count = -1L;
777 G_item->Gmi_selected = preselected ? 1 : 0;
778 G_item->Gmi_accelerator = ch;
779 G_item->Gmi_groupacc = gch;
780 G_item->Gmi_itemflags = itemflags;
781 G_item->Gmi_attr = attr;
782 G_item->Gmi_str = copy_of(newstr);
783 mar_add_menu(window, G_item);
784}
785
786/*
787 * End a menu in this window, window must a type NHW_MENU.

Callers 1

Gem_get_ext_cmdFunction · 0.85

Calls 4

copy_ofFunction · 0.85
mar_add_menuFunction · 0.85
panicFunction · 0.50
allocFunction · 0.50

Tested by

no test coverage detected