diff --git a/src/search/Makefile.am b/src/search/Makefile.am index 601053a58..f45b71874 100644 --- a/src/search/Makefile.am +++ b/src/search/Makefile.am @@ -7,7 +7,8 @@ libsearch_la_SOURCES = \ lib.c \ normal.c \ regex.c \ - glob.c + glob.c \ + hex.c libsearch_la_CFLAGS=-I../ -I$(top_srcdir)/src \ $(GLIB_CFLAGS) \ diff --git a/src/search/hex.c b/src/search/hex.c new file mode 100644 index 000000000..422f397f9 --- /dev/null +++ b/src/search/hex.c @@ -0,0 +1,88 @@ +/* + Search text engine. + HEX-style pattern matching + + Copyright (C) 2009 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2009. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + + +#include "../src/global.h" +#include "../src/search/search.h" +#include "../src/search/internal.h" +#include "../src/strutil.h" +#include "../src/charsets.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +//mc_search__regex_is_char_escaped (char *start, char *current) + +static GString * +mc_search__hex_translate_to_regex (gchar * str, gsize * len) +{ + GString *buff = g_string_new (""); + return buff; +} + +/*** public functions ****************************************************************************/ + +void +mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * mc_search, + mc_search_cond_t * mc_search_cond) +{ + GString *tmp = mc_search__hex_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len); + + g_string_free (mc_search_cond->str, TRUE); + mc_search_cond->str = tmp; + + mc_search__cond_struct_new_init_regex (charset, mc_search, mc_search_cond); + +} + +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_search__run_hex (mc_search_t * mc_search, const void *user_data, + gsize start_search, gsize end_search, gsize * found_len) +{ + return mc_search__run_regex (mc_search, user_data, start_search, end_search, found_len); +} + +/* --------------------------------------------------------------------------------------------- */ + +GString * +mc_search_hex_prepare_replace_str (mc_search_t * mc_search, GString * replace_str) +{ + return mc_search_regex_prepare_replace_str (mc_search, replace_str); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/search/regex.c b/src/search/regex.c index cb14ca8d3..cf2c8b836 100644 --- a/src/search/regex.c +++ b/src/search/regex.c @@ -73,8 +73,20 @@ mc_search__regex_str_append_if_special (GString * copy_to, GString * regex_str, spec_chr_len = strlen (*spec_chr); if (!strncmp (tmp_regex_str, *spec_chr, spec_chr_len)) { if (!mc_search__regex_is_char_escaped (regex_str->str, tmp_regex_str - 1)) { - g_string_append_len (copy_to, *spec_chr, spec_chr_len); + if (!strncmp("\\x",*spec_chr, spec_chr_len)) + { + if (*(tmp_regex_str+spec_chr_len) == '{') + { + while((spec_chr_len < regex_str->len - *offset) && *(tmp_regex_str+spec_chr_len) != '}') + spec_chr_len++; + if (*(tmp_regex_str+spec_chr_len) == '}') + spec_chr_len++; + } else + spec_chr_len+=2; + } + g_string_append_len (copy_to, tmp_regex_str, spec_chr_len); *offset += spec_chr_len; +mc_log("%s\n",copy_to->str); return TRUE; } } @@ -221,6 +233,7 @@ mc_search__regex_found_cond_one (mc_search_t * mc_search, mc_search_regex_t * re if (!g_regex_match_full (regex, search_str->str, -1, 0, 0, &mc_search->regex_match_info, &error)) { g_match_info_free (mc_search->regex_match_info); + mc_search->regex_match_info = NULL; if (error) { mc_search->error = MC_SEARCH_E_REGEX; mc_search->error_str = str_conv_gerror_message (error, _(" Regular expression error ")); @@ -279,6 +292,7 @@ mc_search__regex_found_cond (mc_search_t * mc_search, GString * search_str) /* --------------------------------------------------------------------------------------------- */ +#if ! GLIB_CHECK_VERSION (2, 14, 0) static int mc_search_regex__get_num_replace_tokens (const gchar * str, gsize len) { @@ -296,7 +310,6 @@ mc_search_regex__get_num_replace_tokens (const gchar * str, gsize len) /* --------------------------------------------------------------------------------------------- */ -#if ! GLIB_CHECK_VERSION (2, 14, 0) static void mc_search_regex__append_found_token_by_num (const mc_search_t * mc_search, const gchar * fnd_str, GString * str, gsize index) diff --git a/src/search/search.c b/src/search/search.c index 156bec204..9d8f89068 100644 --- a/src/search/search.c +++ b/src/search/search.c @@ -36,8 +36,6 @@ /*** global variables ****************************************************************************/ - - /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -76,6 +74,8 @@ mc_search__cond_struct_new (mc_search_t * mc_search, const char *str, mc_search__cond_struct_new_init_regex (charset, mc_search, mc_search_cond); break; case MC_SEARCH_T_HEX: + mc_search__cond_struct_new_init_hex (charset, mc_search, mc_search_cond); + break; default: break; } @@ -272,6 +272,8 @@ mc_search_run (mc_search_t * mc_search, const void *user_data, ret = mc_search__run_glob (mc_search, user_data, start_search, end_search, found_len); break; case MC_SEARCH_T_HEX: + ret = mc_search__run_hex (mc_search, user_data, start_search, end_search, found_len); + break; default: break; } @@ -286,12 +288,10 @@ mc_search_is_type_avail (mc_search_type_t search_type) switch (search_type) { case MC_SEARCH_T_GLOB: case MC_SEARCH_T_NORMAL: - return TRUE; - break; case MC_SEARCH_T_REGEX: + case MC_SEARCH_T_HEX: return TRUE; break; - case MC_SEARCH_T_HEX: default: break; } diff --git a/src/search/search.h b/src/search/search.h index 5d3630f57..4a47a0623 100644 --- a/src/search/search.h +++ b/src/search/search.h @@ -91,11 +91,6 @@ typedef struct mc_search_struct { #endif /* HAVE_LIBPCRE */ #endif /* ! GLIB_CHECK_VERSION (2, 14, 0) */ - - - /* some data for glob */ - GPatternSpec *glob_match_info; - /* private data */ /* prepared conditions */