root/lib/search.h

/* [previous][next][first][last][top][bottom][index][help]  */

INCLUDED FROM


   1 #ifndef MC__SEARCH_H
   2 #define MC__SEARCH_H
   3 
   4 #include <config.h>
   5 
   6 #include "lib/global.h"         /* <glib.h> */
   7 
   8 #include <sys/types.h>
   9 
  10 #ifdef SEARCH_TYPE_PCRE
  11 #include <pcre.h>
  12 #endif
  13 
  14 /*** typedefs(not structures) and defined constants **********************************************/
  15 
  16 typedef enum mc_search_cbret_t mc_search_cbret_t;
  17 
  18 typedef mc_search_cbret_t (*mc_search_fn) (const void *user_data, gsize char_offset,
  19                                            int *current_char);
  20 typedef mc_search_cbret_t (*mc_update_fn) (const void *user_data, gsize char_offset);
  21 
  22 #define MC_SEARCH__NUM_REPLACE_ARGS 64
  23 
  24 #ifdef SEARCH_TYPE_GLIB
  25 #define mc_search_matchinfo_t GMatchInfo
  26 #else
  27 #define mc_search_matchinfo_t pcre_extra
  28 #endif
  29 
  30 /*** enums ***************************************************************************************/
  31 
  32 typedef enum
  33 {
  34     MC_SEARCH_E_OK = 0,
  35     MC_SEARCH_E_INPUT,
  36     MC_SEARCH_E_REGEX_COMPILE,
  37     MC_SEARCH_E_REGEX,
  38     MC_SEARCH_E_REGEX_REPLACE,
  39     MC_SEARCH_E_NOTFOUND,
  40     MC_SEARCH_E_ABORT
  41 } mc_search_error_t;
  42 
  43 typedef enum
  44 {
  45     MC_SEARCH_T_INVALID = -1,
  46     MC_SEARCH_T_NORMAL,
  47     MC_SEARCH_T_REGEX,
  48     MC_SEARCH_T_HEX,
  49     MC_SEARCH_T_GLOB
  50 } mc_search_type_t;
  51 
  52 enum mc_search_cbret_t
  53 {
  54     MC_SEARCH_CB_OK = 0,
  55     MC_SEARCH_CB_INVALID = -1,
  56     MC_SEARCH_CB_ABORT = -2,
  57     MC_SEARCH_CB_SKIP = -3,
  58     MC_SEARCH_CB_NOTFOUND = -4
  59 };
  60 
  61 /*** structures declarations (and typedefs of structures)*****************************************/
  62 
  63 typedef struct mc_search_struct
  64 {
  65     /* public input data */
  66 
  67 #ifdef HAVE_CHARSET
  68     /* search in all charsets */
  69     gboolean is_all_charsets;
  70 #endif
  71 
  72     /* case sensitive search */
  73     gboolean is_case_sensitive;
  74 
  75     /* search only once.  Is this for replace? */
  76     gboolean is_once_only;
  77 
  78     /* search only whole words (from begin to end). Used only with NORMAL search type */
  79     gboolean whole_words;
  80 
  81     /* search entire string (from begin to end). Used only with GLOB search type */
  82     gboolean is_entire_line;
  83 
  84     /* function, used for getting data. NULL if not used */
  85     mc_search_fn search_fn;
  86 
  87     /* function, used for updatin current search status. NULL if not used */
  88     mc_update_fn update_fn;
  89 
  90     /* type of search */
  91     mc_search_type_t search_type;
  92 
  93     /* public output data */
  94 
  95     /* some data for normal */
  96     off_t normal_offset;
  97 
  98     off_t start_buffer;
  99     /* some data for regexp */
 100     int num_results;
 101     gboolean is_utf8;
 102     mc_search_matchinfo_t *regex_match_info;
 103     GString *regex_buffer;
 104 #ifdef SEARCH_TYPE_PCRE
 105     int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
 106 #endif                          /* SEARCH_TYPE_PCRE */
 107 
 108     /* private data */
 109 
 110     /* prepared conditions */
 111     GPtrArray *conditions;
 112 
 113     /* original search string */
 114     gchar *original;
 115     gsize original_len;
 116 #ifdef HAVE_CHARSET
 117     gchar *original_charset;
 118 #endif
 119 
 120     /* error code after search */
 121     mc_search_error_t error;
 122     gchar *error_str;
 123 } mc_search_t;
 124 
 125 typedef struct mc_search_type_str_struct
 126 {
 127     const char *str;
 128     mc_search_type_t type;
 129 } mc_search_type_str_t;
 130 
 131 /*** global variables defined in .c file *********************************************************/
 132 
 133 /* Error messages */
 134 extern const char *STR_E_NOTFOUND;
 135 extern const char *STR_E_UNKNOWN_TYPE;
 136 extern const char *STR_E_RPL_NOT_EQ_TO_FOUND;
 137 extern const char *STR_E_RPL_INVALID_TOKEN;
 138 
 139 /*** declarations of public functions ************************************************************/
 140 
 141 mc_search_t *mc_search_new (const gchar * original, const gchar * original_charset);
 142 
 143 mc_search_t *mc_search_new_len (const gchar * original, gsize original_len,
 144                                 const gchar * original_charset);
 145 
 146 void mc_search_free (mc_search_t * lc_mc_search);
 147 
 148 gboolean mc_search_prepare (mc_search_t * mc_search);
 149 
 150 gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search,
 151                         gsize end_search, gsize * found_len);
 152 
 153 gboolean mc_search_is_type_avail (mc_search_type_t);
 154 
 155 const mc_search_type_str_t *mc_search_types_list_get (size_t * num);
 156 
 157 GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
 158 char *mc_search_prepare_replace_str2 (mc_search_t * lc_mc_search, const char *replace_str);
 159 
 160 gboolean mc_search_is_fixed_search_str (mc_search_t *);
 161 
 162 gchar **mc_search_get_types_strings_array (size_t * num);
 163 
 164 gboolean mc_search (const gchar * pattern, const gchar * pattern_charset, const gchar * str,
 165                     mc_search_type_t type);
 166 
 167 int mc_search_getstart_result_by_num (mc_search_t *, int);
 168 int mc_search_getend_result_by_num (mc_search_t *, int);
 169 
 170 /* *INDENT-OFF* */
 171 void mc_search_set_error (mc_search_t * lc_mc_search, mc_search_error_t code, const gchar * format, ...)
 172      G_GNUC_PRINTF (3, 4);
 173 /* *INDENT-ON* */
 174 
 175 #endif

/* [previous][next][first][last][top][bottom][index][help]  */