]> git.itanic.dy.fi Git - linux-stable/commitdiff
kconfig: factor out common code shared by mconf and nconf
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 3 Dec 2023 10:25:23 +0000 (19:25 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 10 Dec 2023 06:34:37 +0000 (15:34 +0900)
Separate out the duplicated code to mnconf-common.c.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/Makefile
scripts/kconfig/mconf.c
scripts/kconfig/mnconf-common.c [new file with mode: 0644]
scripts/kconfig/mnconf-common.h [new file with mode: 0644]
scripts/kconfig/nconf.c

index 322c061b464d2cebbdcf4ab27f0c251d5b0db702..7c025f82718e21e6e411015145963a1bef8b5ceb 100644 (file)
@@ -174,7 +174,7 @@ conf-objs   := conf.o $(common-objs)
 
 # nconf: Used for the nconfig target based on ncurses
 hostprogs      += nconf
-nconf-objs     := nconf.o nconf.gui.o $(common-objs)
+nconf-objs     := nconf.o nconf.gui.o mnconf-common.o $(common-objs)
 
 HOSTLDLIBS_nconf       = $(call read-file, $(obj)/nconf-libs)
 HOSTCFLAGS_nconf.o     = $(call read-file, $(obj)/nconf-cflags)
@@ -187,7 +187,7 @@ $(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags
 hostprogs      += mconf
 lxdialog       := $(addprefix lxdialog/, \
                     checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
-mconf-objs     := mconf.o $(lxdialog) $(common-objs)
+mconf-objs     := mconf.o $(lxdialog) mnconf-common.o $(common-objs)
 
 HOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs)
 $(foreach f, mconf.o $(lxdialog), \
index 3795c36a9181aaca25fb39d3771e4531e67063f8..5df32148a86951f78dca309db7d06d77f2364259 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "lkc.h"
 #include "lxdialog/dialog.h"
+#include "mnconf-common.h"
 
 static const char mconf_readme[] =
 "Overview\n"
@@ -286,7 +287,6 @@ static int single_menu_mode;
 static int show_all_options;
 static int save_and_exit;
 static int silent;
-static int jump_key_char;
 
 static void conf(struct menu *menu, struct menu *active_menu);
 
@@ -378,58 +378,6 @@ static void show_help(struct menu *menu)
        str_free(&help);
 }
 
-struct search_data {
-       struct list_head *head;
-       struct menu *target;
-};
-
-static int next_jump_key(int key)
-{
-       if (key < '1' || key > '9')
-               return '1';
-
-       key++;
-
-       if (key > '9')
-               key = '1';
-
-       return key;
-}
-
-static int handle_search_keys(int key, size_t start, size_t end, void *_data)
-{
-       struct search_data *data = _data;
-       struct jump_key *pos;
-       int index = 0;
-
-       if (key < '1' || key > '9')
-               return 0;
-
-       list_for_each_entry(pos, data->head, entries) {
-               index = next_jump_key(index);
-
-               if (pos->offset < start)
-                       continue;
-
-               if (pos->offset >= end)
-                       break;
-
-               if (key == index) {
-                       data->target = pos->target;
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
-int get_jump_key_char(void)
-{
-       jump_key_char = next_jump_key(jump_key_char);
-
-       return jump_key_char;
-}
-
 static void search_conf(void)
 {
        struct symbol **sym_arr;
diff --git a/scripts/kconfig/mnconf-common.c b/scripts/kconfig/mnconf-common.c
new file mode 100644 (file)
index 0000000..18cb9a6
--- /dev/null
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include "expr.h"
+#include "list.h"
+#include "mnconf-common.h"
+
+int jump_key_char;
+
+int next_jump_key(int key)
+{
+       if (key < '1' || key > '9')
+               return '1';
+
+       key++;
+
+       if (key > '9')
+               key = '1';
+
+       return key;
+}
+
+int handle_search_keys(int key, size_t start, size_t end, void *_data)
+{
+       struct search_data *data = _data;
+       struct jump_key *pos;
+       int index = 0;
+
+       if (key < '1' || key > '9')
+               return 0;
+
+       list_for_each_entry(pos, data->head, entries) {
+               index = next_jump_key(index);
+
+               if (pos->offset < start)
+                       continue;
+
+               if (pos->offset >= end)
+                       break;
+
+               if (key == index) {
+                       data->target = pos->target;
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+int get_jump_key_char(void)
+{
+       jump_key_char = next_jump_key(jump_key_char);
+
+       return jump_key_char;
+}
diff --git a/scripts/kconfig/mnconf-common.h b/scripts/kconfig/mnconf-common.h
new file mode 100644 (file)
index 0000000..ab6292c
--- /dev/null
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef MNCONF_COMMON_H
+#define MNCONF_COMMON_H
+
+#include <stddef.h>
+
+struct search_data {
+       struct list_head *head;
+       struct menu *target;
+};
+
+extern int jump_key_char;
+
+int next_jump_key(int key);
+int handle_search_keys(int key, size_t start, size_t end, void *_data);
+int get_jump_key_char(void);
+
+#endif /* MNCONF_COMMON_H */
index 8cd72fe259740583f76701a6be4445f7d366417f..1148163cfa7e71c037ba28eab8183cf304fc5b85 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 
 #include "lkc.h"
+#include "mnconf-common.h"
 #include "nconf.h"
 #include <ctype.h>
 
@@ -279,7 +280,6 @@ static const char *current_instructions = menu_instructions;
 
 static char *dialog_input_result;
 static int dialog_input_result_len;
-static int jump_key_char;
 
 static void selected_conf(struct menu *menu, struct menu *active_menu);
 static void conf(struct menu *menu);
@@ -691,57 +691,6 @@ static int do_exit(void)
        return 0;
 }
 
-struct search_data {
-       struct list_head *head;
-       struct menu *target;
-};
-
-static int next_jump_key(int key)
-{
-       if (key < '1' || key > '9')
-               return '1';
-
-       key++;
-
-       if (key > '9')
-               key = '1';
-
-       return key;
-}
-
-static int handle_search_keys(int key, size_t start, size_t end, void *_data)
-{
-       struct search_data *data = _data;
-       struct jump_key *pos;
-       int index = 0;
-
-       if (key < '1' || key > '9')
-               return 0;
-
-       list_for_each_entry(pos, data->head, entries) {
-               index = next_jump_key(index);
-
-               if (pos->offset < start)
-                       continue;
-
-               if (pos->offset >= end)
-                       break;
-
-               if (key == index) {
-                       data->target = pos->target;
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
-int get_jump_key_char(void)
-{
-       jump_key_char = next_jump_key(jump_key_char);
-
-       return jump_key_char;
-}
 
 static void search_conf(void)
 {