*** lynx2-7-1/src/GridText.c.orig	Sat Aug 16 13:50:27 1997
--- lynx2-7-1/src/GridText.c	Fri Aug 29 16:46:37 1997
***************
*** 2052,2058 ****
  		/*
  		 *  JIS X0201 Kana in SJIS support. - by ASATAKU
  		 */
! 	        if ((text->kcode == SJIS) &&
  		    ((unsigned char)ch >= 0xA1) &&
  		    ((unsigned char)ch <= 0xDF)) {
  		    unsigned char c = (unsigned char)ch;
--- 2052,2059 ----
  		/*
  		 *  JIS X0201 Kana in SJIS support. - by ASATAKU
  		 */
! 	        if (((text->kcode == SJIS) ||
! 		     (text->kcode == NOKANJI) && (text->in_sjis)) &&
  		    ((unsigned char)ch >= 0xA1) &&
  		    ((unsigned char)ch <= 0xDF)) {
  		    unsigned char c = (unsigned char)ch;
***************
*** 7490,7493 ****
--- 7491,7507 ----
       *  or other directives not to use a cached rendition. - FM
       */
      return(FALSE);
+ }
+ 
+ PUBLIC HTkcode HText_getKcode ARGS1(
+ 	HText *, 	text)
+ {
+       return text->kcode;
+ }
+ 
+ PUBLIC void HText_updateKcode ARGS2(
+ 	HText *,	text,
+ 	HTkcode,	kcode)
+ {
+       text->kcode = kcode;
  }
*** lynx2-7-1/src/GridText.h.orig	Sun Aug 10 00:49:00 1997
--- lynx2-7-1/src/GridText.h	Fri Aug 29 16:46:37 1997
***************
*** 10,15 ****
--- 10,19 ----
  #include "HTForms.h"
  #endif /* HTFORMS_H */
  
+ #ifndef HTCJK_H
+ #include "HTCJK.h"
+ #endif /* HTCJK_H */
+ 
  #define LY_UNDERLINE_START_CHAR	'\003'
  #define LY_UNDERLINE_END_CHAR	'\004'
  #define LY_BOLD_START_CHAR	'\005'
***************
*** 189,193 ****
--- 193,200 ----
  extern BOOL HText_AreDifferent PARAMS((
  	HTParentAnchor *	anchor,
  	CONST char *		full_address));
+ 
+ extern HTkcode HText_getKcode PARAMS((HText *text));
+ extern void HText_updateKcode PARAMS((HText *text, HTkcode kcode));
  
  #endif /* LYGRIDTEXT_H */
*** lynx2-7-1/src/HTML.c.orig	Sat Aug 16 13:50:27 1997
--- lynx2-7-1/src/HTML.c	Sun Aug 31 16:52:20 1997
***************
*** 68,73 ****
--- 68,74 ----
  
  extern BOOL HTPassEightBitRaw;
  extern HTCJKlang HTCJK;
+ extern HTkcode kanji_code;
  
  extern BOOLEAN HT_Is_Gopher_URL;
  
***************
*** 4276,4281 ****
--- 4277,4283 ----
  	    BOOL UseALTasVALUE = FALSE;
  	    BOOL HaveSRClink = FALSE;
  	    BOOL IsSubmitOrReset = FALSE;
+ 	    HTkcode kcode;
  
  	    /* init */
  	    I.align=NULL; I.accept=NULL; I.checked=NO; I.class=NULL;
***************
*** 4653,4658 ****
--- 4655,4664 ----
  		for (; chars > 0; chars--)
  		    HTML_put_character(me, '_');
  	    } else {
+ 		if (HTCJK != NOCJK) {
+ 		    kcode = HText_getKcode(me->text);
+ 		    HText_updateKcode(me->text, kanji_code);
+ 		}
  		if (me->sp[0].tag_number == HTML_PRE ||
  		    !me->sp->style->freeFormat) {
  		    /*
***************
*** 4692,4697 ****
--- 4698,4705 ----
  		    while (i < chars)
  			HTML_put_character(me, HT_NON_BREAK_SPACE);
  		}
+ 		if (HTCJK != NOCJK)
+ 		    HText_updateKcode(me->text, kcode);
  	    }
  	    HText_setIgnoreExcess(me->text, FALSE);
  	}
***************
*** 4733,4740 ****
  
  	if (present && present[HTML_TEXTAREA_COLS] &&
  	    value[HTML_TEXTAREA_COLS] &&
! 	    isdigit((unsigned char)*value[HTML_TEXTAREA_COLS]))  
! 	    StrAllocCopy(me->textarea_cols, value[HTML_TEXTAREA_COLS]);
  	else
  	    StrAllocCopy(me->textarea_cols, "60");
  
--- 4741,4755 ----
  
  	if (present && present[HTML_TEXTAREA_COLS] &&
  	    value[HTML_TEXTAREA_COLS] &&
! 	    isdigit((unsigned char)*value[HTML_TEXTAREA_COLS])) {
! 		int tmp = atoi(value[HTML_TEXTAREA_COLS]);
! 
! 		if (tmp > 70)
! 		    StrAllocCopy(me->textarea_cols, "70");
! 		else
! 	    	    StrAllocCopy(me->textarea_cols, value[HTML_TEXTAREA_COLS]);
! 	    }
! 	    /* StrAllocCopy(me->textarea_cols, value[HTML_TEXTAREA_COLS]); */
  	else
  	    StrAllocCopy(me->textarea_cols, "60");
  
***************
*** 6488,6493 ****
--- 6503,6510 ----
      case HTML_SELECT:
  	{
  	    char *ptr;
+ 	    HTkcode kcode;
+ 
  	    if (!me->text)
  	        UPDATE_STYLE;
  
***************
*** 6562,6567 ****
--- 6579,6588 ----
  		 *  Output popup box with the default option to screen,
  		 *  but use non-breaking spaces for output.
  		 */
+ 		if (HTCJK != NOCJK) {
+ 		    kcode = HText_getKcode(me->text);
+ 		    HText_updateKcode(me->text, kanji_code);
+ 		}
  	        if (ptr &&
  		    (me->sp[0].tag_number == HTML_PRE || me->inPRE == TRUE ||
  		     !me->sp->style->freeFormat) &&
***************
*** 6589,6594 ****
--- 6610,6617 ----
  	        /*
  		 *  Add end option character.
  		 */
+ 		if (HTCJK != NOCJK)
+ 		    HText_updateKcode(me->text, kcode);
  	        HText_appendCharacter(me->text, ']');
  		HText_setLastChar(me->text, ']');
  		me->in_word = YES;
*** lynx2-7-1/src/LYBookmark.c.orig	Mon Jul 21 09:09:21 1997
--- lynx2-7-1/src/LYBookmark.c	Fri Aug 29 16:48:07 1997
***************
*** 11,16 ****
--- 11,17 ----
  #include "LYCharUtils.h"
  #include "LYCurses.h"
  #include "GridText.h"
+ #include "HTCJK.h"
  
  #ifdef DOSPATH
  #include "HTDOS.h"
***************
*** 28,33 ****
--- 29,37 ----
  PRIVATE BOOLEAN is_mosaic_hotlist=FALSE;
  PRIVATE char * convert_mosaic_bookmark_file PARAMS((char *filename_buffer));
  
+ extern HTkcode kanji_code;
+ extern HTCJKlang HTCJK;
+ 
  /*
   *  Tries to open a bookmark file for reading, which may be
   *  the default, or based on offering the user a choice from
***************
*** 225,230 ****
--- 229,235 ----
      char *bookmark_URL = NULL;
      char filename_buffer[256];
      char string_buffer[256];
+     char tmp_buffer[512];
      char *Address = NULL;
      char *Title = NULL;
      int i, c;
***************
*** 294,300 ****
       *  Allow user to change the title. - FM
       */
      string_buffer[255] = '\0';
!     LYstrncpy(string_buffer, title, 255);
      convert_to_spaces(string_buffer, FALSE);
      LYMBM_statusline(TITLE_PROMPT);
      LYgetstr(string_buffer, VISIBLE, sizeof(string_buffer), NORECALL);
--- 299,319 ----
       *  Allow user to change the title. - FM
       */
      string_buffer[255] = '\0';
!     if (HTCJK == JAPANESE) {
! 	switch(kanji_code) {
! 	case EUC:
! 	    TO_EUC(title, tmp_buffer);
! 	    break;
! 	case SJIS:
! 	    TO_SJIS(title, tmp_buffer);
! 	    break;
! 	default:
! 	    break;
! 	}
! 	LYstrncpy(string_buffer, tmp_buffer, 255);
!     } else {
! 	LYstrncpy(string_buffer, title, 255);
!     }
      convert_to_spaces(string_buffer, FALSE);
      LYMBM_statusline(TITLE_PROMPT);
      LYgetstr(string_buffer, VISIBLE, sizeof(string_buffer), NORECALL);
***************
*** 310,316 ****
       *  converted to &lt; entities and any ampersands
       *  converted to &amp; entities.  - FM
       */
!     StrAllocCopy(Title, string_buffer);
      LYEntify(&Title, TRUE);
  
      /*
--- 329,340 ----
       *  converted to &lt; entities and any ampersands
       *  converted to &amp; entities.  - FM
       */
!     if (HTCJK == JAPANESE) {
! 	TO_JIS(string_buffer, tmp_buffer);
! 	StrAllocCopy(Title, tmp_buffer);
!     } else {
!         StrAllocCopy(Title, string_buffer);
!     }
      LYEntify(&Title, TRUE);
  
      /*
***************
*** 347,353 ****
      if (first_time) {
  	fprintf(fp,"<head>\n");
  #ifdef EXP_CHARTRANS
! 	LYAddMETAcharsetToFD(fp, -1);
  #endif
  	fprintf(fp,"<title>%s</title>\n</head>\n",BOOKMARK_TITLE);
  	fprintf(fp,"\
--- 371,382 ----
      if (first_time) {
  	fprintf(fp,"<head>\n");
  #ifdef EXP_CHARTRANS
!  	if (HTCJK != JAPANESE)
!  	    LYAddMETAcharsetToFD(fp, -1);
!  	else
!  	    fprintf(fp, "<META %s %s>\n",
!  			"http-equiv=\"content-type\"",
!  			"conetnt=\"text/html;charset=iso-2022-jp\""); 
  #endif
  	fprintf(fp,"<title>%s</title>\n</head>\n",BOOKMARK_TITLE);
  	fprintf(fp,"\
*** lynx2-7-1/src/LYCharUtils.c.orig	Fri Aug 22 15:01:02 1997
--- lynx2-7-1/src/LYCharUtils.c	Fri Aug 29 16:46:40 1997
***************
*** 77,82 ****
--- 77,86 ----
      char *p = *str;
      char *q = NULL, *cp = NULL;
      int amps = 0, lts = 0, gts = 0;
+     enum _state
+         { S_text, S_esc, S_dollar, S_paren,
+           S_nonascii_text, S_dollar_paren } state = S_text;
+     int in_sjis = 0;
      
      if (p == NULL || *p == '\0')
          return;
***************
*** 125,130 ****
--- 129,214 ----
      if ((cp = q) == NULL)
          outofmem(__FILE__, "LYEntify");
      for (p = *str; *p; p++) {
+ 	if (HTCJK != NOCJK) {
+ 	    switch(state) {
+ 		case S_text:
+ 		    if (*p == '\033') {
+ 			state = S_esc;
+ 			*q++ = *p;
+ 			continue;
+                     }
+                     break;
+ 
+ 		case S_esc:
+ 		    if (*p == '$') {
+ 			state = S_dollar;
+ 			*q++ = *p;
+ 			continue;
+ 		    } else if (*p == '(') {
+ 			state = S_paren;
+ 			*q++ = *p;
+ 			continue;
+ 		    } else {
+ 			state = S_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    }
+ 
+ 		case S_dollar:
+ 		    if (*p == '@' || *p == 'B' || *p == 'A') {
+ 			state = S_nonascii_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    } else if (*p == '(') {
+ 			state = S_dollar_paren;
+ 			*q++ = *p;
+ 			continue;
+ 		    } else {
+ 			state = S_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    }
+ 
+ 		case S_dollar_paren:
+ 		    if (*p == 'C') {
+ 			state = S_nonascii_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    } else {
+ 			state = S_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    }
+ 
+ 		case S_paren:
+ 		    if (*p == 'B' || *p == 'J' || *p =='T') {
+ 			state = S_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    } else if (*p == 'I') {
+ 			state = S_nonascii_text;
+ 			*q++ = *p;
+ 			continue;
+ 		    }
+ 
+ 		case S_nonascii_text:
+ 		    if (*p == '\033') 
+ 			state = S_esc;
+ 		    *q++ = *p;
+ 		    continue;
+ 
+ 		default:
+ 		    break;
+ 	    }
+ 	    if (*(p+1) != '\0' &&
+ 		(IS_EUC((unsigned char)*p, (unsigned char)*(p+1)) ||
+ 		 IS_SJIS((unsigned char)*p, (unsigned char)*(p+1), in_sjis) ||
+ 		 IS_BIG5((unsigned char)*p, (unsigned char)*(p+1)))) {
+ 		*q++ = *p++;
+ 		*q++ = *p;
+ 		continue;
+ 	    }
+ 	}
      	if (*p == '&') {
  	    *q++ = '&';
  	    *q++ = 'a';
***************
*** 145,150 ****
--- 229,235 ----
  	    *q++ = *p;
  	}
      }
+     *q = '\0';
      StrAllocCopy(*str, cp);
      FREE(cp);
  }
***************
*** 2524,2529 ****
--- 2609,2615 ----
  	 *  Handle end tag.
  	 */
  	char *ptr;
+ 	HTkcode kcode;
  	if (!me->text)
  	    UPDATE_STYLE;
  
***************
*** 2578,2583 ****
--- 2664,2673 ----
  	     *  Output popup box with the default option to screen,
  	     *  but use non-breaking spaces for output.
  	     */
+ 	    if (HTCJK != NOCJK) {
+ 	    	kcode = HText_getKcode(me->text);
+ 		HText_updateKcode(me->text, kanji_code);
+ 	    }
  	    if (ptr &&
  		me->sp[0].tag_number == HTML_PRE && strlen(ptr) > 6) {
  	        /*
***************
*** 2588,2599 ****
  		for (i = 0; i < 6; i++) {
  		    if (*ptr == ' ')
  	                HText_appendCharacter(me->text, HT_NON_BREAK_SPACE); 
! 		    else
  	    	        HText_appendCharacter(me->text, *ptr);
  		    ptr++;
  		}
  		HText_setIgnoreExcess(me->text, TRUE);
  	    }
  	    for (; ptr && *ptr != '\0'; ptr++) {
  		if (*ptr == ' ')
  	            HText_appendCharacter(me->text, HT_NON_BREAK_SPACE); 
--- 2678,2690 ----
  		for (i = 0; i < 6; i++) {
  		    if (*ptr == ' ')
  	                HText_appendCharacter(me->text, HT_NON_BREAK_SPACE); 
! 		    else 
  	    	        HText_appendCharacter(me->text, *ptr);
  		    ptr++;
  		}
  		HText_setIgnoreExcess(me->text, TRUE);
  	    }
+ 	    
  	    for (; ptr && *ptr != '\0'; ptr++) {
  		if (*ptr == ' ')
  	            HText_appendCharacter(me->text, HT_NON_BREAK_SPACE); 
***************
*** 2607,2612 ****
--- 2698,2705 ----
  	    HText_setLastChar(me->text, ']');
  	    me->in_word = YES;
  	    HText_setIgnoreExcess(me->text, FALSE); 
+ 	    if (HTCJK != NOCJK)
+ 	    	HText_updateKcode(me->text, kcode);
  	}
      	HTChunkClear(&me->option);
  
*** lynx2-7-1/WWW/Library/Implementation/SGML.c.orig	Fri Jul 25 14:30:57 1997
--- lynx2-7-1/WWW/Library/Implementation/SGML.c	Fri Aug 29 16:56:26 1997
***************
*** 96,101 ****
--- 96,104 ----
  		S_esc_dq, S_dollar_dq, S_paren_dq, S_nonascii_text_dq,
  		S_dollar_paren_dq,
  		S_in_kanji, S_junk_tag} state;
+     HTkcode			kcode;
+     unsigned char		kanji_buf;
+     int				in_sjis;
  #ifdef CALLERDATA
      void *			callerData;
  #endif /* CALLERDATA */
***************
*** 1136,1142 ****
--- 1139,1159 ----
      switch(context->state) {
  
      case S_in_kanji:
+ 	if (HTCJK == JAPANESE && context->kcode == NOKANJI) {
+ 	    unsigned char hi = context->kanji_buf;
+ 	    unsigned char lo = unsign_c;
+ 
+ 	    if (IS_SJIS(hi, lo, context->in_sjis) &&
+ 		IS_EUC(hi, lo)) {
+ 		context->kcode = NOKANJI;
+ 	    } else if (IS_SJIS(hi, lo, context->in_sjis)) {
+ 		context->kcode = SJIS;
+ 	    } else if (IS_EUC(hi, lo)) {
+ 		context->kcode = EUC;
+ 	    }
+ 	}
  	context->state = S_text;
+ 	context->kanji_buf = '\0';
  	PUTC(c);
  	break;
  
***************
*** 1146,1152 ****
  	    **  Setting up for Kanji multibyte handling (based on
  	    **  Takuya ASADA's (asada@three-a.co.jp) CJK Lynx). - FM
  	    */
! 	    context->state = S_in_kanji;
  	    PUTC(c);
  	    break;
  	} else if (HTCJK != NOCJK && c == '\033') {
--- 1163,1178 ----
  	    **  Setting up for Kanji multibyte handling (based on
  	    **  Takuya ASADA's (asada@three-a.co.jp) CJK Lynx). - FM
  	    */
! 	    if (HTCJK != NOCJK && unsign_c == 160) {
! 		PUTC(1);
! 		break;
! 	    }
! 	    if ((HTCJK != JAPANESE) ||
! 		(context->kcode != SJIS) ||
! 		(unsign_c < 161) || (unsign_c > 223)) {
! 	        context->state = S_in_kanji;
! 	        context->kanji_buf = unsign_c;
! 	    }
  	    PUTC(c);
  	    break;
  	} else if (HTCJK != NOCJK && c == '\033') {
***************
*** 2532,2537 ****
--- 2558,2566 ----
      context->actions = (HTStructuredClass*)(((HTStream*)target)->isa);
      					/* Ugh: no OO */
      context->state = S_text;
+     context->kcode = NOKANJI;
+     context->kanji_buf = '\0';
+     context->in_sjis = 0;
      context->element_stack = 0;			/* empty */
  #ifdef CALLERDATA		  
      context->callerData = (void*) callerData;
