1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-04 22:51:42 +02:00

21943, 21945: ZLE_UNICODE_SUPPORT -> MULTIBYTE_SUPPORT;

use multibyte versions of nicechar wherever possible.
This commit is contained in:
Peter Stephenson 2005-10-28 17:34:33 +00:00
parent 5f11a38bea
commit aea7715261
20 changed files with 131 additions and 117 deletions

View file

@ -1,6 +1,16 @@
2005-10-28 Peter Stephenson <pws@csr.com> 2005-10-28 Peter Stephenson <pws@csr.com>
* 21942: Src/Zle/zle_fresh.c: another bug found when deleting * 21943, 21945: configure.ac, Src/prompt.c, Src/string.c,
Src/system.h, Src/utils.c, Src/zsh.h, Src/Zle/complist.c,
Src/Zle/compmatch.c, Src/Zle/compresult.c, Src/Zle/zle.h,
Src/Zle/zle_hist.c, Src/Zle/zle_keymap.c, Src/Zle/zle_main.c,
Src/Zle/zle_misc.c, Src/Zle/zle_refresh.c, Src/Zle/zle_thingy.c,
Src/Zle/zle_tricky.c, Src/Zle/zle_utils.c, Src/Zle/zle_vi.c:
Replace ZLE_UNICODE_SUPPORT by MULTIBYTE_SUPPORT throughout.
Use multibyte versions of "nicechar" functions wherever
possible.
* 21942: Src/Zle/zle_refresh.c: another bug found when deleting
an extra-wide character. an extra-wide character.
2005-10-26 Peter Stephenson <pws@csr.com> 2005-10-26 Peter Stephenson <pws@csr.com>

View file

