Ticket #1790: mc crashes on start
[midnight-commander.git] / src / search / search.h
blob176fcfaef8475a89d15a1c883065c345cf1b23ab
1 #ifndef MC__SEARCH_H
2 #define MC__SEARCH_H
4 #include <config.h>
6 #include "../src/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);
18 #define MC_SEARCH__NUM_REPLACE_ARGS 64
20 #ifdef SEARCH_TYPE_GLIB
21 # define mc_search_matchinfo_t GMatchInfo
22 #else
23 # define mc_search_matchinfo_t pcre_extra
24 #endif
26 /*** enums ***************************************************************************************/
28 typedef enum {
29 MC_SEARCH_E_OK,
30 MC_SEARCH_E_INPUT,
31 MC_SEARCH_E_REGEX_COMPILE,
32 MC_SEARCH_E_REGEX,
33 MC_SEARCH_E_REGEX_REPLACE,
34 MC_SEARCH_E_NOTFOUND
35 } mc_search_error_t;
37 typedef enum {
38 MC_SEARCH_T_NORMAL,
39 MC_SEARCH_T_REGEX,
40 MC_SEARCH_T_HEX,
41 MC_SEARCH_T_GLOB
42 } mc_search_type_t;
44 typedef enum {
45 MC_SEARCH_CB_ABORT = -1,
46 MC_SEARCH_CB_SKIP = -2
47 } mc_search_cbret_t;
50 /*** structures declarations (and typedefs of structures)*****************************************/
52 typedef struct mc_search_struct {
54 /* public input data */
56 /* search in all charsets */
57 gboolean is_all_charsets;
59 /* case sentitive search */
60 gboolean is_case_sentitive;
62 /* search only once. Is this for replace? */
63 gboolean is_once_only;
65 /* search only whole words (from begin to end). Used only with NORMAL search type */
66 gboolean whole_words;
68 /* search entire string (from begin to end). Used only with GLOB search type */
69 gboolean is_entire_line;
71 /* function, used for getting data. NULL if not used */
72 mc_search_fn search_fn;
74 /* function, used for updatin current search status. NULL if not used */
75 mc_search_fn update_fn;
77 /* type of search */
78 mc_search_type_t search_type;
81 /* public output data */
83 /* some data for normal */
84 off_t normal_offset;
86 off_t start_buffer;
87 /* some data for regexp */
88 int num_rezults;
89 mc_search_matchinfo_t *regex_match_info;
90 GString *regex_buffer;
91 #ifdef SEARCH_TYPE_PCRE
92 int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
93 #endif /* SEARCH_TYPE_PCRE */
95 /* private data */
97 /* prepared conditions */
98 GPtrArray *conditions;
100 /* original search string */
101 gchar *original;
102 gsize original_len;
104 /* error code after search */
105 mc_search_error_t error;
106 gchar *error_str;
108 } mc_search_t;
110 typedef struct mc_search_type_str_struct {
111 const char *str;
112 mc_search_type_t type;
113 } mc_search_type_str_t;
115 /*** global variables defined in .c file *********************************************************/
117 /*** declarations of public functions ************************************************************/
119 mc_search_t *mc_search_new (const gchar * original, gsize original_len);
121 void mc_search_free (mc_search_t * mc_search);
123 gboolean mc_search_prepare (mc_search_t * mc_search);
125 gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
126 gsize end_search, gsize * found_len);
128 gboolean mc_search_is_type_avail (mc_search_type_t);
130 const mc_search_type_str_t *mc_search_types_list_get (size_t *num);
132 GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
133 char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
135 gboolean mc_search_is_fixed_search_str (mc_search_t *);
137 gchar **mc_search_get_types_strings_array (size_t *num);
139 gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
141 int mc_search_getstart_rezult_by_num (mc_search_t *, int);
142 int mc_search_getend_rezult_by_num (mc_search_t *, int);
144 #endif