Search engine:
* fixed double-free memory * changed logic of parce regexp-string for \x{HEX} token * added template file hex.c for HEX search type
Этот коммит содержится в:
родитель
7ec7294713
Коммит
0eb537d8d5
@ -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) \
|
||||
|
88
src/search/hex.c
Обычный файл
88
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 <slavazanko@gmail.com>, 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 <config.h>
|
||||
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user