Warning fix: return discards qualifiers from pointer target type
[midnight-commander.git] / src / search / search.h
blob5b8f0a421c47ce4610bcc03d71e398b8550ce8a9
1 #ifndef MC__SEARCH_H
2 #define MC__SEARCH_H
4 #include <config.h>
6 #include "../src/global.h" /* <glib.h> */
8 #if ! GLIB_CHECK_VERSION (2, 14, 0)
9 # if HAVE_LIBPCRE
10 # include <pcre.h>
11 # else
12 # include <stdio.h>
13 # include <string.h>
14 # include <sys/types.h>
15 # include <regex.h>
16 # endif
17 #endif
19 /*** typedefs(not structures) and defined constants **********************************************/
21 typedef int (*mc_search_fn) (const void *user_data, gsize char_offset);
23 #define MC_SEARCH__NUM_REPL_ARGS 64
25 #if GLIB_CHECK_VERSION (2, 14, 0)
26 #define mc_search_matchinfo_t GMatchInfo
27 #else
28 # if HAVE_LIBPCRE
29 # define mc_search_matchinfo_t pcre_extra
30 # else
31 # define mc_search_matchinfo_t regmatch_t
32 # endif
33 #endif
35 #define MC_SEARCH__PCRE_MAX_MATCHES 64
37 /*** enums ***************************************************************************************/
39 typedef enum {
40 MC_SEARCH_E_OK,
41 MC_SEARCH_E_INPUT,
42 MC_SEARCH_E_REGEX_COMPILE,
43 MC_SEARCH_E_REGEX,
44 MC_SEARCH_E_REGEX_REPLACE,
45 MC_SEARCH_E_NOTFOUND
46 } mc_search_error_t;
48 typedef enum {
49 MC_SEARCH_T_NORMAL,
50 MC_SEARCH_T_REGEX,
51 MC_SEARCH_T_HEX,
52 MC_SEARCH_T_GLOB
53 } mc_search_type_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 sentitive search */
66 gboolean is_case_sentitive;
68 /* search only once. Is this for replace? */
69 gboolean is_once_only;
71 /* function, used for getting data. NULL if not used */
72 mc_search_fn search_fn;
74 /* type of search */
75 mc_search_type_t search_type;
78 /* public output data */
80 /* some data for normal */
81 gsize normal_offset;
83 /* some data for regexp */
84 mc_search_matchinfo_t *regex_match_info;
85 GString *regex_buffer;
86 #if ! GLIB_CHECK_VERSION (2, 14, 0)
87 int num_rezults;
88 #if HAVE_LIBPCRE
89 int iovector[MC_SEARCH__PCRE_MAX_MATCHES * 2];
90 #else /* HAVE_LIBPCRE */
91 #endif /* HAVE_LIBPCRE */
92 #endif /* ! GLIB_CHECK_VERSION (2, 14, 0) */
94 /* private data */
96 /* prepared conditions */
97 GPtrArray *conditions;
99 /* original search string */
100 gchar *original;
101 gsize original_len;
103 /* error code after search */
104 mc_search_error_t error;
105 gchar *error_str;
107 } mc_search_t;
109 typedef struct mc_search_type_str_struct {
110 char *str;
111 mc_search_type_t type;
112 } mc_search_type_str_t;
114 /*** global variables defined in .c file *********************************************************/
116 /*** declarations of public functions ************************************************************/
118 mc_search_t *mc_search_new (const gchar * original, gsize original_len);
120 void mc_search_free (mc_search_t * mc_search);
122 gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
123 gsize end_search, gsize * founded_len);
125 gboolean mc_search_is_type_avail (mc_search_type_t);
127 const mc_search_type_str_t *mc_search_types_list_get (void);
129 GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
131 gboolean mc_search_is_fixed_search_str (mc_search_t *);
133 gchar **mc_search_get_types_strings_array (void);
135 gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
137 int mc_search_getstart_rezult_by_num(mc_search_t *, int);
138 int mc_search_getend_rezult_by_num(mc_search_t *, int);
140 #endif