aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-03-09 18:18:32 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-03-09 18:18:32 +0530
commite0eea578458977ad4f816402052cd8073fec7859 (patch)
tree8d52f2b25ffc32aa8743a5c7348dc2ecbd3b6c51
parent2a85da09d5e0215807ed4d154e6e7722a1abf4f5 (diff)
downloadnnn-e0eea578458977ad4f816402052cd8073fec7859.tar.gz
Fix regression
-rw-r--r--src/nnn.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 017b04c..5392a7f 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1944,19 +1944,25 @@ static inline void resetdircolor(int flags)
static char *unescape(const char *str, uint maxcols)
{
static wchar_t wbuf[NAME_MAX + 1] __attribute__ ((aligned));
- static wchar_t *buf = wbuf;
- static size_t len, lencount;
+ wchar_t *buf = wbuf;
+ size_t len, lencount = 0;
/* Convert multi-byte to wide char */
len = mbstowcs(wbuf, str, NAME_MAX);
- //g_buf[0] = '\0';
+ while (*buf && lencount <= maxcols) {
+ if (*buf <= '\x1f' || *buf == '\x7f')
+ *buf = '\?';
+
+ ++buf;
+ ++lencount;
+ }
+
+ len = lencount = wcswidth(wbuf, len);
- if (maxcols) {
- len = lencount = wcswidth(wbuf, len);
- /* Reduce number of wide chars to max columns */
- if (len > maxcols)
- lencount = maxcols + 1;
+ /* Reduce number of wide chars to max columns */
+ if (len > maxcols) {
+ lencount = maxcols + 1;
/* Reduce wide chars one by one till it fits */
while (len > maxcols)
@@ -1965,13 +1971,6 @@ static char *unescape(const char *str, uint maxcols)
wbuf[lencount] = L'\0';
}
- while (*buf) {
- if (*buf <= '\x1f' || *buf == '\x7f')
- *buf = '\?';
-
- ++buf;
- }
-
/* Convert wide char to multi-byte */
wcstombs(g_buf, wbuf, NAME_MAX);
return g_buf;