/* Moves item to the first position. Returns zero on success or non-zero when * item wasn't found in the history. */ static int move_to_first_position(hist_t *hist, const char item[]) { const int pos = string_array_pos(hist->items, hist->pos + 1, item); if(pos == 0) { return 0; } else if(pos > 0) { char *const item = hist->items[pos]; memmove(hist->items + 1, hist->items, sizeof(char *)*pos); hist->items[0] = item; return 0; } return 1; }
int show_colorschemes_menu(FileView *view) { static menu_info m; init_menu_info(&m, strdup("Choose the default Color Scheme"), strdup("No color schemes found")); m.execute_handler = &execute_colorscheme_cb; m.items = list_color_schemes(&m.len); qsort(m.items, m.len, sizeof(*m.items), &sorter); /* It's safe to set m.pos to negative value, since menus.c handles this * correctly. */ #ifndef _WIN32 m.pos = string_array_pos(m.items, m.len, cfg.cs.name); #else m.pos = string_array_pos_case(m.items, m.len, cfg.cs.name); #endif return display_menu(&m, view); }
int is_in_string_array(char *array[], size_t len, const char item[]) { const int pos = string_array_pos(array, len, item); return pos >= 0; }