diffviewer: clarify support of UTF-8 codeset.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2015-01-10 20:08:37 +03:00
parent da149a0ae6
commit 67f465209b
2 changed files with 30 additions and 11 deletions

View File

@ -114,9 +114,13 @@ typedef struct WDiff
int tab_size;
diff_place_t ord;
int full;
#ifdef HAVE_CHARSET
gboolean utf8;
/* converter for translation of text */
GIConv converter;
#endif /* HAVE_CHARSET */
struct
{
int quality;

View File

@ -573,6 +573,7 @@ dview_get_byte (char *str, gboolean * result)
/* --------------------------------------------------------------------------------------------- */
#ifdef HAVE_CHARSET
/**
* 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);
}
#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)
{
int utf_ch = 0;
#ifdef HAVE_CHARSET
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)
skip += ch_len - 1;
(void) utf_ch;
#endif
skip--;
}
else
{
@ -1511,15 +1515,16 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
}
else if (skip != 0)
{
int utf_ch = 0;
#ifdef HAVE_CHARSET
gboolean res;
int ch_len;
int ch_len = 1;
skip--;
utf_ch = dview_get_utf ((char *) src, &ch_len, &res);
(void) dview_get_utf ((char *) src, &ch_len, &res);
if (ch_len > 1)
skip += ch_len - 1;
(void) utf_ch;
#endif
skip--;
}
else
{
@ -2428,8 +2433,8 @@ dview_init (WDiff * dview, const char *args, const char *file1, const char *file
dview->merged[DIFF_RIGHT] = FALSE;
dview->hdiff = NULL;
dview->dsrc = dsrc;
dview->converter = str_cnv_from_term;
#ifdef HAVE_CHARSET
dview->converter = str_cnv_from_term;
dview_set_codeset (dview);
#endif
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]);
}
#if HAVE_CHARSET
if (dview->converter != str_cnv_from_term)
str_close_conv (dview->converter);
#endif
destroy_hdiff (dview);
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];
#ifdef HAVE_CHARSET
if (dview->utf8)
k = dview_str_utf8_offset_to_pos (p->p, width);
else
#endif
k = width;
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;
#ifdef HAVE_CHARSET
if (dview->utf8)
{
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 = '.';
}
else
#endif
next_ch = dview_get_byte (buf + cnt, &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)
tty_setcolor (DFF_CHH_COLOR);
#ifdef HAVE_CHARSET
if (dview->utf8)
k = dview_str_utf8_offset_to_pos (p->p, width);
else
#endif
k = width;
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;
#ifdef HAVE_CHARSET
if (dview->utf8)
{
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 = '.';
}
else
#endif
next_ch = dview_get_byte (buf + cnt, &ch_res);
if (ch_res)
{