From 4f11c3b8e356ea835f7791e9de4b73fd23d5daa9 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 17 Sep 2006 19:23:38 +0000 Subject: 22729: trunction in computil.c did't handle multibyte characters --- ChangeLog | 3 +++ Src/Zle/computil.c | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f0ff9666..defb28bf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-09-17 Peter Stephenson + * 22729: Src/Zle/computil.c: truncation of description didn't + handle multibyte characters. + * 22727: Src/init.c, Src/Zle/zle_main.c: "use 'exit' to exit" was suboptimal. diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index fab854736..5ecc4b6be 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -616,8 +616,22 @@ cd_get(char **params) memset(buf, ' ', cd_state.pre); memcpy(buf, str->str, str->len); strcpy(sufp, str->desc); - if (strlen(buf) >= columns - 1) - buf[columns - 1] = '\0'; + if (MB_METASTRWIDTH(buf) >= columns - 1) { + char *termptr = buf; + int w; + MB_METACHARINIT(); + for (w = columns - 1; *termptr && w > 0; ) { + convchar_t cchar; + int cw; + termptr += MB_METACHARLENCONV(termptr, &cchar); + cw = WCWIDTH(cchar); + if (cw >= 0) + w -= cw; + else + w--; + } + *termptr = '\0'; + } *dp++ = ztrdup(buf); } *mp = *dp = NULL; -- cgit 1.4.1