Merge branch '1838_codeset_autodetect_fix'
* 1838_codeset_autodetect_fix: edit_load_file_fast(): don't reset utf8 flag that was set early. edit_set_codeset(): new function to set codeset in MC editor. Some optimization of viewer initialization. Ticket #1838: fix of broken charset autodetection.
Этот коммит содержится в:
Коммит
12969b4974
@ -687,7 +687,7 @@ tree_box (const char *current_dir)
|
||||
dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
|
||||
tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
mytree = tree_new (0, 2, 2, dlg->lines - 6, dlg->cols - 5);
|
||||
mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
|
||||
add_widget (dlg, mytree);
|
||||
bar = buttonbar_new (TRUE);
|
||||
add_widget (dlg, bar);
|
||||
|
@ -193,6 +193,7 @@ void edit_update_curs_row (WEdit * edit);
|
||||
void edit_update_curs_col (WEdit * edit);
|
||||
void edit_find_bracket (WEdit * edit);
|
||||
int edit_reload_line (WEdit * edit, const char *filename, long line);
|
||||
void edit_set_codeset (WEdit *edit);
|
||||
|
||||
void edit_block_copy_cmd (WEdit * edit);
|
||||
void edit_block_move_cmd (WEdit * edit);
|
||||
|
@ -327,9 +327,10 @@ edit_load_file_fast (WEdit * edit, const char *filename)
|
||||
long buf, buf2;
|
||||
int file = -1;
|
||||
int ret = 1;
|
||||
|
||||
edit->curs2 = edit->last_byte;
|
||||
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
|
||||
edit->utf8 = 0;
|
||||
|
||||
file = mc_open (filename, O_RDONLY | O_BINARY);
|
||||
if (file == -1)
|
||||
{
|
||||
@ -904,28 +905,10 @@ edit_init (WEdit * edit, int lines, int columns, const char *filename, long line
|
||||
edit->stack_size = START_STACK_SIZE;
|
||||
edit->stack_size_mask = START_STACK_SIZE - 1;
|
||||
edit->undo_stack = g_malloc0 ((edit->stack_size + 10) * sizeof (long));
|
||||
|
||||
edit->utf8 = 0;
|
||||
edit->converter = str_cnv_from_term;
|
||||
#ifdef HAVE_CHARSET
|
||||
{
|
||||
const char *cp_id = NULL;
|
||||
cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage);
|
||||
|
||||
if (cp_id != NULL)
|
||||
{
|
||||
GIConv conv;
|
||||
conv = str_crt_conv_from (cp_id);
|
||||
if (conv != INVALID_CONV)
|
||||
{
|
||||
if (edit->converter != str_cnv_from_term)
|
||||
str_close_conv (edit->converter);
|
||||
edit->converter = conv;
|
||||
}
|
||||
}
|
||||
if (cp_id != NULL)
|
||||
edit->utf8 = str_isutf8 (cp_id);
|
||||
}
|
||||
#endif
|
||||
edit_set_codeset (edit);
|
||||
|
||||
if (edit_load_file (edit))
|
||||
{
|
||||
@ -1069,6 +1052,33 @@ edit_reload_line (WEdit * edit, const char *filename, long line)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
edit_set_codeset (WEdit *edit)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
const char *cp_id;
|
||||
|
||||
cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage);
|
||||
|
||||
if (cp_id != NULL)
|
||||
{
|
||||
GIConv conv;
|
||||
conv = str_crt_conv_from (cp_id);
|
||||
if (conv != INVALID_CONV)
|
||||
{
|
||||
if (edit->converter != str_cnv_from_term)
|
||||
str_close_conv (edit->converter);
|
||||
edit->converter = conv;
|
||||
}
|
||||
}
|
||||
|
||||
if (cp_id != NULL)
|
||||
edit->utf8 = str_isutf8 (cp_id);
|
||||
#else
|
||||
(void) edit;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Recording stack for undo:
|
||||
|
@ -56,7 +56,7 @@
|
||||
#include "src/history.h"
|
||||
#include "src/widget.h" /* listbox_new() */
|
||||
#include "src/layout.h" /* clr_scr() */
|
||||
#include "src/main.h" /* mc_home source_codepage */
|
||||
#include "src/main.h" /* mc_home */
|
||||
#include "src/help.h" /* interactive_display() */
|
||||
#include "src/wtools.h" /* message() */
|
||||
#include "src/charsets.h"
|
||||
@ -2880,26 +2880,8 @@ void
|
||||
edit_select_codepage_cmd (WEdit * edit)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
const char *cp_id = NULL;
|
||||
if (do_select_codepage ())
|
||||
{
|
||||
cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage);
|
||||
|
||||
if (cp_id != NULL)
|
||||
{
|
||||
GIConv conv;
|
||||
conv = str_crt_conv_from (cp_id);
|
||||
if (conv != INVALID_CONV)
|
||||
{
|
||||
if (edit->converter != str_cnv_from_term)
|
||||
str_close_conv (edit->converter);
|
||||
edit->converter = conv;
|
||||
}
|
||||
}
|
||||
|
||||
if (cp_id != NULL)
|
||||
edit->utf8 = str_isutf8 (cp_id);
|
||||
}
|
||||
edit_set_codeset (edit);
|
||||
|
||||
edit->force = REDRAW_COMPLETELY;
|
||||
edit_refresh_cmd (edit);
|
||||
|
@ -285,11 +285,11 @@ info_event (Gpm_Event * event, void *data)
|
||||
}
|
||||
|
||||
WInfo *
|
||||
info_new (void)
|
||||
info_new (int y, int x, int lines, int cols)
|
||||
{
|
||||
struct WInfo *info = g_new (struct WInfo, 1);
|
||||
|
||||
init_widget (&info->widget, 0, 0, 0, 0, info_callback, info_event);
|
||||
init_widget (&info->widget, y, x, lines, cols, info_callback, info_event);
|
||||
|
||||
/* We do not want the cursor */
|
||||
widget_want_cursor (info->widget, 0);
|
||||
|
@ -9,6 +9,6 @@
|
||||
struct WInfo;
|
||||
typedef struct WInfo WInfo;
|
||||
|
||||
WInfo *info_new (void);
|
||||
WInfo *info_new (int y, int x, int lines, int cols);
|
||||
|
||||
#endif
|
||||
#endif /* MC_INFO_H */
|
||||
|
16
src/layout.c
16
src/layout.c
@ -946,20 +946,21 @@ set_display_type (int num, panel_view_mode_t type)
|
||||
case view_nothing:
|
||||
case view_listing:
|
||||
new_widget = restore_into_right_dir_panel (num, old_widget);
|
||||
widget_set_size (new_widget, y, x, lines, cols);
|
||||
break;
|
||||
|
||||
case view_info:
|
||||
new_widget = (Widget *) info_new ();
|
||||
break;
|
||||
new_widget = (Widget *) info_new (y, x, lines, cols);
|
||||
break;
|
||||
|
||||
case view_tree:
|
||||
new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
|
||||
new_widget = (Widget *) tree_new (y, x, lines, cols, TRUE);
|
||||
break;
|
||||
|
||||
case view_quick:
|
||||
new_widget = (Widget *) mcview_new (0, 0, 0, 0, 1);
|
||||
the_other_panel = (WPanel *) panels[the_other].widget;
|
||||
if (the_other_panel)
|
||||
new_widget = (Widget *) mcview_new (y, x, lines, cols, TRUE);
|
||||
the_other_panel = (WPanel *) panels [the_other].widget;
|
||||
if (the_other_panel != NULL)
|
||||
file_name = the_other_panel->dir.list[the_other_panel->selected].fname;
|
||||
else
|
||||
file_name = "";
|
||||
@ -976,9 +977,6 @@ set_display_type (int num, panel_view_mode_t type)
|
||||
panels[num].type = type;
|
||||
panels[num].widget = new_widget;
|
||||
|
||||
/* We set the same size the old widget had */
|
||||
widget_set_size (new_widget, y, x, lines, cols);
|
||||
|
||||
/* We use replace to keep the circular list of the dialog in the */
|
||||
/* same state. Maybe we could just kill it and then replace it */
|
||||
if ((midnight_dlg != NULL) && (old_widget != NULL))
|
||||
|
@ -1123,7 +1123,7 @@ tree_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
|
||||
WTree *
|
||||
tree_new (int is_panel, int y, int x, int lines, int cols)
|
||||
tree_new (int y, int x, int lines, int cols, gboolean is_panel)
|
||||
{
|
||||
WTree *tree = g_new (WTree, 1);
|
||||
|
||||
|
@ -6,12 +6,14 @@
|
||||
#ifndef MC_TREE_H
|
||||
#define MC_TREE_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
typedef struct WTree WTree;
|
||||
|
||||
extern WTree *the_tree;
|
||||
extern int xtree_mode;
|
||||
|
||||
WTree *tree_new (int is_panel, int y, int x, int lines, int cols);
|
||||
WTree *tree_new (int y, int x, int lines, int cols, gboolean is_panel);
|
||||
|
||||
void tree_chdir (WTree *tree, const char *dir);
|
||||
char *tree_selected_name (const WTree *tree);
|
||||
@ -22,4 +24,4 @@ struct Dlg_head;
|
||||
|
||||
WTree *find_tree (struct Dlg_head *h);
|
||||
|
||||
#endif /* MC_TREE_H */
|
||||
#endif /* MC_TREE_H */
|
||||
|
@ -245,6 +245,8 @@ mcview_hook (void *v)
|
||||
else
|
||||
return;
|
||||
|
||||
mcview_done (view);
|
||||
mcview_init (view);
|
||||
mcview_load (view, 0, panel->dir.list[panel->selected].fname, 0);
|
||||
mcview_display (view);
|
||||
}
|
||||
@ -365,7 +367,6 @@ mcview_execute_cmd (mcview_t * view, unsigned long command)
|
||||
break;
|
||||
case CK_ViewToggleNroffMode:
|
||||
mcview_toggle_nroff_mode (view);
|
||||
view->dirty++;
|
||||
break;
|
||||
case CK_ViewToggleHexNavMode:
|
||||
view->hexview_in_text = !view->hexview_in_text;
|
||||
|
@ -286,6 +286,7 @@ void mcview_toggle_wrap_mode (mcview_t * view);
|
||||
void mcview_toggle_nroff_mode (mcview_t * view);
|
||||
void mcview_toggle_hex_mode (mcview_t * view);
|
||||
gboolean mcview_ok_to_quit (mcview_t * view);
|
||||
void mcview_init (mcview_t * view);
|
||||
void mcview_done (mcview_t * view);
|
||||
void mcview_select_encoding (mcview_t * view);
|
||||
void mcview_set_codeset (mcview_t * view);
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
@ -79,6 +80,8 @@ mcview_toggle_magic_mode (mcview_t * view)
|
||||
filename = g_strdup (view->filename);
|
||||
command = g_strdup (view->command);
|
||||
|
||||
mcview_done (view);
|
||||
mcview_init (view);
|
||||
mcview_load (view, command, filename, 0);
|
||||
g_free (filename);
|
||||
g_free (command);
|
||||
@ -120,13 +123,13 @@ mcview_toggle_hex_mode (mcview_t * view)
|
||||
{
|
||||
view->hex_cursor = view->dpy_start;
|
||||
view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line);
|
||||
view->widget.options |= W_WANT_CURSOR;
|
||||
widget_want_cursor (view->widget, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
view->dpy_start = view->hex_cursor;
|
||||
mcview_moveto_bol (view);
|
||||
view->widget.options &= ~W_WANT_CURSOR;
|
||||
widget_want_cursor (view->widget, 0);
|
||||
}
|
||||
mcview_altered_hex_mode = 1;
|
||||
view->dpy_bbar_dirty = TRUE;
|
||||
@ -161,6 +164,53 @@ mcview_ok_to_quit (mcview_t * view)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mcview_init (mcview_t * view)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
view->filename = NULL;
|
||||
view->command = NULL;
|
||||
view->search_nroff_seq = NULL;
|
||||
|
||||
mcview_set_datasource_none (view);
|
||||
|
||||
view->growbuf_in_use = FALSE;
|
||||
/* leave the other growbuf fields uninitialized */
|
||||
|
||||
view->hexedit_lownibble = FALSE;
|
||||
view->coord_cache = NULL;
|
||||
|
||||
view->dpy_start = 0;
|
||||
view->dpy_text_column = 0;
|
||||
view->dpy_end = 0;
|
||||
view->hex_cursor = 0;
|
||||
view->cursor_col = 0;
|
||||
view->cursor_row = 0;
|
||||
view->change_list = NULL;
|
||||
|
||||
/* {status,ruler,data}_area are left uninitialized */
|
||||
|
||||
view->dirty = 0;
|
||||
view->dpy_bbar_dirty = TRUE;
|
||||
view->bytes_per_line = 1;
|
||||
|
||||
view->search_start = 0;
|
||||
view->search_end = 0;
|
||||
|
||||
view->want_to_quit = FALSE;
|
||||
|
||||
view->marker = 0;
|
||||
for (i = 0; i < sizeof (view->marks) / sizeof (view->marks[0]); i++)
|
||||
view->marks[i] = 0;
|
||||
|
||||
view->move_dir = 0;
|
||||
view->update_steps = 0;
|
||||
view->update_activate = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mcview_done (mcview_t * view)
|
||||
{
|
||||
@ -183,8 +233,10 @@ mcview_done (mcview_t * view)
|
||||
|
||||
/* view->widget needs no destructor */
|
||||
|
||||
g_free (view->filename), view->filename = NULL;
|
||||
g_free (view->command), view->command = NULL;
|
||||
g_free (view->filename);
|
||||
view->filename = NULL;
|
||||
g_free (view->command);
|
||||
view->command = NULL;
|
||||
|
||||
mcview_close_datasource (view);
|
||||
/* the growing buffer is freed with the datasource */
|
||||
|
@ -202,21 +202,13 @@ mcview_set_keymap (mcview_t * view)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
mcview_t *
|
||||
mcview_new (int y, int x, int lines, int cols, int is_panel)
|
||||
mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
|
||||
{
|
||||
mcview_t *view = g_new0 (mcview_t, 1);
|
||||
size_t i;
|
||||
|
||||
init_widget (&view->widget, y, x, lines, cols, mcview_callback, mcview_real_event);
|
||||
|
||||
view->filename = NULL;
|
||||
view->command = NULL;
|
||||
view->search_nroff_seq = NULL;
|
||||
|
||||
mcview_set_datasource_none (view);
|
||||
|
||||
view->growbuf_in_use = FALSE;
|
||||
/* leave the other growbuf fields uninitialized */
|
||||
mcview_set_keymap (view);
|
||||
|
||||
view->hex_mode = FALSE;
|
||||
view->hexedit_mode = FALSE;
|
||||
@ -224,38 +216,11 @@ mcview_new (int y, int x, int lines, int cols, int is_panel)
|
||||
view->text_nroff_mode = FALSE;
|
||||
view->text_wrap_mode = FALSE;
|
||||
view->magic_mode = FALSE;
|
||||
view->utf8 = FALSE;
|
||||
|
||||
view->hexedit_lownibble = FALSE;
|
||||
view->coord_cache = NULL;
|
||||
|
||||
view->dpy_frame_size = is_panel ? 1 : 0;
|
||||
view->dpy_start = 0;
|
||||
view->dpy_text_column = 0;
|
||||
view->dpy_end = 0;
|
||||
view->hex_cursor = 0;
|
||||
view->cursor_col = 0;
|
||||
view->cursor_row = 0;
|
||||
view->change_list = NULL;
|
||||
view->converter = str_cnv_from_term;
|
||||
mcview_set_codeset (view);
|
||||
/* {status,ruler,data}_area are left uninitialized */
|
||||
|
||||
view->dirty = 0;
|
||||
view->dpy_bbar_dirty = TRUE;
|
||||
view->bytes_per_line = 1;
|
||||
|
||||
view->search_start = 0;
|
||||
view->search_end = 0;
|
||||
|
||||
view->want_to_quit = FALSE;
|
||||
view->marker = 0;
|
||||
for (i = 0; i < sizeof (view->marks) / sizeof (view->marks[0]); i++)
|
||||
view->marks[i] = 0;
|
||||
|
||||
view->move_dir = 0;
|
||||
view->update_steps = 0;
|
||||
view->update_activate = 0;
|
||||
mcview_init (view);
|
||||
|
||||
if (mcview_default_hex_mode)
|
||||
mcview_toggle_hex_mode (view);
|
||||
@ -266,8 +231,6 @@ mcview_new (int y, int x, int lines, int cols, int is_panel)
|
||||
if (mcview_default_magic_flag)
|
||||
mcview_toggle_magic_mode (view);
|
||||
|
||||
mcview_set_keymap (view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -285,7 +248,7 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start
|
||||
view_dlg = create_dlg (0, 0, LINES, COLS, NULL, mcview_dialog_callback,
|
||||
"[Internal File Viewer]", NULL, DLG_WANT_TAB);
|
||||
|
||||
lc_mcview = mcview_new (0, 0, LINES - 1, COLS, 0);
|
||||
lc_mcview = mcview_new (0, 0, LINES - 1, COLS, FALSE);
|
||||
add_widget (view_dlg, lc_mcview);
|
||||
|
||||
add_widget (view_dlg, buttonbar_new (TRUE));
|
||||
@ -314,38 +277,25 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start
|
||||
gboolean
|
||||
mcview_load (mcview_t * view, const char *command, const char *file, int start_line)
|
||||
{
|
||||
int i, type;
|
||||
int fd = -1;
|
||||
char tmp[BUF_MEDIUM];
|
||||
char *canon_fname;
|
||||
struct stat st;
|
||||
|
||||
gboolean retval = FALSE;
|
||||
|
||||
assert (view->bytes_per_line != 0);
|
||||
mcview_done (view);
|
||||
|
||||
/* Set up the state */
|
||||
mcview_set_datasource_none (view);
|
||||
view->filename = g_strdup (file);
|
||||
view->command = 0;
|
||||
|
||||
/* Clear the markers */
|
||||
view->marker = 0;
|
||||
for (i = 0; i < 10; i++)
|
||||
view->marks[i] = 0;
|
||||
|
||||
if (!mcview_is_in_panel (view))
|
||||
{
|
||||
view->dpy_text_column = 0;
|
||||
}
|
||||
|
||||
if (command && (view->magic_mode || file == NULL || file[0] == '\0'))
|
||||
{
|
||||
mcview_set_codeset (view);
|
||||
|
||||
if (command != NULL && (view->magic_mode || file == NULL || file[0] == '\0'))
|
||||
retval = mcview_load_command_output (view, command);
|
||||
}
|
||||
else if (file != NULL && file[0] != '\0')
|
||||
{
|
||||
int fd = -1;
|
||||
char tmp[BUF_MEDIUM];
|
||||
struct stat st;
|
||||
|
||||
/* Open the file */
|
||||
fd = mc_open (file, O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1)
|
||||
@ -386,6 +336,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
}
|
||||
else
|
||||
{
|
||||
int type;
|
||||
|
||||
type = get_compression_type (fd, file);
|
||||
|
||||
if (view->magic_mode && (type != COMPRESSION_NONE))
|
||||
@ -410,8 +362,10 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
|
||||
if (mcview_remember_file_position && view->filename != NULL && start_line == 0)
|
||||
{
|
||||
char *canon_fname;
|
||||
long line, col;
|
||||
off_t new_offset;
|
||||
|
||||
canon_fname = vfs_canon (view->filename);
|
||||
load_file_position (canon_fname, &line, &col, &new_offset);
|
||||
new_offset = min (new_offset, mcview_get_filesize (view));
|
||||
@ -419,9 +373,7 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
g_free (canon_fname);
|
||||
}
|
||||
else if (start_line > 0)
|
||||
{
|
||||
mcview_moveto (view, start_line - 1, 0);
|
||||
}
|
||||
|
||||
view->hexedit_lownibble = FALSE;
|
||||
view->hexview_in_text = FALSE;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#ifndef MC_VIEWER_H
|
||||
#define MC_VIEWER_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants ********************/
|
||||
|
||||
struct mcview_struct;
|
||||
@ -35,7 +37,7 @@ extern char *mcview_show_eof;
|
||||
|
||||
/* Creates a new mcview_t object with the given properties. Caveat: the
|
||||
* origin is in y-x order, while the extent is in x-y order. */
|
||||
extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, int is_panel);
|
||||
extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, gboolean is_panel);
|
||||
|
||||
|
||||
/* Shows {file} or the output of {command} in the internal viewer,
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user