Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: minor zle_utils fix
- X-seq: zsh-workers 20726
- From: Clint Adams <clint@xxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: PATCH: minor zle_utils fix
- Date: Tue, 18 Jan 2005 20:26:30 -0500
- Cc: zsh-workers@xxxxxxxxxx
- In-reply-to: <200501171040.j0HAe6mY003515@xxxxxxxxxxxxxx>
- Mail-followup-to: Peter Stephenson <pws@xxxxxxx>, zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20050116162247.GA26801@xxxxxxxxxxx> <200501171040.j0HAe6mY003515@xxxxxxxxxxxxxx>
> 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