summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-02-24 15:32:36 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-02-24 15:32:36 +0000
commit691dd7e5294d232a7ab8327e2038f9779732fa3c (patch)
tree9d73edabb8e0c4c26a7cf60ceceb3cc23e74d8dd
parentc4a4c1340abeaedda251b90e99e4c9ae77880848 (diff)
downloadzsh-691dd7e5294d232a7ab8327e2038f9779732fa3c.tar.gz
zsh-691dd7e5294d232a7ab8327e2038f9779732fa3c.zip
20861: Fix statusline in Unicode, apart from isearch
-rw-r--r--ChangeLog7
-rw-r--r--Src/Zle/complist.c49
-rw-r--r--Src/Zle/zle.h4
-rw-r--r--Src/Zle/zle_hist.c6
-rw-r--r--Src/Zle/zle_main.c6
-rw-r--r--Src/Zle/zle_misc.c61
-rw-r--r--Src/Zle/zle_refresh.c17
-rw-r--r--Src/Zle/zle_thingy.c9
-rw-r--r--Src/Zle/zle_vi.c4
9 files changed, 106 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index 02d4d3448..b754c96ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-02-24 Peter Stephenson <pws@csr.com>
+
+ * 20861: Src/Zle/complist.c, Src/Zle/zle.h, Src/Zle/zle_hist.c,
+ Src/Zle/zle_main.c, Src/Zle/zle_misc.c, Src/Zle/zle_refresh.c,
+ Src/Zle/zle_thingy.c, Src/Zle/zle_vi.c: Fix use of statusline
+ with Unicode, apart from isearch.
+
2005-02-23 Andrey Borzenkov <bor@zsh.org>
* 20857 (modified): Src/Zle/zle.h, Src/Zle/zle_refresh.c: use
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index a4e9dcbd9..51b160919 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -2115,8 +2115,8 @@ domenuselect(Hookdef dummy, Chdata dat)
}
first = 0;
if (mode == MM_INTER) {
- statusline = status;
- statusll = strlen(status);
+ statusline = stringaszleline((unsigned char *)status,
+ &statusll, NULL);
} else if (mode) {
int l = sprintf(status, "%s%sisearch%s: ",
((msearchstate & MS_FAILED) ? "failed " : ""),
@@ -2125,15 +2125,18 @@ domenuselect(Hookdef dummy, Chdata dat)
strncat(status, msearchstr, MAX_STATUS - l - 1);
- statusline = status;
- statusll = strlen(status);
+ statusline = stringaszleline((unsigned char *)status,
+ &statusll, NULL);
} else {
statusline = NULL;
statusll = 0;
}
zrefresh();
- statusline = NULL;
- statusll = 0;
+ if (statusline) {
+ free(statusline);
+ statusline = NULL;
+ statusll = 0;
+ }
inselect = 1;
if (noselect) {
broken = 1;
@@ -2291,9 +2294,13 @@ domenuselect(Hookdef dummy, Chdata dat)
if (nmatches < 1 || !minfo.cur || !*(minfo.cur)) {
nolist = 1;
if (mode == MM_INTER) {
- statusline = status;
- statusll = strlen(status);
- }
+ statusline = stringaszleline((unsigned char *)status,
+ &statusll, NULL);
+ } else {
+ /* paranoia */
+ statusline = NULL;
+ statusll = 0;
+ }
if (nmessages) {
showinglist = -2;
zrefresh();
@@ -2310,8 +2317,11 @@ domenuselect(Hookdef dummy, Chdata dat)
zrefresh();
showinglist = clearlist = 0;
}
- statusline = NULL;
- statusll = 0;
+ if (statusline) {
+ free(statusline);
+ statusline = NULL;
+ statusll = 0;
+ }
goto getk;
}
@@ -2425,12 +2435,19 @@ domenuselect(Hookdef dummy, Chdata dat)
if (nolist) {
if (mode == MM_INTER) {
- statusline = status;
- statusll = strlen(status);
- }
+ statusline = stringaszleline((unsigned char *)status,
+ &statusll, NULL);
+ } else {
+ /* paranoia */
+ statusline = NULL;
+ statusll = 0;
+ }
zrefresh();
- statusline = NULL;
- statusll = 0;
+ if (statusline) {
+ free(statusline);
+ statusline = NULL;
+ statusll = 0;
+ }
goto getk;
}
if (mode)
diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h
index 23d5e3cd5..091d9e8e3 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -46,6 +46,7 @@ typedef wint_t ZLE_INT_T;
/* Convert character or string to wide character or string */
#define ZWC(c) L ## c
+#define ZWS(s) L ## s
#define ZLEEOF WEOF
@@ -68,8 +69,9 @@ typedef unsigned char *ZLE_STRING_T;
typedef int ZLE_INT_T;
#define ZLE_CHAR_SIZE sizeof(unsigned char)
-/* Leave character or string as is */
+/* Leave character or string as is, but string must be unsigned char * */
#define ZWC(c) c
+#define ZWS(s) (unsigned char *)s
#define ZLEEOF EOF
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index 18800fd26..0f8e354fa 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -766,6 +766,10 @@ get_isrch_spot(int num, int *hlp, int *posp, int *csp, int *lenp, int *dirp, int
#define NORM_PROMPT_POS 8
#define FIRST_SEARCH_CHAR (NORM_PROMPT_POS + 14)
+/*
+ * TODO: use of isearch buffer and strings need fixing for Unicode.
+ */
+
/**/
static void
doisearch(char **args, int dir)
@@ -866,7 +870,7 @@ doisearch(char **args, int dir)
statusline = ibuf + NORM_PROMPT_POS;
}
sbuf[sbptr] = '_';
- statusll = sbuf - statusline + sbptr + 1;
+ statusll = sbuf - (char *)/*TODO*/statusline + sbptr + 1;
ref:
zrefresh();
if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) {
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 091012d17..1333e5f75 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -137,7 +137,7 @@ mod_export Widget compwidget;
/* the status line, and its length */
/**/
-mod_export char *statusline;
+mod_export ZLE_STRING_T statusline;
/**/
mod_export int statusll;
@@ -1374,8 +1374,8 @@ describekeybriefly(UNUSED(char **args))
if (statusline)
return 1;
clearlist = 1;
- statusline = "Describe key briefly: _";
- statusll = strlen(statusline);
+ statusline = ZWS("Describe key briefly: _");
+ statusll = ZS_strlen(statusline);
zrefresh();
seq = getkeymapcmd(curkeymap, &func, &str);
statusline = NULL;
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index a017c6709..e9082255f 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -738,7 +738,11 @@ makequote(ZLE_STRING_T str, size_t *len)
return ol;
}
-static char *cmdbuf;
+/*
+ * cmdstr is the buffer used for execute-named-command converted
+ * to a metafied multibyte string.
+ */
+static char *cmdstr;
static LinkList cmdll;
static int cmdambig;
@@ -749,7 +753,7 @@ scancompcmd(HashNode hn, UNUSED(int flags))
int l;
Thingy t = (Thingy) hn;
- if(strpfx(cmdbuf, t->nam)) {
+ if(strpfx(cmdstr, t->nam)) {
addlinknode(cmdll, t->nam);
l = pfxlen(peekfirst(cmdll), t->nam);
if (l < cmdambig)
@@ -765,20 +769,22 @@ Thingy
executenamedcommand(char *prmt)
{
Thingy cmd;
- int len, l = strlen(prmt), feep = 0, listed = 0, curlist = 0;
+ int l, len, feep = 0, listed = 0, curlist = 0;
int ols = (listshown && validlist), olll = lastlistlen;
- char *ptr;
+ ZLE_STRING_T cmdbuf, ptr, zprmt;
char *okeymap = ztrdup(curkeymapname);
clearlist = 1;
- cmdbuf = zhalloc(l + NAMLEN + 2);
- strcpy(cmdbuf, prmt);
+ zprmt = stringaszleline((unsigned char *)prmt, &l, NULL);
+ cmdbuf = zhalloc((l + NAMLEN + 2) * ZLE_CHAR_SIZE);
+ ZS_memcpy(cmdbuf, zprmt, l);
+ free(zprmt);
statusline = cmdbuf;
selectkeymap("main", 1);
ptr = cmdbuf += l;
len = 0;
for (;;) {
- *ptr = '_';
+ *ptr = ZWC('_');
statusll = l + len + 1;
zrefresh();
if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) {
@@ -814,35 +820,31 @@ executenamedcommand(char *prmt)
zmult = zmultsav;
}
} else if(cmd == Th(z_viquotedinsert)) {
- *ptr = '^';
+ *ptr = ZWC('^');
zrefresh();
getfullchar(0);
if(LASTFULLCHAR == ZLEEOF || !LASTFULLCHAR || len == NAMLEN)
feep = 1;
else {
- /* TODO: convert back to multibyte string */
- *ptr++ = lastchar, len++, curlist = 0;
+ *ptr++ = LASTFULLCHAR, len++, curlist = 0;
}
} else if(cmd == Th(z_quotedinsert)) {
if(getfullchar(0) == ZLEEOF ||
!LASTFULLCHAR || len == NAMLEN)
feep = 1;
else {
- /* TODO: convert back to multibyte string */
- *ptr++ = lastchar, len++, curlist = 0;
+ *ptr++ = LASTFULLCHAR, len++, curlist = 0;
}
} else if(cmd == Th(z_backwarddeletechar) ||
cmd == Th(z_vibackwarddeletechar)) {
if (len) {
- /* TODO: backward full character in multibyte string. Yuk. */
len--, ptr--, curlist = 0;
}
} else if(cmd == Th(z_killregion) || cmd == Th(z_backwardkillword) ||
cmd == Th(z_vibackwardkillword)) {
if (len)
curlist = 0;
- /* TODO: backward full character in multibyte string. Yuk. */
- while (len && (len--, *--ptr != '-'));
+ while (len && (len--, *--ptr != ZWC('-')));
} else if(cmd == Th(z_killwholeline) || cmd == Th(z_vikillline) ||
cmd == Th(z_backwardkillline)) {
len = 0;
@@ -855,7 +857,10 @@ executenamedcommand(char *prmt)
Thingy r;
unambiguous:
*ptr = 0;
- r = rthingy(cmdbuf);
+ cmdstr = zlelineasstring(cmdbuf, len, 0, NULL, NULL, 0);
+ r = rthingy(cmdstr);
+ free(cmdstr);
+ cmdstr = NULL;
if (!(r->flags & DISABLED)) {
unrefthingy(r);
statusline = NULL;
@@ -881,9 +886,11 @@ executenamedcommand(char *prmt)
cmdambig = 100;
cmdll = newlinklist();
- *ptr = 0;
+ cmdstr = zlelineasstring(cmdbuf, len, 0, NULL, NULL, 0);
scanhashtable(thingytab, 1, 0, DISABLED, scancompcmd, 0);
+ free(cmdstr);
+ cmdstr = NULL;
if (empty(cmdll)) {
feep = 1;
@@ -893,7 +900,7 @@ executenamedcommand(char *prmt)
} else if (cmd == Th(z_listchoices) ||
cmd == Th(z_deletecharorlist)) {
int zmultsav = zmult;
- *ptr = '_';
+ *ptr = ZWC('_');
statusll = l + len + 1;
zmult = 1;
listlist(cmdll);
@@ -901,14 +908,21 @@ executenamedcommand(char *prmt)
showinglist = 0;
zmult = zmultsav;
} else if (!nextnode(firstnode(cmdll))) {
- strcpy(ptr = cmdbuf, peekfirst(cmdll));
- ptr += (len = strlen(ptr));
+ ZLE_STRING_T ztmp = stringaszleline(peekfirst(cmdll),
+ &len, NULL);
+ ZS_memcpy(ptr = cmdbuf, ztmp, len);
+ ptr += len;
+ free(ztmp);
if(cmd == Th(z_acceptline) || cmd == Th(z_vicmdmode))
goto unambiguous;
} else {
- strcpy(cmdbuf, peekfirst(cmdll));
+ int ltmp;
+ ZLE_STRING_T ztmp = stringaszleline(peekfirst(cmdll),
+ &ltmp, NULL);
+ ZS_mempcy(cmdbuf, ztmp, ltmp);
+ free(ztmp);
ptr = cmdbuf + cmdambig;
- *ptr = '_';
+ *ptr = ZWC('_');
if (isset(AUTOLIST) &&
!(isset(LISTAMBIGUOUS) && cmdambig > len)) {
int zmultsav = zmult;
@@ -938,8 +952,7 @@ executenamedcommand(char *prmt)
feep = 1;
}
else {
- /* TODO: convert back to multibyte string */
- *ptr++ = lastchar, len++, curlist = 0;
+ *ptr++ = LASTFULLCHAR, len++, curlist = 0;
}
}
}
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 4dca5628a..aa94930fe 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -320,9 +320,8 @@ zrefresh(void)
ZLE_STRING_T s, /* pointer into the video buffer */
sen, /* pointer to end of the video buffer (eol) */
t, /* pointer into the real buffer */
- scs; /* pointer to cursor position in real buffer */
- unsigned char *u; /* pointer for status line stuff
- TODO convert to wide characters */
+ scs, /* pointer to cursor position in real buffer */
+ u; /* pointer for status line stuff */
ZLE_STRING_T tmpline, /* line with added pre/post text */
*qbuf; /* tmp */
int tmpcs, tmpll; /* ditto cursor position and line length */
@@ -509,7 +508,11 @@ zrefresh(void)
nbuf[ln][winw + 1] = ZWC('\n'); /* text wrapped */
nextline
}
+#ifdef ZLE_UNICODE_SUPPORT
*s++ = ((*t == 127) || (*t > 255)) ? ZWC('?') : (*t | ZWC('@'));
+#else
+ *s++ = (*t == 127) ? ZWC('?') : (*t | ZWC('@'));
+#endif
} else { /* normal character */
*s++ = *t;
}
@@ -538,9 +541,9 @@ zrefresh(void)
tosln = ln + 1;
nbuf[ln][winw + 1] = ZWC('\0'); /* text not wrapped */
snextline
- u = (unsigned char *)statusline;
- for (; u < (unsigned char *)statusline + statusll; u++) {
- if (icntrl(*u)) { /* simplified processing in the status line */
+ u = statusline;
+ for (; u < statusline + statusll; u++) {
+ if (ZC_icntrl(*u)) { /* simplified processing in the status line */
*s++ = ZWC('^');
if (s == sen) {
nbuf[ln][winw + 1] = ZWC('\n'); /* text wrapped */
@@ -771,7 +774,7 @@ refreshline(int ln)
/* 0: setup */
nl = nbuf[ln];
rnllen = nllen = nl ? ZS_strlen(nl) : 0;
- ol = obuf[ln] ? obuf[ln] : ZWC("");
+ ol = obuf[ln] ? obuf[ln] : ZWS("");
ollen = ZS_strlen(ol);
/* optimisation: can easily happen for clearing old lines. If the terminal has
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index 494e1ade5..5885fb10f 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -407,7 +407,7 @@ bin_zle_list(UNUSED(char *name), char **args, Options ops, UNUSED(char func))
static int
bin_zle_refresh(UNUSED(char *name), char **args, Options ops, UNUSED(char func))
{
- char *s = statusline;
+ ZLE_STRING_T s = statusline;
int sl = statusll, ocl = clearlist;
if (!zleactive)
@@ -416,8 +416,8 @@ bin_zle_refresh(UNUSED(char *name), char **args, Options ops, UNUSED(char func))
statusll = 0;
if (*args) {
if (**args) {
- statusline = *args;
- statusll = strlen(statusline);
+ statusline = stringaszleline((unsigned char *)*args, &statusll,
+ NULL);
}
if (*++args) {
LinkList l = newlinklist();
@@ -442,6 +442,9 @@ bin_zle_refresh(UNUSED(char *name), char **args, Options ops, UNUSED(char func))
}
zrefresh();
+ if (statusline)
+ free(statusline);
+
clearlist = ocl;
statusline = s;
statusll = sl;
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index e4a36b219..f44452550 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -831,8 +831,8 @@ vicapslockpanic(UNUSED(char **args))
{
clearlist = 1;
zbeep();
- statusline = "press a lowercase key to continue";
- statusll = strlen(statusline);
+ statusline = ZWS("press a lowercase key to continue");
+ statusll = ZS_strlen(statusline);
zrefresh();
#ifdef ZLE_UNICODE_SUPPORT
while (!iswlower(getfullchar(0)));