From 87979e779bb2cdf98253f22050d5d3d58cf68183 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 12 Oct 2009 14:56:46 +0300 Subject: [PATCH] Ticket #1532: Key configuration doesn't save properly Problem: need to escape ';' char (as '\;'), but mc_config_set_string function escape this to '\\;' Solution: Added mc_config_direct_set_string() function. Also, into src/learn.c characters '\' and ';' is escaped manually. Signed-off-by: Slava Zanko --- src/learn.c | 11 +++++++++-- src/mcconfig/mcconfig.h | 4 ++++ src/mcconfig/set.c | 52 +++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/learn.c b/src/learn.c index 505973920..c97fab6b7 100644 --- a/src/learn.c +++ b/src/learn.c @@ -47,6 +47,7 @@ #include "learn.h" #include "wtools.h" #include "strutil.h" +#include "strescape.h" #define UX 4 #define UY 3 @@ -311,12 +312,18 @@ learn_save (void) int i; int profile_changed = 0; char *section = g_strconcat ("terminal:", getenv ("TERM"), (char *) NULL); + char *esc_str; for (i = 0; i < learn_total; i++) { if (learnkeys [i].sequence != NULL) { profile_changed = 1; - mc_config_set_string(mc_main_config, section, - key_name_conv_tab [i].name, learnkeys [i].sequence); + + esc_str = strutils_escape (learnkeys [i].sequence, -1, ";\\", TRUE); + + mc_config_direct_set_string(mc_main_config, section, + key_name_conv_tab [i].name, esc_str); + + g_free(esc_str); } } diff --git a/src/mcconfig/mcconfig.h b/src/mcconfig/mcconfig.h index bf98b4937..29e78bfa9 100644 --- a/src/mcconfig/mcconfig.h +++ b/src/mcconfig/mcconfig.h @@ -71,6 +71,10 @@ int *mc_config_get_int_list (mc_config_t *, const gchar *, /* mcconfig/set.c: */ void +mc_config_direct_set_string (mc_config_t *, const gchar *, + const gchar *, const gchar *); + +void mc_config_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *); diff --git a/src/mcconfig/set.c b/src/mcconfig/set.c index 30c67cbaf..047c26cae 100644 --- a/src/mcconfig/set.c +++ b/src/mcconfig/set.c @@ -35,19 +35,14 @@ extern int utf8_display; /*** file scope variables **********************************************/ /*** file scope functions **********************************************/ +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/*** public functions **************************************************/ - -void -mc_config_set_string (mc_config_t * mc_config, const gchar * group, - const gchar * param, const gchar * value) +static gchar * +mc_config_normalize_before_save(const gchar * value) { GIConv conv; GString *buffer; - if (!mc_config || !group || !param || !value) - return; - if (utf8_display) { buffer = g_string_new(value); @@ -69,8 +64,45 @@ mc_config_set_string (mc_config_t * mc_config, const gchar * group, str_close_conv (conv); } - g_key_file_set_string (mc_config->handle, group, param, buffer->str); - g_string_free(buffer, TRUE); + return g_string_free(buffer, FALSE); +} + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +/*** public functions **************************************************/ +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +void +mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group, + const gchar * param, const gchar * value) +{ + gchar *buffer; + + if (!mc_config || !group || !param || !value) + return; + + buffer = mc_config_normalize_before_save(value); + + g_key_file_set_value (mc_config->handle, group, param, buffer); + + g_free(buffer); +} + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +void +mc_config_set_string (mc_config_t * mc_config, const gchar * group, + const gchar * param, const gchar * value) +{ + gchar *buffer; + + if (!mc_config || !group || !param || !value) + return; + + buffer = mc_config_normalize_before_save(value); + + g_key_file_set_string (mc_config->handle, group, param, buffer); + + g_free(buffer); } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -- 2.11.4.GIT