return the index of the matched item, or -1 if no such item exists */
| 504 | |
| 505 | /* return the index of the matched item, or -1 if no such item exists */ |
| 506 | static int get_mext_match(const char *match_str, match_f flag) |
| 507 | { |
| 508 | int match_start, index; |
| 509 | |
| 510 | /* Do not search if the menu is empty (i.e. items_num == 0) */ |
| 511 | match_start = item_index(current_item(curses_menu)); |
| 512 | if (match_start == ERR) |
| 513 | return -1; |
| 514 | |
| 515 | if (flag == FIND_NEXT_MATCH_DOWN) |
| 516 | ++match_start; |
| 517 | else if (flag == FIND_NEXT_MATCH_UP) |
| 518 | --match_start; |
| 519 | |
| 520 | match_start = (match_start + items_num) % items_num; |
| 521 | index = match_start; |
| 522 | while (true) { |
| 523 | char *str = k_menu_items[index].str; |
| 524 | if (strcasestr(str, match_str) != NULL) |
| 525 | return index; |
| 526 | if (flag == FIND_NEXT_MATCH_UP || |
| 527 | flag == MATCH_TINKER_PATTERN_UP) |
| 528 | --index; |
| 529 | else |
| 530 | ++index; |
| 531 | index = (index + items_num) % items_num; |
| 532 | if (index == match_start) |
| 533 | return -1; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /* Make a new item. */ |
| 538 | static void item_make(struct menu *menu, char tag, const char *fmt, ...) |