Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: minor zle_utils fix



> The API for the Unicode version is not yet defined, but it will probably
> be that way.  The alternative is to create it on the heap, but I hope
> it will usually be easy enough to free it explicitly.  The existing
> non-Unicode version will presumably remain the way it is.

I'm not committing this because it changes the non-Unicode version;
would you rather ifdef the free()'s in the calling functions?

--- orig/Src/Zle/zle_utils.c
+++ mod/Src/Zle/zle_utils.c
@@ -89,10 +89,36 @@
 mod_export unsigned char *
 zlegetline(int *ll, int *cs)
 {
+    char *s;
+#ifdef ZLE_UNICODE_SUPPORT
+    char *mb_cursor;
+    int i, j;
+    size_t wc_len, mb_len = 0;
+
+    wc_len = wcslen(zleline);
+    mb_cursor = s = zalloc(wc_len * MB_CUR_MAX); /* perhaps try less first then realloc */
+
+    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
 }
 
 



Messages sorted by: Reverse Date, Date, Thread, Author