Index: mc-4.6.1/src/main.c =================================================================== --- mc-4.6.1/src/main.c (revision 3) +++ mc-4.6.1/src/main.c (revision 6) @@ -699,7 +699,7 @@ load_prompt (int fd, void *unused) int prompt_len; prompt = strip_ctrl_codes (subshell_prompt); - prompt_len = strlen (prompt); + prompt_len = mbstrlen (prompt); /* Check for prompts too big */ if (COLS > 8 && prompt_len > COLS - 8) { Index: mc-4.6.1/src/util.c =================================================================== --- mc-4.6.1/src/util.c (revision 3) +++ mc-4.6.1/src/util.c (revision 6) @@ -240,7 +240,67 @@ int msglen (const char *text, int *lines) return max; } +#ifdef UTF8 /* + * Skip zero-width characters from the beginning of str. + */ +static const char * +mbchomp(const char *str) +{ + for (; *str; str++) + { + wchar_t c; + size_t len; + + len = mbrtowc (&c, str, MB_CUR_MAX, NULL); + + if (len == (size_t)(-1) || len == (size_t)(-2)) + break; + + if (len > 0) + { + int wcsize = wcwidth(c); + + if (wcsize != 0) + break; + + str += len-1; + } + } + + return str; +} +#endif + +#ifdef UTF8 +/* + * Return substring containing up to n characters from the tail. + * slen is pre-calculated number of characters in str. + */ +static const char * +mbright(const char *str, int slen, int n) +{ + for (; slen > n; str++) + { + wchar_t c; + ssize_t len; + + len = mbrtowc (&c, str, MB_CUR_MAX, NULL); + + if (len > 0) + { + int wcsize = wcwidth(c); + + slen -= wcsize > 0 ? wcsize : 0; + str += len-1; + } + } + + return mbchomp(str); +} +#endif + +/* * Copy from s to d, and trim the beginning if necessary, and prepend * "..." in this case. The destination string can have at most len * bytes, not counting trailing 0. @@ -253,7 +313,7 @@ trim (const char *s, char *d, int len) /* Sanity check */ len = max (len, 0); - source_len = strlen (s); + source_len = mbstrlen (s); if (source_len > len) { /* Cannot fit the whole line */ if (len <= 3) { @@ -264,7 +324,12 @@ trim (const char *s, char *d, int len) } else { /* Begin with ... and add the rest of the source string */ memset (d, '.', 3); - strcpy (d + 3, s + 3 + source_len - len); +#ifdef UTF8 + if (SLsmg_Is_Unicode) + strcpy (d + 3, mbright(s, source_len, len-3)); + else +#endif + strcpy (d + 3, s + 3 + source_len - len); } } else /* We can copy the whole line */ Index: mc-4.6.1/src/screen.c =================================================================== --- mc-4.6.1/src/screen.c (revision 3) +++ mc-4.6.1/src/screen.c (revision 6) @@ -861,8 +861,8 @@ show_dir (WPanel *panel) widget_move (&panel->widget, 0, 3); - tmp = g_malloc (panel->widget.cols + 1); - tmp[panel->widget.cols] = '\0'; + tmp = g_malloc (panel->widget.cols*MB_CUR_MAX + 1); + tmp[panel->widget.cols*MB_CUR_MAX] = '\0'; trim (strip_home_and_password (panel->cwd), tmp, min (max (panel->widget.cols - 7, 0), panel->widget.cols) );