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)