From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11938 invoked from network); 26 Jan 2005 18:06:59 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Jan 2005 18:06:59 -0000 Received: (qmail 707 invoked from network); 26 Jan 2005 18:06:53 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Jan 2005 18:06:53 -0000 Received: (qmail 13283 invoked by alias); 26 Jan 2005 18:06:49 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20752 Received: (qmail 13262 invoked from network); 26 Jan 2005 18:06:49 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 26 Jan 2005 18:06:49 -0000 Received: (qmail 99836 invoked from network); 26 Jan 2005 18:06:33 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 26 Jan 2005 18:06:28 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Wed, 26 Jan 2005 18:05:05 +0000 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 26 Jan 2005 18:06:12 +0000 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j0QI6RmL021857 for ; Wed, 26 Jan 2005 18:06:27 GMT Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j0QI6Q2d021854 for ; Wed, 26 Jan 2005 18:06:27 GMT Message-Id: <200501261806.j0QI6Q2d021854@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: zle_params.c Date: Wed, 26 Jan 2005 18:06:26 +0000 From: Peter Stephenson X-OriginalArrivalTime: 26 Jan 2005 18:06:12.0825 (UTC) FILETIME=[B87E2490:01C503D1] X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.4 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.4 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 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 **********************************************************************