Index: lynx2-7-1/src/LYForms.c
diff -c lynx2-7-1/src/LYForms.c:1.1.1.2 lynx2-7-1/src/LYForms.c:1.1.1.2.4.2
*** lynx2-7-1/src/LYForms.c:1.1.1.2	Thu Oct 23 14:53:07 1997
--- lynx2-7-1/src/LYForms.c	Wed Nov  5 16:19:39 1997
***************
*** 22,27 ****
--- 22,28 ----
  #endif
  
  extern HTCJKlang HTCJK;
+ extern HTkcode kanji_code;
  
  PRIVATE int form_getstr PARAMS((
  	struct link *	form_link));
***************
*** 268,273 ****
--- 269,277 ----
      int startcol, startline;
      BOOL HaveMaxlength = FALSE;
      int action;
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     BOOL refresh = TRUE;
+ #endif
  
  #ifdef VMS
      extern BOOLEAN HadVMSInterrupt;	/* Flag from cleanup_sig() AST */
***************
*** 343,348 ****
--- 347,360 ----
      for (;;) {
  again:
  	ch = LYgetch();
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 	if (!refresh &&
+ 	    (EditBinding(ch) != LYE_CHAR) && (EditBinding(ch) != LYE_AIX)) {
+ 	    LYEdit1(&MyEdit, 0, LYE_DELP, TRUE);
+ 	    refresh = TRUE;
+ 	    goto again;
+ 	}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  #ifdef VMS
  	if (HadVMSInterrupt) {
  	    HadVMSInterrupt = FALSE;
***************
*** 410,416 ****
--- 422,454 ----
  		/*
  		 *  Make sure the statusline uses editmode help.
  		 */
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  		LYLineEdit(&MyEdit, ch, TRUE);
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 		/* special treatment for jisx0201 kana */
+ 		if (kanji_code == SJIS && refresh == TRUE &&
+ 		    (0xa1 <= ch) && (ch <= 0xdf)) {
+ 		    unsigned char hi, lo;
+ 
+ 		    JISx0201TO0208_SJIS((unsigned char)ch, &hi, &lo);
+ 		    ch = (int)lo;
+ 		    if (LYLineEdit(&MyEdit, hi, TRUE) != 0) {
+ 			break;
+ 		    }
+ 		    refresh = FALSE;
+ 		}
+ 		if (LYLineEdit(&MyEdit, ch, TRUE) == 0) {
+ 		    if (HTCJK != NOCJK && (0x80 <= ch) && (ch <= 0xfe) && refresh)
+ 		        refresh = FALSE;
+ 		    else
+ 		        refresh = TRUE;
+ 		} else {
+ 		    if (!refresh) {
+ 			LYEdit1(&MyEdit, 0, LYE_DELP, TRUE);
+ 			refresh = TRUE;
+ 		    }
+ 		}
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  		if (MyEdit.strlen >= max_length) {
  		    HaveMaxlength = TRUE;
  		} else if (HaveMaxlength &&
***************
*** 421,427 ****
--- 459,470 ----
  		if (strcmp(value, MyEdit.buffer)) {
  		    Edited = TRUE;
  		}
+ #ifndef SUPPORT_MULTIBYTE_EDIT
  		LYRefreshEdit(&MyEdit);
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 		if (refresh)
+ 		    LYRefreshEdit(&MyEdit);
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  	}
      }
  breakfor:
Index: lynx2-7-1/src/LYStrings.c
diff -c lynx2-7-1/src/LYStrings.c:1.1.1.2 lynx2-7-1/src/LYStrings.c:1.1.1.2.4.4
*** lynx2-7-1/src/LYStrings.c:1.1.1.2	Thu Oct 23 14:52:51 1997
--- lynx2-7-1/src/LYStrings.c	Wed Nov  5 16:19:37 1997
***************
*** 22,27 ****
--- 22,28 ----
  
  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
***************
*** 707,712 ****
--- 708,738 ----
      }
  }
  
+ #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,
***************
*** 744,755 ****
  	    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.
--- 770,785 ----
  	    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.
***************
*** 758,773 ****
--- 788,845 ----
  	    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:
