search.h 4.1 KB

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