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: Fri, 21 Jan 2005 22:35:57 -0500 [thread overview]
Message-ID: <20050122033557.GA24905@scowler.net> (raw)
In-Reply-To: <200501191049.j0JAn8US032409@news01.csr.com>
Addressing these two points:
> Your way's probably neater; we probably don't need to lose too much
> sleep about the efficiency of the old interface as long as it's not too
> gross. So the patch will need matching free()s in all callers. I think
> there's just one at the moment.
> As discussed previously, this should just be zlell; we are not using
> terminating wide nulls. This fits in with current usage where we don't
> use terminating ordinary nulls since an ASCII NUL is a valid character
> in unsigned char *zleline.
M Src/Zle/zle_utils.c
M Src/hist.c
* modified files
--- orig/Src/Zle/zle_utils.c
+++ mod/Src/Zle/zle_utils.c
@@ -89,10 +89,35 @@
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
}
--- orig/Src/hist.c
+++ mod/Src/hist.c
@@ -2260,7 +2260,7 @@
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 @@
p[zlell] = '\0';
inpush(p, 0, NULL);
}
+ zsfree(linein);
}
if (zlecs)
zlecs--;
next prev parent reply other threads:[~2005-01-22 5:28 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
2005-01-19 10:49 ` Peter Stephenson
2005-01-22 3:35 ` Clint Adams [this message]
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=20050122033557.GA24905@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).