***************
*** 822,827 ****
--- 894,903 ----
  	 */
  	if (Pos >= length)
  	    break;
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+ 	if (HTCJK != NOCJK && !isascii(Buf[Pos]))
+ 	    Pos++;
+ #endif
  	Pos++;
  	/* fall through */
  
***************
*** 829,840 ****
--- 905,934 ----
          /*
  	 *  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;
  
***************
*** 844,852 ****
--- 938,957 ----
  	 */
  	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;
  
***************
*** 854,861 ****
--- 959,974 ----
          /*
  	 *  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:
***************
*** 863,869 ****
--- 976,989 ----
  	 *  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:
***************
*** 894,899 ****
--- 1014,1023 ----
      int padsize;
      char *str;
      char buffer[3];
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     int begin_multi = 0;
+     int end_multi = 0;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      buffer[0] = buffer[1] = buffer[2] = '\0';
      if (!edit->dirty || (DspWdth == 0))
***************
*** 918,933 ****
--- 1042,1093 ----
   *   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 */
      }
  
      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)
***************
*** 946,960 ****
--- 1106,1134 ----
  		    !(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 */
  		}
  	    }
      }
***************
*** 971,986 ****
--- 1145,1183 ----
       */
      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)
+         lynx_force_repaint();
+ #endif /* !USE_SLANG && !defined(USE_MULTIBYTE_CURSES) */
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
      refresh();
  }
  
***************
*** 994,999 ****
--- 1191,1199 ----
      int x, y, MaxStringSize;
      int ch;
      EditFieldData MyEdit;
+ #ifdef SUPPORT_MULTIBYTE_EDIT
+     BOOL refresh = TRUE;
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
  
      LYGetYX(y, x);		/* Use screen from cursor position to eol */
      MaxStringSize = (bufsize < sizeof(MyEdit.buffer)) ?
***************
*** 1003,1010 ****
--- 1203,1223 ----
  
      for (;;) {
  again:
+ #ifndef SUPPORT_MULTIBYTE_EDIT
          LYRefreshEdit(&MyEdit);
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ 	if (refresh)
+ 	    LYRefreshEdit(&MyEdit);
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
          ch = LYgetch();
+ #ifdef SUPPORT_MULTIBYTE_EDIT 
+ 	if (!refresh &&
+ 	    (EditBinding(ch) != LYE_CHAR) && (EditBinding(ch) != LYE_AIX)) {
+ 		LYEdit1(&MyEdit, 0, LYE_DELP, FALSE);
+ 		refresh = TRUE;
+ 		goto again;
+ 	}
+ #endif
  #ifdef VMS
  	if (term_letter || term_options || term_message || HadVMSInterrupt) {
  	    HadVMSInterrupt = FALSE;
***************
*** 1031,1042 ****
--- 1244,1264 ----
  	     *  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.
***************
*** 1054,1060 ****
--- 1276,1309 ----
              break;
  
          default:
+ #ifndef SUPPORT_MULTIBYTE_EDIT
              LYLineEdit(&MyEdit,ch, FALSE);
+ #else /* SUPPORT_MULTIBYTE_EDIT */
+ normal:
+ 	    /* special treatment for jisx0201 kana */
+ 	    if (kanji_code == SJIS && refresh == TRUE &&
+ 		(0xa1 <= ch) && (ch <= 0xdf)) {
+ 		unsigned char hi, lo;
+ 
+ 		JISx0201TO0208_SJIS((unsigned char)ch, &hi, &lo);
+ 		ch = (int)lo;
+ 		if (LYLineEdit(&MyEdit, hi, FALSE) != 0) {
+ 		    break;
+ 		}
+ 		refresh = FALSE;
+ 	    }
+ 	    if (LYLineEdit(&MyEdit, ch, FALSE) == 0) {
+ 		if (refresh && HTCJK != NOCJK && (0x81 <= ch) && (ch <= 0xfe))
+ 		    refresh = FALSE;
+ 		else
+ 		    refresh = TRUE;
+ 	    } else {
+ 		if (!refresh) {
+ 		    LYEdit1(&MyEdit, 0, LYE_DELP, FALSE);
+ 		    refresh = TRUE;
+ 		}
+ 	    }
+ #endif /* SUPPORT_MULTIBYTE_EDIT */
          }
      }
  }
