| 9205 | |
| 9206 | /* common to msg-types, menu-colors, autopickup-exceptions */ |
| 9207 | staticfn int |
| 9208 | handle_add_list_remove(const char *optname, int numtotal) |
| 9209 | { |
| 9210 | winid tmpwin; |
| 9211 | anything any; |
| 9212 | int i, pick_cnt, opt_idx; |
| 9213 | menu_item *pick_list = (menu_item *) 0; |
| 9214 | static const struct action { |
| 9215 | char letr; |
| 9216 | const char *desc; |
| 9217 | } action_titles[] = { |
| 9218 | { 'a', "add new %s" }, /* [0] */ |
| 9219 | { 'l', "list %s" }, /* [1] */ |
| 9220 | { 'r', "remove existing %s" }, /* [2] */ |
| 9221 | { 'x', "exit this menu" }, /* [3] */ |
| 9222 | }; |
| 9223 | int clr = NO_COLOR; |
| 9224 | |
| 9225 | tmpwin = create_nhwindow(NHW_MENU); |
| 9226 | start_menu(tmpwin, MENU_BEHAVE_STANDARD); |
| 9227 | any = cg.zeroany; |
| 9228 | for (i = 0; i < SIZE(action_titles); i++) { |
| 9229 | char tmpbuf[BUFSZ]; |
| 9230 | |
| 9231 | any.a_int++; |
| 9232 | /* omit list and remove if there aren't any yet */ |
| 9233 | if (!numtotal && (i == 1 || i == 2)) |
| 9234 | continue; |
| 9235 | Sprintf(tmpbuf, action_titles[i].desc, |
| 9236 | (i == 1) ? makeplural(optname) : optname); |
| 9237 | add_menu(tmpwin, &nul_glyphinfo,&any, action_titles[i].letr, |
| 9238 | 0, ATR_NONE, clr, tmpbuf, |
| 9239 | (i == 3) ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE); |
| 9240 | } |
| 9241 | end_menu(tmpwin, "Do what?"); |
| 9242 | if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list)) > 0) { |
| 9243 | opt_idx = pick_list[0].item.a_int - 1; |
| 9244 | if (pick_cnt > 1 && opt_idx == 3) |
| 9245 | opt_idx = pick_list[1].item.a_int - 1; |
| 9246 | free((genericptr_t) pick_list); |
| 9247 | } else |
| 9248 | opt_idx = 3; /* none selected, exit menu */ |
| 9249 | destroy_nhwindow(tmpwin); |
| 9250 | return opt_idx; |
| 9251 | } |
| 9252 | |
| 9253 | RESTORE_WARNING_FORMAT_NONLITERAL |
| 9254 |
no test coverage detected