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

Function X11_add_menu

win/X11/winmenu.c:790–866  ·  view source on GitHub ↗

ARGSUSED*/

Source from the content-addressed store, hash-verified

788
789/*ARGSUSED*/
790void
791X11_add_menu(winid window,
792 const glyph_info *glyphinfo UNUSED,
793 const anything *identifier,
794 char ch, /* selector letter; 0 if not selectable */
795 char gch, /* group accelerator (0 = no group) */
796 int attr,
797 int clr,
798 const char *str,
799 unsigned itemflags)
800{
801 x11_menu_item *item;
802 struct menu_info_t *menu_info;
803 boolean preselected = (itemflags & MENU_ITEMFLAGS_SELECTED) != 0;
804
805 check_winid(window);
806 menu_info = window_list[window].menu_information;
807 if (!menu_info->is_menu) {
808 impossible("add_menu: called before start_menu");
809 return;
810 }
811
812 item = (x11_menu_item *) alloc((unsigned) sizeof(x11_menu_item));
813 item->next = (x11_menu_item *) 0;
814 item->identifier = *identifier;
815 item->attr = attr;
816 item->color = clr;
817 item->itemflags = itemflags;
818 item->selected = item->preselected = preselected;
819 item->pick_count = -1L;
820 item->window = window;
821 item->w = (Widget) 0;
822
823 if (identifier->a_void) {
824 char buf[4 + BUFSZ];
825 int len = strlen(str);
826
827 if (!ch) {
828 /* Supply a keyboard accelerator. Only the first 52 get one. */
829
830 if (menu_info->new_menu.curr_selector) {
831 ch = menu_info->new_menu.curr_selector++;
832 if (ch == 'z')
833 menu_info->new_menu.curr_selector = 'A';
834 else if (ch == 'Z')
835 menu_info->new_menu.curr_selector = 0; /* out */
836 }
837 }
838
839 if (len >= BUFSZ) {
840 /* We *think* everything's coming in off at most BUFSZ bufs... */
841 impossible("Menu item too long (%d).", len);
842 len = BUFSZ - 1;
843 }
844 Sprintf(buf, "%c %c ", ch ? ch : ' ', preselected ? '+' : '-');
845 (void) strncpy(buf + 4, str, len);
846 buf[4 + len] = '\0';
847 item->str = copy_of(buf);

Callers 1

X11_display_fileFunction · 0.85

Calls 3

copy_ofFunction · 0.85
impossibleFunction · 0.50
allocFunction · 0.50

Tested by

no test coverage detected