mnconf-common.c 794 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <list.h>
  3. #include "expr.h"
  4. #include "mnconf-common.h"
  5. int jump_key_char;
  6. int next_jump_key(int key)
  7. {
  8. if (key < '1' || key > '9')
  9. return '1';
  10. key++;
  11. if (key > '9')
  12. key = '1';
  13. return key;
  14. }
  15. int handle_search_keys(int key, size_t start, size_t end, void *_data)
  16. {
  17. struct search_data *data = _data;
  18. struct jump_key *pos;
  19. int index = 0;
  20. if (key < '1' || key > '9')
  21. return 0;
  22. list_for_each_entry(pos, data->head, entries) {
  23. index = next_jump_key(index);
  24. if (pos->offset < start)
  25. continue;
  26. if (pos->offset >= end)
  27. break;
  28. if (key == index) {
  29. data->target = pos->target;
  30. return 1;
  31. }
  32. }
  33. return 0;
  34. }
  35. int get_jump_key_char(void)
  36. {
  37. jump_key_char = next_jump_key(jump_key_char);
  38. return jump_key_char;
  39. }