mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-24 17:00:32 +02:00
20752: fix access to ZLE parameters
This commit is contained in:
parent
3934f7a402
commit
85e0b5f377
8 changed files with 54 additions and 34 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**/
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue