diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Zle/zle_utils.c | 27 | ||||
-rw-r--r-- | Src/hist.c | 3 |
2 files changed, 28 insertions, 2 deletions
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 611e7414f..d769e8363 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -89,10 +89,35 @@ zleaddtoline(int chr) mod_export unsigned char * zlegetline(int *ll, int *cs) { + char *s; +#ifdef ZLE_UNICODE_SUPPORT + char *mb_cursor; + int i, j; + size_t mb_len = 0; + + mb_cursor = s = zalloc(zlell * MB_CUR_MAX); + + for(i=0;i<=zlell;i++) { + if (i == zlecs) + *cs = mb_len; + j = wctomb(mb_cursor, zleline[i]); + if (j == -1) { + /* invalid char; what to do? */ + } else { + mb_len += j; + } + } + + *ll = mb_len; + + return (unsigned char *)s; +#else *ll = zlell; *cs = zlecs; - return zleline; + s = ztrdup(zleline); + return (unsigned char *)s; +#endif } diff --git a/Src/hist.c b/Src/hist.c index 33c5ccfd9..0a557a3cd 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2260,7 +2260,7 @@ bufferwords(LinkList list, char *buf, int *index) if (zlegetlineptr) { linein = zlegetlineptr(&ll, &cs); } else { - linein = ""; + linein = ztrdup(""); ll = cs = 0; } zlell = ll + 1; /* length of line plus space added below */ @@ -2287,6 +2287,7 @@ bufferwords(LinkList list, char *buf, int *index) p[zlell] = '\0'; inpush(p, 0, NULL); } + zsfree(linein); } if (zlecs) zlecs--; |