@ -559,7 +559,7 @@ clnicezputs(Listcols colors, char *s, int ml)
int i = 0, col = 0, ask, oml = ml; int i = 0, col = 0, ask, oml = ml;
char *t; char *t;
ZLE_CHAR_T cc; ZLE_CHAR_T cc;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* ums is the untokenized, unmetafied string (length umlen) * ums is the untokenized, unmetafied string (length umlen)
* uptr is a pointer into it * uptr is a pointer into it
@ -1940,7 +1940,7 @@ msearchpop(int *backp)
static Cmatch ** static Cmatch **
msearch(Cmatch **ptr, int ins, int back, int rep, int *wrapp) msearch(Cmatch **ptr, int ins, int back, int rep, int *wrapp)
{ {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* MB_CUR_MAX may not be constant */ /* MB_CUR_MAX may not be constant */
VARARR(char, s, MB_CUR_MAX+1); VARARR(char, s, MB_CUR_MAX+1);
#else #else
@ -1953,7 +1953,7 @@ msearch(Cmatch **ptr, int ins, int back, int rep, int *wrapp)
msearchpush(ptr, back); msearchpush(ptr, back);
if (ins) { if (ins) {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (lastchar_wide_valid) if (lastchar_wide_valid)
{ {
int len = wctomb(s, lastchar_wide); int len = wctomb(s, lastchar_wide);

View file

@ -1584,7 +1584,7 @@ sub_match(Cmdata md, char *str, int len, int sfx)
{ {
int ret = 0, l, ind, add; int ret = 0, l, ind, add;
char *p, *q; char *p, *q;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
int fulllen = len; int fulllen = len;
char *fullstr = str; char *fullstr = str;
mbstate_t ps; mbstate_t ps;
@ -1619,7 +1619,7 @@ sub_match(Cmdata md, char *str, int len, int sfx)
|| (l < md->len && q[-1] == Meta))) || (l < md->len && q[-1] == Meta)))
l--; l--;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Make sure we don't end in the middle of a multibyte character. * Make sure we don't end in the middle of a multibyte character.
* Don't need to do this if the match ended at the start * Don't need to do this if the match ended at the start

View file

@ -2146,15 +2146,15 @@ iprintm(Cmgroup g, Cmatch *mp, UNUSED(int mc), UNUSED(int ml), int lastc, int wi
printfmt(m->disp, 0, 1, 0); printfmt(m->disp, 0, 1, 0);
return; return;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
len = mb_niceformat(m->disp, shout, NULL); len = mb_niceformat(m->disp, shout, NULL, 0);
#else #else
nicezputs(m->disp, shout); nicezputs(m->disp, shout);
len = niceztrlen(m->disp); len = niceztrlen(m->disp);
#endif #endif
} else { } else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
len = mb_niceformat(m->str, shout, NULL); len = mb_niceformat(m->str, shout, NULL, 0);
#else #else
nicezputs(m->str, shout); nicezputs(m->str, shout);
len = niceztrlen(m->str); len = niceztrlen(m->str);

View file

@ -27,7 +27,7 @@
* *
*/ */
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
typedef wchar_t ZLE_CHAR_T; typedef wchar_t ZLE_CHAR_T;
typedef wchar_t *ZLE_STRING_T; typedef wchar_t *ZLE_STRING_T;
typedef wint_t ZLE_INT_T; typedef wint_t ZLE_INT_T;
@ -67,9 +67,7 @@ typedef wint_t ZLE_INT_T;
* Functions that operate on a metafied string. * Functions that operate on a metafied string.
* These versions handle multibyte characters. * These versions handle multibyte characters.
*/ */
#define ZMB_nicewidth(s) mb_niceformat(s, NULL, NULL) #define ZMB_nicewidth(s) mb_niceformat(s, NULL, NULL, 0)
#define ZMB_niceputs(s, stream) (void)mb_niceformat(s, stream, NULL)
#define ZMB_niceztrdup(s) mb_niceztrdup(s)
/* Functions that operate on ZLE_CHAR_T. */ /* Functions that operate on ZLE_CHAR_T. */
#define ZC_iblank iswspace #define ZC_iblank iswspace
@ -84,7 +82,7 @@ typedef wint_t ZLE_INT_T;
#define LASTFULLCHAR lastchar_wide #define LASTFULLCHAR lastchar_wide
#else /* Not ZLE_UNICODE_SUPPORT: old single-byte code */ #else /* Not MULTIBYTE_SUPPORT: old single-byte code */
typedef int ZLE_CHAR_T; typedef int ZLE_CHAR_T;
typedef unsigned char *ZLE_STRING_T; typedef unsigned char *ZLE_STRING_T;
@ -111,8 +109,6 @@ typedef int ZLE_INT_T;
* These versions don't handle multibyte characters. * These versions don't handle multibyte characters.
*/ */
#define ZMB_nicewidth niceztrlen #define ZMB_nicewidth niceztrlen
#define ZMB_niceputs nicezputs
#define ZMB_niceztrdup(s) nicedup(s, 0)
#define ZC_nicechar nicechar #define ZC_nicechar nicechar

View file

@ -1108,7 +1108,7 @@ doisearch(char **args, int dir)
} else if (cmd == Th(z_magicspace)) { } else if (cmd == Th(z_magicspace)) {
fixmagicspace(); fixmagicspace();
} else if (cmd == Th(z_selfinsert)) { } else if (cmd == Th(z_selfinsert)) {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid) if (!lastchar_wide_valid)
getrestchar(lastchar); getrestchar(lastchar);
#else #else
@ -1305,7 +1305,7 @@ getvisrchstr(void)
if(cmd == Th(z_selfinsertunmeta)) { if(cmd == Th(z_selfinsertunmeta)) {
fixunmeta(); fixunmeta();
} else { } else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid) if (!lastchar_wide_valid)
getrestchar(lastchar); getrestchar(lastchar);
#else #else

View file

@ -725,7 +725,7 @@ scanlistmaps(HashNode hn, int list)
fputs("-- ", stdout); fputs("-- ", stdout);
quotedzputs(n->nam, stdout); quotedzputs(n->nam, stdout);
} else } else
ZMB_niceputs(n->nam, stdout); nicezputs(n->nam, stdout);
putchar('\n'); putchar('\n');
} }
@ -818,7 +818,7 @@ bin_bindkey_meta(char *name, char *kmname, Keymap km, UNUSED(char **argv), UNUSE
zwarnnam(name, "keymap `%s' is protected", kmname, 0); zwarnnam(name, "keymap `%s' is protected", kmname, 0);
return 1; return 1;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
zwarnnam(name, "warning: `bindkey -m' disables multibyte support", zwarnnam(name, "warning: `bindkey -m' disables multibyte support",
NULL, 0); NULL, 0);
#endif #endif
@ -1051,7 +1051,7 @@ bindlistout(struct bindstate *bs)
if (bs->flags & BS_LIST) if (bs->flags & BS_LIST)
quotedzputs(bs->bind->nam, stdout); quotedzputs(bs->bind->nam, stdout);
else else
ZMB_niceputs(bs->bind->nam, stdout); nicezputs(bs->bind->nam, stdout);
} else } else
printbind(bs->str, stdout); printbind(bs->str, stdout);
putchar('\n'); putchar('\n');

View file

