zsh-workers
 help / color / mirror / code / Atom feed
From: Clint Adams <clint@zsh.org>
To: Peter Stephenson <pws@csr.com>
Cc: zsh-workers@sunsite.dk
Subject: Re: PATCH: minor zle_utils fix
Date: Tue, 18 Jan 2005 20:26:30 -0500	[thread overview]
Message-ID: <20050119012630.GA2463@scowler.net> (raw)
In-Reply-To: <200501171040.j0HAe6mY003515@news01.csr.com>

> 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
 }
 
 


  reply	other threads:[~2005-01-19  1:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-16 16:22 Clint Adams
2005-01-17 10:40 ` Peter Stephenson
2005-01-19  1:26   ` Clint Adams [this message]
2005-01-19 10:49     ` Peter Stephenson
2005-01-22  3:35       ` Clint Adams
2005-01-22 16:22       ` Clint Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050119012630.GA2463@scowler.net \
    --to=clint@zsh.org \
    --cc=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).