search.h 3.7 KB

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