xref: /linux/scripts/kconfig/mnconf-common.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <list.h>
3 #include "expr.h"
4 #include "mnconf-common.h"
5 
6 int jump_key_char;
7 
next_jump_key(int key)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 
handle_search_keys(int key,size_t start,size_t end,void * _data)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 
get_jump_key_char(void)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 }
54