| 851 | /* Delete the menu associated with the given NetHack winid from memory */ |
| 852 | |
| 853 | void |
| 854 | curses_del_menu(winid wid, boolean del_wid_too) |
| 855 | { |
| 856 | nhmenu_item *tmp_menu_item; |
| 857 | nhmenu_item *menu_item_ptr; |
| 858 | nhmenu *tmpmenu; |
| 859 | nhmenu *current_menu = get_menu(wid); |
| 860 | |
| 861 | if (current_menu == NULL) { |
| 862 | return; |
| 863 | } |
| 864 | |
| 865 | menu_item_ptr = current_menu->entries; |
| 866 | |
| 867 | /* First free entries associated with this menu from memory */ |
| 868 | if (menu_item_ptr != NULL) { |
| 869 | while (menu_item_ptr->next_item != NULL) { |
| 870 | tmp_menu_item = menu_item_ptr->next_item; |
| 871 | free((genericptr_t) menu_item_ptr->str); |
| 872 | free(menu_item_ptr); |
| 873 | menu_item_ptr = tmp_menu_item; |
| 874 | } |
| 875 | free((genericptr_t) menu_item_ptr->str); |
| 876 | free(menu_item_ptr); /* Last entry */ |
| 877 | current_menu->entries = NULL; |
| 878 | } |
| 879 | |
| 880 | /* Now unlink the menu from the list and free it as well */ |
| 881 | if ((tmpmenu = current_menu->prev_menu) != NULL) { |
| 882 | tmpmenu->next_menu = current_menu->next_menu; |
| 883 | } else { |
| 884 | nhmenus = current_menu->next_menu; /* New head node or NULL */ |
| 885 | } |
| 886 | if ((tmpmenu = current_menu->next_menu) != NULL) { |
| 887 | tmpmenu->prev_menu = current_menu->prev_menu; |
| 888 | } |
| 889 | |
| 890 | if (current_menu->prompt) |
| 891 | free((genericptr_t) current_menu->prompt); |
| 892 | free((genericptr_t) current_menu); |
| 893 | |
| 894 | if (del_wid_too) |
| 895 | curses_del_wid(wid); |
| 896 | } |
| 897 | |
| 898 | |
| 899 | /* return a pointer to the menu associated with the given NetHack winid */ |
no test coverage detected