From 5007553299db71d59cea002fe710ae0f558d2a8e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 13 Sep 2010 13:32:27 +0400 Subject: [PATCH] Remove only supported encodings from path. Signed-off-by: Andrew Borodin --- lib/utilunix.c | 9 +++++++-- lib/vfs/mc-vfs/vfs.c | 22 +++------------------- src/charsets.c | 14 ++++++++++++++ src/charsets.h | 1 + 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/utilunix.c b/lib/utilunix.c index 2252933dc..806ad70a5 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -53,6 +53,9 @@ #include "src/execute.h" #include "src/wtools.h" /* message() */ +#ifdef HAVE_CHARSET +#include "src/charsets.h" +#endif struct sigaction startup_handler; @@ -630,7 +633,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) { /* "token/../foo" -> "foo" */ #if HAVE_CHARSET - if (strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0) + if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0) + && (is_supported_encoding (s + enc_prefix_len))) /* special case: remove encoding */ str_move (s, p + 1); else @@ -657,7 +661,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) if (s == lpath + 1) s[0] = 0; #if HAVE_CHARSET - else if (strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0) + else if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0) + && (is_supported_encoding (s + enc_prefix_len))) { /* special case: remove encoding */ s[0] = '.'; diff --git a/lib/vfs/mc-vfs/vfs.c b/lib/vfs/mc-vfs/vfs.c index 641c172e4..b4b6c4c36 100644 --- a/lib/vfs/mc-vfs/vfs.c +++ b/lib/vfs/mc-vfs/vfs.c @@ -393,24 +393,6 @@ vfs_get_encoding (const char *path) } } -/* return if encoding can by used in vfs (is ascci full compactible) */ -/* contains only a few encoding now */ -static gboolean -vfs_supported_enconding (const char *encoding) -{ - gboolean result = FALSE; - -#ifdef HAVE_CHARSET - int t; - - for (t = 0; t < n_codepages; t++) - result |= (g_ascii_strncasecmp (encoding, codepages[t].id, - strlen (codepages[t].id)) == 0); -#endif - - return result; -} - /* now used only by vfs_translate_path, but could be used in other vfs * plugin to automatic detect encoding * path - path to translate @@ -468,8 +450,10 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer memcpy (encoding, semi, ms); encoding[ms] = '\0'; - if (vfs_supported_enconding (encoding)) +#if HAVE_CHARSET + if (is_supported_encoding (encoding)) coder = str_crt_conv_to (encoding); +#endif if (coder != INVALID_CONV) { diff --git a/src/charsets.c b/src/charsets.c index 0958f7fb5..1638dc459 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -162,6 +162,20 @@ get_codepage_index (const char *id) return -1; } +/* return if encoding can by used in mc */ +gboolean +is_supported_encoding (const char *encoding) +{ + gboolean result = FALSE; + size_t t; + + for (t = 0; t < (size_t) n_codepages; t++) + result |= (g_ascii_strncasecmp (encoding, codepages[t].id, + strlen (codepages[t].id)) == 0); + + return result; +} + static char translate_character (GIConv cd, char c) { diff --git a/src/charsets.h b/src/charsets.h index 087a5bb1f..ea54930df 100644 --- a/src/charsets.h +++ b/src/charsets.h @@ -28,6 +28,7 @@ const char *get_codepage_id (const int n); int get_codepage_index (const char *id); int load_codepages_list (void); void free_codepages_list (void); +gboolean is_supported_encoding (const char *encoding); char *init_translation_table (int cpsource, int cpdisplay); void convert_to_display (char *str); void convert_from_input (char *str); -- 2.11.4.GIT