Index: lynx2-8/src/LYStrings.h
diff -c lynx2-8/src/LYStrings.h:1.1.1.2 lynx2-8/src/LYStrings.h:1.1.1.2.2.1
*** lynx2-8/src/LYStrings.h:1.1.1.2	Mon Mar 16 12:25:06 1998
--- lynx2-8/src/LYStrings.h	Mon Mar 16 14:48:18 1998
***************
*** 114,119 ****
--- 114,122 ----
          int  margin;    /* Number of columns look-ahead/look-back    */
  
          char buffer[1024]; /* String buffer                          */
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 	unsigned char kanji_buf;/* Temporary buffer for kanji input */
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
  } EditFieldData;
  
Index: lynx2-8/src/LYStrings.c
diff -c lynx2-8/src/LYStrings.c:1.1.1.2 lynx2-8/src/LYStrings.c:1.1.1.2.2.1
*** lynx2-8/src/LYStrings.c:1.1.1.2	Mon Mar 16 12:25:14 1998
--- lynx2-8/src/LYStrings.c	Mon Mar 16 14:48:16 1998
***************
*** 23,28 ****
--- 23,29 ----
  
  extern BOOL HTPassHighCtrlRaw;
  extern HTCJKlang HTCJK;
+ extern HTkcode kanji_code;
  
  /* If you want to add mouse support for some new platform, it's fairly
  ** simple to do.  Once you've determined the X and Y coordinates of
***************
*** 726,731 ****
--- 727,735 ----
  #define DspWdth  edit->dspwdth
  #define DspStart edit->xpan
  #define Margin	 edit->margin
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ #define KanjiBuf edit->kanji_buf
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
  PUBLIC void LYSetupEdit ARGS4(
  	EDREC *,	edit,
***************
*** 740,745 ****
--- 744,752 ----
      edit->pad	= ' ';
      edit->dirty = TRUE;
      edit->panon = FALSE;
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     edit->kanji_buf = '\0';
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      StrLen  = strlen(old);
      MaxLen  = maxstr;
***************
*** 780,785 ****
--- 787,817 ----
      }
  }
  
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ PRIVATE int prev_pos ARGS2(
+ 	EDREC *,	edit,
+ 	int,		pos)
+ {
+     int i = 0;
+ 
+     if (pos <= 0)
+ 	return 0;
+     if (HTCJK == NOCJK)
+ 	return (pos - 1);
+     else {
+ 	while (i < pos - 1) {
+ 	    if (!isascii(Buf[i]))
+ 		i++;
+ 	    i++;
+ 	}
+ 	if (i == pos)
+ 	    return (i - 2);
+ 	else
+ 	    return i;
+     }
+ }
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
+ 
  PUBLIC int LYEdit1 ARGS4(
  	EDREC *,	edit,
  	int,		ch,
***************
*** 793,798 ****
--- 825,837 ----
  
      if (MaxLen <= 0)
  	return(0); /* Be defensive */
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     if (HTCJK != NOCJK && (KanjiBuf) &&
+ 	action != LYE_AIX && action != LYE_CHAR) {
+ 	KanjiBuf = '\0';
+ 	return(0);
+     }
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      length=strlen(&Buf[0]);
      StrLen = length;
