mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
diffviewer: clarify support of UTF-8 codeset.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
da149a0ae6
commit
67f465209b
@ -114,9 +114,13 @@ typedef struct WDiff
|
|||||||
int tab_size;
|
int tab_size;
|
||||||
diff_place_t ord;
|
diff_place_t ord;
|
||||||
int full;
|
int full;
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
gboolean utf8;
|
gboolean utf8;
|
||||||
/* converter for translation of text */
|
/* converter for translation of text */
|
||||||
GIConv converter;
|
GIConv converter;
|
||||||
|
#endif /* HAVE_CHARSET */
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int quality;
|
int quality;
|
||||||
|
@ -573,6 +573,7 @@ dview_get_byte (char *str, gboolean * result)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
/**
|
/**
|
||||||
* Get utf multibyte char from string
|
* Get utf multibyte char from string
|
||||||
*
|
*
|
||||||
@ -645,6 +646,7 @@ dview_str_utf8_offset_to_pos (const char *text, size_t length)
|
|||||||
}
|
}
|
||||||
return max (length, (size_t) result);
|
return max (length, (size_t) result);
|
||||||
}
|
}
|
||||||
|
#endif /*HAVE_CHARSET */
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@ -1410,15 +1412,17 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
|
|||||||
}
|
}
|
||||||
else if (skip > 0)
|
else if (skip > 0)
|
||||||
{
|
{
|
||||||
int utf_ch = 0;
|
#ifdef HAVE_CHARSET
|
||||||
gboolean res;
|
gboolean res;
|
||||||
int ch_len;
|
int ch_len = 1;
|
||||||
|
|
||||||
|
(void) dview_get_utf ((char *) src, &ch_len, &res);
|
||||||
|
|
||||||
skip--;
|
|
||||||
utf_ch = dview_get_utf ((char *) src, &ch_len, &res);
|
|
||||||
if (ch_len > 1)
|
if (ch_len > 1)
|
||||||
skip += ch_len - 1;
|
skip += ch_len - 1;
|
||||||
(void) utf_ch;
|
#endif
|
||||||
|
|
||||||
|
skip--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1511,15 +1515,16 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
|
|||||||
}
|
}
|
||||||
else if (skip != 0)
|
else if (skip != 0)
|
||||||
{
|
{
|
||||||
int utf_ch = 0;
|
#ifdef HAVE_CHARSET
|
||||||
gboolean res;
|
gboolean res;
|
||||||
int ch_len;
|
int ch_len = 1;
|
||||||
|
|
||||||
skip--;
|
(void) dview_get_utf ((char *) src, &ch_len, &res);
|
||||||
utf_ch = dview_get_utf ((char *) src, &ch_len, &res);
|
|
||||||
if (ch_len > 1)
|
if (ch_len > 1)
|
||||||
skip += ch_len - 1;
|
skip += ch_len - 1;
|
||||||
(void) utf_ch;
|
#endif
|
||||||
|
|
||||||
|
skip--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2428,8 +2433,8 @@ dview_init (WDiff * dview, const char *args, const char *file1, const char *file
|
|||||||
dview->merged[DIFF_RIGHT] = FALSE;
|
dview->merged[DIFF_RIGHT] = FALSE;
|
||||||
dview->hdiff = NULL;
|
dview->hdiff = NULL;
|
||||||
dview->dsrc = dsrc;
|
dview->dsrc = dsrc;
|
||||||
dview->converter = str_cnv_from_term;
|
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
|
dview->converter = str_cnv_from_term;
|
||||||
dview_set_codeset (dview);
|
dview_set_codeset (dview);
|
||||||
#endif
|
#endif
|
||||||
dview->a[DIFF_LEFT] = g_array_new (FALSE, FALSE, sizeof (DIFFLN));
|
dview->a[DIFF_LEFT] = g_array_new (FALSE, FALSE, sizeof (DIFFLN));
|
||||||
@ -2487,8 +2492,10 @@ dview_fini (WDiff * dview)
|
|||||||
f_close (dview->f[DIFF_LEFT]);
|
f_close (dview->f[DIFF_LEFT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_CHARSET
|
||||||
if (dview->converter != str_cnv_from_term)
|
if (dview->converter != str_cnv_from_term)
|
||||||
str_close_conv (dview->converter);
|
str_close_conv (dview->converter);
|
||||||
|
#endif
|
||||||
|
|
||||||
destroy_hdiff (dview);
|
destroy_hdiff (dview);
|
||||||
if (dview->a[DIFF_LEFT] != NULL)
|
if (dview->a[DIFF_LEFT] != NULL)
|
||||||
@ -2589,9 +2596,11 @@ dview_display_file (const WDiff * dview, diff_place_t ord, int r, int c, int hei
|
|||||||
{
|
{
|
||||||
char att[BUFSIZ];
|
char att[BUFSIZ];
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
if (dview->utf8)
|
if (dview->utf8)
|
||||||
k = dview_str_utf8_offset_to_pos (p->p, width);
|
k = dview_str_utf8_offset_to_pos (p->p, width);
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
k = width;
|
k = width;
|
||||||
|
|
||||||
cvt_mgeta (p->p, p->u.len, buf, k, skip, tab_size, show_cr,
|
cvt_mgeta (p->p, p->u.len, buf, k, skip, tab_size, show_cr,
|
||||||
@ -2603,6 +2612,7 @@ dview_display_file (const WDiff * dview, diff_place_t ord, int r, int c, int hei
|
|||||||
{
|
{
|
||||||
gboolean ch_res;
|
gboolean ch_res;
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
if (dview->utf8)
|
if (dview->utf8)
|
||||||
{
|
{
|
||||||
int ch_len;
|
int ch_len;
|
||||||
@ -2614,6 +2624,7 @@ dview_display_file (const WDiff * dview, diff_place_t ord, int r, int c, int hei
|
|||||||
next_ch = '.';
|
next_ch = '.';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
next_ch = dview_get_byte (buf + cnt, &ch_res);
|
next_ch = dview_get_byte (buf + cnt, &ch_res);
|
||||||
|
|
||||||
if (ch_res)
|
if (ch_res)
|
||||||
@ -2644,9 +2655,11 @@ dview_display_file (const WDiff * dview, diff_place_t ord, int r, int c, int hei
|
|||||||
if (ch == CHG_CH)
|
if (ch == CHG_CH)
|
||||||
tty_setcolor (DFF_CHH_COLOR);
|
tty_setcolor (DFF_CHH_COLOR);
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
if (dview->utf8)
|
if (dview->utf8)
|
||||||
k = dview_str_utf8_offset_to_pos (p->p, width);
|
k = dview_str_utf8_offset_to_pos (p->p, width);
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
k = width;
|
k = width;
|
||||||
cvt_mget (p->p, p->u.len, buf, k, skip, tab_size, show_cr);
|
cvt_mget (p->p, p->u.len, buf, k, skip, tab_size, show_cr);
|
||||||
}
|
}
|
||||||
@ -2676,6 +2689,7 @@ dview_display_file (const WDiff * dview, diff_place_t ord, int r, int c, int hei
|
|||||||
{
|
{
|
||||||
gboolean ch_res;
|
gboolean ch_res;
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
if (dview->utf8)
|
if (dview->utf8)
|
||||||
{
|
{
|
||||||
int ch_len;
|
int ch_len;
|
||||||
@ -2687,6 +2701,7 @@ dview_display_file (const WDiff * dview, diff_place_t ord, int r, int c, int hei
|
|||||||
next_ch = '.';
|
next_ch = '.';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
next_ch = dview_get_byte (buf + cnt, &ch_res);
|
next_ch = dview_get_byte (buf + cnt, &ch_res);
|
||||||
if (ch_res)
|
if (ch_res)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user