Skip to content

Commit 6c07fd8

Browse files
committed
kconfig: factor out common code shared by mconf and nconf
Separate out the duplicated code to mnconf-common.c. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent d821f8a commit 6c07fd8

File tree

5 files changed

+75
-107
lines changed

5 files changed

+75
-107
lines changed

scripts/kconfig/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ conf-objs := conf.o $(common-objs)
174174

175175
# nconf: Used for the nconfig target based on ncurses
176176
hostprogs += nconf
177-
nconf-objs := nconf.o nconf.gui.o $(common-objs)
177+
nconf-objs := nconf.o nconf.gui.o mnconf-common.o $(common-objs)
178178

179179
HOSTLDLIBS_nconf = $(call read-file, $(obj)/nconf-libs)
180180
HOSTCFLAGS_nconf.o = $(call read-file, $(obj)/nconf-cflags)
@@ -187,7 +187,7 @@ $(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags
187187
hostprogs += mconf
188188
lxdialog := $(addprefix lxdialog/, \
189189
checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
190-
mconf-objs := mconf.o $(lxdialog) $(common-objs)
190+
mconf-objs := mconf.o $(lxdialog) mnconf-common.o $(common-objs)
191191

192192
HOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs)
193193
$(foreach f, mconf.o $(lxdialog), \

scripts/kconfig/mconf.c

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "lkc.h"
2323
#include "lxdialog/dialog.h"
24+
#include "mnconf-common.h"
2425

2526
static const char mconf_readme[] =
2627
"Overview\n"
@@ -286,7 +287,6 @@ static int single_menu_mode;
286287
static int show_all_options;
287288
static int save_and_exit;
288289
static int silent;
289-
static int jump_key_char;
290290

291291
static void conf(struct menu *menu, struct menu *active_menu);
292292

@@ -378,58 +378,6 @@ static void show_help(struct menu *menu)
378378
str_free(&help);
379379
}
380380

381-
struct search_data {
382-
struct list_head *head;
383-
struct menu *target;
384-
};
385-
386-
static int next_jump_key(int key)
387-
{
388-
if (key < '1' || key > '9')
389-
return '1';
390-
391-
key++;
392-
393-
if (key > '9')
394-
key = '1';
395-
396-
return key;
397-
}
398-
399-
static int handle_search_keys(int key, size_t start, size_t end, void *_data)
400-
{
401-
struct search_data *data = _data;
402-
struct jump_key *pos;
403-
int index = 0;
404-
405-
if (key < '1' || key > '9')
406-
return 0;
407-
408-
list_for_each_entry(pos, data->head, entries) {
409-
index = next_jump_key(index);
410-
411-
if (pos->offset < start)
412-
continue;
413-
414-
if (pos->offset >= end)
415-
break;
416-
417-
if (key == index) {
418-
data->target = pos->target;
419-
return 1;
420-
}
421-
}
422-
423-
return 0;
424-
}
425-
426-
int get_jump_key_char(void)
427-
{
428-
jump_key_char = next_jump_key(jump_key_char);
429-
430-
return jump_key_char;
431-
}
432-
433381
static void search_conf(void)
434382
{
435383
struct symbol **sym_arr;

scripts/kconfig/mnconf-common.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
#include "expr.h"
3+
#include "list.h"
4+
#include "mnconf-common.h"
5+
6+
int jump_key_char;
7+
8+
int next_jump_key(int key)
9+
{
10+
if (key < '1' || key > '9')
11+
return '1';
12+
13+
key++;
14+
15+
if (key > '9')
16+
key = '1';
17+
18+
return key;
19+
}
20+
21+
int handle_search_keys(int key, size_t start, size_t end, void *_data)
22+
{
23+
struct search_data *data = _data;
24+
struct jump_key *pos;
25+
int index = 0;
26+
27+
if (key < '1' || key > '9')
28+
return 0;
29+
30+
list_for_each_entry(pos, data->head, entries) {
31+
index = next_jump_key(index);
32+
33+
if (pos->offset < start)
34+
continue;
35+
36+
if (pos->offset >= end)
37+
break;
38+
39+
if (key == index) {
40+
data->target = pos->target;
41+
return 1;
42+
}
43+
}
44+
45+
return 0;
46+
}
47+
48+
int get_jump_key_char(void)
49+
{
50+
jump_key_char = next_jump_key(jump_key_char);
51+
52+
return jump_key_char;
53+
}

scripts/kconfig/mnconf-common.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef MNCONF_COMMON_H
3+
#define MNCONF_COMMON_H
4+
5+
#include <stddef.h>
6+
7+
struct search_data {
8+
struct list_head *head;
9+
struct menu *target;
10+
};
11+
12+
extern int jump_key_char;
13+
14+
int next_jump_key(int key);
15+
int handle_search_keys(int key, size_t start, size_t end, void *_data);
16+
int get_jump_key_char(void);
17+
18+
#endif /* MNCONF_COMMON_H */

scripts/kconfig/nconf.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdlib.h>
1313

1414
#include "lkc.h"
15+
#include "mnconf-common.h"
1516
#include "nconf.h"
1617
#include <ctype.h>
1718

@@ -279,7 +280,6 @@ static const char *current_instructions = menu_instructions;
279280

280281
static char *dialog_input_result;
281282
static int dialog_input_result_len;
282-
static int jump_key_char;
283283

284284
static void selected_conf(struct menu *menu, struct menu *active_menu);
285285
static void conf(struct menu *menu);
@@ -691,57 +691,6 @@ static int do_exit(void)
691691
return 0;
692692
}
693693

694-
struct search_data {
695-
struct list_head *head;
696-
struct menu *target;
697-
};
698-
699-
static int next_jump_key(int key)
700-
{
701-
if (key < '1' || key > '9')
702-
return '1';
703-
704-
key++;
705-
706-
if (key > '9')
707-
key = '1';
708-
709-
return key;
710-
}
711-
712-
static int handle_search_keys(int key, size_t start, size_t end, void *_data)
713-
{
714-
struct search_data *data = _data;
715-
struct jump_key *pos;
716-
int index = 0;
717-
718-
if (key < '1' || key > '9')
719-
return 0;
720-
721-
list_for_each_entry(pos, data->head, entries) {
722-
index = next_jump_key(index);
723-
724-
if (pos->offset < start)
725-
continue;
726-
727-
if (pos->offset >= end)
728-
break;
729-
730-
if (key == index) {
731-
data->target = pos->target;
732-
return 1;
733-
}
734-
}
735-
736-
return 0;
737-
}
738-
739-
int get_jump_key_char(void)
740-
{
741-
jump_key_char = next_jump_key(jump_key_char);
742-
743-
return jump_key_char;
744-
}
745694

746695
static void search_conf(void)
747696
{

0 commit comments

Comments
 (0)