lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev changes for Japanese (was: Re: reading SJIS docs)


From: Hataguchi Takeshi
Subject: Re: lynx-dev changes for Japanese (was: Re: reading SJIS docs)
Date: Sun, 16 Jan 2000 20:49:13 +0900 (JST)

On Thu, 13 Jan 2000, Klaus Weide wrote:

> On Thu, 13 Jan 2000, Hataguchi Takeshi wrote:
> 
> > On Wed, 12 Jan 2000, Henry Nelson wrote:
> > 
> > > > (1) If Japanese document's charset is specified explicitely
> > > >     by the MIME tag or HTTP responses, Lynx will assume the charset 
> > > >     as it.
> > > > (2) Change the Japanese charset detection strategy when chaset 
> > > >     isn't specified explicitely.
> > > > 
> > > > Please test these changes with CJK_EX and if necessary, with
> 
> Why should one *not* test these changes *without* CJK_EX?
> Lynx should strive to provide good CJK support without "EXtensions"
> being necessary.

I see. I didn't know how to consider CJK_EX.
I made my changes can be tested without CJK_EX.

> For example, I am willing to test some CJK things - as far as that is
> possible, without a real CJK environment (although I am even
> installing some Japanese fonts and terminal emulator now) - but I am

I greatly appreciate you are considering better CJK support.

I wrote a new patch from my two patches in these mail.
    lynx-dev changes for Japanese (was: Re: reading SJIS docs)
    Re: lynx-dev current_codepage in WIN_EX&&CJK_EX (was: Lynx .IDE file for 
Borland C ++)

The main changes are:

(1) If Japanese document's charset is specified explicitely
    by the MIME tag or HTTP responses, Lynx will assume the charset
    as it.

(2) Change the Japanese charset detection strategy when chaset
    isn't specified explicitely.

(3) wrap a long text which includes only CJK characters in source mode.

(4) avoid to write CJK characters at the 80th column.

(5) improve kanji code override routine
    # My change seemes to have broken this

(6) introduce new macro CONV_JISX0201KANA_TO_JISX0208KANA
    and ALLOW_KANJI_CODE_OVERRIDE.

(7) change the phrase "half width kana" to "JIS x0201 Kana" in comments.
    # The latter has been used originally.

# (1) and (2) are from the first mail. (3) and (4) are from the second mail.
# (5) to (7) are new.

The macros are:
    USE_TH_JP_AUTO_DETECT
        enable (2)

    CONV_JISX0201KANA_TO_JISX0208KANA
        convert JIS X0201 Kana to JIS X0208 Kana, 
        i.e. convert half width kana to full width.
        I've not tested the case not to define this well.

    ALLOW_KANJI_CODE_OVERRIDE
        enable kanji code override routine. 
        The code can be changed by ^L.
        More precisely, this enables us to change the assumption kanji
        code for the document. This assumption overrides the charaset
        by META tag and HTTP responses.

These changes can be tested without CJK_EX nor SH_EX.
I want the first two macros to be default and the last one not to be. 
For someone who likes half width kana, 
it may be good to define ALLOW_KANJI_CODE_OVERRIDE and not to define
CONV_JISX0201KANA_TO_JISX0208KANA, but this may be a little bit buggy.

I'm sorry these macro names seem to be too long. I don't have good 
naming sense.
--
Takeshi Hataguchi
E-mail: address@hidden

%%% Created Sun Jan 16 19:00:54 JST 2000 by target lynx.patch. %%%
diff -bru orig/lynx2-8-3/WWW/Library/Implementation/HTCJK.h 
lynx2-8-3/WWW/Library/Implementation/HTCJK.h
--- orig/lynx2-8-3/WWW/Library/Implementation/HTCJK.h   Sat Jul 31 00:39:54 1999
+++ lynx2-8-3/WWW/Library/Implementation/HTCJK.h        Sun Jan 16 15:13:28 2000
@@ -37,11 +37,21 @@
 #define IS_SJIS_HI1(hi) ((0x81<=hi)&&(hi<=0x9F))       /* 1st lev. */
 #define IS_SJIS_HI2(hi) ((0xE0<=hi)&&(hi<=0xEF))       /* 2nd lev. */
 #define IS_SJIS(hi,lo,in_sjis) 
(!IS_SJIS_LO(lo)?0:IS_SJIS_HI1(hi)?(in_sjis=1):in_sjis&&IS_SJIS_HI2(hi))
+#define IS_SJIS_2BYTE(hi,lo) 
(IS_SJIS_LO(lo)&&(IS_SJIS_HI1(hi)||IS_SJIS_HI2(hi)))
+#define IS_SJIS_X0201KANA(lo) ((0xA1<=lo)&&(lo<=0xDF))
 
+#if 0 /* IS_EUC_LOS isn't used because we are interested only in EUC-JP's
+       * code set 0 to 2 now. -- TH
+       * ref: http://www.isi.edu/in-notes/iana/assignments/character-sets
+       */
 #define IS_EUC_LOS(lo) ((0x21<=lo)&&(lo<=0x7E))        /* standard */
+#endif
 #define IS_EUC_LOX(lo) ((0xA1<=lo)&&(lo<=0xFE))        /* extended */
 #define IS_EUC_HI(hi)  ((0xA1<=hi)&&(hi<=0xFE))
-#define IS_EUC(hi,lo) (IS_EUC_HI(hi) && (IS_EUC_LOS(lo) || IS_EUC_LOX(lo)))
+#define IS_EUC_X0201KANA(hi,lo) ((hi==0x8E)&&(0xA1<=lo)&&(lo<=0xDF))
+#define IS_EUC(hi,lo) ((IS_EUC_HI(hi) && 
IS_EUC_LOX(lo))||IS_EUC_X0201KANA(hi,lo))
+
+#define IS_JAPANESE_2BYTE(hi,lo) (IS_SJIS_2BYTE(hi,lo) || IS_EUC(hi,lo))
 
 #define IS_BIG5_LOS(lo)        ((0x40<=lo)&&(lo<=0x7E))        /* standard */
 #define IS_BIG5_LOX(lo)        ((0xA1<=lo)&&(lo<=0xFE))        /* extended */
