*** src/sldisply.c.orig	Tue Jan 21 15:58:20 1997
--- src/sldisply.c	Wed Aug 27 20:58:54 1997
***************
*** 1246,1251 ****
--- 1246,1254 ----
     unsigned short buffer[256];
     unsigned int n_spaces;
     unsigned short *space_match, *last_buffered_match;
+ #if SLANG_HAS_KANJI_SUPPORT
+    unsigned int new_multi = 0;	/* check for first byte */
+ #endif
  #ifdef HP_GLITCH_CODE
     int handle_hp_glitch = 0;
  #endif
***************
*** 1253,1260 ****
--- 1256,1265 ----
     q = oldd; p = neww;
     qmax = oldd + len;
     pmax = p + len;
+    buffer[0] = '\0';
     
     /* Find out where to begin --- while they match, we are ok */
+ 
     while (1)
       {
  	if (q == qmax) return;
***************
*** 1263,1281 ****
  	  { /* new is kanji */
  	     if ((*q & 0x80) && ((q + 1) < qmax))
  	       { /* old is also kanji */
! 		  if (((0xFF & *q) != (0xFF & *p))
! 		      || ((0xFF & q[1]) != (0xFF & p[1])))
! 		    break; /* both kanji, but not match */
! 		  
! 		  else 
! 		    { /* kanji match ! */
! 		       if (!COLOR_EQS(*q, *p)) break;
! 		       q++; p++;
! 		       if (!COLOR_EQS(*q, *p)) break;
! 		       /* really match! */
! 		       q++; p++;
! 		       continue;
! 		    }
  	       }
  	     else break; /* old is not kanji */
  	  }
--- 1268,1281 ----
  	  { /* new is kanji */
  	     if ((*q & 0x80) && ((q + 1) < qmax))
  	       { /* old is also kanji */
! 		  if (!CHAR_EQS(*q, *p)) break;
! 		  /* first byte match */
! 		  new_multi = 1; 
! 		  if (!CHAR_EQS(*(q+1), *(p+1))) break;
! 		  /* really match! */
! 		  q += 2; p += 2;
! 		  new_multi = 0;
! 		  continue; 
  	       }
  	     else break; /* old is not kanji */
  	  }
***************
*** 1287,1292 ****
--- 1287,1320 ----
  	if (!CHAR_EQS(*q, *p)) break;
  	q++; p++;
       }
+ #if SLANG_HAS_KANJI_SUPPORT
+    {
+       unsigned short *pp = p, *p_tmp = NULL;
+ 
+       if (new_multi && !(*(p+1) & 0x80) && (*(p+1) & 0x8000)) {
+          *p = SPACE_CHAR;
+          pp += 2;
+          new_multi = 0;
+       }
+       while (pp < pmax) {
+          if (*pp & 0x80) {
+             if (!(*(pp-1) & 0x80) && (*(pp-1) & 0x8000)) {
+ 	       /* previous is alt_char */
+ 	       p_tmp = pp;
+             }
+             if (*(pp+1) & 0x80) {
+ 	       pp++;
+             } else {
+ 	       if (p_tmp != NULL) {
+ 	          *p_tmp = SPACE_CHAR;
+ 	       }
+             break;
+             }
+          }
+          pp++;
+       }
+    }
+ #endif
  
     /*position the cursor */
     SLtt_goto_rc (row, (int) (p - neww));
