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-05-05 17:19:32 +04:00
|
|
|
#if ! GLIB_CHECK_VERSION (2, 14, 0)
|
|
|
|
# if HAVE_LIBPCRE
|
|
|
|
# include <pcre.h>
|
|
|
|
# else
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <string.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <regex.h>
|
|
|
|
# endif
|
|
|
|
#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
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION (2, 14, 0)
|
|
|
|
#define mc_search_matchinfo_t GMatchInfo
|
|
|
|
#else
|
|
|
|
# if HAVE_LIBPCRE
|
|
|
|
# define mc_search_matchinfo_t pcre_extra
|
|
|
|
# else
|
|
|
|
# define mc_search_matchinfo_t regmatch_t
|
|
|
|
# endif
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
|
|
/*** 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-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;
|
|
|
|
|
|
|
|
/* type of search */
|
|
|
|
mc_search_type_t search_type;
|
|
|
|
|
|
|
|
|
|
|
|
/* public output data */
|
|
|
|
|
|
|
|
/* some data for normal */
|
|
|
|
gsize normal_offset;
|
|
|
|
|
|
|
|
/* 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-05-05 17:19:32 +04:00
|
|
|
#if ! GLIB_CHECK_VERSION (2, 14, 0)
|
|
|
|
#if HAVE_LIBPCRE
|
2009-06-05 12:51:12 +04:00
|
|
|
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
|
2009-05-05 17:19:32 +04:00
|
|
|
#endif /* HAVE_LIBPCRE */
|
|
|
|
#endif /* ! GLIB_CHECK_VERSION (2, 14, 0) */
|
|
|
|
|
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 {
|
|
|
|
char *str;
|
|
|
|
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-04-23 17:26:14 +04:00
|
|
|
gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
|
|
|
|
gsize end_search, gsize * founded_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-05-08 16:23:38 +04:00
|
|
|
const mc_search_type_str_t *mc_search_types_list_get (void);
|
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-05-06 11:50:12 +04:00
|
|
|
gchar **mc_search_get_types_strings_array (void);
|
|
|
|
|
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
|