Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: zle_params.c



This fixes up access to ZLE parameters.  It seems not to be completely
broken.  It also fixes a typo in zle_params.c.

I've left last_isearch since it's not clear what is to become of it
yet.  Fixing doisearch isn't going to be great fun (240 lines, 2
comments).  It'll have to wait until we decide about input.

Index: Src/system.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/system.h,v
retrieving revision 1.24
diff -u -r1.24 system.h
--- Src/system.h	26 Jan 2005 13:39:51 -0000	1.24
+++ Src/system.h	26 Jan 2005 18:04:32 -0000
@@ -725,6 +725,7 @@
 #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 @@
 #define ZLENL	'\n'
 #define ZLENUL	'\0'
 #define ZLETAB	'\t'
+#define ZLENULSTR	""
 #define ZS_memcpy memcpy
 #define ZC_icntrl icntrl
 #endif
Index: Src/Zle/zle.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle.h,v
retrieving revision 1.5
diff -u -r1.5 zle.h
--- Src/Zle/zle.h	25 Jan 2005 16:41:24 -0000	1.5
+++ Src/Zle/zle.h	26 Jan 2005 18:04:32 -0000
@@ -194,3 +194,9 @@
 /* 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 */
+};
Index: Src/Zle/zle_hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_hist.c,v
retrieving revision 1.16
diff -u -r1.16 zle_hist.c
--- Src/Zle/zle_hist.c	14 Jan 2005 13:05:23 -0000	1.16
+++ Src/Zle/zle_hist.c	26 Jan 2005 18:04:32 -0000
@@ -567,7 +567,7 @@
     remember_edits();
     mkundoent();
     histline = he->histnum;
-    setline(ZLETEXT(he));
+    setline(ZLETEXT(he), ZSL_COPY|ZSL_TOEND);
     setlastline();
     clearlist = 1;
 }
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.57
diff -u -r1.57 zle_main.c
--- Src/Zle/zle_main.c	25 Jan 2005 16:41:24 -0000	1.57
+++ Src/Zle/zle_main.c	26 Jan 2005 18:04:32 -0000
@@ -829,7 +829,7 @@
     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;
Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.21
diff -u -r1.21 zle_params.c
--- Src/Zle/zle_params.c	25 Jan 2005 16:41:24 -0000	1.21
+++ Src/Zle/zle_params.c	26 Jan 2005 18:04:32 -0000
@@ -175,12 +175,8 @@
 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 @@
 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 @@
 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 @@
 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 @@
     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 @@
 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 @@
 }
 
 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);
 }
 
 /**/
Index: Src/Zle/zle_refresh.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v
retrieving revision 1.16
diff -u -r1.16 zle_refresh.c
--- Src/Zle/zle_refresh.c	26 Jan 2005 14:29:17 -0000	1.16
+++ Src/Zle/zle_refresh.c	26 Jan 2005 18:04:32 -0000
@@ -287,7 +287,7 @@
 	*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 */
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.16
diff -u -r1.16 zle_utils.c
--- Src/Zle/zle_utils.c	26 Jan 2005 12:34:48 -0000	1.16
+++ Src/Zle/zle_utils.c	26 Jan 2005 18:04:33 -0000
@@ -410,9 +410,14 @@
 
 /**/
 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 @@
 
     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);
 }
 
 /**/

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author