From dfbe1130d57909f79faed7edcbe2dcc17bf6e7ed Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 9 Sep 2010 09:56:51 +0400 Subject: [PATCH 01/11] Ticket #1512: panel encoding is not shown correctly in "Choose codepage" dialog. Initial step: renamed set_panel_encoding() to panel_change_encoding(). Signed-off-by: Andrew Borodin --- src/cmd.c | 2 +- src/panel.h | 2 +- src/screen.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 52497e74d..333787827 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1551,5 +1551,5 @@ void encoding_cmd (void) { if (SELECTED_IS_PANEL) - set_panel_encoding (MENU_PANEL); + panel_change_encoding (MENU_PANEL); } diff --git a/src/panel.h b/src/panel.h index 65bde5305..4b0e81c4d 100644 --- a/src/panel.h +++ b/src/panel.h @@ -111,7 +111,7 @@ extern int show_mini_info; void panel_reload (WPanel *panel); void panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order); void panel_re_sort (WPanel *panel); -void set_panel_encoding (WPanel *); +void panel_change_encoding (WPanel * panel); #define UP_OPTIMIZE 0 #define UP_RELOAD 1 diff --git a/src/screen.c b/src/screen.c index 14257960d..3b2862fb6 100644 --- a/src/screen.c +++ b/src/screen.c @@ -3065,7 +3065,7 @@ panel_execute_cmd (WPanel * panel, unsigned long command) move_home (panel); break; case CK_PanelSetPanelEncoding: - set_panel_encoding (panel); + panel_change_encoding (panel); break; case CK_PanelStartSearch: start_search (panel); @@ -3502,7 +3502,7 @@ panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order) } void -set_panel_encoding (WPanel * panel) +panel_change_encoding (WPanel * panel) { const char *encoding = NULL; char *cd_path; From 51b14f2b7b259aace48d44901ec0e0ef501f548e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 9 Sep 2010 10:13:05 +0400 Subject: [PATCH 02/11] Don't push directory to history twice. Unified error message. Signed-off-by: Andrew Borodin --- src/cmd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 333787827..66446e7af 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1245,10 +1245,8 @@ nice_cd (const char *text, const char *xtext, const char *help, else cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); - if (do_panel_cd (MENU_PANEL, cd_path, cd_parse_command)) - directory_history_add (MENU_PANEL, (MENU_PANEL)->cwd); - else - message (D_ERROR, MSG_ERROR, _("Cannot chdir to %s"), cd_path); + if (!do_panel_cd (MENU_PANEL, cd_path, cd_parse_command)) + message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); g_free (cd_path); g_free (machine); } From 3a11b04ef3901859cb1ff28427352fd748002f8e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 9 Sep 2010 10:56:51 +0400 Subject: [PATCH 03/11] Load codepage list before loading of configuration. Signed-off-by: Andrew Borodin --- src/setup.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/setup.c b/src/setup.c index a307a90e3..a0a20487d 100644 --- a/src/setup.c +++ b/src/setup.c @@ -721,6 +721,11 @@ load_setup (void) size_t i; char *buffer; const char *kt; +#ifdef HAVE_CHARSET + int cpages = -1; + + cpages = load_codepages_list (); +#endif /* HAVE_CHARSET */ profile = setup_init (); @@ -811,7 +816,7 @@ load_setup (void) /* Remove the temporal entries */ #ifdef HAVE_CHARSET - if (load_codepages_list () > 0) + if (cpages > 0) { buffer = mc_config_get_string (mc_main_config, "Misc", "display_codepage", ""); if (buffer[0] != '\0') @@ -824,7 +829,7 @@ load_setup (void) if (buffer[0] != '\0') { default_source_codepage = get_codepage_index (buffer); - source_codepage = default_source_codepage; /* May be source_codepage don't needed this */ + source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */ cp_source = get_codepage_id (source_codepage); } g_free (buffer); @@ -839,6 +844,7 @@ load_setup (void) if (buffer != NULL) utf8_display = str_isutf8 (buffer); #endif /* HAVE_CHARSET */ + clipboard_store_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_store", ""); clipboard_paste_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_paste", ""); } From 9b51fcc0fa97e4079e5a166d2e87c560ff59a714 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 9 Sep 2010 11:11:19 +0400 Subject: [PATCH 04/11] Minor optimization of panel_new_with_dir(). Type/value accuracy. Signed-off-by: Andrew Borodin --- src/screen.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/screen.c b/src/screen.c index 3b2862fb6..5a771d737 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1323,7 +1323,7 @@ panel_new_with_dir (const char *panel_name, const char *wpath) WPanel *panel; char *section; int i, err; - char curdir[MC_MAXPATHLEN]; + char curdir[MC_MAXPATHLEN] = "\0"; panel = g_new0 (WPanel, 1); @@ -1333,7 +1333,7 @@ panel_new_with_dir (const char *panel_name, const char *wpath) /* We do not want the cursor */ widget_want_cursor (panel->widget, 0); - if (wpath) + if (wpath != NULL) { g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd)); mc_get_current_wd (curdir, sizeof (curdir) - 2); @@ -1371,8 +1371,9 @@ panel_new_with_dir (const char *panel_name, const char *wpath) for (i = 0; i < LIST_TYPES; i++) panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); - panel->search_buffer[0] = 0; + panel->search_buffer[0] = '\0'; panel->frame_size = frame_half; + section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL); if (!mc_config_has_group (mc_main_config, section)) { @@ -1387,12 +1388,7 @@ panel_new_with_dir (const char *panel_name, const char *wpath) if (err != 0) set_panel_formats (panel); - /* Because do_load_dir lists files in current directory */ - if (wpath) - { - int ret; - ret = mc_chdir (wpath); - } + err = mc_chdir (panel->cwd); /* Load the default format */ panel->count = @@ -1400,11 +1396,8 @@ panel_new_with_dir (const char *panel_name, const char *wpath) panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter); /* Restore old right path */ - if (wpath) - { - int ret; - ret = mc_chdir (curdir); - } + if (curdir[0] != '\0') + err = mc_chdir (curdir); return panel; } From f7ee6f8cf2ca06767078b2f00595663f762ed600 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 9 Sep 2010 12:22:51 +0400 Subject: [PATCH 05/11] Added codepage member to the WPanel struct. Signed-off-by: Andrew Borodin --- src/panel.h | 4 +++- src/screen.c | 42 +++++++++++++++++++++++++++++------------- src/selcodepage.h | 4 ---- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/panel.h b/src/panel.h index 4b0e81c4d..2624b097a 100644 --- a/src/panel.h +++ b/src/panel.h @@ -6,7 +6,7 @@ #ifndef MC_PANEL_H #define MC_PANEL_H -#include "lib/global.h" +#include "lib/global.h" /* gboolean */ #include "lib/fs.h" /* MC_MAXPATHLEN */ #include "lib/strutil.h" @@ -95,6 +95,8 @@ typedef struct WPanel { char *panel_name; /* The panel name */ struct stat dir_stat; /* Stat of current dir: used by execute () */ + int codepage; /* panel codepage */ + gboolean searching; char search_buffer [256]; char search_char [MB_LEN_MAX]; /*buffer for multibytes characters*/ diff --git a/src/screen.c b/src/screen.c index 5a771d737..49ae117a7 100644 --- a/src/screen.c +++ b/src/screen.c @@ -60,18 +60,20 @@ #include "main-widgets.h" #include "main.h" #include "mountlist.h" /* my_statfs */ -#include "selcodepage.h" /* select_charset () */ +#include "selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */ +#ifdef HAVE_CHARSET #include "charsets.h" /* get_codepage_id () */ +#endif #include "cmddef.h" /* CK_ cmd name const */ #include "keybind.h" /* global_keymap_t */ #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) ) -#define NORMAL 0 -#define SELECTED 1 -#define MARKED 2 -#define MARKED_SELECTED 3 -#define STATUS 5 +#define NORMAL 0 +#define SELECTED 1 +#define MARKED 2 +#define MARKED_SELECTED 3 +#define STATUS 5 typedef enum { @@ -1368,6 +1370,8 @@ panel_new_with_dir (const char *panel_name, const char *wpath) panel->panel_name = g_strdup (panel_name); panel->user_format = g_strdup (DEFAULT_USER_FORMAT); + panel->codepage = SELECT_CHARSET_NO_TRANSLATE; + for (i = 0; i < LIST_TYPES; i++) panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); @@ -1388,7 +1392,19 @@ panel_new_with_dir (const char *panel_name, const char *wpath) if (err != 0) set_panel_formats (panel); - err = mc_chdir (panel->cwd); +#ifdef HAVE_CHARSET + { + const char *enc = vfs_get_encoding (panel->cwd); + if (enc != NULL) + panel->codepage = get_codepage_index (enc); + } +#endif + + if (mc_chdir (panel->cwd) != 0) + { + panel->codepage = SELECT_CHARSET_NO_TRANSLATE; + mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); + } /* Load the default format */ panel->count = @@ -3503,12 +3519,14 @@ panel_change_encoding (WPanel * panel) char *errmsg; int r; - r = select_charset (-1, -1, default_source_codepage, FALSE); + r = select_charset (-1, -1, panel->codepage, FALSE); if (r == SELECT_CHARSET_CANCEL) return; /* Cancel */ - if (r == SELECT_CHARSET_NO_TRANSLATE) + panel->codepage = r; + + if (panel->codepage == SELECT_CHARSET_NO_TRANSLATE) { /* No translation */ g_free (init_translation_table (display_codepage, display_codepage)); @@ -3518,9 +3536,7 @@ panel_change_encoding (WPanel * panel) return; } - source_codepage = r; - - errmsg = init_translation_table (source_codepage, display_codepage); + errmsg = init_translation_table (panel->codepage, display_codepage); if (errmsg != NULL) { message (D_ERROR, MSG_ERROR, "%s", errmsg); @@ -3528,7 +3544,7 @@ panel_change_encoding (WPanel * panel) return; } - encoding = get_codepage_id (source_codepage); + encoding = get_codepage_id (panel->codepage); #endif if (encoding != NULL) { diff --git a/src/selcodepage.h b/src/selcodepage.h index 3f0eddd6d..c828b07db 100644 --- a/src/selcodepage.h +++ b/src/selcodepage.h @@ -6,8 +6,6 @@ #ifndef MC_SELCODEPAGE_H #define MC_SELCODEPAGE_H -#ifdef HAVE_CHARSET - #include "lib/global.h" int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay); @@ -26,6 +24,4 @@ gboolean do_select_codepage (void); /* In other cases select_charset() returns non-negative value * which is number of codepage in codepage list */ -#endif /* HAVE_CHARSET */ - #endif /* MC_SELCODEPAGE_H */ From c0384e0b6b5aa22f8e19144ba4047d4b8f2313dc Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 9 Sep 2010 16:50:26 +0400 Subject: [PATCH 06/11] When cd to "..", remove encoding at the end of path. Signed-off-by: Andrew Borodin --- lib/utilunix.c | 26 +++++++++++++++++++++++++- src/main.c | 22 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/utilunix.c b/lib/utilunix.c index f855d0d3b..6eec8055d 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -625,7 +625,13 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) else { /* "token/../foo" -> "foo" */ - str_move (s, p + 4); +#if HAVE_CHARSET + /* special case: remove encoding */ + if (strncmp (s, "#enc:", 5) == 0) + str_move (s, p + 1); + else +#endif /* HAVE_CHARSET */ + str_move (s, p + 4); } p = (s > lpath) ? s - 1 : s; continue; @@ -646,6 +652,24 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) /* "foo/token/.." -> "foo" */ if (s == lpath + 1) s[0] = 0; +#if HAVE_CHARSET + else if (strncmp (s, "#enc:", 5) == 0) + { + /* special case: remove encoding */ + s[0] = '.'; + s[1] = '.'; + s[2] = '\0'; + + /* search for the previous token */ + /* s[-1] == PATH_SEP */ + p = s - 1; + while (p >= lpath && *p != PATH_SEP) + p--; + + if (p != NULL) + continue; + } +#endif /* HAVE_CHARSET */ else s[-1] = 0; break; diff --git a/src/main.c b/src/main.c index e3e4ffb0f..9cdc87760 100644 --- a/src/main.c +++ b/src/main.c @@ -99,7 +99,8 @@ #ifdef HAVE_CHARSET #include "charsets.h" -#endif /* HAVE_CHARSET */ +#include "selcodepage.h" +#endif /* HAVE_CHARSET */ #include "keybind.h" /* type global_keymap_t */ @@ -392,7 +393,24 @@ subshell_chdir (const char *directory) int do_cd (const char *new_dir, enum cd_enum exact) { - return (do_panel_cd (current_panel, new_dir, exact)); + gboolean res; + + res = do_panel_cd (current_panel, new_dir, exact); + +#if HAVE_CHARSET + if (res) + { + const char *enc_name; + + enc_name = vfs_get_encoding (current_panel->cwd); + if (enc_name != NULL) + current_panel->codepage = get_codepage_index (enc_name); + else + current_panel->codepage = SELECT_CHARSET_NO_TRANSLATE; + } +#endif /* HAVE_CHARSET */ + + return res ? 1 : 0; } #ifdef HAVE_SUBSHELL_SUPPORT From aff8e42d645e07de5971eecc3accf20b4f36c73c Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 10 Sep 2010 11:27:21 +0400 Subject: [PATCH 07/11] Created macro VFS_ENCODING_PREFIX for "#enc:" encoding prefix. Signed-off-by: Andrew Borodin --- lib/utilunix.c | 10 +++++++--- lib/vfs/mc-vfs/vfs.c | 10 +++++----- lib/vfs/mc-vfs/vfs.h | 3 ++- src/screen.c | 16 ++++++++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/utilunix.c b/lib/utilunix.c index 6eec8055d..2252933dc 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -49,6 +49,8 @@ #include #include "lib/global.h" +#include "lib/vfs/mc-vfs/vfs.h" /* VFS_ENCODING_PREFIX */ + #include "src/execute.h" #include "src/wtools.h" /* message() */ @@ -591,6 +593,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) if (flags & CANON_PATH_REMDOUBLEDOTS) { + const size_t enc_prefix_len = strlen (VFS_ENCODING_PREFIX); + /* Collapse "/.." with the previous part of path */ p = lpath; while (p[0] && p[1] && p[2]) @@ -626,8 +630,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) { /* "token/../foo" -> "foo" */ #if HAVE_CHARSET - /* special case: remove encoding */ - if (strncmp (s, "#enc:", 5) == 0) + if (strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0) + /* special case: remove encoding */ str_move (s, p + 1); else #endif /* HAVE_CHARSET */ @@ -653,7 +657,7 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) if (s == lpath + 1) s[0] = 0; #if HAVE_CHARSET - else if (strncmp (s, "#enc:", 5) == 0) + else if (strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0) { /* special case: remove encoding */ s[0] = '.'; diff --git a/lib/vfs/mc-vfs/vfs.c b/lib/vfs/mc-vfs/vfs.c index d71786560..641c172e4 100644 --- a/lib/vfs/mc-vfs/vfs.c +++ b/lib/vfs/mc-vfs/vfs.c @@ -373,11 +373,11 @@ vfs_get_encoding (const char *path) char *slash; work = g_strdup (path); - semi = g_strrstr (work, "#enc:"); + semi = g_strrstr (work, VFS_ENCODING_PREFIX); if (semi != NULL) { - semi += 5 * sizeof (char); + semi += strlen (VFS_ENCODING_PREFIX); /* skip "#enc:" */ slash = strchr (semi, PATH_SEP); if (slash != NULL) slash[0] = '\0'; @@ -432,8 +432,8 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer size = (size > 0) ? size : (signed int) strlen (path); - /* try found #end: */ - semi = g_strrstr_len (path, size, "#enc:"); + /* try found #enc: */ + semi = g_strrstr_len (path, size, VFS_ENCODING_PREFIX); if (semi != NULL) { char encoding[16]; @@ -454,7 +454,7 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer return state; /* now can be translated part after #enc: */ - semi += 5; + semi += strlen (VFS_ENCODING_PREFIX); slash = strchr (semi, PATH_SEP); /* ignore slashes after size; */ if (slash - path >= size) diff --git a/lib/vfs/mc-vfs/vfs.h b/lib/vfs/mc-vfs/vfs.h index 25877dde9..48c2d4386 100644 --- a/lib/vfs/mc-vfs/vfs.h +++ b/lib/vfs/mc-vfs/vfs.h @@ -85,6 +85,7 @@ char *vfs_translate_url (const char *url); struct vfs_class *vfs_get_class (const char *path); vfs_class_flags_t vfs_file_class_flags (const char *filename); +#define VFS_ENCODING_PREFIX "#enc:" /* return encoding after last #enc: or NULL, if part does not contain #enc: * return static buffer */ const char *vfs_get_encoding (const char *path); @@ -203,7 +204,7 @@ vfs_canon (const char *path) #endif /* ENABLE_VFS */ char *vfs_get_current_dir (void); -/* translate path back to terminal encoding, remove all #enc: +/* translate path back to terminal encoding, remove all #enc: * every invalid character is replaced with question mark * return static buffer */ char *vfs_translate_path (const char *path); diff --git a/src/screen.c b/src/screen.c index 49ae117a7..f1ff120fd 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1059,7 +1059,7 @@ paint_panel (WPanel * panel) /* add "#enc:encodning" to end of path */ /* if path end width a previous #enc:, only encoding is changed no additional - * #enc: is appended + * #enc: is appended * retun new string */ static char * @@ -1069,25 +1069,25 @@ add_encoding_to_path (const char *path, const char *encoding) char *semi; char *slash; - semi = g_strrstr (path, "#enc:"); + semi = g_strrstr (path, VFS_ENCODING_PREFIX); if (semi != NULL) { slash = strchr (semi, PATH_SEP); if (slash != NULL) { - result = g_strconcat (path, "/#enc:", encoding, (char *) NULL); + result = g_strconcat (path, PATH_SEP_STR VFS_ENCODING_PREFIX, encoding, (char *) NULL); } else { - *semi = 0; - result = g_strconcat (path, "/#enc:", encoding, (char *) NULL); + *semi = '\0'; + result = g_strconcat (path, PATH_SEP_STR VFS_ENCODING_PREFIX, encoding, (char *) NULL); *semi = '#'; } } else { - result = g_strconcat (path, "/#enc:", encoding, (char *) NULL); + result = g_strconcat (path, PATH_SEP_STR VFS_ENCODING_PREFIX, encoding, (char *) NULL); } return result; @@ -1107,7 +1107,7 @@ remove_encoding_from_path (const char *path) tmp_path = g_string_new (path); - while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL) + while ((tmp = g_strrstr (tmp_path->str, PATH_SEP_STR VFS_ENCODING_PREFIX)) != NULL) { enc = vfs_get_encoding ((const char *) tmp); converter = enc ? str_crt_conv_to (enc) : str_cnv_to_term; @@ -1115,7 +1115,7 @@ remove_encoding_from_path (const char *path) converter = str_cnv_to_term; tmp2 = tmp + 1; - while (*tmp2 && *tmp2 != '/') + while (*tmp2 && *tmp2 != PATH_SEP) tmp2++; if (*tmp2) From 2a47d77351216ada0dd0ca803e2b07decad1b5d1 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 13 Sep 2010 13:29:29 +0400 Subject: [PATCH 08/11] Don't add current encoding to path again. Signed-off-by: Andrew Borodin --- src/screen.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/screen.c b/src/screen.c index f1ff120fd..ffc66f372 100644 --- a/src/screen.c +++ b/src/screen.c @@ -3548,10 +3548,18 @@ panel_change_encoding (WPanel * panel) #endif if (encoding != NULL) { - cd_path = add_encoding_to_path (panel->cwd, encoding); - if (!do_panel_cd (panel, cd_path, cd_parse_command)) - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); - g_free (cd_path); + const char *enc; + + enc = vfs_get_encoding (panel->cwd); + + /* don't add current encoding */ + if ((enc == NULL) || (strcmp (encoding, enc) != 0)) + { + cd_path = add_encoding_to_path (panel->cwd, encoding); + if (!do_panel_cd (panel, cd_path, cd_parse_command)) + message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); + g_free (cd_path); + } } } From 5007553299db71d59cea002fe710ae0f558d2a8e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 13 Sep 2010 13:32:27 +0400 Subject: [PATCH 09/11] 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); From 268c3642924e61c979723034f7caa0943e1b9bd7 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 23 Sep 2010 15:42:24 +0400 Subject: [PATCH 10/11] Fix of VFS encoding parsing. Signed-off-by: Andrew Borodin --- lib/vfs/mc-vfs/vfs.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/vfs/mc-vfs/vfs.c b/lib/vfs/mc-vfs/vfs.c index b4b6c4c36..e40c64b48 100644 --- a/lib/vfs/mc-vfs/vfs.c +++ b/lib/vfs/mc-vfs/vfs.c @@ -373,11 +373,12 @@ vfs_get_encoding (const char *path) char *slash; work = g_strdup (path); - semi = g_strrstr (work, VFS_ENCODING_PREFIX); + /* try found /#enc: */ + semi = g_strrstr (work, PATH_SEP_STR VFS_ENCODING_PREFIX); if (semi != NULL) { - semi += strlen (VFS_ENCODING_PREFIX); /* skip "#enc:" */ + semi += strlen (VFS_ENCODING_PREFIX) + 1; /* skip "/#enc:" */ slash = strchr (semi, PATH_SEP); if (slash != NULL) slash[0] = '\0'; @@ -405,7 +406,6 @@ static estr_t _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer) { const char *semi; - const char *ps; const char *slash; estr_t state = ESTR_SUCCESS; @@ -414,29 +414,24 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer size = (size > 0) ? size : (signed int) strlen (path); - /* try found #enc: */ - semi = g_strrstr_len (path, size, VFS_ENCODING_PREFIX); + /* try found /#enc: */ + semi = g_strrstr_len (path, size, PATH_SEP_STR VFS_ENCODING_PREFIX); if (semi != NULL) { char encoding[16]; GIConv coder = INVALID_CONV; int ms; - /* first must be translated part before #enc: */ + /* first must be translated part before /#enc: */ ms = semi - path; - /* remove '/' before #enc */ - ps = str_cget_prev_char (semi); - if (ps[0] == PATH_SEP) - ms = ps - path; - state = _vfs_translate_path (path, ms, defcnv, buffer); if (state != ESTR_SUCCESS) return state; - /* now can be translated part after #enc: */ - semi += strlen (VFS_ENCODING_PREFIX); + /* now can be translated part after #enc: */ + semi += strlen (VFS_ENCODING_PREFIX) + 1; /* skip "/#enc:" */ slash = strchr (semi, PATH_SEP); /* ignore slashes after size; */ if (slash - path >= size) @@ -459,11 +454,8 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer { if (slash != NULL) state = str_vfs_convert_to (coder, slash, path + size - slash, buffer); - else if (buffer->str[0] == '\0') - { - /* exmaple "/#enc:utf-8" */ + else if (buffer->len == 0) g_string_append_c (buffer, PATH_SEP); - } str_close_conv (coder); return state; } From ac85fdd3505c0b2c7cc6f85ae659472fa787555c Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 27 Sep 2010 11:02:32 +0300 Subject: [PATCH 11/11] Minor changes: added doxy-comments for functions: - is_supported_encoding(); - panel_new(); - panel_new_with_dir(); - panel_change_encoding(). Signed-off-by: Slava Zanko --- src/charsets.c | 5 ++++- src/screen.c | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/charsets.c b/src/charsets.c index 1638dc459..8b3e8d5a3 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -162,7 +162,10 @@ get_codepage_index (const char *id) return -1; } -/* return if encoding can by used in mc */ +/** Check if specified encoding can be used in mc. + * @param encoding name of encoding + * @returns TRUE if encoding has supported by mc, FALSE otherwise + */ gboolean is_supported_encoding (const char *encoding) { diff --git a/src/screen.c b/src/screen.c index ffc66f372..50f287aa0 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1307,18 +1307,21 @@ panel_format_modified (WPanel * panel) panel->format_modified = 1; } -/* Panel creation */ -/* The parameter specifies the name of the panel for setup retieving */ +/** Panel creation. + * @param panel_name the name of the panel for setup retieving + * @returns new instance of WPanel + */ WPanel * panel_new (const char *panel_name) { return panel_new_with_dir (panel_name, NULL); } -/* Panel creation for specified directory */ -/* The parameter specifies the name of the panel for setup retieving */ -/* and the path of working panel directory. If path is NULL then */ -/* panel will be created for current directory */ +/** Panel creation for specified directory. + * @param panel_name the name of the panel for setup retieving + * @param the path of working panel directory. If path is NULL then panel will be created for current directory + * @returns new instance of WPanel + */ WPanel * panel_new_with_dir (const char *panel_name, const char *wpath) { @@ -3510,6 +3513,10 @@ panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order) panel_re_sort (panel); } +/** + * Change panel encoding. + * @param panel WPanel object + */ void panel_change_encoding (WPanel * panel) {