mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Ticket #2827: tweak and cleanup of code in case of --disable-charset option usage.
First step: tweak vfs-related code. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
05bfb10f16
commit
315c499c09
@ -436,10 +436,12 @@ mc_opendir (const vfs_path_t * vpath)
|
||||
|
||||
path_element->dir.info = info;
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
path_element->dir.converter = (path_element->encoding != NULL) ?
|
||||
str_crt_conv_from (path_element->encoding) : str_cnv_from_term;
|
||||
if (path_element->dir.converter == INVALID_CONV)
|
||||
path_element->dir.converter = str_cnv_from_term;
|
||||
#endif
|
||||
|
||||
handle = vfs_new_handle (path_element->class, vfs_path_element_clone (path_element));
|
||||
|
||||
@ -457,7 +459,9 @@ mc_readdir (DIR * dirp)
|
||||
struct vfs_class *vfs;
|
||||
struct dirent *entry = NULL;
|
||||
vfs_path_element_t *vfs_path_element;
|
||||
#ifdef HAVE_CHARSET
|
||||
estr_t state;
|
||||
#endif
|
||||
|
||||
if (!mc_readdir_result)
|
||||
{
|
||||
@ -491,9 +495,14 @@ mc_readdir (DIR * dirp)
|
||||
entry = (*vfs->readdir) (vfs_path_element->dir.info);
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
|
||||
g_string_set_size (vfs_str_buffer, 0);
|
||||
#ifdef HAVE_CHARSET
|
||||
state =
|
||||
str_vfs_convert_from (vfs_path_element->dir.converter, entry->d_name, vfs_str_buffer);
|
||||
#else
|
||||
g_string_assign (vfs_str_buffer, entry->d_name);
|
||||
#endif
|
||||
mc_readdir_result->d_ino = entry->d_ino;
|
||||
g_strlcpy (mc_readdir_result->d_name, vfs_str_buffer->str, MAXNAMLEN + 1);
|
||||
}
|
||||
@ -516,11 +525,14 @@ mc_closedir (DIR * dirp)
|
||||
{
|
||||
vfs_path_element_t *vfs_path_element;
|
||||
vfs_path_element = vfs_class_data_find_by_handle (handle);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (vfs_path_element->dir.converter != str_cnv_from_term)
|
||||
{
|
||||
str_close_conv (vfs_path_element->dir.converter);
|
||||
vfs_path_element->dir.converter = INVALID_CONV;
|
||||
}
|
||||
#endif
|
||||
|
||||
result = vfs->closedir ? (*vfs->closedir) (vfs_path_element->dir.info) : -1;
|
||||
vfs_free_handle (handle);
|
||||
|
@ -172,6 +172,8 @@ vfs_canon (const char *path)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
/** get encoding after last #enc: or NULL, if part does not contain #enc:
|
||||
*
|
||||
* @param path string
|
||||
@ -208,6 +210,7 @@ vfs_get_encoding (const char *path)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Extract the hostname and username from the path
|
||||
@ -380,9 +383,11 @@ vfs_path_from_str_deprecated_parser (char *path, vfs_path_flag_t flags)
|
||||
local = "";
|
||||
element->path = vfs_translate_path_n (local);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
element->encoding = vfs_get_encoding (local);
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
#endif
|
||||
|
||||
url_params = strchr (op, ':'); /* skip VFS prefix */
|
||||
if (url_params != NULL)
|
||||
@ -403,9 +408,11 @@ vfs_path_from_str_deprecated_parser (char *path, vfs_path_flag_t flags)
|
||||
element->class = g_ptr_array_index (vfs__classes_list, 0);
|
||||
element->path = vfs_translate_path_n (path);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
element->encoding = vfs_get_encoding (path);
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
#endif
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
}
|
||||
|
||||
@ -463,8 +470,9 @@ vfs_path_from_str_uri_parser (char *path, vfs_path_flag_t flags)
|
||||
else
|
||||
{
|
||||
element->path = vfs_translate_path_n (slash_pointer + 1);
|
||||
#ifdef HAVE_CHARSET
|
||||
element->encoding = vfs_get_encoding (slash_pointer);
|
||||
|
||||
#endif
|
||||
*slash_pointer = '\0';
|
||||
}
|
||||
vfs_path_url_split (element, url_delimiter);
|
||||
@ -472,10 +480,14 @@ vfs_path_from_str_uri_parser (char *path, vfs_path_flag_t flags)
|
||||
else
|
||||
{
|
||||
element->path = vfs_translate_path_n (url_delimiter);
|
||||
#ifdef HAVE_CHARSET
|
||||
element->encoding = vfs_get_encoding (url_delimiter);
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_CHARSET
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
#endif
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
|
||||
if ((real_vfs_prefix_start > path && *(real_vfs_prefix_start) == PATH_SEP) ||
|
||||
@ -490,9 +502,11 @@ vfs_path_from_str_uri_parser (char *path, vfs_path_flag_t flags)
|
||||
element = g_new0 (vfs_path_element_t, 1);
|
||||
element->class = g_ptr_array_index (vfs__classes_list, 0);
|
||||
element->path = vfs_translate_path_n (path);
|
||||
#ifdef HAVE_CHARSET
|
||||
element->encoding = vfs_get_encoding (path);
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
#endif
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
}
|
||||
|
||||
@ -533,6 +547,8 @@ vfs_path_tokens_add_class_info (const vfs_path_element_t * element, GString * re
|
||||
|
||||
g_free (url_str);
|
||||
}
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (element->encoding != NULL)
|
||||
{
|
||||
if (ret_tokens->len > 0 && ret_tokens->str[ret_tokens->len - 1] != PATH_SEP)
|
||||
@ -541,6 +557,7 @@ vfs_path_tokens_add_class_info (const vfs_path_element_t * element, GString * re
|
||||
g_string_append (ret_tokens, element->encoding);
|
||||
g_string_append (ret_tokens, PATH_SEP_STR);
|
||||
}
|
||||
#endif
|
||||
|
||||
g_string_append (ret_tokens, element_tokens->str);
|
||||
}
|
||||
@ -647,6 +664,7 @@ vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_fl
|
||||
g_free (url_str);
|
||||
}
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if ((flags & VPF_RECODE) == 0 && vfs_path_element_need_cleanup_converter (element))
|
||||
{
|
||||
if ((flags & VPF_HIDE_CHARSET) == 0)
|
||||
@ -662,6 +680,7 @@ vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_fl
|
||||
g_string_set_size (recode_buffer, 0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
vfs_append_from_path (element->path, is_relative);
|
||||
}
|
||||
@ -847,12 +866,14 @@ vfs_path_element_clone (const vfs_path_element_t * element)
|
||||
new_element->port = element->port;
|
||||
new_element->path = g_strdup (element->path);
|
||||
new_element->class = element->class;
|
||||
new_element->encoding = g_strdup (element->encoding);
|
||||
new_element->vfs_prefix = g_strdup (element->vfs_prefix);
|
||||
#ifdef HAVE_CHARSET
|
||||
new_element->encoding = g_strdup (element->encoding);
|
||||
if (vfs_path_element_need_cleanup_converter (element) && new_element->encoding != NULL)
|
||||
new_element->dir.converter = str_crt_conv_from (new_element->encoding);
|
||||
else
|
||||
new_element->dir.converter = element->dir.converter;
|
||||
#endif
|
||||
new_element->dir.info = element->dir.info;
|
||||
|
||||
return new_element;
|
||||
@ -876,13 +897,14 @@ vfs_path_element_free (vfs_path_element_t * element)
|
||||
g_free (element->password);
|
||||
g_free (element->host);
|
||||
g_free (element->path);
|
||||
g_free (element->encoding);
|
||||
g_free (element->vfs_prefix);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
g_free (element->encoding);
|
||||
|
||||
if (vfs_path_element_need_cleanup_converter (element))
|
||||
{
|
||||
str_close_conv (element->dir.converter);
|
||||
}
|
||||
#endif
|
||||
|
||||
g_free (element);
|
||||
}
|
||||
@ -1010,12 +1032,13 @@ vfs_prefix_to_class (const char *prefix)
|
||||
*
|
||||
* @return TRUE if need cleanup converter or FALSE otherwise
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
gboolean
|
||||
vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element)
|
||||
{
|
||||
return (element->dir.converter != str_cnv_from_term && element->dir.converter != INVALID_CONV);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
@ -1051,8 +1074,9 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
|
||||
|
||||
mc_config_set_string_raw (cpath, groupname, "path", element->path);
|
||||
mc_config_set_string_raw (cpath, groupname, "class-name", element->class->name);
|
||||
#ifdef HAVE_CHARSET
|
||||
mc_config_set_string_raw (cpath, groupname, "encoding", element->encoding);
|
||||
|
||||
#endif
|
||||
mc_config_set_string_raw (cpath, groupname, "vfs_prefix", element->vfs_prefix);
|
||||
|
||||
mc_config_set_string_raw (cpath, groupname, "user", element->user);
|
||||
@ -1120,9 +1144,12 @@ vfs_path_deserialize (const char *data, GError ** error)
|
||||
g_free (cfg_value);
|
||||
|
||||
element->path = mc_config_get_string_raw (cpath, groupname, "path", NULL);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
element->encoding = mc_config_get_string_raw (cpath, groupname, "encoding", NULL);
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
#endif
|
||||
|
||||
element->vfs_prefix = mc_config_get_string_raw (cpath, groupname, "vfs_prefix", NULL);
|
||||
|
||||
|
@ -38,12 +38,16 @@ typedef struct
|
||||
int port;
|
||||
char *path;
|
||||
struct vfs_class *class;
|
||||
#ifdef HAVE_CHARSET
|
||||
char *encoding;
|
||||
#endif
|
||||
char *vfs_prefix;
|
||||
|
||||
struct
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
GIConv converter;
|
||||
#endif
|
||||
DIR *info;
|
||||
} dir;
|
||||
} vfs_path_element_t;
|
||||
@ -77,7 +81,9 @@ void vfs_path_element_free (vfs_path_element_t * element);
|
||||
|
||||
struct vfs_class *vfs_prefix_to_class (const char *prefix);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
|
||||
#endif
|
||||
|
||||
char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
|
||||
vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
|
||||
|
@ -328,7 +328,9 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
|
||||
}
|
||||
|
||||
path_element->host = g_strdup (rest);
|
||||
#ifdef HAVE_CHARSET
|
||||
path_element->dir.converter = INVALID_CONV;
|
||||
#endif
|
||||
|
||||
return path_element;
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ static vfs_path_t *current_path = NULL;
|
||||
static GPtrArray *vfs_openfiles;
|
||||
static long vfs_free_handle_list = -1;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* now used only by vfs_translate_path, but could be used in other vfs
|
||||
@ -108,9 +109,10 @@ static long vfs_free_handle_list = -1;
|
||||
static estr_t
|
||||
_vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer)
|
||||
{
|
||||
estr_t state = ESTR_SUCCESS;
|
||||
#ifdef HAVE_CHARSET
|
||||
const char *semi;
|
||||
const char *slash;
|
||||
estr_t state = ESTR_SUCCESS;
|
||||
|
||||
if (size == 0)
|
||||
return ESTR_SUCCESS;
|
||||
@ -148,10 +150,8 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
|
||||
memcpy (encoding, semi, ms);
|
||||
encoding[ms] = '\0';
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (is_supported_encoding (encoding))
|
||||
coder = str_crt_conv_to (encoding);
|
||||
#endif
|
||||
|
||||
if (coder != INVALID_CONV)
|
||||
{
|
||||
@ -169,6 +169,12 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
|
||||
/* path can be translated whole at once */
|
||||
state = str_vfs_convert_to (defcnv, path, size, buffer);
|
||||
}
|
||||
#else
|
||||
(void) size;
|
||||
(void) defcnv;
|
||||
|
||||
g_string_assign (buffer, path);
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
return state;
|
||||
}
|
||||
@ -579,6 +585,7 @@ _vfs_get_cwd (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
/**
|
||||
* Change encoding for last part (vfs_path_element_t) of vpath
|
||||
*
|
||||
@ -607,6 +614,7 @@ vfs_change_encoding (vfs_path_t * vpath, const char *encoding)
|
||||
|
||||
return vpath;
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -270,7 +270,9 @@ void vfs_free_handle (int handle);
|
||||
void vfs_setup_cwd (void);
|
||||
char *_vfs_get_cwd (void);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
vfs_path_t *vfs_change_encoding (vfs_path_t * vpath, const char *encoding);
|
||||
#endif
|
||||
|
||||
int vfs_preallocate (int dest_desc, off_t src_fsize, off_t dest_fsize);
|
||||
|
||||
|
@ -1740,11 +1740,13 @@ toggle_listing_cmd (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
void
|
||||
encoding_cmd (void)
|
||||
{
|
||||
if (SELECTED_IS_PANEL)
|
||||
panel_change_encoding (MENU_PANEL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -101,7 +101,9 @@ void quick_cmd_no_menu (void);
|
||||
void info_cmd_no_menu (void);
|
||||
void quick_view_cmd (void);
|
||||
void toggle_listing_cmd (void);
|
||||
#ifdef HAVE_CHARSET
|
||||
void encoding_cmd (void);
|
||||
#endif
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__CMD_H */
|
||||
|
@ -684,20 +684,27 @@ static void
|
||||
put_current_path (void)
|
||||
{
|
||||
char *cwd_path;
|
||||
vfs_path_t *cwd_vpath;
|
||||
|
||||
if (!command_prompt)
|
||||
return;
|
||||
|
||||
cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
|
||||
cwd_path = vfs_path_to_str (cwd_vpath);
|
||||
command_insert (cmdline, cwd_path, FALSE);
|
||||
#ifdef HAVE_CHARSET
|
||||
{
|
||||
vfs_path_t *cwd_vpath;
|
||||
|
||||
cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
|
||||
cwd_path = vfs_path_to_str (cwd_vpath);
|
||||
vfs_path_free (cwd_vpath);
|
||||
}
|
||||
#else
|
||||
cwd_path = vfs_path_to_str (current_panel->cwd_vpath);
|
||||
#endif
|
||||
|
||||
command_insert (cmdline, cwd_path, FALSE);
|
||||
if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
|
||||
command_insert (cmdline, PATH_SEP_STR, FALSE);
|
||||
|
||||
g_free (cwd_path);
|
||||
vfs_path_free (cwd_vpath);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -706,7 +713,6 @@ static void
|
||||
put_other_path (void)
|
||||
{
|
||||
char *cwd_path;
|
||||
vfs_path_t *cwd_vpath;
|
||||
|
||||
if (get_other_type () != view_listing)
|
||||
return;
|
||||
@ -714,15 +720,23 @@ put_other_path (void)
|
||||
if (!command_prompt)
|
||||
return;
|
||||
|
||||
cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
|
||||
cwd_path = vfs_path_to_str (cwd_vpath);
|
||||
command_insert (cmdline, cwd_path, FALSE);
|
||||
#ifdef HAVE_CHARSET
|
||||
{
|
||||
vfs_path_t *cwd_vpath;
|
||||
|
||||
cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
|
||||
cwd_path = vfs_path_to_str (cwd_vpath);
|
||||
vfs_path_free (cwd_vpath);
|
||||
}
|
||||
#else
|
||||
cwd_path = vfs_path_to_str (other_panel->cwd_vpath);
|
||||
#endif
|
||||
|
||||
command_insert (cmdline, cwd_path, FALSE);
|
||||
if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
|
||||
command_insert (cmdline, PATH_SEP_STR, FALSE);
|
||||
|
||||
g_free (cwd_path);
|
||||
vfs_path_free (cwd_vpath);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1217,6 +1217,7 @@ panel_correct_path_to_show (WPanel * panel)
|
||||
* @return newly allocated string or NULL if path charset is same as system charset
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
static char *
|
||||
panel_get_encoding_info_str (WPanel * panel)
|
||||
{
|
||||
@ -1229,6 +1230,7 @@ panel_get_encoding_info_str (WPanel * panel)
|
||||
|
||||
return ret_str;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
@ -1264,6 +1266,7 @@ show_dir (WPanel * panel)
|
||||
|
||||
if (panel->is_panelized)
|
||||
tty_printf (" %s ", _("Panelize"));
|
||||
#ifdef HAVE_CHARSET
|
||||
else
|
||||
{
|
||||
tmp = panel_get_encoding_info_str (panel);
|
||||
@ -1274,6 +1277,8 @@ show_dir (WPanel * panel)
|
||||
g_free (tmp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (panel->active)
|
||||
tty_setcolor (REVERSE_COLOR);
|
||||
|
||||
@ -3802,60 +3807,6 @@ update_one_panel (int which, panel_update_flags_t flags, const char *current_fil
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Remove encode info from last path element.
|
||||
*
|
||||
*/
|
||||
|
||||
vfs_path_t *
|
||||
remove_encoding_from_path (const vfs_path_t * vpath)
|
||||
{
|
||||
vfs_path_t *ret_vpath;
|
||||
GString *tmp_conv;
|
||||
int indx;
|
||||
|
||||
ret_vpath = vfs_path_new ();
|
||||
|
||||
tmp_conv = g_string_new ("");
|
||||
|
||||
for (indx = 0; indx < vfs_path_elements_count (vpath); indx++)
|
||||
{
|
||||
GIConv converter;
|
||||
vfs_path_element_t *path_element;
|
||||
|
||||
path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, indx));
|
||||
vfs_path_add_element (ret_vpath, path_element);
|
||||
|
||||
if (path_element->encoding == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
converter = str_crt_conv_to (path_element->encoding);
|
||||
if (converter == INVALID_CONV)
|
||||
continue;
|
||||
|
||||
g_free (path_element->encoding);
|
||||
path_element->encoding = NULL;
|
||||
|
||||
str_vfs_convert_from (converter, path_element->path, tmp_conv);
|
||||
|
||||
g_free (path_element->path);
|
||||
path_element->path = g_strdup (tmp_conv->str);
|
||||
|
||||
g_string_set_size (tmp_conv, 0);
|
||||
|
||||
str_close_conv (converter);
|
||||
str_close_conv (path_element->dir.converter);
|
||||
path_element->dir.converter = INVALID_CONV;
|
||||
}
|
||||
g_string_free (tmp_conv, TRUE);
|
||||
return ret_vpath;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
@ -4111,7 +4062,9 @@ 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);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < LIST_TYPES; i++)
|
||||
panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
|
||||
@ -4146,7 +4099,9 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
|
||||
|
||||
if (mc_chdir (panel->cwd_vpath) != 0)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
|
||||
#endif
|
||||
vfs_setup_cwd ();
|
||||
vfs_path_free (panel->cwd_vpath);
|
||||
panel->cwd_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
|
||||
@ -4525,11 +4480,11 @@ panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
|
||||
* @param panel WPanel object
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
void
|
||||
panel_change_encoding (WPanel * panel)
|
||||
{
|
||||
const char *encoding = NULL;
|
||||
#ifdef HAVE_CHARSET
|
||||
char *errmsg;
|
||||
int r;
|
||||
|
||||
@ -4562,7 +4517,6 @@ panel_change_encoding (WPanel * panel)
|
||||
}
|
||||
|
||||
encoding = get_codepage_id (panel->codepage);
|
||||
#endif
|
||||
if (encoding != NULL)
|
||||
{
|
||||
char *cd_path;
|
||||
@ -4575,6 +4529,57 @@ panel_change_encoding (WPanel * panel)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Remove encode info from last path element.
|
||||
*
|
||||
*/
|
||||
vfs_path_t *
|
||||
remove_encoding_from_path (const vfs_path_t * vpath)
|
||||
{
|
||||
vfs_path_t *ret_vpath;
|
||||
GString *tmp_conv;
|
||||
int indx;
|
||||
|
||||
ret_vpath = vfs_path_new ();
|
||||
|
||||
tmp_conv = g_string_new ("");
|
||||
|
||||
for (indx = 0; indx < vfs_path_elements_count (vpath); indx++)
|
||||
{
|
||||
GIConv converter;
|
||||
vfs_path_element_t *path_element;
|
||||
|
||||
path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, indx));
|
||||
vfs_path_add_element (ret_vpath, path_element);
|
||||
|
||||
if (path_element->encoding == NULL)
|
||||
continue;
|
||||
|
||||
converter = str_crt_conv_to (path_element->encoding);
|
||||
if (converter == INVALID_CONV)
|
||||
continue;
|
||||
|
||||
g_free (path_element->encoding);
|
||||
path_element->encoding = NULL;
|
||||
|
||||
str_vfs_convert_from (converter, path_element->path, tmp_conv);
|
||||
|
||||
g_free (path_element->path);
|
||||
path_element->path = g_strdup (tmp_conv->str);
|
||||
|
||||
g_string_set_size (tmp_conv, 0);
|
||||
|
||||
str_close_conv (converter);
|
||||
str_close_conv (path_element->dir.converter);
|
||||
path_element->dir.converter = INVALID_CONV;
|
||||
}
|
||||
g_string_free (tmp_conv, TRUE);
|
||||
return ret_vpath;
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* This routine reloads the directory in both panels. It tries to
|
||||
|
@ -119,7 +119,9 @@ typedef struct WPanel
|
||||
char *panel_name; /* The panel name */
|
||||
struct stat dir_stat; /* Stat of current dir: used by execute () */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
int codepage; /* panel codepage */
|
||||
#endif
|
||||
|
||||
gboolean searching;
|
||||
char search_buffer[MC_MAXFILENAMELEN];
|
||||
@ -147,7 +149,11 @@ void panel_clean_dir (WPanel * panel);
|
||||
void panel_reload (WPanel * panel);
|
||||
void panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order);
|
||||
void panel_re_sort (WPanel * panel);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
void panel_change_encoding (WPanel * panel);
|
||||
vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath);
|
||||
#endif
|
||||
|
||||
void update_panels (panel_update_flags_t flags, const char *current_file);
|
||||
int set_panel_formats (WPanel * p);
|
||||
@ -164,8 +170,6 @@ void do_file_mark (WPanel * panel, int idx, int val);
|
||||
|
||||
gboolean do_panel_cd (struct WPanel *panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
|
||||
|
||||
vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath);
|
||||
|
||||
gsize panel_get_num_of_sortable_fields (void);
|
||||
const char **panel_get_sortable_fields (gsize *);
|
||||
const panel_field_t *panel_get_field_by_id (const char *);
|
||||
|
Loading…
Reference in New Issue
Block a user