mirror of https://github.com/MidnightCommander/mc
Ticket #2876: code cleanup before 4.8.6 release.
mcedit: better support of --disable-charset. Signed-off-by: Ilia Maslakov <il.smind@gmail.com> Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
ded2b30443
commit
1b1071cdac
|
@ -652,6 +652,7 @@ edit_modification (WEdit * edit)
|
|||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
static char *
|
||||
edit_get_byte_ptr (WEdit * edit, off_t byte_index)
|
||||
{
|
||||
|
@ -670,9 +671,11 @@ edit_get_byte_ptr (WEdit * edit, off_t byte_index)
|
|||
return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] +
|
||||
(byte_index & M_EDIT_BUF_SIZE));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
static int
|
||||
edit_get_prev_utf (WEdit * edit, off_t byte_index, int *char_width)
|
||||
{
|
||||
|
@ -715,6 +718,7 @@ edit_get_prev_utf (WEdit * edit, off_t byte_index, int *char_width)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* high level cursor movement commands */
|
||||
|
@ -1099,6 +1103,7 @@ edit_right_char_move_cmd (WEdit * edit)
|
|||
{
|
||||
int cw = 1;
|
||||
int c = 0;
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
c = edit_get_utf (edit, edit->curs1, &cw);
|
||||
|
@ -1106,6 +1111,7 @@ edit_right_char_move_cmd (WEdit * edit)
|
|||
cw = 1;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
c = edit_get_byte (edit, edit->curs1);
|
||||
}
|
||||
|
@ -1130,12 +1136,14 @@ edit_left_char_move_cmd (WEdit * edit)
|
|||
&& edit->mark1 != edit->mark2
|
||||
&& edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1))
|
||||
return;
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
edit_get_prev_utf (edit, edit->curs1, &cw);
|
||||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
#endif
|
||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||
{
|
||||
edit->over_col--;
|
||||
|
@ -1843,6 +1851,7 @@ edit_get_byte (WEdit * edit, off_t byte_index)
|
|||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
int
|
||||
edit_get_utf (WEdit * edit, off_t byte_index, int *char_width)
|
||||
{
|
||||
|
@ -1903,6 +1912,7 @@ edit_get_utf (WEdit * edit, off_t byte_index, int *char_width)
|
|||
*char_width = width;
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -2263,9 +2273,11 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
|
|||
edit->redo_stack_size_mask = START_STACK_SIZE - 1;
|
||||
edit->redo_stack = g_malloc0 ((edit->redo_stack_size + 10) * sizeof (long));
|
||||
|
||||
edit->utf8 = 0;
|
||||
#ifdef HAVE_CHARSET
|
||||
edit->utf8 = FALSE;
|
||||
edit->converter = str_cnv_from_term;
|
||||
edit_set_codeset (edit);
|
||||
#endif
|
||||
|
||||
if (!edit_load_file (edit))
|
||||
{
|
||||
|
@ -2340,8 +2352,10 @@ edit_clean (WEdit * edit)
|
|||
mc_search_free (edit->search);
|
||||
edit->search = NULL;
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->converter != str_cnv_from_term)
|
||||
str_close_conv (edit->converter);
|
||||
#endif
|
||||
|
||||
edit_purge_widget (edit);
|
||||
|
||||
|
@ -2384,10 +2398,10 @@ edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
|
|||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
void
|
||||
edit_set_codeset (WEdit * edit)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
const char *cp_id;
|
||||
|
||||
cp_id =
|
||||
|
@ -2408,10 +2422,8 @@ edit_set_codeset (WEdit * edit)
|
|||
|
||||
if (cp_id != NULL)
|
||||
edit->utf8 = str_isutf8 (cp_id);
|
||||
#else
|
||||
(void) edit;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -2750,7 +2762,7 @@ edit_delete (WEdit * edit, const int byte_delete)
|
|||
if (!edit->curs2)
|
||||
return 0;
|
||||
|
||||
cw = 1;
|
||||
#ifdef HAVE_CHARSET
|
||||
/* if byte_delete = 1 then delete only one byte not multibyte char */
|
||||
if (edit->utf8 && byte_delete == 0)
|
||||
{
|
||||
|
@ -2758,6 +2770,9 @@ edit_delete (WEdit * edit, const int byte_delete)
|
|||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
#else
|
||||
(void) byte_delete;
|
||||
#endif
|
||||
|
||||
if (edit->mark2 != edit->mark1)
|
||||
edit_push_markers (edit);
|
||||
|
@ -2818,17 +2833,20 @@ edit_backspace (WEdit * edit, const int byte_delete)
|
|||
if (edit->curs1 == 0)
|
||||
return 0;
|
||||
|
||||
cw = 1;
|
||||
|
||||
if (edit->mark2 != edit->mark1)
|
||||
edit_push_markers (edit);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8 && byte_delete == 0)
|
||||
{
|
||||
edit_get_prev_utf (edit, edit->curs1, &cw);
|
||||
if (cw < 1)
|
||||
cw = 1;
|
||||
}
|
||||
#else
|
||||
(void) byte_delete;
|
||||
#endif
|
||||
|
||||
for (i = 1; i <= cw; i++)
|
||||
{
|
||||
if (edit->mark1 >= edit->curs1)
|
||||
|
@ -3096,7 +3114,11 @@ edit_move_forward3 (WEdit * edit, off_t current, long cols, off_t upto)
|
|||
else
|
||||
return p;
|
||||
}
|
||||
else if ((c < 32 || c == 127) && (orig_c == c || (!mc_global.utf8_display && !edit->utf8)))
|
||||
else if ((c < 32 || c == 127) && (orig_c == c
|
||||
#ifdef HAVE_CHARSET
|
||||
|| (!mc_global.utf8_display && !edit->utf8)
|
||||
#endif
|
||||
))
|
||||
/* '\r' is shown as ^M, so we must advance 2 characters */
|
||||
/* Caret notation for control characters */
|
||||
col += 2;
|
||||
|
@ -3658,9 +3680,12 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
|||
if (edit->overwrite)
|
||||
{
|
||||
/* remove char only one time, after input first byte, multibyte chars */
|
||||
if ((!mc_global.utf8_display || edit->charpoint == 0)
|
||||
&& edit_get_byte (edit, edit->curs1) != '\n')
|
||||
edit_delete (edit, 0);
|
||||
#ifdef HAVE_CHARSET
|
||||
if (!mc_global.utf8_display || edit->charpoint == 0)
|
||||
#endif
|
||||
if (edit_get_byte (edit, edit->curs1) != '\n')
|
||||
|
||||
edit_delete (edit, 0);
|
||||
}
|
||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||
edit_insert_over (edit);
|
||||
|
|
|
@ -108,9 +108,6 @@ static inline void
|
|||
status_string (WEdit * edit, char *s, int w)
|
||||
{
|
||||
char byte_str[16];
|
||||
unsigned char cur_byte = 0;
|
||||
unsigned int cur_utf = 0;
|
||||
int cw = 1;
|
||||
|
||||
/*
|
||||
* If we are at the end of file, print <EOF>,
|
||||
|
@ -119,15 +116,12 @@ status_string (WEdit * edit, char *s, int w)
|
|||
*/
|
||||
if (edit->curs1 < edit->last_byte)
|
||||
{
|
||||
if (!edit->utf8)
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
cur_byte = edit_get_byte (edit, edit->curs1);
|
||||
unsigned int cur_utf = 0;
|
||||
int cw = 1;
|
||||
|
||||
g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
|
||||
(int) cur_byte, (unsigned) cur_byte);
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_utf = edit_get_utf (edit, edit->curs1, &cw);
|
||||
if (cw > 0)
|
||||
{
|
||||
|
@ -140,7 +134,15 @@ status_string (WEdit * edit, char *s, int w)
|
|||
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
|
||||
(int) cur_utf, (unsigned) cur_utf);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
unsigned char cur_byte = 0;
|
||||
|
||||
cur_byte = edit_get_byte (edit, edit->curs1);
|
||||
g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
|
||||
(int) cur_byte, (unsigned) cur_byte);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -160,11 +162,9 @@ status_string (WEdit * edit, char *s, int w)
|
|||
edit->curs_line + 1,
|
||||
edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str,
|
||||
#ifdef HAVE_CHARSET
|
||||
mc_global.source_codepage >=
|
||||
0 ? get_codepage_id (mc_global.source_codepage) : ""
|
||||
#else
|
||||
""
|
||||
mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
|
||||
#endif
|
||||
""
|
||||
);
|
||||
else
|
||||
g_snprintf (s, w,
|
||||
|
@ -179,11 +179,9 @@ status_string (WEdit * edit, char *s, int w)
|
|||
edit->curs_line + 1,
|
||||
edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str,
|
||||
#ifdef HAVE_CHARSET
|
||||
mc_global.source_codepage >=
|
||||
0 ? get_codepage_id (mc_global.source_codepage) : ""
|
||||
#else
|
||||
""
|
||||
mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
|
||||
#endif
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -514,7 +512,6 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
|||
int color;
|
||||
int abn_style;
|
||||
int i;
|
||||
int utf8lag = 0;
|
||||
unsigned int cur_line = 0;
|
||||
int book_mark = 0;
|
||||
char line_stat[LINE_STATE_WIDTH + 1] = "\0";
|
||||
|
@ -609,14 +606,16 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
|||
if (q >= edit->found_start && q < (off_t) (edit->found_start + edit->found_len))
|
||||
p->style |= MOD_BOLD;
|
||||
|
||||
if (!edit->utf8)
|
||||
{
|
||||
c = edit_get_byte (edit, q);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
c = edit_get_utf (edit, q, &cw);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
c = edit_get_byte (edit, q);
|
||||
}
|
||||
/* we don't use bg for mc - fg contains both */
|
||||
if (book_mark)
|
||||
{
|
||||
|
@ -630,7 +629,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
|||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
col = (end_col + utf8lag) - edit->start_col + 1; /* quit */
|
||||
col = end_col - edit->start_col + 1; /* quit */
|
||||
break;
|
||||
case '\t':
|
||||
i = TAB_SIZE - ((int) col % TAB_SIZE);
|
||||
|
@ -762,24 +761,23 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
|||
control_char = TRUE;
|
||||
break;
|
||||
}
|
||||
if (!edit->utf8)
|
||||
#ifdef HAVE_CHARSET
|
||||
if (edit->utf8)
|
||||
{
|
||||
if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
|
||||
(!mc_global.utf8_display && is_printable (c)))
|
||||
{
|
||||
if (g_unichar_isprint (c))
|
||||
p->ch = c;
|
||||
p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->ch = '.';
|
||||
p->style = abn_style;
|
||||
p++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (g_unichar_isprint (c))
|
||||
if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
|
||||
(!mc_global.utf8_display && is_printable (c)))
|
||||
{
|
||||
p->ch = c;
|
||||
p++;
|
||||
|
|
|
@ -77,9 +77,13 @@ struct WEdit
|
|||
unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */
|
||||
unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */
|
||||
|
||||
/* UTF8 */
|
||||
#ifdef HAVE_CHARSET
|
||||
/* multibyte support */
|
||||
gboolean utf8; /* It's multibyte file codeset */
|
||||
GIConv converter;
|
||||
char charbuf[4 + 1];
|
||||
int charpoint;
|
||||
#endif
|
||||
|
||||
/* search handler */
|
||||
mc_search_t *search;
|
||||
|
@ -108,7 +112,6 @@ struct WEdit
|
|||
unsigned int delete_file:1; /* New file, needs to be deleted unless modified */
|
||||
unsigned int highlight:1; /* There is a selected block */
|
||||
unsigned int column_highlight:1;
|
||||
unsigned int utf8:1; /* It's multibyte file codeset */
|
||||
unsigned int fullscreen:1; /* Is window fullscreen or not */
|
||||
long prev_col; /* recent column position of the cursor - used when moving
|
||||
up or down past lines that are shorter than the current line */
|
||||
|
@ -159,15 +162,11 @@ struct WEdit
|
|||
GTree *defines; /* List of defines */
|
||||
gboolean is_case_insensitive; /* selects language case sensitivity */
|
||||
|
||||
/* user map stuff */
|
||||
GIConv converter;
|
||||
|
||||
/* line break */
|
||||
LineBreaks lb;
|
||||
gboolean extmod;
|
||||
|
||||
char *labels[10];
|
||||
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
|
Loading…
Reference in New Issue