lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev UCdomap changes - patch


From: Klaus Weide
Subject: lynx-dev UCdomap changes - patch
Date: Mon, 23 Aug 1999 14:57:29 -0500 (CDT)

An alternative to Henry's patch for UCdomap.h.  Should remove the
behavior where translation of some strings in some display character sets
depended on browsing (and charset-changing) history.  This should (must?)
be used together with my previous patch (which changed LYCharUtils.c).
Table-less charsets don't get put into the UCInit[] list any more, in a
way this means reverting back to what was the case before Leonid's change.

There is a bit more code now, but otoh we don't need fake structures
that are mostly empty any more in UCdomap.h.  Lenonid and Henry, what
do you think?

Also an unrelated minor change to UCReverseTransChar
(simplification / check for an ulikely malloc error).

   Klaus

Index: lynx2-8-3/WWW/Library/Implementation/UCDefs.h
--- lynx2-8-3.old/WWW/Library/Implementation/UCDefs.h Fri, 04 Jun 1999 20:57:16 
-0500
+++ lynx2-8-3/WWW/Library/Implementation/UCDefs.h Sun, 22 Aug 1999 18:12:10 
-0500
@@ -12,7 +12,8 @@
 
     CONST char * MIMEname;
     int enc;
-    int codepage;      /* IBM OS/2 specific number */
+    int codepage;      /* if positive, an IBM OS/2 specific number;
+                          if negative, flag for no table translation */
 
     /* parameters below are not used by chartrans mechanism, */
     /* they describe some relationships against built-in Latin1 charset...*/
Index: lynx2-8-3/src/UCdomap.h
--- lynx2-8-3.old/src/UCdomap.h Fri, 04 Jun 1999 20:57:16 -0500
+++ lynx2-8-3/src/UCdomap.h Sun, 22 Aug 1999 19:38:46 -0500
@@ -79,35 +79,25 @@
    *  from Unicode mechanism).  For now we use the MIME name that describes
    *  what is output to the terminal. - KW
    */
-static CONST struct unimapdesc_str dfont_replacedesc_fallback = {0,NULL,0,1};
 
-#define UC_CHARSET_SETUP_euc_cn UC_Charset_Setup("euc-cn","Chinese",\
-       NULL,NULL,0,dfont_replacedesc_fallback,\
-       128,UCT_ENC_CJK,0)
-#define UC_CHARSET_SETUP_euc_jp UC_Charset_Setup("euc-jp","Japanese (EUC-JP)",\
-       NULL,NULL,0,dfont_replacedesc_fallback,\
-       128,UCT_ENC_CJK,0)
-#define UC_CHARSET_SETUP_shift_jis UC_Charset_Setup("shift_jis","Japanese 
(Shift_JIS)",\
-       NULL,NULL,0,dfont_replacedesc_fallback,\
-       128,UCT_ENC_CJK,0)
-#define UC_CHARSET_SETUP_euc_kr UC_Charset_Setup("euc-kr","Korean",\
-       NULL,NULL,0,dfont_replacedesc_fallback,\
-       128,UCT_ENC_CJK,0)
-#define UC_CHARSET_SETUP_big5 UC_Charset_Setup("big5","Taipei (Big5)",\
-       NULL,NULL,0,dfont_replacedesc_fallback,\
-       128,UCT_ENC_CJK,0)
+#define UC_CHARSET_SETUP_euc_cn UC_Charset_NoUctb_Setup("euc-cn","Chinese",\
+       1, 128,UCT_ENC_CJK,0)
+#define UC_CHARSET_SETUP_euc_jp UC_Charset_NoUctb_Setup("euc-jp","Japanese 
(EUC-JP)",\
+       1, 128,UCT_ENC_CJK,0)
+#define UC_CHARSET_SETUP_shift_jis 
UC_Charset_NoUctb_Setup("shift_jis","Japanese (Shift_JIS)",\
+       1, 128,UCT_ENC_CJK,0)
+#define UC_CHARSET_SETUP_euc_kr UC_Charset_NoUctb_Setup("euc-kr","Korean",\
+       1, 128,UCT_ENC_CJK,0)
+#define UC_CHARSET_SETUP_big5 UC_Charset_NoUctb_Setup("big5","Taipei (Big5)",\
+       1, 128,UCT_ENC_CJK,0)
   /*
    *  Placeholder for non-translation mode. - FM
    */