@ -100,7 +100,7 @@ int mark;
/**/ /**/
mod_export int mod_export int
lastchar; lastchar;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/**/ /**/
mod_export ZLE_INT_T lastchar_wide; mod_export ZLE_INT_T lastchar_wide;
/**/ /**/
@ -633,7 +633,7 @@ getbyte(int keytmout, int *timeout)
if (timeout) if (timeout)
*timeout = 0; *timeout = 0;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Reading a single byte always invalidates the status * Reading a single byte always invalidates the status
* of lastchar_wide. We may fix this up in getrestchar * of lastchar_wide. We may fix this up in getrestchar
@ -737,7 +737,7 @@ getfullchar(int keytmout)
{ {
int inchar = getbyte(keytmout, NULL); int inchar = getbyte(keytmout, NULL);
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
return getrestchar(inchar); return getrestchar(inchar);
#else #else
return inchar; return inchar;
@ -746,7 +746,7 @@ getfullchar(int keytmout)
/**/ /**/
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Get the remainder of a character if we support multibyte * Get the remainder of a character if we support multibyte
* input strings. It may not require any more input, but * input strings. It may not require any more input, but
@ -1048,7 +1048,7 @@ execzlefunc(Thingy func, char **args)
if(func->flags & DISABLED) { if(func->flags & DISABLED) {
/* this thingy is not the name of a widget */ /* this thingy is not the name of a widget */
char *nm = ZMB_niceztrdup(func->nam); char *nm = nicedup(func->nam, 0);
char *msg = tricat("No such widget `", nm, "'"); char *msg = tricat("No such widget `", nm, "'");
zsfree(nm); zsfree(nm);
@ -1104,7 +1104,7 @@ execzlefunc(Thingy func, char **args)
if(prog == &dummy_eprog) { if(prog == &dummy_eprog) {
/* the shell function doesn't exist */ /* the shell function doesn't exist */
char *nm = ZMB_niceztrdup(w->u.fnnam); char *nm = nicedup(w->u.fnnam, 0);
char *msg = tricat("No such shell function `", nm, "'"); char *msg = tricat("No such shell function `", nm, "'");
zsfree(nm); zsfree(nm);
@ -1422,7 +1422,7 @@ describekeybriefly(UNUSED(char **args))
if (!func) if (!func)
is = bindztrdup(str); is = bindztrdup(str);
else else
is = ZMB_niceztrdup(func->nam); is = nicedup(func->nam, 0);
msg = appstr(msg, is); msg = appstr(msg, is);
zsfree(is); zsfree(is);
showmsg(msg); showmsg(msg);
@ -1466,7 +1466,7 @@ whereis(UNUSED(char **args))
if (!(ff.func = executenamedcommand("Where is: "))) if (!(ff.func = executenamedcommand("Where is: ")))
return 1; return 1;
ff.found = 0; ff.found = 0;
ff.msg = ZMB_niceztrdup(ff.func->nam); ff.msg = nicedup(ff.func->nam, 0);
scankeymap(curkeymap, 1, scanfindfunc, &ff); scankeymap(curkeymap, 1, scanfindfunc, &ff);
if (!ff.found) if (!ff.found)
ff.msg = appstr(ff.msg, " is not bound to any key"); ff.msg = appstr(ff.msg, " is not bound to any key");

View file

@ -60,7 +60,7 @@ doinsert(ZLE_STRING_T zstr, int len)
mod_export int mod_export int
selfinsert(UNUSED(char **args)) selfinsert(UNUSED(char **args))
{ {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* wint_t and wchar_t not neccessarily the same size */ /* wint_t and wchar_t not neccessarily the same size */
wchar_t tmp; wchar_t tmp;
@ -82,7 +82,7 @@ fixunmeta(void)
lastchar &= 0x7f; lastchar &= 0x7f;
if (lastchar == '\r') if (lastchar == '\r')
lastchar = '\n'; lastchar = '\n';
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* TODO: can we do this better? * TODO: can we do this better?
* We need a wide character to insert. * We need a wide character to insert.
@ -529,7 +529,7 @@ digitargument(UNUSED(char **args))
{ {
int sign = (zmult < 0) ? -1 : 1; int sign = (zmult < 0) ? -1 : 1;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* It's too dangerous to allow metafied input. See * It's too dangerous to allow metafied input. See
* universalargument for comments on (possibly suboptimal) handling * universalargument for comments on (possibly suboptimal) handling
@ -953,7 +953,7 @@ executenamedcommand(char *prmt)
if (len == NAMLEN || cmd != Th(z_selfinsert)) if (len == NAMLEN || cmd != Th(z_selfinsert))
feep = 1; feep = 1;
else { else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid) if (!lastchar_wide_valid)
getrestchar(lastchar); getrestchar(lastchar);
if (iswcntrl(lastchar_wide)) if (iswcntrl(lastchar_wide))
@ -1137,7 +1137,7 @@ iremovesuffix(ZLE_CHAR_T c, int keep)
zsfree(suffixfunc); zsfree(suffixfunc);
suffixfunc = NULL; suffixfunc = NULL;
} else { } else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* TODO: best I can think of for now... */ /* TODO: best I can think of for now... */
int sl = (unsigned int)c <= 256 ? suffixlen[c] : 0; int sl = (unsigned int)c <= 256 ? suffixlen[c] : 0;
#else #else

View file

@ -29,7 +29,7 @@
#include "zle.mdh" #include "zle.mdh"
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* We use a wint_t here, since we need an invalid character as a * We use a wint_t here, since we need an invalid character as a
* placeholder and wint_t guarantees that we can use WEOF to do this. * placeholder and wint_t guarantees that we can use WEOF to do this.
@ -178,7 +178,7 @@ int cost;
void void
zwcputc(ZLE_INT_T c) zwcputc(ZLE_INT_T c)
{ {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
char mbtmp[MB_CUR_MAX + 1]; char mbtmp[MB_CUR_MAX + 1];
mbstate_t mbstate; mbstate_t mbstate;
int i; int i;
@ -197,7 +197,7 @@ zwcputc(ZLE_INT_T c)
static int static int
zwcwrite(REFRESH_STRING s, size_t i) zwcwrite(REFRESH_STRING s, size_t i)
{ {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
size_t j; size_t j;
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
@ -625,7 +625,7 @@ zrefresh(void)
*rpms.s++ = ZWC(' '); *rpms.s++ = ZWC(' ');
while ((++t0) & 7); while ((++t0) & 7);
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
else if (iswprint(*t)) { else if (iswprint(*t)) {
int width = wcwidth(*t); int width = wcwidth(*t);
if (width > rpms.sen - rpms.s) { if (width > rpms.sen - rpms.s) {
@ -663,7 +663,7 @@ zrefresh(void)
if (nextline(&rpms, 1)) if (nextline(&rpms, 1))
break; break;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
*rpms.s++ = ((*t == 127) || (*t > 255)) ? ZWC('?') : *rpms.s++ = ((*t == 127) || (*t > 255)) ? ZWC('?') :
(*t | ZWC('@')); (*t | ZWC('@'));
#else #else
@ -698,7 +698,7 @@ zrefresh(void)
snextline(&rpms); snextline(&rpms);
u = statusline; u = statusline;
for (; u < statusline + statusll; u++) { for (; u < statusline + statusll; u++) {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (iswprint(*u)) { if (iswprint(*u)) {
int width = wcwidth(*u); int width = wcwidth(*u);
/* Handle wide characters as above */ /* Handle wide characters as above */
@ -1071,12 +1071,12 @@ refreshline(int ln)
for (;;) { for (;;) {
if (*nl && *ol && nl[1] == ol[1]) { if (*nl && *ol && nl[1] == ol[1]) {
/* skip only if second chars match */ /* skip only if second chars match */
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
int ccs_was = ccs; int ccs_was = ccs;
#endif #endif
/* skip past all matching characters */ /* skip past all matching characters */
for (; *nl && (*nl == *ol); nl++, ol++, ccs++) ; for (; *nl && (*nl == *ol); nl++, ol++, ccs++) ;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* Make sure ol and nl are pointing to real characters */ /* Make sure ol and nl are pointing to real characters */
while ((*nl == WEOF || *ol == WEOF) && ccs > ccs_was) { while ((*nl == WEOF || *ol == WEOF) && ccs > ccs_was) {
nl--; nl--;
@ -1152,7 +1152,7 @@ refreshline(int ln)
tc_delchars(i); tc_delchars(i);
ol += i; ol += i;
char_ins -= i; char_ins -= i;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
while (*ol == WEOF) { while (*ol == WEOF) {
ol++; ol++;
char_ins--; char_ins--;
@ -1191,13 +1191,13 @@ refreshline(int ln)
} }
/* we can't do any fancy tricks, so just dump the single character /* we can't do any fancy tricks, so just dump the single character
and keep on trying */ and keep on trying */
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
do { do {
#endif #endif
zputc(*nl); zputc(*nl);
nl++, ol++; nl++, ol++;
ccs++, vcs++; ccs++, vcs++;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Make sure we always overwrite the complete width of * Make sure we always overwrite the complete width of
* a character that was there before. * a character that was there before.
@ -1336,7 +1336,7 @@ tc_rightcurs(int ct)
think. think.
*/ */
if (vln == 0 && i < lpromptw && !(termflags & TERM_SHORT)) { if (vln == 0 && i < lpromptw && !(termflags & TERM_SHORT)) {
#ifndef ZLE_UNICODE_SUPPORT #ifndef MULTIBYTE_SUPPORT
if ((int)strlen(lpromptbuf) == lpromptw) if ((int)strlen(lpromptbuf) == lpromptw)
fputs(lpromptbuf + i, shout); fputs(lpromptbuf + i, shout);
else else
@ -1432,7 +1432,7 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs)
int t0, /* tmp */ int t0, /* tmp */
vsiz, /* size of new video buffer */ vsiz, /* size of new video buffer */
nvcs = 0; /* new video cursor column */ nvcs = 0; /* new video cursor column */
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* converted lprompt and pointer: no WEOF hack here since * converted lprompt and pointer: no WEOF hack here since
* we always output the full prompt and count its width. * we always output the full prompt and count its width.
@ -1448,7 +1448,7 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs)
for (vsiz = 1 + lpromptw, t0 = 0; t0 != tmpll; t0++, vsiz++) for (vsiz = 1 + lpromptw, t0 = 0; t0 != tmpll; t0++, vsiz++)
if (tmpline[t0] == ZWC('\t')) if (tmpline[t0] == ZWC('\t'))
vsiz = (vsiz | 7) + 1; vsiz = (vsiz | 7) + 1;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
else if (iswprint(tmpline[t0])) else if (iswprint(tmpline[t0]))
vsiz += wcwidth(tmpline[t0]); vsiz += wcwidth(tmpline[t0]);
#endif #endif
@ -1465,7 +1465,7 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs)
} }
/* only use last part of prompt */ /* only use last part of prompt */
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Convert the entire lprompt so that we know how to count * Convert the entire lprompt so that we know how to count
* characters. * characters.
@ -1514,7 +1514,7 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs)
} else if (tmpline[t0] == ZWC('\n')) { } else if (tmpline[t0] == ZWC('\n')) {
*vp++ = ZWC('\\'); *vp++ = ZWC('\\');
*vp++ = ZWC('n'); *vp++ = ZWC('n');
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
} else if (iswprint(tmpline[t0])) { } else if (iswprint(tmpline[t0])) {
int width; int width;
*vp++ = tmpline[t0]; *vp++ = tmpline[t0];

View file

@ -519,15 +519,15 @@ scanlistwidgets(HashNode hn, int list)
quotedzputs(w->u.fnnam, stdout); quotedzputs(w->u.fnnam, stdout);
} }
} else { } else {
ZMB_niceputs(t->nam, stdout); nicezputs(t->nam, stdout);
if (w->flags & WIDGET_NCOMP) { if (w->flags & WIDGET_NCOMP) {
fputs(" -C ", stdout); fputs(" -C ", stdout);
ZMB_niceputs(w->u.comp.wid, stdout); nicezputs(w->u.comp.wid, stdout);
fputc(' ', stdout); fputc(' ', stdout);
ZMB_niceputs(w->u.comp.func, stdout); nicezputs(w->u.comp.func, stdout);
} else if(strcmp(t->nam, w->u.fnnam)) { } else if(strcmp(t->nam, w->u.fnnam)) {
fputs(" (", stdout); fputs(" (", stdout);
ZMB_niceputs(w->u.fnnam, stdout); nicezputs(w->u.fnnam, stdout);
fputc(')', stdout); fputc(')', stdout);
} }
} }

View file

@ -2244,7 +2244,7 @@ listlist(LinkList l)
if (isset(LISTROWSFIRST)) { if (isset(LISTROWSFIRST)) {
for (col = 1, p = data, lenp = lens; *p; for (col = 1, p = data, lenp = lens; *p;
p++, lenp++, col++) { p++, lenp++, col++) {
ZMB_niceputs(*p, shout); nicezputs(*p, shout);
if (col == ncols) { if (col == ncols) {
col = 0; col = 0;
if (p[1]) if (p[1])
@ -2262,7 +2262,7 @@ listlist(LinkList l)
for (f = data, fl = lens, line = 0; line < nlines; for (f = data, fl = lens, line = 0; line < nlines;
f++, fl++, line++) { f++, fl++, line++) {
for (col = 1, p = f, lenp = fl; *p; col++) { for (col = 1, p = f, lenp = fl; *p; col++) {
ZMB_niceputs(*p, shout); nicezputs(*p, shout);
if (col == ncols) if (col == ncols)
break; break;
if ((i = (pack ? widths[col - 1] : longest) - *lenp + 2) > 0) if ((i = (pack ? widths[col - 1] : longest) - *lenp + 2) > 0)
@ -2276,7 +2276,7 @@ listlist(LinkList l)
} }
} else { } else {
for (p = data; *p; p++) { for (p = data; *p; p++) {
ZMB_niceputs(*p, shout); nicezputs(*p, shout);
putc('\n', shout); putc('\n', shout);
} }
} }
@ -2367,7 +2367,7 @@ void
fixmagicspace(void) fixmagicspace(void)
{ {
lastchar = ' '; lastchar = ' ';
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* This is redundant if the multibyte encoding extends ASCII, * This is redundant if the multibyte encoding extends ASCII,
* since lastchar is a full character, but it's safer anyway... * since lastchar is a full character, but it's safer anyway...
@ -2386,7 +2386,7 @@ magicspace(char **args)
int ret; int ret;
fixmagicspace(); fixmagicspace();
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* TODO: bangchar should really be a multibyte string representing * TODO: bangchar should really be a multibyte string representing
* a single character, since there's no fundamental reason why * a single character, since there's no fundamental reason why

View file

@ -132,7 +132,7 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outllp,
{ {
int outcs, outll; int outcs, outll;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
char *s; char *s;
int i, j; int i, j;
size_t mb_len = 0; size_t mb_len = 0;
@ -167,7 +167,7 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outllp,
* metafiable characters. * metafiable characters.
*/ */
if (outcsp != NULL || outllp != NULL) { if (outcsp != NULL || outllp != NULL) {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
unsigned char *strp = (unsigned char *)s; unsigned char *strp = (unsigned char *)s;
#else #else
unsigned char *strp = instr; unsigned char *strp = instr;
@ -189,7 +189,7 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outllp,
*outllp = outll; *outllp = outll;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (useheap) if (useheap)
{ {
unsigned char *ret = unsigned char *ret =
@ -242,7 +242,7 @@ stringaszleline(unsigned char *instr, int incs,
{ {
ZLE_STRING_T outstr; ZLE_STRING_T outstr;
int ll, sz; int ll, sz;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
mbstate_t ps; mbstate_t ps;
#endif #endif
@ -274,7 +274,7 @@ stringaszleline(unsigned char *instr, int incs,
*outsz = ll; *outsz = ll;
outstr = (ZLE_STRING_T)zalloc(sz); outstr = (ZLE_STRING_T)zalloc(sz);
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (ll) { if (ll) {
char *inptr = (char *)instr; char *inptr = (char *)instr;
wchar_t *outptr = outstr; wchar_t *outptr = outstr;
@ -785,7 +785,7 @@ showmsg(char const *msg)
char const *p; char const *p;
int up = 0, cc = 0; int up = 0, cc = 0;
ZLE_CHAR_T c; ZLE_CHAR_T c;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
char *umsg; char *umsg;
int ulen, ret; int ulen, ret;
size_t width; size_t width;
@ -795,7 +795,7 @@ showmsg(char const *msg)
trashzle(); trashzle();
clearflag = isset(USEZLE) && !termflags && isset(ALWAYSLASTPROMPT); clearflag = isset(USEZLE) && !termflags && isset(ALWAYSLASTPROMPT);
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
umsg = ztrdup(msg); umsg = ztrdup(msg);
p = unmetafy(umsg, &ulen); p = unmetafy(umsg, &ulen);
memset(&ps, 0, sizeof(ps)); memset(&ps, 0, sizeof(ps));

View file

@ -135,7 +135,7 @@ vigetkey(void)
} else if (cmd == Th(z_vicmdmode)) { } else if (cmd == Th(z_vicmdmode)) {
return ZLEEOF; return ZLEEOF;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid) if (!lastchar_wide_valid)
{ {
getrestchar(lastchar); getrestchar(lastchar);
@ -830,7 +830,7 @@ vicapslockpanic(UNUSED(char **args))
statusline = ZWS("press a lowercase key to continue"); statusline = ZWS("press a lowercase key to continue");
statusll = ZS_strlen(statusline); statusll = ZS_strlen(statusline);
zrefresh(); zrefresh();
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
while (!iswlower(getfullchar(0))); while (!iswlower(getfullchar(0)));
#else #else
while (!islower(getfullchar(0))); while (!islower(getfullchar(0)));

View file

@ -736,7 +736,7 @@ addbufspc(int need)
void void
stradd(char *d) stradd(char *d)
{ {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
char *ums, *ups; char *ums, *ups;
int upslen; int upslen;
mbstate_t ps; mbstate_t ps;
@ -861,7 +861,7 @@ countprompt(char *str, int *wp, int *hp, int overf)
{ {
int w = 0, h = 1; int w = 0, h = 1;
int s = 1; int s = 1;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
int mbret, wcw, multi = 0; int mbret, wcw, multi = 0;
char inchar; char inchar;
mbstate_t mbs; mbstate_t mbs;
@ -887,13 +887,13 @@ countprompt(char *str, int *wp, int *hp, int overf)
w++; w++;
else if (s) { else if (s) {
if (*str == Meta) { if (*str == Meta) {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
inchar = *++str ^ 32; inchar = *++str ^ 32;
#else #else
str++; str++;
#endif #endif
} else { } else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Don't look for tab or newline in the middle * Don't look for tab or newline in the middle
* of a multibyte character. Otherwise, we are * of a multibyte character. Otherwise, we are
@ -910,14 +910,14 @@ countprompt(char *str, int *wp, int *hp, int overf)
h++; h++;
continue; continue;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
} }
inchar = *str; inchar = *str;
#endif #endif
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
mbret = mbrtowc(&wc, &inchar, 1, &mbs); mbret = mbrtowc(&wc, &inchar, 1, &mbs);
if (mbret >= -1) { if (mbret >= -1) {
if (mbret > 0) { if (mbret > 0) {
@ -1044,7 +1044,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar)
int twidth, maxwidth; int twidth, maxwidth;
int ntrunc = strlen(t); int ntrunc = strlen(t);
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* Use screen width of string */ /* Use screen width of string */
twidth = mb_width(t); twidth = mb_width(t);
#else #else
@ -1076,7 +1076,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar)
*/ */
char *fulltextptr, *fulltext; char *fulltextptr, *fulltext;
int remw; int remw;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
mbstate_t mbs; mbstate_t mbs;
memset(&mbs, 0, sizeof(mbstate_t)); memset(&mbs, 0, sizeof(mbstate_t));
#endif #endif
@ -1111,7 +1111,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar)
fulltextptr++; fulltextptr++;
} }
} else { } else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Normal text: build up a multibyte character. * Normal text: build up a multibyte character.
*/ */
@ -1170,7 +1170,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar)
* maximum width. * maximum width.
*/ */
char *skiptext = ptr; char *skiptext = ptr;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
mbstate_t mbs; mbstate_t mbs;
memset(&mbs, 0, sizeof(mbstate_t)); memset(&mbs, 0, sizeof(mbstate_t));
#endif #endif
@ -1180,7 +1180,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar)
for (; *skiptext != Outpar && *skiptext; for (; *skiptext != Outpar && *skiptext;
skiptext++); skiptext++);
} else { } else {
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
char inchar; char inchar;
wchar_t cc; wchar_t cc;
int ret; int ret;

View file

@ -55,7 +55,7 @@ ztrdup(const char *s)
} }
/**/ /**/
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/**/ /**/
mod_export wchar_t * mod_export wchar_t *
wcs_ztrdup(const wchar_t *s) wcs_ztrdup(const wchar_t *s)
@ -69,7 +69,7 @@ wcs_ztrdup(const wchar_t *s)
return t; return t;
} }
/**/ /**/
#endif /* ZLE_UNICODE_SUPPORT */ #endif /* MULTIBYTE_SUPPORT */
/* concatenate s1, s2, and s3 in dynamically allocated buffer */ /* concatenate s1, s2, and s3 in dynamically allocated buffer */

View file

@ -692,13 +692,13 @@ extern short ospeed;
#endif #endif
/* /*
* The ZLE_UNICODE_SUPPORT configure-define specifies that we want to enable * The MULTIBYTE_SUPPORT configure-define specifies that we want to enable
* complete Unicode conversion between wide characters and multibyte strings. * complete Unicode conversion between wide characters and multibyte strings.
*/ */
#if defined ZLE_UNICODE_SUPPORT \ #if defined MULTIBYTE_SUPPORT \
|| (defined HAVE_WCHAR_H && defined HAVE_WCTOMB && defined __STDC_ISO_10646__) || (defined HAVE_WCHAR_H && defined HAVE_WCTOMB && defined __STDC_ISO_10646__)
/* /*
* If ZLE_UNICODE_SUPPORT is not defined, these includes provide a subset of * If MULTIBYTE_SUPPORT is not defined, these includes provide a subset of
* Unicode support that makes the \u and \U printf escape sequences work. * Unicode support that makes the \u and \U printf escape sequences work.
*/ */
# include <wchar.h> # include <wchar.h>

View file

@ -35,7 +35,7 @@
/**/ /**/
char *scriptname; char *scriptname;
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* The wordchars variable turned into a wide character array. * The wordchars variable turned into a wide character array.
* This is much more convenient for testing. * This is much more convenient for testing.
@ -156,7 +156,11 @@ zerrmsg(const char *fmt, const char *str, int num)
putc('%', stderr); putc('%', stderr);
break; break;
case 'c': case 'c':
#ifdef MULTIBYTE_SUPPORT
zputs(wcs_nicechar(num, NULL, NULL), stderr);
#else
zputs(nicechar(num), stderr); zputs(nicechar(num), stderr);
#endif
break; break;
case 'e': case 'e':
/* print the corresponding message for this errno */ /* print the corresponding message for this errno */
@ -219,6 +223,10 @@ putshout(int c)
* Note that the returned string is metafied, so that it must be * Note that the returned string is metafied, so that it must be
* treated like any other zsh internal string (and not, for example, * treated like any other zsh internal string (and not, for example,
* output directly). * output directly).
*
* This function is used even if MULTIBYTE_SUPPORT is defined: we
* use it as a fallback in case we couldn't identify a wide character
* in a multibyte string.
*/ */
/**/ /**/
@ -270,7 +278,7 @@ nicechar(int c)
} }
/**/ /**/
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* The number of bytes we need to allocate for a "nice" representation * The number of bytes we need to allocate for a "nice" representation
* of a multibyte character. * of a multibyte character.
@ -380,7 +388,7 @@ wcs_nicechar(wchar_t c, size_t *widthp, char **swidep)
return buf; return buf;
} }
/**/ /**/
#endif /* ZLE_UNICODE_SUPPORT */ #endif /* MULTIBYTE_SUPPORT */
/* Output a string's visible representation. */ /* Output a string's visible representation. */
@ -394,19 +402,6 @@ nicefputs(char *s, FILE *f)
} }
#endif #endif
/* Return the length of the visible representation of a string. */
/**/
size_t
nicestrlen(char *s)
{
size_t l = 0;
for (; *s; s++)
l += strlen(nicechar(STOUC(*s)));
return l;
}
/* get a symlink-free pathname for s relative to PWD */ /* get a symlink-free pathname for s relative to PWD */
/**/ /**/
@ -2542,7 +2537,7 @@ inittyptab(void)
typtab[t0] = IDIGIT | IALNUM | IWORD | IIDENT | IUSER; typtab[t0] = IDIGIT | IALNUM | IWORD | IIDENT | IUSER;
for (t0 = 'a'; t0 <= 'z'; t0++) for (t0 = 'a'; t0 <= 'z'; t0++)
typtab[t0] = typtab[t0 - 'a' + 'A'] = IALPHA | IALNUM | IIDENT | IUSER | IWORD; typtab[t0] = typtab[t0 - 'a' + 'A'] = IALPHA | IALNUM | IIDENT | IUSER | IWORD;
#ifndef ZLE_UNICODE_SUPPORT #ifndef MULTIBYTE_SUPPORT
/* /*
* This really doesn't seem to me the right thing to do when * This really doesn't seem to me the right thing to do when
* we have multibyte character support... it was a hack to assume * we have multibyte character support... it was a hack to assume
@ -2575,7 +2570,7 @@ inittyptab(void)
} }
typtab[STOUC(*s == Meta ? *++s ^ 32 : *s)] |= ISEP; typtab[STOUC(*s == Meta ? *++s ^ 32 : *s)] |= ISEP;
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (wordchars) { if (wordchars) {
char *wordchars_unmeta; char *wordchars_unmeta;
const char *wordchars_ptr; const char *wordchars_ptr;
@ -2602,7 +2597,7 @@ inittyptab(void)
#endif #endif
for (s = wordchars ? wordchars : DEFAULT_WORDCHARS; *s; s++) { for (s = wordchars ? wordchars : DEFAULT_WORDCHARS; *s; s++) {
int c = STOUC(*s == Meta ? *++s ^ 32 : *s); int c = STOUC(*s == Meta ? *++s ^ 32 : *s);
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
if (!isascii(c)) { if (!isascii(c)) {
/* /*
* If we have support for multibyte characters, we don't * If we have support for multibyte characters, we don't
@ -2623,7 +2618,7 @@ inittyptab(void)
} }
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* iword() macro extended to support wide characters. * iword() macro extended to support wide characters.
*/ */
@ -2715,7 +2710,7 @@ zarrdup(char **s)
} }
/**/ /**/
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/**/ /**/
mod_export wchar_t ** mod_export wchar_t **
wcs_zarrdup(wchar_t **s) wcs_zarrdup(wchar_t **s)
@ -2729,7 +2724,7 @@ wcs_zarrdup(wchar_t **s)
return y; return y;
} }
/**/ /**/
#endif /* ZLE_UNICODE_SUPPORT */ #endif /* MULTIBYTE_SUPPORT */
/**/ /**/
static char * static char *
@ -3329,6 +3324,7 @@ zputs(char const *s, FILE *stream)
return 0; return 0;
} }
#ifndef MULTIBYTE_SUPPORT
/* Create a visibly-represented duplicate of a string. */ /* Create a visibly-represented duplicate of a string. */
/**/ /**/
@ -3356,6 +3352,7 @@ nicedup(char const *s, int heap)
*p = '\0'; *p = '\0';
return heap ? dupstring(buf) : ztrdup(buf); return heap ? dupstring(buf) : ztrdup(buf);
} }
#endif
/**/ /**/
mod_export char * mod_export char *
@ -3364,6 +3361,8 @@ nicedupstring(char const *s)
return nicedup(s, 1); return nicedup(s, 1);
} }
#ifndef MULTIBYTE_SUPPORT
/* Unmetafy and output a string, displaying special characters readably. */ /* Unmetafy and output a string, displaying special characters readably. */
/**/ /**/
@ -3387,6 +3386,7 @@ nicezputs(char const *s, FILE *stream)
return 0; return 0;
} }
/* Return the length of the visible representation of a metafied string. */ /* Return the length of the visible representation of a metafied string. */
/**/ /**/
@ -3409,9 +3409,11 @@ niceztrlen(char const *s)
} }
return l; return l;
} }
#endif
/**/ /**/
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
/* /*
* Version of both nicezputs() and niceztrlen() for use with multibyte * Version of both nicezputs() and niceztrlen() for use with multibyte
* characters. Input is a metafied string; output is the screen width of * characters. Input is a metafied string; output is the screen width of
@ -3421,11 +3423,13 @@ niceztrlen(char const *s)
* *
* If outstrp is not NULL, set *outstrp to a zalloc'd version of * If outstrp is not NULL, set *outstrp to a zalloc'd version of
* the output (still metafied). * the output (still metafied).
*
* If "heap" is non-zero, use the heap for *outstrp, else zalloc.
*/ */
/**/ /**/
mod_export size_t mod_export size_t
mb_niceformat(const char *s, FILE *stream, char **outstrp) mb_niceformat(const char *s, FILE *stream, char **outstrp, int heap)
{ {
size_t l = 0, newl, ret; size_t l = 0, newl, ret;
int umlen, outalloc, outleft; int umlen, outalloc, outleft;
@ -3500,7 +3504,7 @@ mb_niceformat(const char *s, FILE *stream, char **outstrp)
if (outstrp) { if (outstrp) {
*outptr = '\0'; *outptr = '\0';
/* Use more efficient storage for returned string */ /* Use more efficient storage for returned string */
*outstrp = ztrdup(outstr); *outstrp = heap ? dupstring(outstr) : ztrdup(outstr);
free(outstr); free(outstr);
} }
@ -3511,11 +3515,11 @@ mb_niceformat(const char *s, FILE *stream, char **outstrp)
/**/ /**/
mod_export char * mod_export char *
mb_niceztrdup(const char *s) nicedup(const char *s, int heap)
{ {
char *retstr; char *retstr;
(void)mb_niceformat(s, NULL, &retstr); (void)mb_niceformat(s, NULL, &retstr, heap);
return retstr; return retstr;
} }
@ -3564,7 +3568,7 @@ mb_width(const char *s)
} }
/**/ /**/
#endif /* ZLE_UNICODE_SUPPORT */ #endif /* MULTIBYTE_SUPPORT */
/* check for special characters in the string */ /* check for special characters in the string */

View file

@ -1432,7 +1432,7 @@ struct histent {
Histent up; /* previous line (moving upward) */ Histent up; /* previous line (moving upward) */
Histent down; /* next line (moving downward) */ Histent down; /* next line (moving downward) */
#ifdef ZLE_UNICODE_SUPPORT #ifdef MULTIBYTE_SUPPORT
wchar_t *zle_text; /* the edited history line */ wchar_t *zle_text; /* the edited history line */
#else #else
unsigned char *zle_text; /* the edited history line */ unsigned char *zle_text; /* the edited history line */
@ -1928,3 +1928,7 @@ typedef unsigned char *(*ZleGetLineFn) _((int *, int *));
#define EXITHOOK (zshhooks + 0) #define EXITHOOK (zshhooks + 0)
#define BEFORETRAPHOOK (zshhooks + 1) #define BEFORETRAPHOOK (zshhooks + 1)
#define AFTERTRAPHOOK (zshhooks + 2) #define AFTERTRAPHOOK (zshhooks + 2)
#ifdef MULTIBYTE_SUPPORT
#define nicezputs(str, outs) (void)mb_niceformat((str), (outs), NULL, 0)
#endif

View file

@ -2087,10 +2087,10 @@ AC_HELP_STRING([--enable-multibyte], [support multibyte chars in the zsh line ed
zsh_cv_c_zle_unicode_support=yes, zsh_cv_c_zle_unicode_support=yes,
zsh_cv_c_zle_unicode_support=no)]) zsh_cv_c_zle_unicode_support=no)])
]) ])
AH_TEMPLATE([ZLE_UNICODE_SUPPORT], AH_TEMPLATE([MULTIBYTE_SUPPORT],
[Define to 1 if you want unicode support in the line editor.]) [Define to 1 if you want support for multibyte character sets.])
if test $zsh_cv_c_zle_unicode_support = yes; then if test $zsh_cv_c_zle_unicode_support = yes; then
AC_DEFINE(ZLE_UNICODE_SUPPORT) AC_DEFINE(MULTIBYTE_SUPPORT)
fi fi
dnl --------------- dnl ---------------