about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-01-26 18:12:08 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-01-26 18:12:08 +0000
commit85e0b5f3770fc0bb84b080740dd578169d4e511c (patch)
treeef55f3c5749a70f8100765f9e19a1bdd43ce639d
parent3934f7a40208adc9334b5f957be4c5b9dee29979 (diff)
downloadzsh-85e0b5f3770fc0bb84b080740dd578169d4e511c.tar.gz
zsh-85e0b5f3770fc0bb84b080740dd578169d4e511c.tar.xz
zsh-85e0b5f3770fc0bb84b080740dd578169d4e511c.zip
20752: fix access to ZLE parameters
-rw-r--r--ChangeLog6
-rw-r--r--Src/Zle/zle.h6
-rw-r--r--Src/Zle/zle_hist.c2
-rw-r--r--Src/Zle/zle_main.c2
-rw-r--r--Src/Zle/zle_params.c52
-rw-r--r--Src/Zle/zle_refresh.c2
-rw-r--r--Src/Zle/zle_utils.c16
-rw-r--r--Src/system.h2
8 files changed, 54 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index a543f0737..c221fa65b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-01-26  Peter Stephenson  <pws@csr.com>
+
+	* 20752: Src/system.h, Src/Zle/zle.h, Src/Zle/zle_hist.c,
+	Src/Zle/zle_main.c, Src/Zle/zle_params.c, Src/Zle/zle_refresh.c,
+	Src/Zle/zle_utils.c: Fix access to zle parameters.
+
 2005-01-26  Clint Adams  <clint@zsh.org>
 
 	* 20747, 20751: Src/Zle/zle_refresh.c, Src/system.h: some
diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h
index 196824094..3b9845f8a 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -194,3 +194,9 @@ struct compldat {
 /* Invalidate the completion list. */
 
 #define invalidatelist() runhookdef(INVALIDATELISTHOOK, NULL)
+
+/* Bit flags to setline */
+enum {
+    ZSL_COPY = 1,		/* Copy the argument, don't modify it */
+    ZSL_TOEND = 2,		/* Go to the end of the new line */
+};
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index 4733d5843..8cd082b72 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -567,7 +567,7 @@ zle_setline(Histent he)
     remember_edits();
     mkundoent();
     histline = he->histnum;
-    setline(ZLETEXT(he));
+    setline(ZLETEXT(he), ZSL_COPY|ZSL_TOEND);
     setlastline();
     clearlist = 1;
 }
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 7780968c9..d25376862 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -829,7 +829,7 @@ zleread(char **lp, char **rp, int flags, int context)
     selectlocalmap(NULL);
     fixsuffix();
     if ((s = (unsigned char *)getlinknode(bufstack))) {
-	setline((char *)s);
+	setline((char *)s, ZSL_TOEND);
 	zsfree((char *)s);
 	if (stackcs != -1) {
 	    zlecs = stackcs;
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index 0698d2c96..7ea408714 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -175,12 +175,8 @@ static void
 set_buffer(UNUSED(Param pm), char *x)
 {
     if(x) {
-	unmetafy(x, &zlell);
-	sizeline(zlell);
-	strcpy((char *)zleline, x);
+	setline(x, 0);
 	zsfree(x);
-	if(zlecs > zlell)
-	    zlecs = zlell;
     } else
 	zlecs = zlell = 0;
     fixsuffix();
@@ -191,7 +187,7 @@ set_buffer(UNUSED(Param pm), char *x)
 static char *
 get_buffer(UNUSED(Param pm))
 {
-    return metafy((char *)zleline, zlell, META_HEAPDUP);
+    return (char *)zlelineasstring((char *)zleline, zlell, 0, NULL, NULL, 1);
 }
 
 /**/
@@ -238,19 +234,22 @@ get_mark(UNUSED(Param pm))
 static void
 set_lbuffer(UNUSED(Param pm), char *x)
 {
-    char *y;
+    ZLE_STRING_T y;
     int len;
 
-    if(x)
-	unmetafy(y = x, &len);
+    if (x && *x != ZLENUL)
+	y = stringaszleline((unsigned char *)x, &len, NULL);
     else
-	y = "", len = 0;
+	y = ZLENULSTR, len = 0;
     sizeline(zlell - zlecs + len);
-    memmove(zleline + len, zleline + zlecs, zlell - zlecs);
-    memcpy(zleline, y, len);
+    memmove((char *)(zleline + len), (char *)(zleline + zlecs),
+	    (zlell - zlecs) * ZLE_CHAR_SIZE);
+    ZS_memcpy(zleline, y, len);
     zlell = zlell - zlecs + len;
     zlecs = len;
     zsfree(x);
+    if (len)
+	free(y);
     fixsuffix();
     menucmp = 0;
 }
@@ -259,7 +258,7 @@ set_lbuffer(UNUSED(Param pm), char *x)
 static char *
 get_lbuffer(UNUSED(Param pm))
 {
-    return metafy((char *)zleline, zlecs, META_HEAPDUP);
+    return (char *)zlelineasstring(zleline, zlecs, 0, NULL, NULL, 1);
 }
 
 /**/
@@ -269,13 +268,15 @@ set_rbuffer(UNUSED(Param pm), char *x)
     char *y;
     int len;
 
-    if(x)
-	unmetafy(y = x, &len);
+    if (x && *x != ZLENUL)
+	y = stringaszleline((unsigned char *)x, &len, NULL);
     else
-	y = "", len = 0;
+	y = ZLENULSTR, len = 0;
     sizeline(zlell = zlecs + len);
-    memcpy(zleline + zlecs, y, len);
+    ZS_memcpy(zleline + zlecs, y, len);
     zsfree(x);
+    if (len)
+	free(y);
     fixsuffix();
     menucmp = 0;
 }
@@ -284,7 +285,8 @@ set_rbuffer(UNUSED(Param pm), char *x)
 static char *
 get_rbuffer(UNUSED(Param pm))
 {
-    return metafy((char *)zleline + zlecs, zlell - zlecs, META_HEAPDUP);
+    return (char *)zlelineasstring(zleline + zlecs, zlell - zlecs,
+				   0, NULL, NULL, 1);
 }
 
 /**/
@@ -547,27 +549,23 @@ unset_killring(Param pm, int exp)
 }
 
 static void
-set_prepost(unsigned char **textvar, int *lenvar, char *x)
+set_prepost(ZLE_STRING_T *textvar, int *lenvar, char *x)
 {
     if (*lenvar) {
-	zfree(*textvar, *lenvar);
+	free(*textvar);
 	*textvar = NULL;
 	*lenvar = 0;
     }
     if (x) {
-	unmetafy(x, lenvar);
-	if (*lenvar) {
-	    *textvar = (unsigned char *)zalloc(*lenvar);
-	    memcpy((char *)*textvar, x, *lenvar);
-	}
+	*textvar = stringaszleline((unsigned char *)x, lenvar, NULL);
 	free(x);
     }
 }
 
 static char *
-get_prepost(unsigned char *text, int len)
+get_prepost(ZLE_STRING_T text, int len)
 {
-    return metafy((char *)text, len, META_HEAPDUP);
+    return (char *)zlelineasstring(text, len, 0, NULL, NULL, 1);
 }
 
 /**/
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index f67c5aeb3..6c63774da 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -287,7 +287,7 @@ zrefresh(void)
 	*sen,			/* pointer to end of the video buffer (eol)  */
 	*u;			/* pointer for status line stuff */
     ZLE_STRING_T t,		/* pointer into the real buffer		     */
-	*scs;			/* pointer to cursor position in real buffer */
+	scs;			/* pointer to cursor position in real buffer */
     char **qbuf;		/* tmp					     */
     ZLE_STRING_T tmpline;	/* line with added pre/post text */
     int tmpcs, tmpll;		/* ditto cursor position and line length */
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 0e8099bd2..ffd94def8 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -410,9 +410,14 @@ foredel(int ct)
 
 /**/
 void
-setline(char const *s)
+setline(char *s, int flags)
 {
-    char *scp = ztrdup(s);
+    char *scp;
+
+    if (flags & ZSL_COPY)
+	scp = ztrdup(s);
+    else
+	scp = s;
     /*
      * TBD: we could make this more efficient by passing the existing
      * allocated line to stringaszleline.
@@ -421,10 +426,13 @@ setline(char const *s)
 
     zleline = stringaszleline(scp, &zlell, &linesz);
 
-    if ((zlecs = zlell) && invicmdmode())
+    if ((flags & ZSL_TOEND) && (zlecs = zlell) && invicmdmode())
 	zlecs--;
+    else if (zlecs > zlell)
+	zlecs = zlell;
 
-    free(scp);
+    if (flags & ZSL_COPY)
+	free(scp);
 }
 
 /**/
diff --git a/Src/system.h b/Src/system.h
index 28828d49d..1dccabda8 100644
--- a/Src/system.h
+++ b/Src/system.h
@@ -725,6 +725,7 @@ typedef wchar_t *ZLE_STRING_T;
 #define ZLENL	L'\n'
 #define ZLENUL	L'\0'
 #define ZLETAB	L'\t'
+#define ZLENULSTR	L""
 #define ZS_memcpy wmemcpy
 #define ZC_icntrl iswcntrl
 #else
@@ -735,6 +736,7 @@ typedef unsigned char *ZLE_STRING_T;
 #define ZLENL	'\n'
 #define ZLENUL	'\0'
 #define ZLETAB	'\t'
+#define ZLENULSTR	""
 #define ZS_memcpy memcpy
 #define ZC_icntrl icntrl
 #endif