Unify widget and dialog message handling.
[midnight-commander.git] / lib / search.h
blob1f6d6bedb016682493e8d7f2b9f2c89273f70e1b
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 int (*mc_search_fn) (const void *user_data, gsize char_offset, int *current_char);
17 typedef int (*mc_update_fn) (const void *user_data, gsize char_offset);
19 #define MC_SEARCH__NUM_REPLACE_ARGS 64
21 #ifdef SEARCH_TYPE_GLIB
22 #define mc_search_matchinfo_t GMatchInfo
23 #else
24 #define mc_search_matchinfo_t pcre_extra
25 #endif
27 /*** enums ***************************************************************************************/
29 typedef enum
31 MC_SEARCH_E_OK,
32 MC_SEARCH_E_INPUT,
33 MC_SEARCH_E_REGEX_COMPILE,
34 MC_SEARCH_E_REGEX,
35 MC_SEARCH_E_REGEX_REPLACE,
36 MC_SEARCH_E_NOTFOUND
37 } mc_search_error_t;
39 typedef enum
41 MC_SEARCH_T_NORMAL,
42 MC_SEARCH_T_REGEX,
43 MC_SEARCH_T_HEX,
44 MC_SEARCH_T_GLOB
45 } mc_search_type_t;
47 typedef enum
49 MC_SEARCH_CB_OK = 0,
50 MC_SEARCH_CB_INVALID = -1,
51 MC_SEARCH_CB_ABORT = -2,
52 MC_SEARCH_CB_SKIP = -3
53 } mc_search_cbret_t;
56 /*** structures declarations (and typedefs of structures)*****************************************/
58 typedef struct mc_search_struct
60 /* public input data */
62 /* search in all charsets */
63 gboolean is_all_charsets;
65 /* case sensitive search */
66 gboolean is_case_sensitive;
68 /* search only once. Is this for replace? */
69 gboolean is_once_only;
71 /* search only whole words (from begin to end). Used only with NORMAL search type */
72 gboolean whole_words;
74 /* search entire string (from begin to end). Used only with GLOB search type */
75 gboolean is_entire_line;
77 /* function, used for getting data. NULL if not used */
78 mc_search_fn search_fn;
80 /* function, used for updatin current search status. NULL if not used */
81 mc_update_fn update_fn;
83 /* type of search */
84 mc_search_type_t search_type;
86 /* public output data */
88 /* some data for normal */
89 off_t normal_offset;
91 off_t start_buffer;
92 /* some data for regexp */
93 int num_results;
94 gboolean is_utf8;
95 mc_search_matchinfo_t *regex_match_info;
96 GString *regex_buffer;
97 #ifdef SEARCH_TYPE_PCRE
98 int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
99 #endif /* SEARCH_TYPE_PCRE */
101 /* private data */
103 /* prepared conditions */
104 GPtrArray *conditions;
106 /* original search string */
107 gchar *original;
108 gsize original_len;
110 /* error code after search */
111 mc_search_error_t error;
112 gchar *error_str;
113 } mc_search_t;
115 typedef struct mc_search_type_str_struct
117 const char *str;
118 mc_search_type_t type;
119 } mc_search_type_str_t;
121 /*** global variables defined in .c file *********************************************************/
123 /*** declarations of public functions ************************************************************/
125 mc_search_t *mc_search_new (const gchar * original, gsize original_len);
127 void mc_search_free (mc_search_t * lc_mc_search);
129 gboolean mc_search_prepare (mc_search_t * mc_search);
131 gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
132 gsize end_search, gsize * found_len);
134 gboolean mc_search_is_type_avail (mc_search_type_t);
136 const mc_search_type_str_t *mc_search_types_list_get (size_t * num);
138 GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
139 char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
141 gboolean mc_search_is_fixed_search_str (mc_search_t *);
143 gchar **mc_search_get_types_strings_array (size_t * num);
145 gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
147 int mc_search_getstart_result_by_num (mc_search_t *, int);
148 int mc_search_getend_result_by_num (mc_search_t *, int);
150 #endif