***************
*** 811,828 ****
  	/*
  	 *  ch is printable or ISO-8859-1 escape character.
  	 */
  	if (Pos <= (MaxLen) && StrLen < (MaxLen)) {
  	    for(i = length; i >= Pos; i--)    /* Make room */
  		Buf[i+1] = Buf[i];
  	    Buf[length+1]='\0';
  	    Buf[Pos] = (unsigned char) ch;
  	    Pos++;
! 	} else if (maxMessage) {
! 	    _statusline(MAXLEN_REACHED_DEL_OR_MOV);
  	}
  	break;
  
      case LYE_BACKW:
  	/*
  	 *  Backword.
  	 *  Definition of word is very naive: 1 or more a/n characters.
--- 850,896 ----
  	/*
  	 *  ch is printable or ISO-8859-1 escape character.
  	 */
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 	if (HTCJK != NOCJK && !(KanjiBuf) && (ch & 0x80)) {
+ 	    if (kanji_code == SJIS && IS_JISX0201_KANA((unsigned char) ch)) {
+ 		unsigned char hi, lo;
+ 
+ 		JISx0201TO0208_SJIS((unsigned char)ch, &hi, &lo);
+ 		KanjiBuf = hi;
+ 		ch = (char)lo;
+ 	    } else {
+ 		KanjiBuf = (unsigned char) ch;
+ 		return(0);
+ 	    }
+ 	}
+ 	if (HTCJK != NOCJK && KanjiBuf &&
+ 	    Pos <= (MaxLen) && StrLen < (MaxLen)) {
+ 	    for(i = length; i >= Pos; i--)    /* Make room */
+ 		Buf[i+2] = Buf[i];
+ 	    Buf[length+2]='\0';
+ 	    Buf[Pos] = KanjiBuf;
+ 	    Buf[Pos+1] = (unsigned char) ch;
+ 	    Pos += 2;
+ 	    KanjiBuf = '\0';
+ 	} else if (Pos <= (MaxLen) && StrLen < (MaxLen)) {
+ #else /* !SUPPORT_MULTIBYTE_EDIT */
  	if (Pos <= (MaxLen) && StrLen < (MaxLen)) {
+ #endif
  	    for(i = length; i >= Pos; i--)    /* Make room */
  		Buf[i+1] = Buf[i];
  	    Buf[length+1]='\0';
  	    Buf[Pos] = (unsigned char) ch;
  	    Pos++;
! 	} else {
! 	    if (maxMessage) {
! 	        _statusline(MAXLEN_REACHED_DEL_OR_MOV);
! 	    }
! 	    return(ch);
  	}
  	break;
  
      case LYE_BACKW:
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	/*
  	 *  Backword.
  	 *  Definition of word is very naive: 1 or more a/n characters.
***************
*** 831,846 ****
--- 899,956 ----
  	    Pos--;
  	while (Pos &&  isalnum(Buf[Pos-1]))
  	    Pos--;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+         /*
+ 	 *  Backword.
+ 	 *  Definition of word is very naive: 1 or more a/n characters,
+ 	 *  or 1 or more multibyte character.
+ 	 */
+ 	{
+ 	    int pos0;
+ 
+ 	    pos0 = prev_pos(edit, Pos);
+ 	    while (Pos &&
+ 		   (HTCJK == NOCJK || isascii(Buf[pos0])) &&
+ 		   !isalnum(Buf[pos0])) {
+ 		Pos = pos0;
+ 		pos0 = prev_pos(edit, Pos);
+ 	    }
+ 	    if (HTCJK != NOCJK && !isascii(Buf[pos0])) {
+ 		while (Pos && !isascii(Buf[pos0])) {
+ 		    Pos = pos0;
+ 		    pos0 = prev_pos(edit, Pos);
+ 		}
+ 	    } else {
+ 		while (Pos && isascii(Buf[pos0]) && isalnum(Buf[pos0])) {
+ 		    Pos = pos0;
+ 		    pos0 = prev_pos(edit, Pos);
+ 		}
+ 	    }
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	break;
  
      case LYE_FORWW:
  	/*
  	 *  Word forward.
  	 */
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	while (isalnum(Buf[Pos]))
  	    Pos++;   /* '\0' is not a/n */
  	while (!isalnum(Buf[Pos]) && Buf[Pos])
  	    Pos++ ;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	if (HTCJK != NOCJK && !isascii(Buf[Pos])) {
+ 	    while (!isascii(Buf[Pos]))
+ 		Pos += 2;
+ 	} else {
+ 	    while (isascii(Buf[Pos]) && isalnum(Buf[Pos]))
+ 		Pos++;	/* '\0' is not a/n */
+ 	}
+ 	while ((HTCJK == NOCJK || isascii(Buf[Pos])) &&
+ 	       !isalnum(Buf[Pos]) && Buf[Pos])
+ 	    Pos++;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	break;
  
      case LYE_ERASE:
***************
*** 895,900 ****
--- 1005,1014 ----
  	 */
  	if (Pos >= length)
  	    break;
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 	if (HTCJK != NOCJK && !isascii(Buf[Pos]))
+ 	    Pos++;
+ #endif
  	Pos++;
  	/* fall through */
  
***************
*** 902,913 ****
--- 1016,1045 ----
  	/*
  	 *  Delete preceding character.
  	 */
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	if (length == 0 || Pos == 0)
  	    break;
  	Pos--;
  	for (i = Pos; i < length; i++)
  	    Buf[i] = Buf[i+1];
  	i--;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	{
+ 	    int offset = 1;
+ 	    int pos0 = Pos;
+ 
+ 	    if (length == 0 || Pos == 0)
+ 		break;
+ 	    if (HTCJK != NOCJK) {
+ 		Pos = prev_pos(edit, pos0);
+ 		offset = pos0 - Pos;
+ 	    } else
+ 		Pos--;
+ 	    for (i = Pos; i < length; i++)
+ 		Buf[i] = Buf[i + offset];
+ 	    i -= offset;
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	Buf[i] = 0;
  	break;
  
***************
*** 917,925 ****
--- 1049,1068 ----
  	 */
  	if (length == 0 || Pos == length)
  	    break;
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	for (i = Pos; i < length; i++)
  	    Buf[i] = Buf[i+1];
  	i--;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	{
+ 	    int offset = 1;
+ 	    if (HTCJK != NOCJK && !isascii(Buf[Pos]))
+ 		offset = 2;
+ 	    for (i = Pos; i < length; i++)
+ 		Buf[i] = Buf[i + offset];
+ 	    i -= offset;
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	Buf[i] = 0;
  	break;
  
***************
*** 927,934 ****
--- 1070,1085 ----
  	/*
  	 *  Move cursor to the right.
  	 */
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	if (Pos < length)
  	    Pos++;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	if (Pos < length) {
+ 	    Pos++;
+ 	    if (HTCJK != NOCJK && !isascii(Buf[Pos-1]))
+ 		Pos++;
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	break;
  
      case LYE_BACK:
***************
*** 936,942 ****
--- 1087,1100 ----
  	 *  Left-arrow move cursor to the left.
  	 */
  	if (Pos > 0)
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	    Pos--;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	    if (HTCJK != NOCJK)
+ 		Pos = prev_pos(edit, Pos);
+ 	    else
+ 		Pos--;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	break;
  
      case LYE_UPPER:
***************
*** 967,972 ****
--- 1125,1143 ----
      int padsize;
      char *str;
      char buffer[3];
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     int begin_multi = 0;
+     int end_multi = 0;
+     int prev_start;
+     BOOL force_refresh = FALSE;
+ 
+     if (HTCJK != NOCJK && KanjiBuf) /* don't refresh */
+ 	return;
+     prev_start = DspStart;
+     if (Buf[Pos] & 0x80) {
+ 	force_refresh = TRUE;
+     }
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      buffer[0] = buffer[1] = buffer[2] = '\0';
      if (!edit->dirty || (DspWdth == 0))
***************
*** 991,1006 ****
--- 1162,1218 ----
   *   data entry at low baudrates.
   */
      if ((DspStart + DspWdth) <= length)
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	if (Pos >= (DspStart + DspWdth) - Margin)
  	    DspStart=(Pos - DspWdth) + Margin;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	if (Pos >= (DspStart + DspWdth) - Margin) {
+ 	    if (HTCJK != NOCJK) {
+ 		int tmp = (Pos - DspWdth) + Margin;
+ 
+ 		while (DspStart < tmp) {
+ 		    if (!isascii(Buf[DspStart]))
+ 			DspStart++;
+ 		    DspStart++;
+ 		}
+ 	    } else
+ 		DspStart=(Pos - DspWdth) + Margin;
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      if (Pos < DspStart + Margin) {
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	DspStart = Pos - Margin;
  	if (DspStart < 0)
  	    DspStart = 0;
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	if (HTCJK != NOCJK) {
+ 	    int tmp = Pos - Margin;
+ 
+ 	    DspStart = 0;
+ 	    while (DspStart < tmp) {
+ 		if (!isascii(Buf[DspStart]))
+ 		    DspStart++;
+ 		DspStart++;
+ 	    }
+ 	} else {
+ 	    DspStart = Pos - Margin;
+ 	    if (DspStart < 0)
+ 		DspStart = 0;
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
      }
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     if (HTCJK != NOCJK && DspStart != prev_start) {
+ 	force_refresh = TRUE;
+     }
+ #endif
  
      str = &Buf[DspStart];
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     if (HTCJK != NOCJK && !isascii(str[0]))
+ 	begin_multi = 1;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      nrdisplayed = length-DspStart;
      if (nrdisplayed > DspWdth)
***************
*** 1019,1033 ****
--- 1231,1259 ----
  		    !(LYCharSet_UC[current_char_set].like8859
  		      & UCT_R_8859SPECL))))) {
  		addch(' ');
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 		end_multi = 0;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	    } else {
  		/* For CJK strings, by Masanobu Kimura */
  		if (HTCJK != NOCJK && !isascii(buffer[0])) {
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  		    if (i < (nrdisplayed - 1))
  			buffer[1] = str[++i];
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 		    if (i < (nrdisplayed - 1)) {
+ 		        buffer[1] = str[++i];
+ 			end_multi = 1;
+ 		    } else
+ 			end_multi = 0;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  		    addstr(buffer);
  		    buffer[1] = '\0';
  		} else {
  		    addstr(buffer);
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 		    end_multi = 0;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  		}
  	    }
      }
***************
*** 1044,1059 ****
--- 1270,1308 ----
       */
      if (edit->panon) {
  	if ((DspStart + nrdisplayed) < length) {
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	    move(edit->sy, edit->sx+nrdisplayed-1);
  	    addch('}');
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	    if (end_multi) {
+ 		move(edit->sy, edit->sx+nrdisplayed-2);
+ 		addstr(" }");
+ 	    } else {
+ 	        move(edit->sy, edit->sx+nrdisplayed-1);
+ 	        addch('}');
+ 	    }
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	}
  	if (DspStart) {
  	    move(edit->sy, edit->sx);
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	    addch('{');
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	    if (begin_multi)
+ 		addstr("{ ");
+ 	    else
+ 		addch('{');
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	}
      }
  
      move(edit->sy, edit->sx + Pos - DspStart);
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ #if (!USE_SLANG && !defined(USE_MULTIBYTE_CURSES))
+     if (HTCJK != NOCJK && force_refresh)
+         lynx_force_repaint();
+ #endif /* !USE_SLANG && !defined(USE_MULTIBYTE_CURSES) */
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
      refresh();
  }
  
***************
*** 1104,1115 ****
--- 1353,1373 ----
  	     *	character in the current display character set.
  	     *	Otherwise, we treat this as LYE_ENTER.
  	     */
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  	    if (ch != '\t' &&
  		(HTCJK != NOCJK ||
  		 LYlowest_eightbit[current_char_set] <= 0x97)) {
  		LYLineEdit(&MyEdit,ch, FALSE);
  		break;
  	    }
+ #else /* SUPPORT_MULTIBYTE_EDIT (quick hack) */
+ 	    if (ch != '\t' &&
+ 		(HTCJK != NOCJK ||
+ 		 LYlowest_eightbit[current_char_set] <= 0x97)) {
+ 		goto normal;
+ 	    }
+ 	    /* fall through */
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	case LYE_ENTER:
  	    /*
  	     *	Terminate the string and return.
***************
*** 1135,1142 ****
  	    break;
  
  	default:
! 	    LYLineEdit(&MyEdit, ch, FALSE);
! 	}
      }
  }
  
--- 1393,1403 ----
  	    break;
  
  	default:
! #ifdef SUPPORT_MULTIBYTE_EDIT
! normal:
! #endif /* SUPPORT_MULTIBYTE_EDIT */
!             LYLineEdit(&MyEdit, ch, FALSE);
!         }
      }
  }
  
***************
*** 1398,1404 ****
  		 }
  		if (*tmpchptr == '\0') {
  		     break;
! 	    }
  	    }
  	} else if (!(IS_UTF_EXTRA(*chptr) ||
  		      IsSpecialAttrChar(*chptr))) {
--- 1659,1665 ----
  		 }
  		if (*tmpchptr == '\0') {
  		     break;
! 	        }
  	    }
  	} else if (!(IS_UTF_EXTRA(*chptr) ||
  		      IsSpecialAttrChar(*chptr))) {
***************
*** 1537,1543 ****
  		 }
  		if (*tmpchptr == '\0') {
  		     break;
! 	    }
  	    }
  	} else if (!(IS_UTF_EXTRA(*chptr) ||
  		      IsSpecialAttrChar(*chptr))) {
--- 1798,1804 ----
  		 }
  		if (*tmpchptr == '\0') {
  		     break;
!                 }
  	    }
  	} else if (!(IS_UTF_EXTRA(*chptr) ||
  		      IsSpecialAttrChar(*chptr))) {
