Manual pages: mcmcdiffmceditmcview

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 /*** typedefs(not structures) and defined constants **********************************************/
  11 
  12 typedef enum mc_search_cbret_t mc_search_cbret_t;
  13 
  14 typedef mc_search_cbret_t (*mc_search_fn) (const void *user_data, off_t char_offset,
  15                                            int *current_char);
  16 typedef mc_search_cbret_t (*mc_update_fn) (const void *user_data, off_t char_offset);
  17 
  18 #define MC_SEARCH__NUM_REPLACE_ARGS 64
  19 
  20 /*** enums ***************************************************************************************/
  21 
  22 typedef enum
  23 {
  24     MC_SEARCH_E_OK = 0,
  25     MC_SEARCH_E_INPUT,
  26     MC_SEARCH_E_REGEX_COMPILE,
  27     MC_SEARCH_E_REGEX,
  28     MC_SEARCH_E_REGEX_REPLACE,
  29     MC_SEARCH_E_NOTFOUND,
  30     MC_SEARCH_E_ABORT
  31 } mc_search_error_t;
  32 
  33 typedef enum
  34 {
  35     MC_SEARCH_T_INVALID = -1,
  36     MC_SEARCH_T_NORMAL,
  37     MC_SEARCH_T_REGEX,
  38     MC_SEARCH_T_HEX,
  39     MC_SEARCH_T_GLOB
  40 } mc_search_type_t;
  41 
  42 /**
  43  * enum to store search conditions check results.
  44  * (whether the search condition has BOL (^) or EOL ($) regexp characters).
  45  */
  46 typedef enum
  47 {
  48     MC_SEARCH_LINE_NONE = 0,
  49     MC_SEARCH_LINE_BEGIN = 1 << 0,
  50     MC_SEARCH_LINE_END = 1 << 1,
  51     MC_SEARCH_LINE_ENTIRE = MC_SEARCH_LINE_BEGIN | MC_SEARCH_LINE_END
  52 } mc_search_line_t;
  53 
  54 enum mc_search_cbret_t
  55 {
  56     MC_SEARCH_CB_OK = 0,
  57     MC_SEARCH_CB_INVALID = -1,
  58     MC_SEARCH_CB_ABORT = -2,
  59     MC_SEARCH_CB_SKIP = -3,
  60     MC_SEARCH_CB_NOTFOUND = -4
  61 };
  62 
  63 /*** structures declarations (and typedefs of structures)*****************************************/
  64 
  65 typedef struct mc_search_struct
  66 {
  67     // public input data
  68 
  69     // search in all charsets
  70     gboolean is_all_charsets;
  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     GMatchInfo *regex_match_info;
 103     GString *regex_buffer;
 104 
 105     // private data
 106 
 107     struct
 108     {
 109         GPtrArray *conditions;
 110         gboolean result;
 111     } prepared;
 112 
 113     // original search string
 114     struct
 115     {
 116         GString *str;
 117         gchar *charset;
 118     } original;
 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, off_t start_search,
 151                         off_t end_search, gsize *found_len);
 152 
 153 gboolean mc_search_is_type_avail (mc_search_type_t search_type);
 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 (const mc_search_t *lc_mc_search);
 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 mc_search_line_t mc_search_get_line_type (const mc_search_t *search);
 168 
 169 int mc_search_getstart_result_by_num (mc_search_t *lc_mc_search, int lc_index);
 170 int mc_search_getend_result_by_num (mc_search_t *lc_mc_search, int lc_index);
 171 
 172 void mc_search_set_error (mc_search_t *lc_mc_search, mc_search_error_t code, const gchar *format,
 173                           ...) G_GNUC_PRINTF (3, 4);
 174 
 175 #endif

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