search.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  3. *
  4. * Authors Holger Hans Peter Freyther <zecke@openmoko.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef WL_SEARCH_H
  20. #define WL_SEARCH_H
  21. #include <inttypes.h>
  22. #define TARGET_SIZE 6
  23. #define RESULT_START 34
  24. #define RESULT_HEIGHT 19
  25. #define MAX_TITLE_SEARCH 64
  26. #define MAX_TITLE_ACTUAL 256
  27. #define NUMBER_OF_FIRST_PAGE_RESULTS 9
  28. #define NUMBER_OF_RESULTS_KEYBOARD 5
  29. #define PIXEL_START (RESULT_START - RESULT_HEIGHT + 2)
  30. #define CHAR_LANGUAGE_LINK_TITLE_DELIMITER 1
  31. #define MAX_DAT_FILES 64
  32. // How does this compare to: lcd_draw_buf.h: FILE_BUFFER_SIZE
  33. // Presently set the same. Is it possible to assume 2:1 compression ratio?
  34. #define MAX_COMPRESSED_ARTICLE (512 * 1024)
  35. enum {
  36. SEARCH_RELOAD_NORMAL,
  37. SEARCH_RELOAD_KEEP_RESULT,
  38. SEARCH_RELOAD_NO_POPULATE,
  39. SEARCH_RELOAD_KEEP_REFRESH,
  40. };
  41. enum {
  42. SEARCH_TO_BE_RELOADED_CLEAR,
  43. SEARCH_TO_BE_RELOADED_SET,
  44. SEARCH_TO_BE_RELOADED_CHECK,
  45. };
  46. // IDX file structure: uint32_t #entries, #entries * [ARTICLE_PTR]
  47. typedef struct __attribute__((packed)) _ARTICLE_PTR {
  48. uint32_t offset_dat; // offset to pedia?.dat for the article content
  49. uint32_t offset_fnd; // offset to pedia.fnd for the title (for search)
  50. uint8_t file_id; // pedia file id 0..255
  51. } ARTICLE_PTR;
  52. // FND file is just a concatenation of the following records
  53. // Note: 1. sTitleActual is placed right after the '\0' of sTitleSearch in the file
  54. // some re-arrangement will be required
  55. // 2. if the first byte of either title is in the range 1..31
  56. // then it represents 2..32 chars of prefix to be copied from the previous title
  57. typedef struct __attribute__((packed)) _TITLE_SEARCH {
  58. uint32_t idxArticle; // article number [1..N]
  59. char cZero; // null character for backward search
  60. char sTitleSearch[MAX_TITLE_SEARCH]; // null terminated bigram encoded title for search
  61. char sTitleActual[MAX_TITLE_ACTUAL]; // null terminated utf-8 encoded actual title
  62. } TITLE_SEARCH;
  63. /*
  64. * Highlevel search interface...
  65. */
  66. void search_select_down(void);
  67. void search_select_up(void);
  68. int search_current_selection(void);
  69. // const char *search_fetch_result();
  70. int retrieve_article(long idx_article);
  71. void memrcpy(char *dest, char *src, int len); // memory copy starting from the last byte
  72. void random_article(void);
  73. void get_article_title_from_idx(long idx, char *title);
  74. long result_list_offset_next(void);
  75. long result_list_next_result(long offset_next, long *idxArticle, char *sTitleSearch);
  76. /**
  77. * Initialize the search engine. Once.
  78. */
  79. void search_init();
  80. /**
  81. * Load trigrams. return if done..
  82. */
  83. int search_load_trigram(void);
  84. /**
  85. * Repaint, reselect the current screen..
  86. */
  87. void search_reload(int flag);
  88. void search_to_be_reloaded(int to_be_reloaded_flag, int reload_flag);
  89. /**
  90. * Search for another char. It needs to be lower case
  91. */
  92. int search_add_char(char c, unsigned long ev_time);
  93. /**
  94. * Remove the last char from the search
  95. */
  96. int search_remove_char(int bPopulate, unsigned long ev_time);
  97. /**
  98. * Return search result count
  99. */
  100. unsigned int search_result_count();
  101. /**
  102. * Return the index of search result currently selected item
  103. */
  104. int search_result_selected();
  105. /**
  106. * Return the index of the first item displayed on the screen
  107. */
  108. unsigned int search_result_first_item();
  109. void search_set_selection(int new_selection);
  110. void search_open_article(int new_selection);
  111. int fetch_search_result(long input_offset_fnd_start, long input_offset_fnd_end, int bInit);
  112. void search_fetch();
  113. void search_result_display();
  114. int clear_search_string();
  115. int get_search_string_len();
  116. int check_search_string_change(void);
  117. uint32_t get_article_idx_by_title(char *titleSearch, char *titleActual);
  118. #endif