Merge branch '2203_vfs_encodings'
* 2203_vfs_encodings: Applied MC indentation policy. Fixed build with --disable-charset option. Minor optimization. Ticket #2203: VFS: use codepage list loaded from mc.charsets file.
Этот коммит содержится в:
Коммит
159927cb2c
@ -52,6 +52,9 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/strutil.h"
|
#include "lib/strutil.h"
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
|
#include "src/charsets.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "src/wtools.h" /* message() */
|
#include "src/wtools.h" /* message() */
|
||||||
#include "src/main.h" /* print_vfs_message */
|
#include "src/main.h" /* print_vfs_message */
|
||||||
@ -96,21 +99,6 @@ static long vfs_free_handle_list = -1;
|
|||||||
static struct vfs_class *localfs_class;
|
static struct vfs_class *localfs_class;
|
||||||
static GString *vfs_str_buffer;
|
static GString *vfs_str_buffer;
|
||||||
|
|
||||||
static const char *supported_encodings[] = {
|
|
||||||
"UTF8",
|
|
||||||
"UTF-8",
|
|
||||||
"BIG5",
|
|
||||||
"ASCII",
|
|
||||||
"ISO8859",
|
|
||||||
"ISO-8859",
|
|
||||||
"ISO_8859",
|
|
||||||
"KOI8",
|
|
||||||
"CP852",
|
|
||||||
"CP866",
|
|
||||||
"CP125",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Create new VFS handle and put it to the list */
|
/** Create new VFS handle and put it to the list */
|
||||||
static int
|
static int
|
||||||
vfs_new_handle (struct vfs_class *vclass, void *fsinfo)
|
vfs_new_handle (struct vfs_class *vclass, void *fsinfo)
|
||||||
@ -404,17 +392,18 @@ vfs_get_encoding (const char *path)
|
|||||||
|
|
||||||
/* return if encoding can by used in vfs (is ascci full compactible) */
|
/* return if encoding can by used in vfs (is ascci full compactible) */
|
||||||
/* contains only a few encoding now */
|
/* contains only a few encoding now */
|
||||||
static int
|
static gboolean
|
||||||
vfs_supported_enconding (const char *encoding)
|
vfs_supported_enconding (const char *encoding)
|
||||||
{
|
{
|
||||||
int t;
|
gboolean result = FALSE;
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
for (t = 0; supported_encodings[t] != NULL; t++)
|
#ifdef HAVE_CHARSET
|
||||||
{
|
int t;
|
||||||
result += (g_ascii_strncasecmp (encoding, supported_encodings[t],
|
|
||||||
strlen (supported_encodings[t])) == 0);
|
for (t = 0; t < n_codepages; t++)
|
||||||
}
|
result |= (g_ascii_strncasecmp (encoding, codepages[t].id,
|
||||||
|
strlen (codepages[t].id)) == 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -434,18 +423,20 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
|
|||||||
const char *ps;
|
const char *ps;
|
||||||
const char *slash;
|
const char *slash;
|
||||||
estr_t state = ESTR_SUCCESS;
|
estr_t state = ESTR_SUCCESS;
|
||||||
static char encoding[16];
|
|
||||||
GIConv coder;
|
|
||||||
int ms;
|
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return 0;
|
return ESTR_SUCCESS;
|
||||||
|
|
||||||
size = (size > 0) ? size : (signed int) strlen (path);
|
size = (size > 0) ? size : (signed int) strlen (path);
|
||||||
|
|
||||||
/* try found #end: */
|
/* try found #end: */
|
||||||
semi = g_strrstr_len (path, size, "#enc:");
|
semi = g_strrstr_len (path, size, "#enc:");
|
||||||
if (semi != NULL)
|
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;
|
ms = semi - path;
|
||||||
|
|
||||||
@ -474,42 +465,32 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
|
|||||||
memcpy (encoding, semi, ms);
|
memcpy (encoding, semi, ms);
|
||||||
encoding[ms] = '\0';
|
encoding[ms] = '\0';
|
||||||
|
|
||||||
switch (vfs_supported_enconding (encoding))
|
if (vfs_supported_enconding (encoding))
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
coder = str_crt_conv_to (encoding);
|
coder = str_crt_conv_to (encoding);
|
||||||
if (coder != INVALID_CONV)
|
|
||||||
|
if (coder != INVALID_CONV)
|
||||||
|
{
|
||||||
|
if (slash != NULL)
|
||||||
|
state = str_vfs_convert_to (coder, slash, path + size - slash, buffer);
|
||||||
|
else if (buffer->str[0] == '\0')
|
||||||
{
|
{
|
||||||
if (slash != NULL)
|
/* exmaple "/#enc:utf-8" */
|
||||||
{
|
g_string_append_c (buffer, PATH_SEP);
|
||||||
state = str_vfs_convert_to (coder, slash, path + size - slash, buffer);
|
|
||||||
}
|
|
||||||
else if (buffer->str[0] == '\0')
|
|
||||||
{
|
|
||||||
/* exmaple "/#enc:utf-8" */
|
|
||||||
g_string_append_c (buffer, PATH_SEP);
|
|
||||||
}
|
|
||||||
str_close_conv (coder);
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
else
|
str_close_conv (coder);
|
||||||
{
|
return state;
|
||||||
errno = EINVAL;
|
|
||||||
return ESTR_FAILURE;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
errno = EINVAL;
|
|
||||||
return ESTR_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errno = EINVAL;
|
||||||
|
state = ESTR_FAILURE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* path can be translated whole at once */
|
/* path can be translated whole at once */
|
||||||
state = str_vfs_convert_to (defcnv, path, size, buffer);
|
state = str_vfs_convert_to (defcnv, path, size, buffer);
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ESTR_SUCCESS;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
907
src/ext.c
907
src/ext.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
x
Ссылка в новой задаче
Block a user