about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-02-22 13:12:35 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-02-22 13:12:35 +0000
commitb83f0e229097626fa8e667486c48d7a3139d2e4a (patch)
treedd125c9521986e7a40e4d13a67db90757aee9ad5 /Src/Zle
parentc8883a5a08e6a9c0fbb088acab11c1ef8788b3d8 (diff)
downloadzsh-b83f0e229097626fa8e667486c48d7a3139d2e4a.tar.gz
zsh-b83f0e229097626fa8e667486c48d7a3139d2e4a.tar.xz
zsh-b83f0e229097626fa8e667486c48d7a3139d2e4a.zip
Andrej: 20838: get ZLE_UNICODE_SUPPORT basically working
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle.h2
-rw-r--r--Src/Zle/zle_main.c8
-rw-r--r--Src/Zle/zle_misc.c8
-rw-r--r--Src/Zle/zle_tricky.c8
-rw-r--r--Src/Zle/zle_utils.c15
5 files changed, 25 insertions, 16 deletions
diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h
index 3d9f880b0..9c99f0b75 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -47,6 +47,7 @@ typedef wint_t   ZLE_INT_T;
 #define ZLENL	L'\n'
 #define ZLENUL	L'\0'
 #define ZLETAB	L'\t'
+#define ZLESPC	L' '
 
 #define DIGIT_1		L'1'
 #define DIGIT_9		L'9'
@@ -75,6 +76,7 @@ typedef int ZLE_INT_T;
 #define ZLENL	'\n'
 #define ZLENUL	'\0'
 #define ZLETAB	'\t'
+#define ZLESPC	' '
 
 #define DIGIT_1		'1'
 #define DIGIT_9		'9'
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 1f7b7cbfa..f0e34a28a 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -748,10 +748,11 @@ getfullchar(int keytmout)
 mod_export ZLE_INT_T
 getrestchar(int inchar)
 {
-    char cnull = '\0';
+    /* char cnull = '\0'; */
     char buf[MB_CUR_MAX], *ptr;
     wchar_t outchar;
     int ret;
+    mbstate_t ps;
 
     /*
      * We are guaranteed to set a valid wide last character,
@@ -764,7 +765,8 @@ getrestchar(int inchar)
 	return lastchar_wide = WEOF;
 
     /* reset shift state by converting null */
-    mbrtowc(&outchar, &cnull, 1, &ps);
+    /* mbrtowc(&outchar, &cnull, 1, &ps); */
+    memset (&ps, '\0', sizeof (ps));
 
     ptr = buf;
     *ptr++ = inchar;
@@ -785,7 +787,7 @@ getrestchar(int inchar)
 	    return lastchar_wide = WEOF;
 	*ptr++ = inchar;
     }
-    return lastchar_wide = (wint_t)outchar;
+    return lastchar_wide = (ZLE_INT_T)outchar;
 }
 /**/
 #endif
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 081c720cd..2c7c364a2 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -61,9 +61,13 @@ mod_export int
 selfinsert(UNUSED(char **args))
 {
 #ifdef ZLE_UNICODE_SUPPORT
+    /* wint_t and wchar_t not neccessarily the same size */
+    wchar_t tmp;
+
     if (!lastchar_wide_valid)
 	getrestchar(lastchar);
-    doinsert(&lastchar_wide, 1);
+    tmp = lastchar_wide;
+    doinsert(&tmp, 1);
 #else
     char s = lastchar;
     doinsert(&s, 1);
@@ -921,7 +925,7 @@ executenamedcommand(char *prmt)
 #ifdef ZLE_UNICODE_SUPPORT
 		    if (!lastchar_wide_valid)
 			getrestchar(0);
-		    if (iswcntrl(lastchar))
+		    if (iswcntrl(lastchar_wide))
 #else
 		    if (icntrl(lastchar))
 #endif
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index f7559f08c..620f615a2 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -159,12 +159,12 @@ int hascompwidgets;
 static int
 usetab(void)
 {
-    unsigned char *s = zleline + zlecs - 1;
+    ZLE_STRING_T s = zleline + zlecs - 1;
 
     if (keybuf[0] != '\t' || keybuf[1])
 	return 0;
-    for (; s >= zleline && *s != '\n'; s--)
-	if (*s != '\t' && *s != ' ')
+    for (; s >= zleline && *s != ZLENL; s--)
+	if (*s != ZLETAB && *s != ZLESPC)
 	    return 0;
     if (compfunc) {
 	wouldinstab = 1;
@@ -866,7 +866,7 @@ addx(char **ptmp)
 	(instring && (zleline[zlecs] == '"' || zleline[zlecs] == '\'')) ||
 	(addspace = (comppref && !iblank(zleline[zlecs])))) {
 	*ptmp = (char *)zleline;
-	zleline = (unsigned char *)zhalloc(strlen((char *)zleline) + 3 +
+	zleline = (ZLE_STRING_T)zhalloc(strlen((char *)zleline) + 3 +
 					   addspace);
 	memcpy(zleline, *ptmp, zlecs);
 	zleline[zlecs] = 'x';
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index e6f696935..a5fe799eb 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -111,22 +111,22 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outll,
 {
 #ifdef ZLE_UNICODE_SUPPORT
     char *s;
-    char *mb_cursor;
     int i, j;
     size_t mb_len = 0;
 
-    mb_cursor = s = zalloc(inll * MB_CUR_MAX);
+    s = zalloc(inll * MB_CUR_MAX + 1);
 
-    for(i=0;i<=inll;i++) {
+    for(i=0; i < inll; i++) {
 	if (outcs != NULL && i == incs)
 	    *outcs = mb_len;
-	j = wctomb(mb_cursor, instr[i]);
+	j = wctomb(s + mb_len, instr[i]);
 	if (j == -1) {
 	    /* invalid char; what to do? */
 	} else {
 	    mb_len += j;
 	}
     }
+    s[mb_len] = '\0';
 
     if (outll != NULL)
 	*outll = mb_len;
@@ -135,7 +135,7 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outll,
 	unsigned char *ret =
 	    (unsigned char *) metafy((char *) s, mb_len, META_HEAPDUP);
 
-	zfree((char *)s, inll * MB_CUR_MAX);
+	zfree((char *)s, inll * MB_CUR_MAX + 1);
 
 	return ret;
     }
@@ -201,11 +201,12 @@ stringaszleline(unsigned char *instr, int *outll, int *outsz)
 #ifdef ZLE_UNICODE_SUPPORT
     if (ll) {
 	/* reset shift state by converting null. */
-	char cnull = '\0';
+	/* char cnull = '\0'; */
 	char *inptr = (char *)instr;
 	wchar_t *outptr = outstr;
 
-	mbrtowc(outstr, &cnull, 1, &ps);
+	/* mbrtowc(outstr, &cnull, 1, &ps); */
+	memset(&ps, \0, sizeof(ps));
 
 	while (ll) {
 	    size_t ret = mbrtowc(outptr, inptr, ll, &ps);