diff -bru orig/lynx2-8-3/WWW/Library/Implementation/SGML.c 
lynx2-8-3/WWW/Library/Implementation/SGML.c
--- orig/lynx2-8-3/WWW/Library/Implementation/SGML.c    Fri Jan  7 12:02:22 2000
+++ lynx2-8-3/WWW/Library/Implementation/SGML.c Sun Jan 16 17:14:56 2000
@@ -39,9 +39,11 @@
 # include <LYPrettySrc.h>
 #endif
 
+#ifdef 0
 #ifdef CJK_EX  /* 1997/12/12 (Fri) 16:54:58 */
 extern HTkcode last_kcode;
 #endif
+#endif
 
 #define INVALID (-1)
 
@@ -157,6 +159,7 @@
                S_esc_dq, S_dollar_dq, S_paren_dq, S_nonascii_text_dq,
                S_dollar_paren_dq,
                S_in_kanji, S_junk_tag, S_junk_pi} state;
+    unsigned char kanji_buf;
 #ifdef CALLERDATA
     void *                     callerData;
 #endif /* CALLERDATA */
@@ -1473,10 +1476,10 @@
     ** we can revert back to the unchanged c_in. - KW
     */
 #define unsign_c clong
-#ifdef CJK_EX  /* 1997/12/12 (Fri) 18:08:48 */
+#if 0
     static unsigned char sjis_1st = '\0';
-    unsigned char sjis_hi, sjis_lo;
 #endif
+    unsigned char sjis_hi, sjis_lo;
 
     c = c_in;
     clong = (unsigned char)c;  /* a.k.a. unsign_c */
@@ -1690,6 +1693,9 @@
        HTCJK == NOCJK)
        goto after_switch;
 
+#if 0  /* This JIS X0201 Kana to JIS X0208 Kana conversion is/should be
+        * done in the HTextAppendCharacter. -- TH
+        */
 #ifdef CJK_EX  /* 1998/11/24 (Tue) 17:02:31 */
     if (HTCJK == JAPANESE && last_kcode == SJIS) {
        if (sjis_1st == '\0' && (IS_SJIS_HI1(c) || IS_SJIS_HI2(c))) {
@@ -1708,6 +1714,7 @@
        }
     }
 #endif
+#endif
 
     /*
     ** Ignore 127 if we don't have HTPassHighCtrlRaw
@@ -1727,6 +1734,24 @@
        !(PASSHICTRL || HTCJK != NOCJK))
        goto after_switch;
 
+    /* Almost all CJK characters are double byte but only Japanese
+     * JIS X0201 Kana is single byte. To prevent to fail SGML parsing
+     * we have to care them here. -- TH
+     */
+    if ((HTCJK==JAPANESE) && (context->state==S_in_kanji) &&
+       !IS_JAPANESE_2BYTE(context->kanji_buf,(unsigned char)c)) {
+#ifdef CONV_JISX0201KANA_TO_JISX0208KANA
+       if (IS_SJIS_X0201KANA(context->kanji_buf)) {
+           JISx0201TO0208_SJIS(context->kanji_buf, &sjis_hi, &sjis_lo);
+           PUTC(sjis_hi);
+           PUTC(sjis_lo);
+       }
+       else
+#endif
+           PUTC(context->kanji_buf);
+       context->state = S_text;
+    }
+
     /*
     ** Handle character based on context->state.
     */
@@ -1744,6 +1769,7 @@
        **  (see below). - FM
        */
        context->state = S_text;
+       PUTC(context->kanji_buf);
        PUTC(c);
        break;
 
@@ -1772,7 +1798,7 @@
            **  to having raw mode off with CJK. - FM
            */
            context->state = S_in_kanji;
