zsh-workers
 help / color / mirror / code / Atom feed
* changing ZLE_CHAR_T?
@ 2005-10-28 22:58 Wayne Davison
  2005-10-29  9:59 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Wayne Davison @ 2005-10-28 22:58 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

One thing I don't like about the current definition of ZLE_CHAR_T is
that, in the non-multibyte code, you don't end up with a ZLE_STRING_T
if you take the address of a ZLE_CHAR_T variable (due to ZLE_CHAR_T
being an "int" and ZLE_STRING_T being an "unsigned char *").  Since
we have a ZLE_INT_T for those variables that need to be able to hold
a ZLEEOF value, I thought it would be cleaner to change ZLE_CHAR_T.

For my first try, I changed ZLE_CHAR_T into an "unsigned char", which
caused a bunch of problems with comparisons against char constants,
such as "Comma", because the strings in the rest of zsh are based on
"char", not "unsigned char".  I then decided to change ZLE_CHAR_T to
be a "char" and to also change ZLE_STRING_T into a "char *".  This
change worked with just a few other tweaks to the code, and all the
tests pass.

However, I won't commit this until I hear some assent that this is a
desired change.  Attached is the patch.

..wayne..

[-- Attachment #2: char-typedef.patch --]
[-- Type: text/plain, Size: 2576 bytes --]

--- Src/zsh.h	28 Oct 2005 22:14:22 -0000	1.81
+++ Src/zsh.h	28 Oct 2005 22:49:25 -0000
@@ -1435,7 +1435,7 @@ struct histent {
 #ifdef MULTIBYTE_SUPPORT
     wchar_t *zle_text;		/* the edited history line          */
 #else
-    unsigned char *zle_text;	/* the edited history line          */
+    char *zle_text;		/* the edited history line          */
 #endif
     int zle_len;		/* length of zle_text */
     time_t stim;		/* command started time (datestamp) */
--- Src/Zle/zle.h	28 Oct 2005 17:34:33 -0000	1.21
+++ Src/Zle/zle.h	28 Oct 2005 22:49:25 -0000
@@ -84,14 +84,14 @@ typedef wint_t   ZLE_INT_T;
 
 #else  /* Not MULTIBYTE_SUPPORT: old single-byte code */
 
-typedef int ZLE_CHAR_T;
-typedef unsigned char *ZLE_STRING_T;
+typedef char ZLE_CHAR_T;
+typedef char *ZLE_STRING_T;
 typedef int ZLE_INT_T;
-#define ZLE_CHAR_SIZE	sizeof(unsigned char)
+#define ZLE_CHAR_SIZE	sizeof(char)
 
 /* Leave character or string as is, but string must be unsigned char * */
 #define ZWC(c)	c
-#define ZWS(s)	(unsigned char *)s
+#define ZWS(s)	(char *)s
 
 #define ZLEEOF	EOF
 
--- Src/Zle/zle_misc.c	28 Oct 2005 17:34:33 -0000	1.30
+++ Src/Zle/zle_misc.c	28 Oct 2005 22:49:25 -0000
@@ -60,18 +60,14 @@ doinsert(ZLE_STRING_T zstr, int len)
 mod_export int
 selfinsert(UNUSED(char **args))
 {
-#ifdef MULTIBYTE_SUPPORT
-    /* wint_t and wchar_t not neccessarily the same size */
-    wchar_t tmp;
+    ZLE_CHAR_T tmp;
 
+#ifdef MULTIBYTE_SUPPORT
     if (!lastchar_wide_valid)
 	getrestchar(lastchar);
-    tmp = lastchar_wide;
-    doinsert(&tmp, 1);
-#else
-    unsigned char s = lastchar;
-    doinsert(&s, 1);
 #endif
+    tmp = LASTFULLCHAR;
+    doinsert(&tmp, 1);
     return 0;
 }
 
@@ -89,7 +85,7 @@ fixunmeta(void)
      * selfinsertunmeta is intrinsically problematic
      * with multibyte input.
      */
-    lastchar_wide = (ZLE_CHAR_T)lastchar;
+    lastchar_wide = (ZLE_INT_T)lastchar;
     lastchar_wide_valid = 1;
 #endif
 }
@@ -1098,7 +1094,7 @@ makesuffixstr(char *f, char *s, int n)
 
 /**/
 mod_export void
-iremovesuffix(ZLE_CHAR_T c, int keep)
+iremovesuffix(ZLE_INT_T c, int keep)
 {
     if (suffixfunc) {
 	Eprog prog = getshfunc(suffixfunc);
--- Src/Zle/zle_utils.c	28 Oct 2005 17:34:33 -0000	1.30
+++ Src/Zle/zle_utils.c	28 Oct 2005 22:49:25 -0000
@@ -170,7 +170,7 @@ zlelineasstring(ZLE_STRING_T instr, int 
 #ifdef MULTIBYTE_SUPPORT
 	unsigned char *strp = (unsigned char *)s;
 #else
-	unsigned char *strp = instr;
+	unsigned char *strp = (unsigned char *)instr;
 #endif
 	unsigned char *stopcs = strp + outcs;
 	unsigned char *stopll = strp + outll;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-01 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-28 22:58 changing ZLE_CHAR_T? Wayne Davison
2005-10-29  9:59 ` Peter Stephenson
2005-10-31 21:45   ` Wayne Davison
2005-11-01  4:31     ` Wayne Davison
2005-11-01 10:20       ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).