blob: 18cb9a6c5aaad648c4b7f04c5457bd4442064226 [file] [log] [blame]
Patrick Georgi77612372024-03-13 13:01:21 +01001// SPDX-License-Identifier: GPL-2.0-only
2#include "expr.h"
3#include "list.h"
4#include "mnconf-common.h"
5
6int jump_key_char;
7
8int 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
21int 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
48int get_jump_key_char(void)
49{
50 jump_key_char = next_jump_key(jump_key_char);
51
52 return jump_key_char;
53}