Package: ncmpc
Version: 0.11.1+svn-r3362-1
Severity: normal
Tags: patch l10n
ncmpc incorrectly calculates the lengths of UTF-8 strings (see
screenshots at the bug #326074. Attached patch fixes the problem for me.
Please, consider applying and submitting upstream.
-- System Information:
Debian Release: testing/unstable
APT prefers testing
APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.15-1-686
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Versions of packages ncmpc depends on:
ii libc6 2.3.5-8 GNU C Library: Shared libraries an
ii libglib2.0-0 2.8.6-1 The GLib library of C routines
ii libncursesw5 5.5-1.1 Shared libraries for terminal hand
Versions of packages ncmpc recommends:
ii mpd 0.11.5-5.1 Music Player Daemon, the name says
-- no debconf information
diff -pur ncmpc-0.11.1+svn-r3362/src/list_window.c ncmpc-0.11.1+svn-r3362.utf-8/src/list_window.c
--- ncmpc-0.11.1+svn-r3362/src/list_window.c 2005-12-14 19:37:45.000000000 +0300
+++ ncmpc-0.11.1+svn-r3362.utf-8/src/list_window.c 2006-02-20 23:08:40.000000000 +0300
@@ -203,7 +203,8 @@ list_window_paint(list_window_t *lw,
if( show_cursor && selected )
wattron(lw->w, A_REVERSE);
- waddnstr(lw->w, label, lw->cols);
+// waddnstr(lw->w, label, lw->cols);
+ waddstr(lw->w, label);
if( fill && len<lw->cols )
mvwhline(lw->w, i, len, ' ', lw->cols-len);
diff -pur ncmpc-0.11.1+svn-r3362/src/screen.c ncmpc-0.11.1+svn-r3362.utf-8/src/screen.c
--- ncmpc-0.11.1+svn-r3362/src/screen.c 2005-12-14 19:37:45.000000000 +0300
+++ ncmpc-0.11.1+svn-r3362.utf-8/src/screen.c 2006-02-20 23:09:21.000000000 +0300
@@ -187,9 +187,9 @@ paint_top_window(char *header, mpdclient
static int prev_header_len = -1;
WINDOW *w = screen->top_window.w;
- if(prev_header_len!=strlen(header))
+ if(prev_header_len!=my_strlen(header))
{
- prev_header_len = strlen(header);
+ prev_header_len = my_strlen(header);
clear = 1;
}
@@ -244,7 +244,7 @@ paint_top_window(char *header, mpdclient
g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
}
colors_use(w, COLOR_TITLE);
- mvwaddstr(w, 0, screen->top_window.cols-strlen(buf), buf);
+ mvwaddstr(w, 0, screen->top_window.cols-my_strlen(buf), buf);
flags[0] = 0;
if( c->status->repeat )
@@ -333,7 +333,7 @@ paint_status_window(mpdclient_t *c)
if( str )
{
waddstr(w, str);
- x += strlen(str)+1;
+ x += my_strlen(str)+1;
}
/* create time string */
@@ -367,7 +367,7 @@ paint_status_window(mpdclient_t *c)
if( (IS_PLAYING(status->state) || IS_PAUSED(status->state)) )
{
char songname[MAX_SONGNAME_LENGTH];
- int width = COLS-x-strlen(screen->buf);
+ int width = COLS-x-my_strlen(screen->buf);
if( song )
strfsong(songname, MAX_SONGNAME_LENGTH, STATUS_FORMAT, song);
@@ -376,7 +376,7 @@ paint_status_window(mpdclient_t *c)
colors_use(w, COLOR_STATUS);
/* scroll if the song name is to long */
- if( strlen(songname) > width )
+ if( my_strlen(songname) > width )
{
static scroll_state_t st = { 0, 0 };
char *tmp = strscroll(songname, " *** ", width, &st);
@@ -384,7 +384,8 @@ paint_status_window(mpdclient_t *c)
g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
g_free(tmp);
}
- mvwaddnstr(w, 0, x, songname, width);
+// mvwaddnstr(w, 0, x, songname, width);
+ mvwaddstr(w, 0, x, songname);
}
/* display time string */
diff -pur ncmpc-0.11.1+svn-r3362/src/support.c ncmpc-0.11.1+svn-r3362.utf-8/src/support.c
--- ncmpc-0.11.1+svn-r3362/src/support.c 2005-12-14 19:37:45.000000000 +0300
+++ ncmpc-0.11.1+svn-r3362.utf-8/src/support.c 2006-02-20 23:08:40.000000000 +0300
@@ -106,6 +106,7 @@ strcasestr(const char *haystack, const c
}
#endif /* HAVE_STRCASESTR */
+// FIXME: utf-8 length
char *
strscroll(char *str, char *separator, int width, scroll_state_t *st)
{
@@ -123,17 +124,28 @@ strscroll(char *str, char *separator, in
tmp = g_malloc(size);
g_strlcpy(tmp, str, size);
g_strlcat(tmp, separator, size);
- len = strlen(tmp);
+ len = my_strlen(tmp);
if( st->offset >= len )
st->offset = 0;
/* create the new scrolled string */
size = width+1;
- buf = g_malloc(size);
- g_strlcpy(buf, tmp+st->offset, size);
- if( strlen(buf) < width )
- g_strlcat(buf, tmp, size);
+ if (g_utf8_validate(tmp, -1, NULL) )
+ {
+ int ulen;
+ buf = g_malloc(size*6);// max length of utf8 char is 6
+ g_utf8_strncpy(buf, g_utf8_offset_to_pointer(tmp,st->offset), size);
+ if( (ulen = g_utf8_strlen(buf, -1)) < width )
+ g_utf8_strncpy(buf+strlen(buf), tmp, size - ulen - 1);
+ }
+ else
+ {
+ buf = g_malloc(size);
+ g_strlcpy(buf, tmp+st->offset, size);
+ if( strlen(buf) < width )
+ g_strlcat(buf, tmp, size);
+ }
if( time(NULL)-st->t >= 1 )
{