summaryrefslogtreecommitdiff
path: root/Src/Zle/zle_utils.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-04-20 21:17:29 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-04-20 21:17:29 +0000
commitb8ec06c870ac09d5949907640dca4c1a2b711ed5 (patch)
treef5676d7f945f34fe69e30e67fa7fbc8a82730b94 /Src/Zle/zle_utils.c
parenta12b1f35aaeff5724c1d7b4824de62cb4e480698 (diff)
downloadzsh-b8ec06c870ac09d5949907640dca4c1a2b711ed5.tar.gz
zsh-b8ec06c870ac09d5949907640dca4c1a2b711ed5.zip
24853: use metafied strings for inner loops over history
Diffstat (limited to 'Src/Zle/zle_utils.c')
-rw-r--r--Src/Zle/zle_utils.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 7d29bd649..06c6ebd09 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -106,6 +106,54 @@ zleaddtoline(int chr)
}
/*
+ * Convert a line editor character to a possibly multibyte character
+ * in a metafied string. To be safe buf should have space for at least
+ * 2 * MB_CUR_MAX chars for multibyte mode and 2 otherwise. Returns the
+ * length of the string added.
+ */
+
+/**/
+int
+zlecharasstring(ZLE_CHAR_T inchar, char *buf)
+{
+#ifdef MULTIBYTE_SUPPORT
+ size_t ret;
+ char *ptr;
+
+ ret = wctomb(buf, inchar);
+ if (ret <= 0) {
+ /* Ick. */
+ buf[0] = '?';
+ return 1;
+ }
+ ptr = buf + ret - 1;
+ for (;;) {
+ if (imeta(*ptr)) {
+ char *ptr2 = buf + ret - 1;
+ for (;;) {
+ ptr2[1] = ptr2[0];
+ if (ptr2 == ptr)
+ break;
+ ptr2--;
+ }
+ *ptr = Meta;
+ ret++;
+ }
+
+ if (ptr == buf)
+ return ret;
+ ptr--;
+ }
+#else
+ if (imeta(inchar)) {
+ buf[0] = Meta;
+ buf[1] = inchar ^ 32;
+ } else
+ buf[0] = inchar;
+#endif
+}
+
+/*
* Input a line in internal zle format, possibly using wide characters,
* possibly not, together with its length and the cursor position.
* The length must be accurate and includes all characters (no NULL
@@ -621,7 +669,7 @@ void
setline(char *s, int flags)
{
char *scp;
-
+
if (flags & ZSL_COPY)
scp = ztrdup(s);
else
@@ -639,7 +687,6 @@ setline(char *s, int flags)
else if (zlecs > zlell)
zlecs = zlell;
CCRIGHT();
-
if (flags & ZSL_COPY)
free(scp);
}