-#define UC_CHARSET_SETUP_x_transparent 
UC_Charset_Setup("x-transparent","Transparent",\
-       NULL,NULL,0,dfont_replacedesc_fallback,\
-       128,1,0)
+#define UC_CHARSET_SETUP_x_transparent 
UC_Charset_NoUctb_Setup("x-transparent","Transparent",\
+       1, 128,UCT_ENC_8BIT,0)
 
-static CONST struct unimapdesc_str dfont_replacedesc_NO_fallback = 
{0,NULL,0,0};
-
-#define UC_CHARSET_SETUP_utf_8 UC_Charset_Setup("utf-8","UNICODE (UTF-8)",\
-       NULL,NULL,0,dfont_replacedesc_NO_fallback,\
-       128,UCT_ENC_UTF8,0)
+#define UC_CHARSET_SETUP_utf_8 UC_Charset_NoUctb_Setup("utf-8","UNICODE 
(UTF-8)",\
+       0, 128,UCT_ENC_UTF8,-4)
 
 
 #endif /* UCDOMAP_H */
Index: lynx2-8-3/src/UCdomap.c
--- lynx2-8-3.old/src/UCdomap.c Fri, 04 Jun 1999 20:45:47 -0500
+++ lynx2-8-3/src/UCdomap.c Sun, 22 Aug 1999 19:38:43 -0500
@@ -1046,6 +1046,8 @@
     CONST u16 * ut;
 
     if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {
+       if (LYCharSet_UC[charset_out].codepage < 0)
+           return (unicode < 128) ? (int)unicode : 
LYCharSet_UC[charset_out].codepage;
        if ((UChndl_out = default_UChndl) < 0)
            return -12;
        isdefault = 1;
@@ -1100,6 +1102,8 @@
        return -13;
 
     if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {
+       if (LYCharSet_UC[charset_out].codepage < 0)
+           return LYCharSet_UC[charset_out].codepage;
        if ((UChndl_out = default_UChndl) < 0)
            return -12;
        isdefault = 1;
@@ -1231,6 +1235,8 @@
     if ((UChndl_in = LYCharSet_UC[charset_in].UChndl) < 0)
        return -11;
     if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {
+       if (LYCharSet_UC[charset_out].codepage < 0)
+           return LYCharSet_UC[charset_out].codepage;
        if ((UChndl_out = default_UChndl) < 0)
            return -12;
        isdefault = 1;
@@ -1322,7 +1328,7 @@
        int,            charset_out)
 {
     int Gn;
-    int rc;
+    int rc = -1;
     int UChndl_in, UChndl_out;
     int isdefault;
     int i_ch = (unsigned char)ch_out;
@@ -1341,6 +1347,8 @@
     if (charset_out < 0)
        return -12;
     if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {
+       if (LYCharSet_UC[charset_out].codepage < 0)
+           return LYCharSet_UC[charset_out].codepage;
        if ((UChndl_out = default_UChndl) < 0)
            return -12;
        isdefault = 1;
@@ -1357,19 +1365,14 @@
         */
        ut = UCInfo[UChndl_out].unitable;
        if (ut == UC_current_unitable) {
-           if ((Gn = UCInfo[UChndl_in].GN) >= 0) {
-               UC_translate = set_translate(Gn);
-               rc = inv_translate[i_ch];
-               if (rc >= 32) {
-                   return rc;
-               }
-           } else {
+           if ((Gn = UCInfo[UChndl_in].GN) < 0) {
                Gn = UC_MapGN(UChndl_in,1);
-               UC_translate = set_translate(Gn);
+           }
+           UC_translate = set_translate(Gn);
+           if (inv_translate)
                rc = inv_translate[i_ch];
-               if (rc >= 32) {
-                   return rc;
-               }
+           if (rc >= 32) {
+               return rc;
            }
        }
     }
@@ -1411,6 +1414,8 @@
     if (!UCInfo[UChndl_in].num_uni)
        return -11;
     if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) {
+       if (LYCharSet_UC[charset_out].codepage < 0)
+           return LYCharSet_UC[charset_out].codepage;
        if ((UChndl_out = default_UChndl) < 0)
            return -12;
        isdefault = 1;
@@ -2000,6 +2005,113 @@
     UCInfo[s].uc_status = status;
     if (found < 0)
        UCNumCharsets++;
+    return;
+}
+
+/*
+ *  UC_NoUctb_Register_with_LYCharSets, UC_Charset_NoUctb_Setup -
+ *  Alternative functions for adding character set info to the lists
+ *  kept in LYCharSets.c.
+ *  These are for character sets without any real tables of their own.
+ *  We don't keep an entry in UCinfo[] for them.
+ */
+PRIVATE int UC_NoUctb_Register_with_LYCharSets ARGS5(
+       CONST char *,   UC_MIMEcharset,
+       CONST char *,   UC_LYNXcharset,
+       int,            lowest_eightbit,
+       int,                    UC_rawuni,
+       int,                    codepage)
+{
+    int i, LYhndl = -1;
+
+    if (LYNumCharsets == 0) {
+       /*
+        *  Initialize here; so whoever changes
+        *  LYCharSets.c doesn't have to count...
+        */
+       for (i = 0; (i < MAXCHARSETS) && LYchar_set_names[i]; i++) {
+           LYNumCharsets = i+1;
+       }
+    }
+
+    /*
+     * Search by MIME name, (LYchar_set_names may differ...)
+     *  ignore if already present!
+     */
+    for (i = 0; i < MAXCHARSETS && LYchar_set_names[i] && LYhndl < 0; i++) {
+       if (LYCharSet_UC[i].MIMEname &&
+           !strcmp(UC_MIMEcharset, LYCharSet_UC[i].MIMEname)) {
+           return -1;
+       }
+    }
+
+    /* not found */
+    if (LYNumCharsets >= MAXCHARSETS) {
+       CTRACE(tfp, "UC_NoUctb_Register_with_LYCharSets: Too many.  Ignoring 
%s/%s.",
+              UC_MIMEcharset, UC_LYNXcharset);
+       return -1;
+    }
+    /*
+        *  Add to LYCharSets.c lists.
+        */
+    LYhndl = LYNumCharsets;
+    LYNumCharsets ++;
+    LYlowest_eightbit[LYhndl] = lowest_eightbit;
+    LYCharSets[LYhndl] = SevenBitApproximations;
+    LYchar_set_names[LYhndl] = UC_LYNXcharset;
+    LYchar_set_names[LYhndl+1] = NULL;
+    /*
+     *  Terminating NULL may be looked for by Lynx code.
+     */
+    
+    LYCharSet_UC[LYhndl].UChndl = -1; /* no corresponding UChndl ! */
+    LYCharSet_UC[LYhndl].MIMEname = UC_MIMEcharset;
+    LYCharSet_UC[LYhndl].enc = UC_rawuni;
+    LYCharSet_UC[LYhndl].codepage = codepage;
+
+    /*
+     * @@@ We really SHOULD get more info from the table files,
+     * and set relevant flags in the LYCharSet_UC[] entry with
+     * that info...  For now, let's try it without. - KW
+     */
+
+    return LYhndl;
+}
+
+/*
+ *  A wrapper for the previous function.
+ */
+PRIVATE void UC_Charset_NoUctb_Setup ARGS6(
+       CONST char *,           UC_MIMEcharset,
+       CONST char *,           UC_LYNXcharset,
+       int,                    trydefault,
+       int,                    lowest_eight,
+       int,                    UC_rawuni,
+       int,                    codepage)
+{
+    int i;
+
+    /*
+     * Ignore completely if already in slot.
+     */
+    for (i = 0; i < UCNumCharsets; i++) {
+       if (!strcmp(UCInfo[i].MIMEname, UC_MIMEcharset)) {
+           return;
+       }
+    }
+    if (UC_rawuni == UCT_ENC_UTF8)
+       lowest_eight = 128;  /* cheat here */
+    /* 'codepage' doubles as a flag for 'do not try any table
+    ** lookup, not even default' when negative.  The value will
+    ** be returned immediately by UCTrans* functions.
+    */
+    if (!trydefault && codepage == 0)
+       codepage = -12; /* if not already set; any negative should do. */
+    UC_NoUctb_Register_with_LYCharSets(UC_MIMEcharset,
+                                      UC_LYNXcharset,
+                                      lowest_eight,
+                                      UC_rawuni,
+                                      codepage);
     return;
 }
 


reply via email to

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