search.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef MC__SEARCH_H
  2. #define MC__SEARCH_H
  3. #include <config.h>
  4. #include "lib/global.h" /* <glib.h> */
  5. #include <sys/types.h>
  6. #ifdef SEARCH_TYPE_PCRE
  7. #include <pcre.h>
  8. #endif
  9. /*** typedefs(not structures) and defined constants **********************************************/
  10. typedef int (*mc_search_fn) (const void *user_data, gsize char_offset);
  11. #define MC_SEARCH__NUM_REPLACE_ARGS 64
  12. #ifdef SEARCH_TYPE_GLIB
  13. #define mc_search_matchinfo_t GMatchInfo
  14. #else
  15. #define mc_search_matchinfo_t pcre_extra
  16. #endif
  17. /*** enums ***************************************************************************************/
  18. typedef enum
  19. {
  20. MC_SEARCH_E_OK,
  21. MC_SEARCH_E_INPUT,
  22. MC_SEARCH_E_REGEX_COMPILE,
  23. MC_SEARCH_E_REGEX,
  24. MC_SEARCH_E_REGEX_REPLACE,
  25. MC_SEARCH_E_NOTFOUND
  26. } mc_search_error_t;
  27. typedef enum
  28. {
  29. MC_SEARCH_T_NORMAL,
  30. MC_SEARCH_T_REGEX,
  31. MC_SEARCH_T_HEX,
  32. MC_SEARCH_T_GLOB
  33. } mc_search_type_t;
  34. typedef enum
  35. {
  36. MC_SEARCH_CB_OK = 0,
  37. MC_SEARCH_CB_INVALID = -1,
  38. MC_SEARCH_CB_ABORT = -2,
  39. MC_SEARCH_CB_SKIP = -3
  40. } mc_search_cbret_t;
  41. /*** structures declarations (and typedefs of structures)*****************************************/
  42. typedef struct mc_search_struct
  43. {
  44. /* public input data */
  45. /* search in all charsets */
  46. gboolean is_all_charsets;
  47. /* case sensitive search */
  48. gboolean is_case_sensitive;
  49. /* search only once. Is this for replace? */
  50. gboolean is_once_only;
  51. /* search only whole words (from begin to end). Used only with NORMAL search type */
  52. gboolean whole_words;
  53. /* search entire string (from begin to end). Used only with GLOB search type */
  54. gboolean is_entire_line;
  55. /* function, used for getting data. NULL if not used */
  56. mc_search_fn search_fn;
  57. /* function, used for updatin current search status. NULL if not used */
  58. mc_search_fn update_fn;
  59. /* type of search */
  60. mc_search_type_t search_type;
  61. /* public output data */
  62. /* some data for normal */
  63. off_t normal_offset;
  64. off_t start_buffer;
  65. /* some data for regexp */
  66. int num_results;
  67. gboolean is_utf8;
  68. mc_search_matchinfo_t *regex_match_info;
  69. GString *regex_buffer;
  70. #ifdef SEARCH_TYPE_PCRE
  71. int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
  72. #endif /* SEARCH_TYPE_PCRE */
  73. /* private data */
  74. /* prepared conditions */
  75. GPtrArray *conditions;
  76. /* original search string */
  77. gchar *original;
  78. gsize original_len;
  79. /* error code after search */
  80. mc_search_error_t error;
  81. gchar *error_str;
  82. } mc_search_t;
  83. typedef struct mc_search_type_str_struct
  84. {
  85. const char *str;
  86. mc_search_type_t type;
  87. } mc_search_type_str_t;
  88. /*** global variables defined in .c file *********************************************************/
  89. /*** declarations of public functions ************************************************************/
  90. mc_search_t *mc_search_new (const gchar * original, gsize original_len);
  91. void mc_search_free (mc_search_t * lc_mc_search);
  92. gboolean mc_search_prepare (mc_search_t * mc_search);
  93. gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
  94. gsize end_search, gsize * found_len);
  95. gboolean mc_search_is_type_avail (mc_search_type_t);
  96. const mc_search_type_str_t *mc_search_types_list_get (size_t * num);
  97. GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
  98. char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
  99. gboolean mc_search_is_fixed_search_str (mc_search_t *);
  100. gchar **mc_search_get_types_strings_array (size_t * num);
  101. gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
  102. int mc_search_getstart_result_by_num (mc_search_t *, int);
  103. int mc_search_getend_result_by_num (mc_search_t *, int);
  104. #endif