6 #include "lib/global.h" /* <glib.h> */
10 #ifdef SEARCH_TYPE_PCRE
12 #define PCRE2_CODE_UNIT_WIDTH 8
17 #endif /* SEARCH_TYPE_PCRE */
18 /*** typedefs(not structures) and defined constants **********************************************/
20 typedef enum mc_search_cbret_t mc_search_cbret_t
;
22 typedef mc_search_cbret_t (*mc_search_fn
) (const void *user_data
, gsize char_offset
,
24 typedef mc_search_cbret_t (*mc_update_fn
) (const void *user_data
, gsize char_offset
);
26 #define MC_SEARCH__NUM_REPLACE_ARGS 64
28 #ifdef SEARCH_TYPE_GLIB
29 #define mc_search_matchinfo_t GMatchInfo
32 /* no pcre_extra in PCRE2. pcre2_jit_compile (equivalent of pcre_study) handles
33 * all of this internally. but we can use this to hold the pcre2_matches data
34 * until the search is complete */
35 #define mc_search_matchinfo_t pcre2_match_data
37 #define mc_search_matchinfo_t pcre_extra
41 /*** enums ***************************************************************************************/
47 MC_SEARCH_E_REGEX_COMPILE
,
49 MC_SEARCH_E_REGEX_REPLACE
,
56 MC_SEARCH_T_INVALID
= -1,
63 enum mc_search_cbret_t
66 MC_SEARCH_CB_INVALID
= -1,
67 MC_SEARCH_CB_ABORT
= -2,
68 MC_SEARCH_CB_SKIP
= -3,
69 MC_SEARCH_CB_NOTFOUND
= -4
72 /*** structures declarations (and typedefs of structures)*****************************************/
74 typedef struct mc_search_struct
76 /* public input data */
79 /* search in all charsets */
80 gboolean is_all_charsets
;
83 /* case sensitive search */
84 gboolean is_case_sensitive
;
86 /* search only once. Is this for replace? */
87 gboolean is_once_only
;
89 /* search only whole words (from begin to end). Used only with NORMAL search type */
92 /* search entire string (from begin to end). Used only with GLOB search type */
93 gboolean is_entire_line
;
95 /* function, used for getting data. NULL if not used */
96 mc_search_fn search_fn
;
98 /* function, used for updatin current search status. NULL if not used */
99 mc_update_fn update_fn
;
102 mc_search_type_t search_type
;
104 /* public output data */
106 /* some data for normal */
110 /* some data for regexp */
113 mc_search_matchinfo_t
*regex_match_info
;
114 GString
*regex_buffer
;
115 #ifdef SEARCH_TYPE_PCRE
117 /* pcre2 will provide a pointer to a match_data structure that can be manipulated like an iovector */
120 int iovector
[MC_SEARCH__NUM_REPLACE_ARGS
* 2];
122 #endif /* SEARCH_TYPE_PCRE */
128 GPtrArray
*conditions
;
132 /* original search string */
141 /* error code after search */
142 mc_search_error_t error
;
146 typedef struct mc_search_type_str_struct
149 mc_search_type_t type
;
150 } mc_search_type_str_t
;
152 /*** global variables defined in .c file *********************************************************/
155 extern const char *STR_E_NOTFOUND
;
156 extern const char *STR_E_UNKNOWN_TYPE
;
157 extern const char *STR_E_RPL_NOT_EQ_TO_FOUND
;
158 extern const char *STR_E_RPL_INVALID_TOKEN
;
160 /*** declarations of public functions ************************************************************/
162 mc_search_t
*mc_search_new (const gchar
* original
, const gchar
* original_charset
);
164 mc_search_t
*mc_search_new_len (const gchar
* original
, gsize original_len
,
165 const gchar
* original_charset
);
167 void mc_search_free (mc_search_t
* lc_mc_search
);
169 gboolean
mc_search_prepare (mc_search_t
* mc_search
);
171 gboolean
mc_search_run (mc_search_t
* mc_search
, const void *user_data
, gsize start_search
,
172 gsize end_search
, gsize
* found_len
);
174 gboolean
mc_search_is_type_avail (mc_search_type_t search_type
);
176 const mc_search_type_str_t
*mc_search_types_list_get (size_t *num
);
178 GString
*mc_search_prepare_replace_str (mc_search_t
* mc_search
, GString
* replace_str
);
179 char *mc_search_prepare_replace_str2 (mc_search_t
* lc_mc_search
, const char *replace_str
);
181 gboolean
mc_search_is_fixed_search_str (const mc_search_t
* lc_mc_search
);
183 gchar
**mc_search_get_types_strings_array (size_t *num
);
185 gboolean
mc_search (const gchar
* pattern
, const gchar
* pattern_charset
, const gchar
* str
,
186 mc_search_type_t type
);
188 int mc_search_getstart_result_by_num (mc_search_t
* lc_mc_search
, int lc_index
);
189 int mc_search_getend_result_by_num (mc_search_t
* lc_mc_search
, int lc_index
);
192 void mc_search_set_error (mc_search_t
* lc_mc_search
, mc_search_error_t code
, const gchar
* format
, ...)
193 G_GNUC_PRINTF (3, 4);
196 #endif /* MC__SEARCH_H */