Remove min() and max() macros. Use MIN() and MAX() macros from GLib.
[midnight-commander.git] / lib / search.h
blob52a6a30a555a2ad1f62bb6f481343de8976e3593
1 #ifndef MC__SEARCH_H
2 #define MC__SEARCH_H
4 #include <config.h>
6 #include "lib/global.h" /* <glib.h> */
8 #include <sys/types.h>
10 #ifdef SEARCH_TYPE_PCRE
11 #include <pcre.h>
12 #endif
14 /*** typedefs(not structures) and defined constants **********************************************/
16 typedef enum mc_search_cbret_t mc_search_cbret_t;
18 typedef mc_search_cbret_t (*mc_search_fn) (const void *user_data, gsize char_offset,
19 int *current_char);
20 typedef mc_search_cbret_t (*mc_update_fn) (const void *user_data, gsize char_offset);
22 #define MC_SEARCH__NUM_REPLACE_ARGS 64
24 #ifdef SEARCH_TYPE_GLIB
25 #define mc_search_matchinfo_t GMatchInfo
26 #else
27 #define mc_search_matchinfo_t pcre_extra
28 #endif
30 /*** enums ***************************************************************************************/
32 typedef enum
34 MC_SEARCH_E_OK,
35 MC_SEARCH_E_INPUT,
36 MC_SEARCH_E_REGEX_COMPILE,
37 MC_SEARCH_E_REGEX,
38 MC_SEARCH_E_REGEX_REPLACE,
39 MC_SEARCH_E_NOTFOUND
40 } mc_search_error_t;
42 typedef enum
44 MC_SEARCH_T_INVALID = -1,
45 MC_SEARCH_T_NORMAL,
46 MC_SEARCH_T_REGEX,
47 MC_SEARCH_T_HEX,
48 MC_SEARCH_T_GLOB
49 } mc_search_type_t;
51 enum mc_search_cbret_t
53 MC_SEARCH_CB_OK = 0,
54 MC_SEARCH_CB_INVALID = -1,
55 MC_SEARCH_CB_ABORT = -2,
56 MC_SEARCH_CB_SKIP = -3
59 /*** structures declarations (and typedefs of structures)*****************************************/
61 typedef struct mc_search_struct
63 /* public input data */
65 #ifdef HAVE_CHARSET
66 /* search in all charsets */
67 gboolean is_all_charsets;
68 #endif
70 /* case sensitive search */
71 gboolean is_case_sensitive;
73 /* search only once. Is this for replace? */
74 gboolean is_once_only;
76 /* search only whole words (from begin to end). Used only with NORMAL search type */
77 gboolean whole_words;
79 /* search entire string (from begin to end). Used only with GLOB search type */
80 gboolean is_entire_line;
82 /* function, used for getting data. NULL if not used */
83 mc_search_fn search_fn;
85 /* function, used for updatin current search status. NULL if not used */
86 mc_update_fn update_fn;
88 /* type of search */
89 mc_search_type_t search_type;
91 /* public output data */
93 /* some data for normal */
94 off_t normal_offset;
96 off_t start_buffer;
97 /* some data for regexp */
98 int num_results;
99 gboolean is_utf8;
100 mc_search_matchinfo_t *regex_match_info;
101 GString *regex_buffer;
102 #ifdef SEARCH_TYPE_PCRE
103 int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
104 #endif /* SEARCH_TYPE_PCRE */
106 /* private data */
108 /* prepared conditions */
109 GPtrArray *conditions;
111 /* original search string */
112 gchar *original;
113 gsize original_len;
114 #ifdef HAVE_CHARSET
115 gchar *original_charset;
116 #endif
118 /* error code after search */
119 mc_search_error_t error;
120 gchar *error_str;
121 } mc_search_t;
123 typedef struct mc_search_type_str_struct
125 const char *str;
126 mc_search_type_t type;
127 } mc_search_type_str_t;
129 /*** global variables defined in .c file *********************************************************/
131 /* Error messages */
132 extern const char *STR_E_NOTFOUND;
133 extern const char *STR_E_UNKNOWN_TYPE;
134 extern const char *STR_E_RPL_NOT_EQ_TO_FOUND;
135 extern const char *STR_E_RPL_INVALID_TOKEN;
137 /*** declarations of public functions ************************************************************/
139 mc_search_t *mc_search_new (const gchar * original, const gchar * original_charset);
141 mc_search_t *mc_search_new_len (const gchar * original, gsize original_len,
142 const gchar * original_charset);
144 void mc_search_free (mc_search_t * lc_mc_search);
146 gboolean mc_search_prepare (mc_search_t * mc_search);
148 gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
149 gsize end_search, gsize * found_len);
151 gboolean mc_search_is_type_avail (mc_search_type_t);
153 const mc_search_type_str_t *mc_search_types_list_get (size_t * num);
155 GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
156 char *mc_search_prepare_replace_str2 (mc_search_t * lc_mc_search, const char *replace_str);
158 gboolean mc_search_is_fixed_search_str (mc_search_t *);
160 gchar **mc_search_get_types_strings_array (size_t * num);
162 gboolean mc_search (const gchar * pattern, const gchar * pattern_charset, const gchar * str,
163 mc_search_type_t type);
165 int mc_search_getstart_result_by_num (mc_search_t *, int);
166 int mc_search_getend_result_by_num (mc_search_t *, int);
168 #endif