From 4586834cb9d4d84b4493bbb58e36d9c32abfb409 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 7 Aug 2009 14:47:26 +0300 Subject: [PATCH] Ticket #414 (shell patterns in copy dialog) Handle asterisks into replace template string. Signed-off-by: Slava Zanko --- src/search/glob.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/search/glob.c b/src/search/glob.c index c35b7121a..08caab4dd 100644 --- a/src/search/glob.c +++ b/src/search/glob.c @@ -110,6 +110,33 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len) return buff; } +/* --------------------------------------------------------------------------------------------- */ + +static GString * +mc_search__translate_replace_glob_to_regex (gchar *str) +{ + GString *buff = g_string_new (""); + int cnt = '0'; + + while (*str) { + char c = *str++; + switch (c) { + case '*': + case '?': + g_string_append_c (buff, '\\'); + c = ++cnt; + break; + /* breaks copying: mc uses "\0" internally, it must not be changed */ + /*case '\\':*/ + case '&': + g_string_append_c (buff, '\\'); + break; + } + g_string_append_c (buff, c); + } + return buff; +} + /*** public functions ****************************************************************************/ void @@ -141,8 +168,15 @@ mc_search__run_glob (mc_search_t * mc_search, const void *user_data, } /* --------------------------------------------------------------------------------------------- */ + + GString * mc_search_glob_prepare_replace_str (mc_search_t * mc_search, GString * replace_str) { - return mc_search_regex_prepare_replace_str (mc_search, replace_str); + GString *repl = mc_search__translate_replace_glob_to_regex(replace_str->str); + GString *res = mc_search_regex_prepare_replace_str (mc_search, repl); + g_string_free (repl, TRUE); + return res; } + +/* --------------------------------------------------------------------------------------------- */