mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
Created macro VFS_ENCODING_PREFIX for "#enc:" encoding prefix.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
c0384e0b6b
commit
aff8e42d64
@ -49,6 +49,8 @@
|
||||
#include <grp.h>
|
||||
|
||||
#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] = '.';
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
14
src/screen.c
14
src/screen.c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user