-           PUTC(c);
+           context->kanji_buf = c;
            break;
        } else if (HTCJK != NOCJK && TOASCII(c) == '\033') {  /* S/390 -- gil 
-- 0881 */
            /*
@@ -4097,6 +4123,8 @@
            context->state = S_esc;
        }
        PUTC(c);
+       if (c < 32)
+           context->state = S_text;
        break;
 
     case S_esc_sq:     /* Expecting '$'or '(' following CJK ESC. */
@@ -4383,6 +4411,7 @@
 /*    context->extra_tags = dtd->tags + dtd->number_of_tags; */
     context->current_tag = context->slashedtag = NULL;
     context->state = S_text;
+    context->kanji_buf = '\0';
     context->element_stack = 0;                        /* empty */
     context->inSELECT = FALSE;
     context->no_lynx_specialcodes = NO;        /* special codes normally 
generated */
diff -bru orig/lynx2-8-3/src/GridText.c lynx2-8-3/src/GridText.c
--- orig/lynx2-8-3/src/GridText.c       Fri Jan  7 12:02:22 2000
+++ lynx2-8-3/src/GridText.c    Sun Jan 16 18:57:58 2000
@@ -100,8 +100,10 @@
 extern BOOL HTPassHighCtrlRaw;
 extern HTCJKlang HTCJK;
 
-#ifdef CJK_EX
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
 PUBLIC HTkcode last_kcode = NOKANJI;   /* 1997/11/14 (Fri) 09:09:26 */
+#endif
+#ifdef CJK_EX
 #define CHAR_WIDTH 6
 #else
 #define CHAR_WIDTH 1
@@ -386,6 +388,16 @@
        STable_info *           stbl;
 
        HTkcode                 kcode;                  /* Kanji code? */
+       HTkcode                 specified_kcode;        /* Specified Kanji code 
*/
+#ifdef USE_TH_JP_AUTO_DETECT
+       enum _detected_kcode  { DET_SJIS, DET_EUC, DET_NOTYET, DET_MIXED } 
+                               detected_kcode;         /* Detected Kanji code 
*/
+       enum _SJIS_status     { SJIS_state_neutral, SJIS_state_in_kanji, 
+                               SJIS_state_has_bad_code } SJIS_status;
+       enum _EUC_status      { EUC_state_neutral, EUC_state_in_kanji, 
+                               EUC_state_in_kana, EUC_state_has_bad_code } 
+                               EUC_status;
+#endif
        enum grid_state       { S_text, S_esc, S_dollar, S_paren,
                                S_nonascii_text, S_dollar_paren,
                                S_jisx0201_text }
@@ -824,6 +836,12 @@
     HTMainAnchor = anchor;
     self->display_on_the_fly = 0;
     self->kcode = NOKANJI;
+    self->specified_kcode = NOKANJI;
+#ifdef USE_TH_JP_AUTO_DETECT
+    self->detected_kcode = DET_NOTYET;
+    self->SJIS_status = SJIS_state_neutral;
+    self->EUC_status = EUC_state_neutral;
+#endif
     self->state = S_text;
     self->kanji_buf = '\0';
     self->in_sjis = 0;
@@ -1342,11 +1360,19 @@
                    buffer[1] = '\0';
                    data += utf_extra;
                    utf_extra = 0;
+#ifdef CONV_JISX0201KANA_TO_JISX0208KANA
                } else if (HTCJK != NOCJK && !isascii((unsigned 
char)buffer[0])) {
+#else
+               } else if (HTCJK != NOCJK && !isascii((unsigned char)buffer[0]) 
&&
+                          kanji_code != SJIS) {
+#endif
                    /*
                     *  For CJK strings, by Masanobu Kimura.
                     */
+                   if (i >= LYcols) goto after_while;
+
                    buffer[1] = *data;
+                   buffer[2] = '\0';
                    data++;
                    i++;
                    addstr(buffer);
@@ -1379,6 +1405,7 @@
        } /* end of switch */
     } /* end of while */
 
+after_while:
 #if !defined(NCURSES_VERSION)
     if (text->has_utf8) {
        LYtouchline(scrline);
@@ -1515,7 +1542,7 @@
     }
     move(0, 0);
     clrtoeol();
-#if defined(CJK_EX) && defined(SH_EX)
+#if defined(SH_EX) && defined(ALLOW_KANJI_CODE_OVERRIDE)
     addstr(str_kcode(last_kcode));
 #endif
     if (text->top_of_screen > 0 && HText_hasToolbar(text)) {
@@ -3498,6 +3525,100 @@
        text->halted = 3;
        return;
     }
