search.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 NUMBER_OF_FIRST_PAGE_RESULTS 9
  27. #define NUMBER_OF_RESULTS_KEYBOARD 5
  28. #define PIXEL_START (RESULT_START - RESULT_HEIGHT + 2)
  29. /* MAX_DAT_FILES cannot be less than the number of batches in the rendering process */
  30. #define MAX_DAT_FILES 64
  31. #define MAX_COMPRESSED_ARTICLE 256*1024
  32. enum {
  33. SEARCH_RELOAD_NORMAL,
  34. SEARCH_RELOAD_KEEP_RESULT,
  35. SEARCH_RELOAD_NO_POPULATE,
  36. SEARCH_RELOAD_KEEP_REFRESH,
  37. };
  38. enum {
  39. SEARCH_TO_BE_RELOADED_CLEAR,
  40. SEARCH_TO_BE_RELOADED_SET,
  41. SEARCH_TO_BE_RELOADED_CHECK,
  42. };
  43. typedef struct _ARTICLE_PTR {
  44. uint32_t offset_dat; /* offset to pedia?.dat for the article content */
  45. uint32_t offset_fnd; /* offset to pedia.fnd for the title (for search) */
  46. uint32_t file_id_compressed_len; /* byte 0: bit0~1 - compress method (00 - lzo, 01 - bzlib, 10 - 7z), bit 2~7 pedia file id */
  47. /* byte 1~3: compressed article length */
  48. } ARTICLE_PTR;
  49. typedef struct _TITLE_SEARCH { /* used to mask the porinter to the remainder of the title for search */
  50. uint32_t idxArticle;
  51. char cZero; /* null character for backward search */
  52. char sTitleSearch[MAX_TITLE_SEARCH]; /* null terminated title for search (with bigram encoded) */
  53. } TITLE_SEARCH;
  54. /*
  55. * Highlevel search interface...
  56. */
  57. void search_select_down(void);
  58. void search_select_up(void);
  59. int search_current_selection(void);
  60. // const char *search_fetch_result();
  61. int retrieve_article(long idx_article);
  62. void memrcpy(char *dest, char *src, int len); // memory copy starting from the last byte
  63. void random_article(void);
  64. void get_article_title_from_idx(long idx, char *title);
  65. long result_list_offset_next(void);
  66. long result_list_next_result(long offset_next, long *idxArticle, char *sTitleSearch);
  67. /**
  68. * Initialize the search engine. Once.
  69. */
  70. void search_init();
  71. /**
  72. * Load trigrams. return if done..
  73. */
  74. int search_load_trigram(void);
  75. /**
  76. * Repaint, reselect the current screen..
  77. */
  78. void search_reload(int flag);
  79. void search_to_be_reloaded(int to_be_reloaded_flag, int reload_flag);
  80. /**
  81. * Search for another char. It needs to be lower case
  82. */
  83. int search_add_char(char c, unsigned long ev_time);
  84. /**
  85. * Remove the last char from the search
  86. */
  87. int search_remove_char(int bPopulate, unsigned long ev_time);
  88. /**
  89. * Return search result count
  90. */
  91. unsigned int search_result_count();
  92. /**
  93. * Return the index of search result currently selected item
  94. */
  95. int search_result_selected();
  96. /**
  97. * Return the index of the first item displayed on the screen
  98. */
  99. unsigned int search_result_first_item();
  100. void search_set_selection(int new_selection);
  101. void search_open_article(int new_selection);
  102. int fetch_search_result(long input_offset_fnd_start, long input_offset_fnd_end, int bInit);
  103. void search_fetch();
  104. void search_result_display();
  105. int clear_search_string();
  106. int get_search_string_len();
  107. int check_search_string_change(void);
  108. #endif