***************
*** 1374,1380 ****
  		  if (*q & 0x80) 
  		    { /* old is also kanji */
   			  if (((0xFF & *q) != (0xFF & *p)) 
! 			      || ((0xFF & q[1]) != (0xFF & p[1])))
  			 {
  			    /* both kanji, but not match */
  			    *buf++ = *p++;
--- 1402,1408 ----
  		  if (*q & 0x80) 
  		    { /* old is also kanji */
   			  if (((0xFF & *q) != (0xFF & *p)) 
! 			      || ((0xFF & *(q+1)) != (0xFF & *(p+1))))
  			 {
  			    /* both kanji, but not match */
  			    *buf++ = *p++;
***************
*** 1389,1394 ****
--- 1417,1423 ----
  				 /* code is match ,but color is diff */
  				 *buf++ = *p++;
  				 *buf++ = *p++;
+ 				 q += 2;
  				 continue;
  			      }
  			    /* really match ! */
***************
*** 1404,1411 ****
  		    }
  	       }
  	     else 
! 	       { /* new is not kanji */
!  		  if (*q & 0x80) 
  		    { /* old is kanji */
  		       *buf++ = *p++;
  		       q++;
--- 1433,1440 ----
  		    }
  	       }
  	     else 
! 	       {
!  		  if ((*q & 0x80))
  		    { /* old is kanji */
  		       *buf++ = *p++;
  		       q++;
***************
*** 1432,1438 ****
  	 * of a possible match of new and old.  If this is the case, skip 
  	 * some more.
  	 */
! #if !SLANG_HAS_KANJI_SUPPORT	
  	while ((p < pmax) && CHAR_EQS(*p, *q))
  	  {
  	     *buf++ = *p++;
--- 1461,1467 ----
  	 * of a possible match of new and old.  If this is the case, skip 
  	 * some more.
  	 */
! #if !SLANG_HAS_KANJI_SUPPORT
  	while ((p < pmax) && CHAR_EQS(*p, *q))
  	  {
  	     *buf++ = *p++;
***************
*** 1447,1457 ****
  		  if (*q & 0x80) 
  		    { /* old is also kanji */
  		       if (((0xFF & *q) == (0xFF & *p)) 
! 			   && ((0xFF & q[1]) == (0xFF & p[1])))
  			 {
  			    /* kanji match ? */
  			    if (!COLOR_EQS(*q, *p) 
! 				|| !COLOR_EQS(q[1], p[1]))
  			      break;
  			    
  			    *buf++ = *p++;
--- 1476,1486 ----
  		  if (*q & 0x80) 
  		    { /* old is also kanji */
  		       if (((0xFF & *q) == (0xFF & *p)) 
! 			   && ((0xFF & *(q+1)) == (0xFF & *(p+1))))
  			 {
  			    /* kanji match ? */
  			    if (!COLOR_EQS(*q, *p) 
! 				|| !COLOR_EQS(*(q+1), *(p+1)))
  			      break;
  			    
  			    *buf++ = *p++;
***************
*** 1459,1465 ****
  			    if (p >= pmax) 
  			      {
  				 *buf++ = SPACE_CHAR;
! 				 p++;
  				 break;
  			      }
  			    else 
--- 1488,1494 ----
  			    if (p >= pmax) 
  			      {
  				 *buf++ = SPACE_CHAR;
! 				 q++;
  				 break;
  			      }
  			    else 
***************
*** 1618,1623 ****
--- 1647,1655 ----
     char *term, *t, ch;
     int is_xterm;
     int almost_vtxxx;
+ #if SLANG_HAS_KANJI_SUPPORT
+    int is_kterm;
+ #endif
     
     get_color_info ();
     
***************
*** 1638,1646 ****
--- 1670,1684 ----
         && (ch = *t, (ch >= '1') && (ch <= '9'))) Vt100_Like = 1; 
  
     is_xterm = !strncmp (term, "xterm", 5);
+ #if SLANG_HAS_KANJI_SUPPORT
+    is_kterm = !strncmp (term, "kterm", 5);
+ #endif
     almost_vtxxx = (Vt100_Like
  		   || Linux_Console
  		   || is_xterm
+ #if SLANG_HAS_KANJI_SUPPORT
+ 		   || is_kterm
+ #endif
  		   || !strcmp (term, "screen"));
       
  #ifndef USE_TERMCAP
***************
*** 1702,1707 ****
--- 1740,1748 ----
     if ((Vt100_Like && (term[2] != '1'))
         || Linux_Console
         || is_xterm
+ #if SLANG_HAS_KANJI_SUPPORT
+        || is_kterm
+ #endif
         )
       {
  	if (Del_N_Lines_Str == NULL) Del_N_Lines_Str = "\033[%dM";
***************
*** 1717,1722 ****
--- 1758,1766 ----
  	   && (NULL == Rev_Scroll_Str)))
       {
  	if (is_xterm
+ #if SLANG_HAS_KANJI_SUPPORT
+ 	    || is_kterm
+ #endif
  	    || Linux_Console
  	    )
  	  {
***************
*** 1736,1743 ****
--- 1780,1792 ----
     /* Although xterm cannot blink, it does display the blinking characters
      * as bold ones.  Some Rxvt will display the background as high intensity.
      */
+ #if SLANG_HAS_KANJI_SUPPORT
+    if ((NULL == (Blink_Vid_Str = SLtt_tgetstr("mb")))
+        && (is_xterm || is_kterm))
+ #else
     if ((NULL == (Blink_Vid_Str = SLtt_tgetstr("mb")))
         && is_xterm)
+ #endif
       Blink_Vid_Str = "\033[5m";
     
     UnderLine_Vid_Str = SLtt_tgetstr("us");
***************
*** 1783,1790 ****
  	  }
       }
     
      /* aixterm added by willi */
!    if (is_xterm || !strncmp (term, "aixterm", 7))
       {
  	Start_Alt_Chars_Str = "\016";
  	End_Alt_Chars_Str = "\017";
--- 1832,1847 ----
  	  }
       }
     
+ #if SLANG_HAS_KANJI_SUPPORT
+    if (is_kterm)
+      {
+        Start_Alt_Chars_Str = "\033(0";
+        End_Alt_Chars_Str = "\033(B";
+        Enable_Alt_Char_Set = "";
+      }
+ #endif
      /* aixterm added by willi */
!    if (!strncmp (term, "aixterm", 7))
       {
  	Start_Alt_Chars_Str = "\016";
  	End_Alt_Chars_Str = "\017";
*** src/slgetkey.c.orig	Wed Sep 10 18:47:16 1997
--- src/slgetkey.c	Wed Sep 10 18:45:48 1997
***************
*** 10,15 ****
--- 10,16 ----
  #include <stdio.h>
  #include "slang.h"
  #include "_slang.h"
+ #include "sl-feat.h"
  
  unsigned int SLang_Input_Buffer_Len = 0;
  unsigned char SLang_Input_Buffer [MAX_INPUT_BUFFER_LEN];
***************
*** 24,29 ****
--- 25,36 ----
  # if defined(__unix__) || defined(vms)
  #  define DEC_8BIT_HACK 64
  # endif
+ #endif
+ /* if SLANG_HAS_KANJI_SUPPORT is 1, cancel DEC_8BIT_HACK for multibyte
+  * character input
+  */
+ #if SLANG_HAS_KANJI_SUPPORT
+ # undef DEC_8BIT_HACK
  #endif
  
  unsigned int SLang_getkey (void)