+#ifdef USE_TH_JP_AUTO_DETECT
+    if ((HTCJK == JAPANESE) && (text->detected_kcode != DET_MIXED) &&
+       (text->specified_kcode != SJIS) && (text->specified_kcode != EUC)) {
+       unsigned char c;
+       int save_d_kcode;
+
+       c = ch;
+       save_d_kcode = text->detected_kcode;
+       switch (text->SJIS_status) {
+       case SJIS_state_has_bad_code:
+           break;
+       case SJIS_state_neutral:
+           if (IS_SJIS_HI1(c) || IS_SJIS_HI2(c)) {
+               text->SJIS_status = SJIS_state_in_kanji;
+           }
+           else if ((c & 0x80) && !IS_SJIS_X0201KANA(c)) {
+               text->SJIS_status = SJIS_state_has_bad_code;
+               if (text->EUC_status == EUC_state_has_bad_code)
+                   text->detected_kcode = DET_MIXED;
+               else
+                   text->detected_kcode = DET_EUC;
+           }
+           break;
+       case SJIS_state_in_kanji:
+           if (IS_SJIS_LO(c)) {
+               text->SJIS_status = SJIS_state_neutral;
+           }
+           else {
+               text->SJIS_status = SJIS_state_has_bad_code;
+               if (text->EUC_status == EUC_state_has_bad_code)
+                   text->detected_kcode = DET_MIXED;
+               else
+                   text->detected_kcode = DET_EUC;
+           }
+           break;
+       }
+       switch (text->EUC_status) {
+       case EUC_state_has_bad_code:
+           break;
+       case EUC_state_neutral:
+           if (IS_EUC_HI(c)) {
+               text->EUC_status = EUC_state_in_kanji;
+           }
+           else if (c == 0x8e) {
+               text->EUC_status = EUC_state_in_kana;
+           }
+           else if (c & 0x80) {
+               text->EUC_status = EUC_state_has_bad_code;
+               if (text->SJIS_status == SJIS_state_has_bad_code)
+                   text->detected_kcode = DET_MIXED;
+               else
+                   text->detected_kcode = DET_SJIS;
+           }
+           break;
+       case EUC_state_in_kanji:
+           if (IS_EUC_LOX(c)) {
+               text->EUC_status = EUC_state_neutral;
+           }
+           else {
+               text->EUC_status = EUC_state_has_bad_code;
+               if (text->SJIS_status == SJIS_state_has_bad_code)
+                   text->detected_kcode = DET_MIXED;
+               else
+                   text->detected_kcode = DET_SJIS;
+           }
+           break;
+       case EUC_state_in_kana:
+           if ((0xA1<=c)&&(c<=0xDF)) {
+               text->EUC_status = EUC_state_neutral;
+           }
+           else {
+               text->EUC_status = EUC_state_has_bad_code;
+               if (text->SJIS_status == SJIS_state_has_bad_code)
+                   text->detected_kcode = DET_MIXED;
+               else
+                   text->detected_kcode = DET_SJIS;
+           }
+           break;
+       }
+       if (save_d_kcode != text->detected_kcode) {
+           switch (text->detected_kcode) {
+           case DET_SJIS:
+               CTRACE((tfp, "TH_JP_AUTO_DETECT: This document's kcode seems 
SJIS.\n"));
+               break;
+           case DET_EUC:
+               CTRACE((tfp, "TH_JP_AUTO_DETECT: This document's kcode seems 
EUC.\n"));
+               break;
+           case DET_MIXED:
+               CTRACE((tfp, "TH_JP_AUTO_DETECT: This document's kcode seems 
mixed!\n"));
+               break;
+           }
+       }
+    }
+#endif /* USE_TH_JP_AUTO_DETECT */
     /*
      *  Make sure we don't hang on escape sequences.
      */
@@ -3567,6 +3688,8 @@
                 */
                if (ch == '@' || ch == 'B' || ch=='A') {
                    text->state = S_nonascii_text;
+                   if (ch == '@' || ch == 'B')
+                       text->kcode = JIS;
                    return;
                } else if (ch == '(') {
                    text->state = S_dollar_paren;
@@ -3605,6 +3728,7 @@
                     *  Can split here. - FM
                     */
                    text->permissible_split = text->last_line->size;
+                   text->kcode = JIS;
                    return;
                } else {
                    text->state = S_text;
@@ -3618,7 +3742,16 @@
                if (ch == CH_ESC) {  /* S/390 -- gil -- 1553 */
                    text->state = S_esc;
                    text->kanji_buf = '\0';
+                   if (HTCJK == JAPANESE) {
+                       text->kcode = NOKANJI;
+                   }
                    return;
+               } else if ((0 <= ch) && (ch < 32)) {
+                   text->state = S_text;
+                   text->kanji_buf = '\0';
+                   if (HTCJK == JAPANESE) {
+                       text->kcode = NOKANJI;
+                   }
                } else {
                    ch |= 0200;
                }
@@ -3631,10 +3764,12 @@
                if (ch == CH_ESC) {  /* S/390 -- gil -- 1570 */
                    text->state = S_esc;
                    text->kanji_buf = '\0';
+                   text->kcode = NOKANJI;
                    return;
                } else {
                    text->kanji_buf = '\216';
                    ch |= 0200;
+#if 0 /* This conversion is done after. --TH */
 #ifdef SH_EX
                    /**** Add Next Line by patakuti ****/
                    text->permissible_split = (int)text->last_line->size;
@@ -3645,6 +3780,7 @@
                        ch = low;
                }
 #endif
+#endif
        }
                break;
        } /* end switch */
@@ -3654,10 +3790,25 @@
                /*
                 *  JIS X0201 Kana in SJIS support. - by ASATAKU
                 */
+               if ((text->kcode != JIS) && 
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
+                   ((last_kcode == SJIS) ||
+                    ((last_kcode == NOKANJI) &&
+#else
+                   ((
+#endif
+                     ((text->kcode == SJIS) || 
+#ifdef USE_TH_JP_AUTO_DETECT
+                      (text->detected_kcode == DET_SJIS) ||
+#endif
+                      ((text->kcode == NOKANJI) && (text->specified_kcode == 
SJIS))))) &&
+#if 0
                if ((text->kcode == SJIS) &&
+#endif
                    ((unsigned char)ch >= 0xA1) &&
                    ((unsigned char)ch <= 0xDF))
                {
+#ifdef CONV_JISX0201KANA_TO_JISX0208KANA
                    unsigned char c = (unsigned char)ch;
                    unsigned char kb = (unsigned char)text->kanji_buf;
                    JISx0201TO0208_SJIS(c,
@@ -3665,6 +3816,7 @@
                                        (unsigned char *)&c);
                    ch = (char)c;
                    text->kanji_buf = kb;
+#endif
                    /* 1998/01/19 (Mon) 09:06:15 */
                    text->permissible_split = (int)text->last_line->size;
                } else {
@@ -3677,7 +3829,7 @@
                }
            }
        } else {
-           goto check_IgnoreExcess;
+           goto check_WrapSource;
        }
     } else if (ch == CH_ESC) {  /* S/390 -- gil -- 1587 */
        return;
@@ -3952,20 +4104,33 @@
        }
        return;
     } /* if tab */
-    else if ( (text->source || dont_wrap_pre) && text == HTMainText) {
+
+check_WrapSource:
+    if ( (text->source || dont_wrap_pre) && text == HTMainText) {
        /*
         * If we're displaying document source, wrap long lines to keep all of
         * the source visible.
         */
        int target = (int)(line->offset + line->size) - ctrl_chars_on_this_line;
        int target_cu = target + utfxtra_on_this_line;
-       if (target >= (LYcols-1) - style->rightIndent ||
+       if (target >= (LYcols-1) - style->rightIndent - 
+           (((HTCJK != NOCJK) && text->kanji_buf) ? 1 : 0) ||
            (text->T.output_utf8 &&
             target_cu + UTF_XLEN(ch) >= (LYcols_cu-1))
            ) {
+           int saved_kanji_buf;
+           int saved_state;
+
            new_line(text);
            line = text->last_line;
+
+           saved_kanji_buf = text->kanji_buf;
+           saved_state = text->state;
+           text->kanji_buf = '\0';
+           text->state = S_text;
            HText_appendCharacter (text, LY_SOFT_NEWLINE);
+           text->kanji_buf = saved_kanji_buf;
+           text->state = saved_state;
        }
     }
 
@@ -3998,6 +4163,7 @@
      */
     if (((indent + (int)line->offset + (int)line->size) +
         (int)style->rightIndent - ctrl_chars_on_this_line +
+        (((HTCJK != NOCJK) && text->kanji_buf) ? 1 : 0) +
         ((line->size > 0) &&
          (int)(line->data[line->size-1] ==
                                LY_SOFT_HYPHEN ?
@@ -4078,12 +4244,40 @@
 
        line = text->last_line; /* May have changed */
 
-#ifdef CJK_EX  /* 1997/11/14 (Fri) 09:10:03 */
        if (HTCJK != NOCJK && text->kanji_buf) {
            hi = (unsigned char)text->kanji_buf;
            lo = (unsigned char)ch;
 
            if (HTCJK == JAPANESE) {
+               if (text->kcode != JIS) {
+                   if (IS_SJIS_2BYTE(hi, lo)) {
+                       if (IS_EUC(hi, lo)) {
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
+                           if (last_kcode != NOKANJI)
+                               text->kcode = last_kcode;
+                           else
+#endif
+                               if (text->specified_kcode != NOKANJI)
+                                   text->kcode = text->specified_kcode;
+#ifdef USE_TH_JP_AUTO_DETECT
+                               else if (text->detected_kcode == DET_EUC)
+                                   text->kcode = EUC;
+                               else if (text->detected_kcode == DET_SJIS)
+                                   text->kcode = SJIS;
+#endif
+                               else if (IS_EUC_X0201KANA(hi, lo) && 
(text->kcode != EUC))
+                                   text->kcode = SJIS;
+                       }
+                       else
+                           text->kcode = SJIS;
+                   }
+                   else if (IS_EUC(hi, lo))
+                       text->kcode = EUC;
+                   else
+                       text->kcode = NOKANJI;
+               }
+
+#if 0 /* This judgement routine is replaced by above one. -- TH */
                if (text->kcode == NOKANJI)
                {
                    if (IS_SJIS(hi, lo, text->in_sjis) && IS_EUC(hi, lo)) {
@@ -4094,6 +4288,7 @@
                        text->kcode = EUC;
                    }
                }
+#endif
 
                switch (kanji_code) {
                case EUC:
@@ -4101,37 +4296,39 @@
                        SJIS_TO_EUC1(hi, lo, tmp);
                        line->data[line->size++] = tmp[0];
                        line->data[line->size++] = tmp[1];
-                   } else if (text->kcode == EUC) {
+                   } else if (IS_EUC(hi, lo)) {
+#ifdef CONV_JISX0201KANA_TO_JISX0208KANA
                        JISx0201TO0208_EUC(hi, lo, &hi, &lo);
+#endif
                        line->data[line->size++] = hi;
                        line->data[line->size++] = lo;
+                   } else {
+                       CTRACE((tfp, "This character (%X:%X) doesn't seem 
Japanese\n", hi, lo));
+                       line->data[line->size++] = '=';
+                       line->data[line->size++] = '=';
                    }
                    break;
 
                case SJIS:
-                   if (last_kcode != SJIS && text->kcode == EUC)
+                   if ((text->kcode == EUC) || (text->kcode == JIS))
+                   {
+#ifndef CONV_JISX0201KANA_TO_JISX0208KANA
+                       if (IS_EUC_X0201KANA(hi, lo))
+                           line->data[line->size++] = lo;
+                       else
+#endif
                    {
                        EUC_TO_SJIS1(hi, lo, tmp);
                        line->data[line->size++] = tmp[0];
                        line->data[line->size++] = tmp[1];
-                   } else {
-                       /* text->kcode == (SJIS or NOKANJI) */
-#ifdef CJK_EX  /* 1998/01/20 (Tue) 16:46:34 */
-                       if (last_kcode == EUC) {
-                           if (lo == 0) {      /* BAD EUC code */
-                               hi = '=';
-                               lo = '=';
-                           } else if (hi == 0x8e) {
-                               text->kcode = NOKANJI;
-                               JISx0201TO0208_EUC(hi, lo, &hi, &lo);
-                               EUC_TO_SJIS1(hi, lo, tmp);
-                               hi = tmp[0];
-                               lo = tmp[1];
                            }
-                       }
-#endif
+                   } else if (IS_SJIS_2BYTE(hi, lo)) {
                        line->data[line->size++] = hi;
                        line->data[line->size++] = lo;
+                   } else {
+                       line->data[line->size++] = '=';
+                       line->data[line->size++] = '=';
+                       CTRACE((tfp, "This character (%X:%X) doesn't seem 
Japanese\n", hi, lo));
                    }
                    break;
 
@@ -4144,7 +4341,7 @@
            }
            text->kanji_buf = 0;
        }
-#else
+#if 0
        if (HTCJK != NOCJK && text->kanji_buf) {
            hi = (unsigned char)text->kanji_buf, lo = (unsigned char)ch;
            if (HTCJK == JAPANESE && text->kcode == NOKANJI) {
@@ -4163,7 +4360,9 @@
                line->data[line->size++] = tmp[1];
            } else if (HTCJK == JAPANESE &&
                       (kanji_code == EUC) && (text->kcode == EUC)) {
+#ifdef CONV_JISX0201KANA_TO_JISX0208KANA
                JISx0201TO0208_EUC(hi, lo, &hi, &lo);
+#endif
                line->data[line->size++] = hi;
                line->data[line->size++] = lo;
            } else if (HTCJK == JAPANESE &&
@@ -4178,6 +4377,13 @@
            text->kanji_buf = 0;
        }
 #endif
+#ifndef CONV_JISX0201KANA_TO_JISX0208KANA
+       else if ((HTCJK == JAPANESE) && IS_SJIS_X0201KANA((unsigned char)(ch)) 
&& 
+                (kanji_code == EUC)) {
+           line->data[line->size++] = 0x8e;
+           line->data[line->size++] = ch;
+       }
+#endif
        else if (HTCJK != NOCJK) {
            line->data[line->size++] = (char) (
                                       (kanji_code != NOKANJI) ?
@@ -11172,6 +11378,8 @@
        CONST char *,   charset,
        LYUCcharset *,  p_in)
 {
+    BOOL explicit;
+
     if (!text)
        return;
 
@@ -11181,6 +11389,7 @@
     if (!charset && !p_in) {
        return;
     }
+    explicit = charset ? TRUE : FALSE;
     /*
     **  If no explicit charset string, use the implied one. - kw
     */
@@ -11209,8 +11418,10 @@
               !strcmp(charset, "x-euc") ||     /* 1997/11/28 (Fri) 18:11:24 */
               !strcmp(charset, "euc-jp") ||
               !strncmp(charset, "x-euc-", 6) ||
+#if 0 /* iso-2022-jp* shouldn't be treated as euc-jp */
               !strcmp(charset, "iso-2022-jp") ||
               !strcmp(charset, "iso-2022-jp-2") ||
+#endif
               !strcmp(charset, "euc-kr") ||
               !strcmp(charset, "iso-2022-kr") ||
               !strcmp(charset, "big5") ||
@@ -11225,7 +11436,7 @@
        **  If we get to here, it's not CJK, so disable that if
        **  it is enabled.  But only if we are quite sure. - FM & kw
        */
-#ifdef CJK_EX
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
        last_kcode = text->kcode = NOKANJI;
 #else
        text->kcode = NOKANJI;
@@ -11235,6 +11446,7 @@
                HTCJK = NOCJK;
        }
     }
+    text->specified_kcode = explicit ? text->kcode : NOKANJI;
 
     return;
 }
@@ -13650,7 +13862,6 @@
 }
 #endif
 
-#ifdef CJK_EX
 PUBLIC HTkcode HText_getKcode ARGS1(
        HText *,        text)
 {
@@ -13663,7 +13874,19 @@
 {
     text->kcode = kcode;
 }
-#endif
+
+PUBLIC HTkcode HText_getSpecifiedKcode ARGS1(
+       HText *,        text)
+{
+    return text->specified_kcode;
+}
+
+PUBLIC void HText_updateSpecifiedKcode ARGS2(
+       HText *,        text,
+       HTkcode,        kcode)
+{
+    text->specified_kcode = kcode;
+}
 
 PUBLIC int HTMainText_Get_UCLYhndl NOARGS
 {
diff -bru orig/lynx2-8-3/src/GridText.h lynx2-8-3/src/GridText.h
--- orig/lynx2-8-3/src/GridText.h       Fri Jan  7 12:02:22 2000
+++ lynx2-8-3/src/GridText.h    Sun Jan 16 09:20:48 2000
@@ -310,14 +310,15 @@
 
 extern int HTMainText_Get_UCLYhndl NOPARAMS;
 
-#ifdef CJK_EX
-
 #include <HTCJK.h>
+
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
 extern HTkcode last_kcode;
+#endif
 
 extern HTkcode HText_getKcode PARAMS((HText * text));
 extern void HText_updateKcode PARAMS((HText * text, HTkcode kcode));
-
-#endif
+extern HTkcode HText_getSpecifiedKcode PARAMS((HText * text));
+extern void HText_updateSpecifiedKcode PARAMS((HText * text, HTkcode kcode));
 
 #endif /* LYGRIDTEXT_H */
diff -bru orig/lynx2-8-3/src/HTML.c lynx2-8-3/src/HTML.c
--- orig/lynx2-8-3/src/HTML.c   Fri Jan  7 12:02:22 2000
+++ lynx2-8-3/src/HTML.c        Sun Jan 16 09:32:12 2000
@@ -243,7 +243,7 @@
 */
 PUBLIC void HTML_put_character ARGS2(HTStructured *, me, char, c)
 {
-#ifdef CJK_EX
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
     static unsigned char save_ch1 = 0;
     static unsigned char save_ch2 = 0;
 #endif
@@ -427,7 +427,7 @@
            } else {
                me->inP = TRUE;
                me->inLABEL = FALSE;
-#ifdef CJK_EX
+#if 0 /* Should this check be done in HText_appendCharacter? */
                if (last_kcode == EUC) {
                    if (save_ch1 && !save_ch2) {
                        if ((unsigned char)c & 0x80) {
@@ -445,9 +445,8 @@
                } else {
                    HText_appendCharacter(me->text, c);
                }
-#else
-               HText_appendCharacter(me->text, c);
 #endif
+               HText_appendCharacter(me->text, c);
                me->in_word = YES;
            }
        }
@@ -4964,9 +4963,8 @@
            BOOL HaveSRClink = FALSE;
            char* ImageSrc = NULL;
            BOOL IsSubmitOrReset = FALSE;
-#ifdef CJK_EX
            HTkcode kcode = 0;
-#endif
+           HTkcode specified_kcode = 0;
            /* init */
            I.align=NULL; I.accept=NULL; I.checked=NO; I.class=NULL;
            I.disabled=NO; I.error=NULL; I.height= NULL; I.id=NULL;
@@ -5397,12 +5395,12 @@
                for (; chars > 0; chars--)
                    HTML_put_character(me, '_');
            } else {
-#ifdef CJK_EX
-               if (HTCJK != NOCJK) {
+               if (HTCJK == JAPANESE) {
                    kcode = HText_getKcode(me->text);
                    HText_updateKcode(me->text, kanji_code);
+                   specified_kcode = HText_getSpecifiedKcode(me->text);
+                   HText_updateSpecifiedKcode(me->text, kanji_code);
                }
-#endif
                if (me->sp[0].tag_number == HTML_PRE ||
                    !me->sp->style->freeFormat) {
                    /*
@@ -5442,10 +5440,10 @@
                    while (i < chars)
                        HTML_put_character(me, HT_NON_BREAK_SPACE);
                }
-#ifdef CJK_EX
-               if (HTCJK != NOCJK)
+               if (HTCJK == JAPANESE) {
                    HText_updateKcode(me->text, kcode);
-#endif
+                   HText_updateSpecifiedKcode(me->text, specified_kcode);
+               }
            }
            HText_setIgnoreExcess(me->text, FALSE);
            FREE(ImageSrc);
@@ -7551,8 +7549,21 @@
                for (; ptr && *ptr != '\0'; ptr++) {
                    if (*ptr == ' ')
                        HText_appendCharacter(me->text,HT_NON_BREAK_SPACE);
-                   else
+                   else {
+                       HTkcode kcode = 0;
+                       HTkcode specified_kcode = 0;
+                       if (HTCJK == JAPANESE) {
+                           kcode = HText_getKcode(me->text);
+                           HText_updateKcode(me->text, kanji_code);
+                           specified_kcode = HText_getSpecifiedKcode(me->text);
+                           HText_updateSpecifiedKcode(me->text, kanji_code);
+                       }
                        HText_appendCharacter(me->text,*ptr);
+                       if (HTCJK == JAPANESE) {
+                           HText_updateKcode(me->text, kcode);
+                           HText_updateSpecifiedKcode(me->text, 
specified_kcode);
+                       }
+                   }
                }
                /*
                 *  Add end option character.
@@ -8810,19 +8821,19 @@
 #ifdef SH_EX   /* 1998/04/02 (Thu) 16:02:00 */
 
     /* for proxy server 1998/12/19 (Sat) 11:53:30 */
-    if (stricmp(newtitle + 1, "internal-gopher-menu") == 0) {
+    if (AS_casecomp(newtitle + 1, "internal-gopher-menu") == 0) {
        StrAllocCopy(newtitle, "+");
-    } else if (stricmp(newtitle + 1, "internal-gopher-unknown") == 0) {
+    } else if (AS_casecomp(newtitle + 1, "internal-gopher-unknown") == 0) {
        StrAllocCopy(newtitle, " ");
     } else {
        /* normal title */
        ptr = strrchr(newtitle, '.');
        if (ptr) {
-         if (stricmp(ptr, ".gif") == 0)
+         if (AS_casecomp(ptr, ".gif") == 0)
            *ptr = '\0';
-         else if (stricmp(ptr, ".jpg") == 0)
+         else if (AS_casecomp(ptr, ".jpg") == 0)
            *ptr = '\0';
-         else if (stricmp(ptr, ".jpeg") == 0)
+         else if (AS_casecomp(ptr, ".jpeg") == 0)
            *ptr = '\0';
        }
        StrAllocCat(newtitle, "]");
diff -bru orig/lynx2-8-3/src/LYCharUtils.c lynx2-8-3/src/LYCharUtils.c
--- orig/lynx2-8-3/src/LYCharUtils.c    Wed Dec  1 12:33:02 1999
+++ lynx2-8-3/src/LYCharUtils.c Sun Jan 16 15:32:56 2000
@@ -1658,7 +1658,7 @@
     enum _parsing_what
        { P_text, P_utf8, P_hex, P_decimal, P_named
        } what = P_text;
-#ifdef CJK_EX  /* 1997/12/12 (Fri) 18:08:48 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
     static unsigned char sjis_1st = '\0';
     unsigned char sjis_str[3];
 #endif
@@ -1763,13 +1763,14 @@
        switch(state) {
        case S_text:
            code = (unsigned char)(*p);
-#ifdef CJK_EX  /* 1997/12/13 (Sat) 14:41:53 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
            if (HTCJK == JAPANESE && last_kcode == SJIS) {
                if (sjis_1st == '\0' && (IS_SJIS_HI1(code)||IS_SJIS_HI2(code))){
                    sjis_1st = (unsigned char)code;
                } else if (sjis_1st && IS_SJIS_LO(code)) {
                    sjis_1st = '\0';
                } else {
+#ifdef CONV_JISX0201KANA_TO_JISX0208KANA
                    if (0xA1 <= code && code <= 0xDF) {
                        sjis_str[2] = '\0';
                        JISx0201TO0208_SJIS((unsigned char)code,
@@ -1778,6 +1779,7 @@
                        p++;
                        continue;
                    }
+#endif
                }
            }
 #endif
diff -bru orig/lynx2-8-3/src/LYKeymap.c lynx2-8-3/src/LYKeymap.c
--- orig/lynx2-8-3/src/LYKeymap.c       Wed Dec  1 12:33:02 1999
+++ lynx2-8-3/src/LYKeymap.c    Sun Jan 16 17:26:22 2000
@@ -69,16 +69,20 @@
 LYK_HISTORY,    LYK_FASTFORW_LINK,  LYK_ACTIVATE,  LYK_COOKIE_JAR,
 /* bs */            /* ht */        /* nl */       /* ^K */
 
-#ifdef SH_EX   /* 1998/10/02 (Fri) 08:48:44 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
 LYK_CHG_KCODE,    LYK_ACTIVATE,     LYK_DOWN_TWO,      0,
 /* ^L */            /* cr */        /* ^N */       /* ^O */
 
-LYK_UP_TWO,       LYK_CHG_CENTER,   LYK_RELOAD,    LYK_TO_CLIPBOARD,
-/* ^P */            /* XON */       /* ^R */       /* ^S */
 #else
 LYK_REFRESH,      LYK_ACTIVATE,     LYK_DOWN_TWO,      0,
 /* ^L */            /* cr */        /* ^N */       /* ^O */
+#endif
+
+#ifdef SH_EX   /* 1998/10/02 (Fri) 08:48:44 */
+LYK_UP_TWO,       LYK_CHG_CENTER,   LYK_RELOAD,    LYK_TO_CLIPBOARD,
+/* ^P */            /* XON */       /* ^R */       /* ^S */
 
+#else
 LYK_UP_TWO,             0,          LYK_RELOAD,        0,
 /* ^P */            /* XON */       /* ^R */       /* XOFF */
 #endif
diff -bru orig/lynx2-8-3/src/LYKeymap.h lynx2-8-3/src/LYKeymap.h
--- orig/lynx2-8-3/src/LYKeymap.h       Wed Dec  1 12:33:02 1999
+++ lynx2-8-3/src/LYKeymap.h    Sun Jan 16 17:27:48 2000
@@ -228,9 +228,10 @@
 #ifdef SH_EX
   , LYK_CHG_CENTER
   , LYK_TO_CLIPBOARD
-  , LYK_CHG_KCODE
 #endif /* SH_EX */
-
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
+  , LYK_CHG_KCODE
+#endif
 } LYKeymapCode;
 
 
diff -bru orig/lynx2-8-3/src/LYMail.c lynx2-8-3/src/LYMail.c
--- orig/lynx2-8-3/src/LYMail.c Wed Sep 29 20:40:38 1999
+++ lynx2-8-3/src/LYMail.c      Sat Jan  8 20:45:20 2000
@@ -2048,7 +2048,7 @@
     while ((n = fread(buf, 1, sizeof(buf), fd)) != 0) {
        fwrite(buf, 1, n, fp);
     }
-#if defined(DOSPATH) || defined(SH_EX)
+#if defined(DOSPATH) || (defined(SH_EX) && defined(WIN_EX))
 #ifdef SH_EX   /* 1998/05/04 (Mon) 22:40:35 */
     if (mail_is_blat) {
        StrAllocCopy(command,
diff -bru orig/lynx2-8-3/src/LYMainLoop.c lynx2-8-3/src/LYMainLoop.c
--- orig/lynx2-8-3/src/LYMainLoop.c     Fri Jan  7 12:02:22 2000
+++ lynx2-8-3/src/LYMainLoop.c  Sun Jan 16 17:26:54 2000
@@ -39,11 +39,16 @@
 #include <LYMainLoop.h>
 #include <LYPrettySrc.h>
 
-#if defined(CJK_EX)    /* 1999/05/25 (Tue) 11:10:45 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
 #include <HTCJK.h>
 extern HTCJKlang HTCJK;
+#endif
+
+#if defined(CJK_EX)    /* 1999/05/25 (Tue) 11:10:45 */
 extern char *string_short(char *str, int cut_pos);     /* LYExtern.c */
+#endif
 
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
 PUBLIC char *str_kcode(HTkcode code)
 {
     char *p;
@@ -90,17 +95,21 @@
 
     return buff;
 }
+#endif
 
+#ifdef CJK_EX
 #ifdef WIN_EX
 
 PRIVATE char *str_sjis(char *to, char *from)
 {
     if (!LYRawMode) {
        strcpy(to, from);
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
     } else if (last_kcode == EUC) {
        EUC_TO_SJIS(from, to);
     } else if (last_kcode == SJIS) {
        strcpy(to, from);
+#endif
     } else {
        TO_SJIS(from, to);
     }
@@ -3173,7 +3182,7 @@
                }
 
        } else {
-#ifdef CJK_EX  /* 1997/12/13 (Sat) 15:20:18 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
            if (HTCJK == JAPANESE) {
                last_kcode = NOKANJI;   /* AUTO */
            }
@@ -4718,7 +4727,7 @@
                *refresh_screen = TRUE;
            return;
        }
-#if defined(CJK_EX)    /* 1997/12/13 (Sat) 15:20:18 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
        if (HTCJK == JAPANESE) {
            last_kcode = NOKANJI;       /* AUTO */
        }
@@ -6796,7 +6805,7 @@
            break;
 #endif
 
-#if defined(CJK_EX) && defined(SH_EX)  /* 1999/02/25 (Thu) 15:29:05 */
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
        case LYK_CHG_KCODE:     /* ^L */
            if (LYRawMode && (HTCJK == JAPANESE)) {
                switch(last_kcode) {
diff -bru orig/lynx2-8-3/src/LYUtils.c lynx2-8-3/src/LYUtils.c
--- orig/lynx2-8-3/src/LYUtils.c        Fri Jan  7 12:02:22 2000
+++ lynx2-8-3/src/LYUtils.c     Sun Jan 16 09:42:48 2000
@@ -1984,7 +1984,7 @@
        if (kanji_code == EUC) {
            TO_EUC((CONST unsigned char *)text_buff, temp);
        } else if (kanji_code == SJIS) {
-#ifdef CJK_EX
+#ifdef ALLOW_KANJI_CODE_OVERRIDE
            if (!LYRawMode || last_kcode == SJIS)
                strcpy(temp, text_buff);
            else
diff -bru orig/lynx2-8-3/src/UCdomap.c lynx2-8-3/src/UCdomap.c
--- orig/lynx2-8-3/src/UCdomap.c        Thu Nov  4 11:41:38 1999
+++ lynx2-8-3/src/UCdomap.c     Sat Jan  8 20:45:20 2000
@@ -1578,13 +1578,13 @@
     }
 #endif
 #if !NO_CHARSET_euc_jp
-    if (!strncasecomp(value, "iso-2022-jp", 11) ||
-       !strcasecomp(value, "x-euc-jp")) {
+    if (!strcasecomp(value, "x-euc-jp")) {
        return UCGetLYhndl_byMIME("euc-jp");
     }
 #endif
 #if !NO_CHARSET_shift_jis
-    if (!strcasecomp(value, "x-shift-jis")) {
+    if ((!strcasecomp(value, "x-shift-jis")) ||
+       (!strcasecomp(value, "x-sjis"))) {
        return UCGetLYhndl_byMIME("shift_jis");
     }
 #endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]