2009-04-22 19:52:49 +04:00
|
|
|
#ifndef MC__SEARCH_H
|
|
|
|
#define MC__SEARCH_H
|
|
|
|
|
2009-04-22 20:20:42 +04:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-04-23 17:26:14 +04:00
|
|
|
#include "../src/global.h" /* <glib.h> */
|
2009-04-22 20:20:42 +04:00
|
|
|
|
2009-09-22 13:35:09 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-07-07 12:11:29 +04:00
|
|
|
#ifdef SEARCH_TYPE_PCRE
|
2009-06-19 17:08:48 +04:00
|
|
|
# include <pcre.h>
|
2009-05-05 17:19:32 +04:00
|
|
|
#endif
|
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
|
|
|
typedef int (*mc_search_fn) (const void *user_data, gsize char_offset);
|
|
|
|
|
2009-06-02 13:09:16 +04:00
|
|
|
#define MC_SEARCH__NUM_REPLACE_ARGS 64
|
2009-05-05 17:19:32 +04:00
|
|
|
|
2009-07-07 12:11:29 +04:00
|
|
|
#ifdef SEARCH_TYPE_GLIB
|
|
|
|
# define mc_search_matchinfo_t GMatchInfo
|
2009-05-05 17:19:32 +04:00
|
|
|
#else
|
2009-06-19 17:08:48 +04:00
|
|
|
# define mc_search_matchinfo_t pcre_extra
|
2009-05-05 17:19:32 +04:00
|
|
|
#endif
|
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MC_SEARCH_E_OK,
|
|
|
|
MC_SEARCH_E_INPUT,
|
2009-04-25 11:15:56 +04:00
|
|
|
MC_SEARCH_E_REGEX_COMPILE,
|
2009-04-22 19:52:49 +04:00
|
|
|
MC_SEARCH_E_REGEX,
|
2009-04-29 19:45:21 +04:00
|
|
|
MC_SEARCH_E_REGEX_REPLACE,
|
2009-04-24 02:47:22 +04:00
|
|
|
MC_SEARCH_E_NOTFOUND
|
2009-04-22 19:52:49 +04:00
|
|
|
} mc_search_error_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MC_SEARCH_T_NORMAL,
|
|
|
|
MC_SEARCH_T_REGEX,
|
|
|
|
MC_SEARCH_T_HEX,
|
2009-04-24 02:47:22 +04:00
|
|
|
MC_SEARCH_T_GLOB
|
2009-04-22 19:52:49 +04:00
|
|
|
} mc_search_type_t;
|
|
|
|
|
2009-06-25 13:53:34 +04:00
|
|
|
typedef enum {
|
|
|
|
MC_SEARCH_CB_ABORT = -1,
|
|
|
|
MC_SEARCH_CB_SKIP = -2
|
|
|
|
} mc_search_cbret_t;
|
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
|
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
|
|
|
|
|
|
|
typedef struct mc_search_struct {
|
|
|
|
|
|
|
|
/* public input data */
|
|
|
|
|
|
|
|
/* search in all charsets */
|
|
|
|
gboolean is_all_charsets;
|
|
|
|
|
|
|
|
/* case sentitive search */
|
|
|
|
gboolean is_case_sentitive;
|
|
|
|
|
|
|
|
/* search only once. Is this for replace? */
|
|
|
|
gboolean is_once_only;
|
|
|
|
|
2009-08-22 15:06:01 +04:00
|
|
|
/* search only whole words (from begin to end). Used only with NORMAL search type */
|
|
|
|
gboolean whole_words;
|
|
|
|
|
2009-06-10 12:57:45 +04:00
|
|
|
/* search entire string (from begin to end). Used only with GLOB search type */
|
|
|
|
gboolean is_entire_line;
|
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
/* function, used for getting data. NULL if not used */
|
|
|
|
mc_search_fn search_fn;
|
|
|
|
|
2009-06-25 13:53:34 +04:00
|
|
|
/* function, used for updatin current search status. NULL if not used */
|
|
|
|
mc_search_fn update_fn;
|
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
/* type of search */
|
|
|
|
mc_search_type_t search_type;
|
|
|
|
|
|
|
|
|
|
|
|
/* public output data */
|
|
|
|
|
|
|
|
/* some data for normal */
|
2009-08-10 13:44:43 +04:00
|
|
|
off_t normal_offset;
|
2009-04-22 19:52:49 +04:00
|
|
|
|
2009-08-10 13:44:43 +04:00
|
|
|
off_t start_buffer;
|
2009-04-22 19:52:49 +04:00
|
|
|
/* some data for regexp */
|
2009-06-02 13:09:16 +04:00
|
|
|
int num_rezults;
|
2009-05-05 17:19:32 +04:00
|
|
|
mc_search_matchinfo_t *regex_match_info;
|
2009-04-30 11:32:45 +04:00
|
|
|
GString *regex_buffer;
|
2009-07-07 12:11:29 +04:00
|
|
|
#ifdef SEARCH_TYPE_PCRE
|
2009-06-05 12:51:12 +04:00
|
|
|
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
|
2009-07-07 12:11:29 +04:00
|
|
|
#endif /* SEARCH_TYPE_PCRE */
|
2009-05-05 17:19:32 +04:00
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
/* private data */
|
|
|
|
|
|
|
|
/* prepared conditions */
|
|
|
|
GPtrArray *conditions;
|
|
|
|
|
|
|
|
/* original search string */
|
|
|
|
gchar *original;
|
2009-04-23 17:16:00 +04:00
|
|
|
gsize original_len;
|
2009-04-22 19:52:49 +04:00
|
|
|
|
|
|
|
/* error code after search */
|
|
|
|
mc_search_error_t error;
|
|
|
|
gchar *error_str;
|
|
|
|
|
|
|
|
} mc_search_t;
|
|
|
|
|
2009-04-29 17:13:12 +04:00
|
|
|
typedef struct mc_search_type_str_struct {
|
2009-07-15 22:53:13 +04:00
|
|
|
const char *str;
|
2009-04-29 17:13:12 +04:00
|
|
|
mc_search_type_t type;
|
|
|
|
} mc_search_type_str_t;
|
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
|
|
|
/*** declarations of public functions ************************************************************/
|
|
|
|
|
2009-04-23 17:16:00 +04:00
|
|
|
mc_search_t *mc_search_new (const gchar * original, gsize original_len);
|
2009-04-22 19:52:49 +04:00
|
|
|
|
|
|
|
void mc_search_free (mc_search_t * mc_search);
|
|
|
|
|
2009-06-22 21:46:34 +04:00
|
|
|
gboolean mc_search_prepare (mc_search_t * mc_search);
|
|
|
|
|
2009-04-23 17:26:14 +04:00
|
|
|
gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
|
2009-06-25 13:53:34 +04:00
|
|
|
gsize end_search, gsize * found_len);
|
2009-04-23 15:30:14 +04:00
|
|
|
|
2009-04-25 11:15:56 +04:00
|
|
|
gboolean mc_search_is_type_avail (mc_search_type_t);
|
|
|
|
|
2009-09-22 13:35:09 +04:00
|
|
|
const mc_search_type_str_t *mc_search_types_list_get (size_t *num);
|
2009-04-29 17:13:12 +04:00
|
|
|
|
2009-04-30 11:32:45 +04:00
|
|
|
GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
|
2009-06-12 18:10:38 +04:00
|
|
|
char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
|
2009-04-29 19:45:21 +04:00
|
|
|
|
2009-04-30 17:06:24 +04:00
|
|
|
gboolean mc_search_is_fixed_search_str (mc_search_t *);
|
2009-04-30 15:21:39 +04:00
|
|
|
|
2009-09-22 13:35:09 +04:00
|
|
|
gchar **mc_search_get_types_strings_array (size_t *num);
|
2009-05-06 11:50:12 +04:00
|
|
|
|
2009-05-06 20:12:32 +04:00
|
|
|
gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
|
|
|
|
|
2009-06-02 13:09:16 +04:00
|
|
|
int mc_search_getstart_rezult_by_num (mc_search_t *, int);
|
|
|
|
int mc_search_getend_rezult_by_num (mc_search_t *, int);
|
2009-05-06 20:12:32 +04:00
|
|
|
|
2009-04-22 19:52:49 +04:00
|
|
|
#endif
|