build: scripts/config - update to kconfig-v5.14
[openwrt/staging/noltari.git] / scripts / config / nconf.c
index 66c82344980c233ded4409b580a97cbbdf750940..b75cabe017cabdc701753fa1f6707496d79e6d2d 100644 (file)
@@ -271,7 +271,7 @@ static int mwin_max_cols;
 static MENU *curses_menu;
 static ITEM *curses_menu_items[MAX_MENU_ITEMS];
 static struct mitem k_menu_items[MAX_MENU_ITEMS];
-static int items_num;
+static unsigned int items_num;
 static int global_exit;
 /* the currently selected button */
 static const char *current_instructions = menu_instructions;
@@ -373,18 +373,18 @@ static void print_function_line(void)
        int lines = getmaxy(stdscr);
 
        for (i = 0; i < function_keys_num; i++) {
-               (void) wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]);
+               wattrset(main_window, attr_function_highlight);
                mvwprintw(main_window, lines-3, offset,
                                "%s",
                                function_keys[i].key_str);
-               (void) wattrset(main_window, attributes[FUNCTION_TEXT]);
+               wattrset(main_window, attr_function_text);
                offset += strlen(function_keys[i].key_str);
                mvwprintw(main_window, lines-3,
                                offset, "%s",
                                function_keys[i].func);
                offset += strlen(function_keys[i].func) + skip;
        }
-       (void) wattrset(main_window, attributes[NORMAL]);
+       wattrset(main_window, attr_normal);
 }
 
 /* help */
@@ -499,16 +499,20 @@ typedef enum {MATCH_TINKER_PATTERN_UP, MATCH_TINKER_PATTERN_DOWN,
 /* return the index of the matched item, or -1 if no such item exists */
 static int get_mext_match(const char *match_str, match_f flag)
 {
-       int match_start = item_index(current_item(curses_menu));
-       int index;
+       int match_start, index;
+
+       /* Do not search if the menu is empty (i.e. items_num == 0) */
+       match_start = item_index(current_item(curses_menu));
+       if (match_start == ERR)
+               return -1;
 
        if (flag == FIND_NEXT_MATCH_DOWN)
                ++match_start;
        else if (flag == FIND_NEXT_MATCH_UP)
                --match_start;
 
+       match_start = (match_start + items_num) % items_num;
        index = match_start;
-       index = (index + items_num) % items_num;
        while (true) {
                char *str = k_menu_items[index].str;
                if (strcasestr(str, match_str) != NULL)
@@ -630,19 +634,12 @@ static int item_is_tag(char tag)
 
 static char filename[PATH_MAX+1];
 static char menu_backtitle[PATH_MAX+128];
-static const char *set_config_filename(const char *config_filename)
+static void set_config_filename(const char *config_filename)
 {
-       int size;
+       snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s",
+                config_filename, rootmenu.prompt->text);
 
-       size = snprintf(menu_backtitle, sizeof(menu_backtitle),
-                       "%s - %s", config_filename, rootmenu.prompt->text);
-       if (size >= sizeof(menu_backtitle))
-               menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
-
-       size = snprintf(filename, sizeof(filename), "%s", config_filename);
-       if (size >= sizeof(filename))
-               filename[sizeof(filename)-1] = '\0';
-       return menu_backtitle;
+       snprintf(filename, sizeof(filename), "%s", config_filename);
 }
 
 /* return = 0 means we are successful.
@@ -758,7 +755,6 @@ static void build_conf(struct menu *menu)
                        switch (ptype) {
                        case P_MENU:
                                child_count++;
-                               prompt = prompt;
                                if (single_menu_mode) {
                                        item_make(menu, 'm',
                                                "%s%*c%s",
@@ -960,16 +956,15 @@ static void show_menu(const char *prompt, const char *instructions,
        current_instructions = instructions;
 
        clear();
-       (void) wattrset(main_window, attributes[NORMAL]);
-       print_in_middle(stdscr, 1, 0, getmaxx(stdscr),
+       print_in_middle(stdscr, 1, getmaxx(stdscr),
                        menu_backtitle,
-                       attributes[MAIN_HEADING]);
+                       attr_main_heading);
 
-       (void) wattrset(main_window, attributes[MAIN_MENU_BOX]);
+       wattrset(main_window, attr_main_menu_box);
        box(main_window, 0, 0);
-       (void) wattrset(main_window, attributes[MAIN_MENU_HEADING]);
+       wattrset(main_window, attr_main_menu_heading);
        mvwprintw(main_window, 0, 3, " %s ", prompt);
-       (void) wattrset(main_window, attributes[NORMAL]);
+       wattrset(main_window, attr_normal);
 
        set_menu_items(curses_menu, curses_menu_items);
 
@@ -1072,7 +1067,6 @@ static int do_match(int key, struct match_state *state, int *ans)
 static void conf(struct menu *menu)
 {
        struct menu *submenu = NULL;
-       const char *prompt = menu_get_prompt(menu);
        struct symbol *sym;
        int res;
        int current_index = 0;
@@ -1090,9 +1084,8 @@ static void conf(struct menu *menu)
                if (!child_count)
                        break;
 
-               show_menu(prompt ? prompt : "Main Menu",
-                               menu_instructions,
-                               current_index, &last_top_row);
+               show_menu(menu_get_prompt(menu), menu_instructions,
+                         current_index, &last_top_row);
                keypad((menu_win(curses_menu)), TRUE);
                while (!global_exit) {
                        if (match_state.in_search) {
@@ -1418,7 +1411,7 @@ static void conf_load(void)
                                return;
                        if (!conf_read(dialog_input_result)) {
                                set_config_filename(dialog_input_result);
-                               sym_set_change_count(1);
+                               conf_set_changed(true);
                                return;
                        }
                        btn_dialog(main_window, "File does not exist!", 0);
@@ -1537,9 +1530,9 @@ int main(int ac, char **av)
        menu_opts_on(curses_menu, O_NONCYCLIC);
        menu_opts_on(curses_menu, O_IGNORECASE);
        set_menu_mark(curses_menu, " ");
-       set_menu_fore(curses_menu, attributes[MAIN_MENU_FORE]);
-       set_menu_back(curses_menu, attributes[MAIN_MENU_BACK]);
-       set_menu_grey(curses_menu, attributes[MAIN_MENU_GREY]);
+       set_menu_fore(curses_menu, attr_main_menu_fore);
+       set_menu_back(curses_menu, attr_main_menu_back);
+       set_menu_grey(curses_menu, attr_main_menu_grey);
 
        set_config_filename(conf_get_configname());
        setup_windows();