lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH 2.8.4dev.18] display charset autoswitch


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.4dev.18] display charset autoswitch
Date: Tue, 13 Feb 2001 21:03:08 -0500
User-agent: Mutt/1.2.5i

The following patch enables automatic switching of display charsets.
Currently, it is supported under OS/2 only.  A couple of lines should
make it work in LINUX too: express the semantic of
_Switch_Display_Charset() in terms of the existing UCChangeTerminalCodepage.

I put the following in my lynx-cfg file:

CHARSETS_DIRECTORY:I:/get/tfont10/dir1
CHARSET_SWITCH_RULES: koi8-r ISO-8859-5 windows-1251 cp866u KOI8-U :cp866, 
iso-8859-1 windows-1252:cp850

The first variable may be not needed outside of OS/2 (the directory
which contains glyph tables, as generated/usable with tfont).  [Used
for full-screen sessions only.]  The second variables may go at the
future, when Lynx knows how to auto-deduce it itself.  Format of
CHARSET_SWITCH_RULES

  source1 source2 source3 : dest1, source4 source5 : dest2

Issues which may want to be addressed sooner or later:

a) Do we switch the charset back when shelling out?  When starting the editor?

b) Do we need to switch the keyboard too?

c) When resizing, the height/width of the character-cell may change.
   So the glyph table may need to be reloaded.

d) Lynx may be able to calculate "distance between charsets", so may
   be able to find the info as in CHARSET_SWITCH_RULES itself.  For
   this one needs to find a sniffer routine to find which charsets are
   switchable to (already known for windowed VIO sessions on OS/2,
   when you cannot load glyph tables, so you have only the choice
   between two preloaded codepages).

e) Currently Lynx assumes that the user wants auto-switch whenever she
   choses an "autodetected" codepage.  Does it make sense to select
   these features one-by-one?

Enjoy,
Ilya

--- ./src/GridText.c.orig       Tue Feb 13 00:43:54 2001
+++ ./src/GridText.c    Tue Feb 13 00:46:16 2001
@@ -1796,13 +1796,11 @@ PRIVATE void display_page ARGS3(
        LYCursesON) {
        charset_last_displayed = current_char_set;
 #ifdef EXP_CHARTRANS_AUTOSWITCH
-#ifdef LINUX
        /*
         *  Currently implemented only for LINUX
         */
        UCChangeTerminalCodepage(current_char_set,
                                 &LYCharSet_UC[current_char_set]);
-#endif /* LINUX */
 #endif /* EXP_CHARTRANS_AUTOSWITCH */
     }
 
@@ -7285,6 +7283,12 @@ PUBLIC BOOL HText_select ARGS1(
        }
 #endif /* DISP_PARTIAL */
 
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+       /* text->UCLYhndl is not reset by META, so use a more circumvent way */
+       if ( text->node_anchor->UCStages->s[UCT_STAGE_HTEXT].LYhndl
+            != current_char_set )
+           
Switch_Display_Charset(text->node_anchor->UCStages->s[UCT_STAGE_HTEXT].LYhndl, 
0);
+#endif
        if (HTMainText) {
            if (HText_hasUTF8OutputSet(HTMainText) &&
                HTLoadedDocumentEightbit() &&
--- ./src/LYCharSets.h.orig     Tue Feb 13 00:43:54 2001
+++ ./src/LYCharSets.h  Tue Feb 13 20:02:50 2001
@@ -96,11 +96,25 @@ extern void init_charset_subsets NOPARAM
 #if !defined(NO_AUTODETECT_DISPLAY_CHARSET)
 #  ifdef __EMX__
 #    define CAN_AUTODETECT_DISPLAY_CHARSET
+#    ifdef EXP_CHARTRANS_AUTOSWITCH
+#      define CAN_SWITCH_DISPLAY_CHARSET
+#    endif
 #  endif
 #endif
 
 #ifdef CAN_AUTODETECT_DISPLAY_CHARSET
 extern int auto_display_charset;
+#endif
+
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+extern int Switch_Display_Charset PARAMS((int ord, int really));
+extern int Find_Best_Display_Charset PARAMS((int ord));
+extern char *charsets_directory;
+extern char *charset_switch_rules;
+extern int switch_display_charsets;
+extern int auto_other_display_charset;
+extern int codepages[2];
+extern int real_charsets[2];   /* Non "auto-" charsets for the codepages */
 #endif
 
 #endif /* LYCHARSETS_H */
--- ./src/LYCharUtils.c.orig    Tue Feb 13 00:43:56 2001
+++ ./src/LYCharUtils.c Tue Feb 13 00:46:16 2001
@@ -2834,6 +2834,29 @@ PUBLIC void LYHandleMETA ARGS4(
            *cp4 = '\0';
            cp4 = cp3;
            chndl = UCGetLYhndl_byMIME(cp3);
+
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+           /* Allow a switch to a more suitable display charset */
+           if (Switch_Display_Charset (chndl, 0)) {
+               /* UCT_STAGE_STRUCTURED and UCT_STAGE_HTEXT
+                  should have the same setting for UCInfoStage. */
+               int structured = HTAnchor_getUCInfoStage(me->node_anchor,
+                                                        UCT_STAGE_STRUCTURED);
+               me->outUCLYhndl = current_char_set;
+               HTAnchor_setUCInfoStage(me->node_anchor,
+                                       current_char_set,
+                                       UCT_STAGE_HTEXT,
+                                       UCT_SETBY_MIME); /* highest priorty! */
+               HTAnchor_setUCInfoStage(me->node_anchor,
+                                       current_char_set,
+                                       UCT_STAGE_STRUCTURED,
+                                       UCT_SETBY_MIME); /* highest priorty! */
+               me->outUCI = HTAnchor_getUCInfoStage(me->node_anchor,
+                                                    UCT_STAGE_HTEXT);
+               /* The SGML stage will be reset in change_chartrans_handling */
+           }       
+#endif
+
            if (UCCanTranslateFromTo(chndl, current_char_set)) {
                chartrans_ok = YES;
                StrAllocCopy(me->node_anchor->charset, cp4);
--- ./src/LYClean.c.orig        Tue Feb 13 00:43:56 2001
+++ ./src/LYClean.c     Tue Feb 13 00:46:16 2001
@@ -172,12 +172,10 @@ PUBLIC void cleanup NOARGS
     }
 
 #ifdef EXP_CHARTRANS_AUTOSWITCH
-#ifdef LINUX
     /*
      * Currently implemented only for LINUX: Restore original font.
      */
     UCChangeTerminalCodepage(-1, (LYUCcharset*)0);
-#endif /* LINUX */
 #endif /* EXP_CHARTRANS_AUTOSWITCH */
 
 #ifdef EXP_PERSISTENT_COOKIES
--- ./src/LYMain.c.orig Mon Feb 12 22:57:44 2001
+++ ./src/LYMain.c      Tue Feb 13 14:04:34 2001
@@ -1519,6 +1519,10 @@ PUBLIC int main ARGS2(
        }
        LYStdinArgs_free();
     }
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+    if (current_char_set == auto_display_charset) /* Better: explicit option */
+       switch_display_charsets = 1;
+#endif
 
 #undef TTY_DEVICE
 #undef NUL_DEVICE
--- ./src/LYOptions.c.orig      Mon Feb 12 22:57:44 2001
+++ ./src/LYOptions.c   Tue Feb 13 16:09:32 2001
@@ -989,6 +989,12 @@ draw_options:
                        LYclrtoeol();
                        LYaddstr(LYRawMode ? "ON " : "OFF");
                    }
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+                   /* Deduce whether the user wants autoswitch: */
+                   switch_display_charsets =
+                       (current_char_set == auto_display_charset
+                           || current_char_set == auto_other_display_charset);
+#endif
                }
                response = ' ';
                if (LYSelectPopups) {
@@ -2954,14 +2960,20 @@ PUBLIC int postoptions ARGS1(
        /*
         * charset settings: the order is essential here.
         */
-       if (display_char_set_old != current_char_set) {
-               /*
-                *  Set the LYUseDefaultRawMode value and character
-                *  handling if LYRawMode was changed. - FM
-                */
-               LYUseDefaultRawMode = TRUE;
-               HTMLUseCharacterSet(current_char_set);
-           }
+        if (display_char_set_old != current_char_set) {
+            /*
+             *  Set the LYUseDefaultRawMode value and character
+             *  handling if LYRawMode was changed. - FM
+             */
+            LYUseDefaultRawMode = TRUE;
+            HTMLUseCharacterSet(current_char_set);
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+            /* Deduce whether the user wants autoswitch: */
+            switch_display_charsets =
+                (current_char_set == auto_display_charset
+                 || current_char_set == auto_other_display_charset);
+#endif
+        }
        if (assume_char_set_changed && HTCJK != JAPANESE) {
                LYRawMode = (BOOL) (UCLYhndl_for_unspec == current_char_set);
            }
--- ./src/LYReadCFG.c.orig      Mon Feb 12 22:57:44 2001
+++ ./src/LYReadCFG.c   Tue Feb 13 14:08:22 2001
@@ -602,7 +602,9 @@ static int character_set_fun ARGS1(
 
     if (i < 0) {
 #ifdef CAN_AUTODETECT_DISPLAY_CHARSET
-       if (auto_display_charset >= 0 && !strnicmp(value,"AutoDetect ",11))
+       if (auto_display_charset >= 0
+           && (!strnicmp(value,"AutoDetect ",11)
+               || !strnicmp(value,"AutoDetect-2 ",13)))
            current_char_set = auto_display_charset;
 #endif
        /* do nothing here: so fallback to userdefs.h */
@@ -1431,6 +1433,10 @@ static Config_Type Config_Table [] =
      PARSE_SET("bold_name_anchors", CONF_BOOL, &bold_name_anchors),
      PARSE_SET("case_sensitive_always_on", CONF_BOOL, &case_sensitive),
      PARSE_FUN("character_set", CONF_FUN, character_set_fun),
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+     PARSE_SET("charset_switch_rules", CONF_STR, &charset_switch_rules),
+     PARSE_SET("charsets_directory", CONF_STR, &charsets_directory),
+#endif
      PARSE_SET("checkmail", CONF_BOOL, &check_mail),
      PARSE_SET("collapse_br_tags", CONF_BOOL, &LYCollapseBRs),
 #ifdef USE_COLOR_TABLE
--- ./src/UCAuto.c.orig Tue Feb 13 00:43:56 2001
+++ ./src/UCAuto.c      Tue Feb 13 20:05:48 2001
@@ -23,9 +23,29 @@
 #include <LYGlobalDefs.h>
 #include <LYClean.h>
 #include <LYLeaks.h>
+#include <LYCharSets.h>
 
 #ifdef EXP_CHARTRANS_AUTOSWITCH
 
+#  ifdef CAN_SWITCH_DISPLAY_CHARSET
+int auto_other_display_charset = -1;
+int codepages[2];
+int real_charsets[2] = {-1, -1};       /* Non "auto-" charsets for the cps */
+char *charsets_directory;
+char *charset_switch_rules;
+int switch_display_charsets;
+#  endif
+
+#  ifdef __EMX__
+/* If we "jusg include" <os2.h>, BOOLEAN conflicts. */
+#  define BOOLEAN OS2_BOOLEAN          /* This file doesn't use it, conflicts 
*/
+#  define INCL_VIO                     /* I want some Vio functions.. */
+#  define INCL_DOSPROCESS                      /* TIB PIB. */
+#  define INCL_DOSNLS                  /* DosQueryCp. */
+#  include <os2.h>                     /* Misc stuff.. */
+#  include <os2thunk.h>                        /* 32 bit to 16 bit pointer 
conv */
+#  endif
+
 #ifdef LINUX
 typedef enum {
     Is_Unset, Is_Set, Dunno, Dont_Care
@@ -440,15 +460,217 @@ PUBLIC void UCChangeTerminalCodepage ARG
 #ifdef __EMX__
     int res = 0;
 
-    if (p->codepage > 0) {
-       res = VioSetCp(0, p->codepage, 0);
-       CTRACE((tfp, "UCChangeTerminalCodepage: VioSetCp(%d) returned %d\n", 
p->codepage, res));
-    }
+    if (newcs < 0)
+       newcs = auto_display_charset;
+    res = Switch_Display_Charset(newcs, 1);
+    CTRACE((tfp, "UCChangeTerminalCodepage: Switch_Display_Charset(%d) 
returned %d\n", newcs, res));
 #else
     CTRACE((tfp, "UCChangeTerminalCodepage: Called, but not implemented!"));
 #endif
 }
 #endif /* LINUX */
+
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+
+PUBLIC int Find_Best_Display_Charset ARGS1 (int, ord)
+{
+    CONST char *name = LYCharSet_UC[ord].MIMEname;
+    char *s = charset_switch_rules, *r;
+    char buf[160];
+    static int lowercase;
+    int n = strlen(name), source = 1;
+
+    if (!s && !n)
+       return ord;
+    if (!lowercase++)
+       strlwr(charset_switch_rules);
+    while (1) {
+       while (*s && strchr(" \t,", *s))
+           s++;                        /* Go to start of a name or ':' */
+       if (!*s && source)
+           return ord;                 /* OK to find nothing */
+       if (!*s) {
+           sprintf(buf, "No destination for '%.80s' in CHARSET_SWITCH_RULES",
+                   name);
+           HTInfoMsg(buf);
+           return ord;
+       }
+       if (*s == ':') {
+           /* Before the replacement name */
+           while (*s && strchr(" \t:", *s))
+               s++;                    /* Go to the replacement */
+           /* At start of the replacement name */
+           r = s;
+           while (*s && !strchr(" \t,:", *s))
+               s++;                    /* Skip the replacement */
+           if (source)
+               continue;
+           break;
+       }
+       /* At start of the source name */
+       if (source && !strnicmp(name, s, n) && strchr(" \t,", s[n])) {/* Found! 
*/
+           source = 0;
+           s += n;
+           continue;                   /* Look for the replacement */
+       }
+       while (*s && !strchr(" \t,:", *s))
+           s++;                        /* Skip the other source names */
+    }
+    /* Here r point to the replacement, s to the end of the replacement. */
+    if (s >= r + sizeof(buf)) {
+       HTInfoMsg("Charset name in CHARSET_SWITCH_RULES too long");
+       return ord;
+    }
+    strncpy(buf, r, s-r);
+    buf[s-r] = '\0';
+    n = UCGetLYhndl_byMIME(buf);
+    if (n < 0) {
+       sprintf(buf, "Unknown charset name '%.*s' in CHARSET_SWITCH_RULES",
+               s-r, r);
+       HTInfoMsg(buf);
+       return ord;
+    }
+    return n;
+}
+
+#  ifdef __EMX__
+/* Switch display for the best fit for LYCharSet_UC[ord].
+   If !REALLY, the switch is tentative only, another switch may happen
+   before the actual display.
+
+   Returns the charset we switched to.  */
+PRIVATE int _Switch_Display_Charset ARGS2 (int, ord, int, really)
+{
+    CONST char *name;
+    unsigned short cp;
+    static int font_loaded_for = -1;
+    int rc, ord1;
+    UCHAR msgbuf[MAXPATHLEN + 80];
+
+    CTRACE((tfp, "_Switch_Display_Charset(cp=%d, really=%d).\n", ord, really));
+    /* Do not trust current_char_set if really, we fake it without really! */
+    if (ord == current_char_set && !really)
+       return ord;
+    if (ord == auto_other_display_charset
+       || ord == auto_display_charset || ord == font_loaded_for) {
+       if (!really)
+           return ord; /* Report success, to avoid flicker, switch later */
+    } else     /* Currently supports only koi8-r to cp866 translation */
+       ord = Find_Best_Display_Charset(ord);
+
+    if (ord == real_charsets[0] || ord == real_charsets[1]) {
+       ord1 = (ord == real_charsets[1]
+              ? auto_other_display_charset : auto_display_charset);
+       if (!really)
+           return ord; /* Can switch later, report success to avoid flicker */
+    } else
+       ord1 = ord;
+    if (ord == current_char_set && !really)
+       return ord;
+
+    name = LYCharSet_UC[ord1].MIMEname;
+    if (ord1 == auto_other_display_charset || ord1 == auto_display_charset) {
+      retry:
+       rc = VioSetCp(0,codepages[ord1 == auto_other_display_charset],0);
+       if (rc == 0)
+           goto report;
+      err:
+       sprintf(msgbuf, "Can't change to '%s': err=%#lx=%ld", name, rc, rc);
+       HTInfoMsg(msgbuf);
+       return -1;
+    }
+    
+    /* Not a "prepared" codepage.  Need to load the user font. */
+    if (ord1 == font_loaded_for) {     /* The same as the previous font */
+       if ((rc = VioSetCp(0, -1, 0)))  /* -1: User font */
+           goto err;
+    } else if (charsets_directory) {
+       TIB *tib;                       /* Can't load font in a windowed-VIO */
+       PIB *pib;
+       VIOFONTINFO f[2];
+       VIOFONTINFO *font;
+       UCHAR b[1<<17];
+       UCHAR *buf = b;
+       UCHAR fnamebuf[MAXPATHLEN];
+       FILE  *file;
+       APIRET rc;
+       long i, j;
+
+       /* 0 means a FS protected-mode session */
+       if (DosGetInfoBlocks(&tib, &pib) || pib->pib_ultype != 0) {
+           ord = ord1 = auto_display_charset;
+           goto retry;
+       }
+       /* Should not cross 64K boundaries: */
+       font = f;
+       if (((((ULONG)(char*)f) + sizeof(*font)) & 0xFFFF) < sizeof(*font))
+           font++;
+       if (((ULONG)buf) & 0xFFFF)
+           buf += 0x10000 - (((ULONG)buf) & 0xFFFF);
+       font->cb = sizeof(*font);       /* How large is this structure */
+       font->type=0;                   /* Not the BIOS, the loaded font. */
+       font->cbData = 65535;           /* How large is my buffer? */
+       font->pbData = _emx_32to16(buf); /* Wants an 16:16 pointer */
+
+       rc = VioGetFont(font,0);        /* Retrieve data for current font */
+       if (rc) {
+           sprintf(msgbuf, "Can't fetch current font info: err=%#lx=%ld", rc, 
rc);
+           HTInfoMsg(msgbuf);
+           ord = ord1 = auto_display_charset;
+           goto retry;
+       }       
+       sprintf(fnamebuf, "%s/%dx%d/%s.fnt",
+               charsets_directory, font->cyCell, font->cxCell, name);
+       file = fopen(fnamebuf,"rb");
+       if (!file) {
+           sprintf(msgbuf, "Can't open font file '%s'", fnamebuf);
+           HTInfoMsg(msgbuf);
+           ord = ord1 = auto_display_charset;
+           goto retry;
+       }       
+       i = ftell(file);
+       fseek(file, 0, SEEK_END);
+       if (ftell(file) - i != font->cbData) {
+           fclose(file);
+           sprintf(msgbuf, "Mismatch of size of font file '%s'", fnamebuf);
+           HTAlert(msgbuf);
+           ord = ord1 = auto_display_charset;
+           goto retry;
+       }
+       fseek(file, i, SEEK_SET);
+       fread(buf, 1, font->cbData,file);
+       fclose(file);
+       rc = VioSetFont(font,0);        /* Put it all back.. */
+       if (rc) {
+           sprintf(msgbuf, "Can't set font: err=%#lx=%ld", rc, rc);
+           HTInfoMsg(msgbuf);
+           ord = ord1 = auto_display_charset;
+           goto retry;
+       }
+       font_loaded_for = ord1;
+    }
+  report:
+    CTRACE((tfp, "Display font set to '%s'.\n", name));
+    return ord;
+}
+#  endif
+
+PUBLIC int Switch_Display_Charset ARGS2 (CONST int, ord, CONST int, really)
+{
+    int prev = current_char_set;
+    int res;
+
+    if (!switch_display_charsets && !really)
+       return 0;
+    res = _Switch_Display_Charset(ord, really);
+    if (res < 0 || prev == res)                /* No change */
+       return 0;
+    /* Register the change */
+    current_char_set = res;
+    HTMLUseCharacterSet(current_char_set);
+    return 1;
+}
+#endif
 
 #else /* EXP_CHARTRANS_AUTOSWITCH not defined: */
 /*
--- ./src/UCdomap.c.orig        Tue Feb 13 00:43:56 2001
+++ ./src/UCdomap.c     Tue Feb 13 20:04:54 2001
@@ -75,12 +75,6 @@
 
 #ifdef CAN_AUTODETECT_DISPLAY_CHARSET
 int auto_display_charset = -1;
-#  ifdef __EMX__
-/* If we include <os2.h>, BOOLEAN conflicts.  Just copy the proto: */
-unsigned long DosQueryCp (unsigned long ulLength,
-                         unsigned long* pCodePageList,
-                         unsigned long* pDataLength);
-#  endif
 #endif
 
 /*
@@ -2164,6 +2158,47 @@ PRIVATE void UCcleanup_mem NOARGS
 }
 #endif /* LY_FIND_LEAKS */
 
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+#  ifdef __EMX__
+PRIVATE int CpOrdinal ARGS2 (CONST unsigned long, cp, CONST int, other)
+{
+    char lyName[80];
+    char myMimeName[80];
+    char *mimeName, *mName = NULL, *lName = NULL;
+    int s, i, exists = 0, ret;
+
+    CTRACE((tfp, "CpOrdinal(cp=%ul, other=%d).\n", cp, other));
+    sprintf(myMimeName, "auto%s-cp%lu", (other ? "2" : ""), cp);
+    mimeName = myMimeName + 5 + (other != 0);
+    sprintf(lyName, "AutoDetect%s (cp%lu)", 
+           (other ? "-2" : ""), cp);
+    /* Find slot. */
+    s = -1;
+    for (i = 0; i < UCNumCharsets; i++) {
+       if (!strcmp(UCInfo[i].LYNXname, lyName))
+           return UCGetLYhndl_byMIME(myMimeName);
+       else if (!stricmp(UCInfo[i].MIMEname, mimeName))
+           s = i;
+    }
+    if (s < 0)
+       return -1;
+    /* Store the "real" charset info */
+    real_charsets[other != 0] = UCGetLYhndl_byMIME(mimeName);
+    /* Duplicate the record. */
+    StrAllocCopy(mName, myMimeName);
+    StrAllocCopy(lName, lyName);
+    UC_Charset_Setup(mName, lName,
+                    UCInfo[s].unicount, UCInfo[s].unitable,
+                    UCInfo[s].num_uni, UCInfo[s].replacedesc,
+                    UCInfo[s].lowest_eight, UCInfo[s].enc, 
+                    UCInfo[s].codepage);
+    ret = UCGetLYhndl_byMIME(myMimeName);
+    CTRACE((tfp, "Found %i.\n", ret));
+    return ret;
+}
+#  endif
+#endif
+
 PUBLIC void UCInit NOARGS
 {
 
@@ -2241,34 +2276,21 @@ PUBLIC void UCInit NOARGS
 #  ifdef __EMX__
     {
        unsigned long lst[3];
-       unsigned long len;
+       unsigned long len, rc;
 
-       if (DosQueryCp(sizeof(lst), lst, &len) == 0 && len >= 1) {
-           static char lyName[80];
-           static char myMimeName[80];
-           char *mimeName;
-           int s, i, exists = 0;
-
-           sprintf(myMimeName, "auto-cp%lu", lst[0]);
-           mimeName = myMimeName + 5;
-           sprintf(lyName, "AutoDetect (cp%lu)", lst[0]);
-           /* Find slot. */
-           s = -1;
-           for (i = 0; i < UCNumCharsets; i++) {
-                   if (!strcmp(UCInfo[i].LYNXname, lyName))
-                       exists = 1;
-                   else if (!stricmp(UCInfo[i].MIMEname, mimeName))
-                       s = i;
-           }
-           if (s >= 0 && !exists) {
-               /* Duplicate the record. */
-               UC_Charset_Setup(myMimeName, lyName,
-                                UCInfo[s].unicount, UCInfo[s].unitable,
-                                UCInfo[s].num_uni, UCInfo[s].replacedesc,
-                                UCInfo[s].lowest_eight, UCInfo[s].enc,
-                                UCInfo[s].codepage);
-               auto_display_charset = UCGetLYhndl_byMIME(myMimeName);
+       rc = DosQueryCp(sizeof(lst), lst, &len);
+       if (rc == 0) {
+           if (len >= 1)
+               auto_display_charset = CpOrdinal(lst[0], 0);
+#    ifdef CAN_SWITCH_DISPLAY_CHARSET
+           if (len >= 3) {
+               codepages[0] = lst[0];
+               codepages[1] = (lst[0] == lst[1] ? lst[2] : lst[1]);
+               auto_other_display_charset = CpOrdinal(codepages[1], 1);
            }
+#    endif
+       } else {
+           CTRACE((tfp, "DosQueryCp() returned %#lx=%lu.\n", rc, rc));
        }
     }
 #  endif
--- ./WWW/Library/Implementation/HTAnchor.c.orig        Tue Feb 13 04:13:36 2001
+++ ./WWW/Library/Implementation/HTAnchor.c     Tue Feb 13 01:55:58 2001
@@ -1398,6 +1398,20 @@ PUBLIC int HTAnchor_getUCLYhndl ARGS2(
     return( -1);
 }
 
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+PRIVATE void setup_switch_display_charset ARGS2(HTParentAnchor *, me, int, h)
+{
+    if (!Switch_Display_Charset(h,0))
+       return;
+    HTAnchor_setUCInfoStage(me, current_char_set,
+                           UCT_STAGE_HTEXT, UCT_SETBY_MIME); /* highest 
priorty! */
+    HTAnchor_setUCInfoStage(me, current_char_set,
+                           UCT_STAGE_STRUCTURED, UCT_SETBY_MIME); /* highest 
priorty! */
+    CTRACE((tfp, "changing UCInfoStage: HTEXT/STRUCTURED stages 
charset='%s'.\n",
+           LYCharSet_UC[current_char_set].MIMEname));
+}
+#endif
+
 PUBLIC LYUCcharset * HTAnchor_setUCInfoStage ARGS4(
        HTParentAnchor *,       me,
        int,                    LYhndl,
@@ -1413,10 +1427,17 @@ PUBLIC LYUCcharset * HTAnchor_setUCInfoS
         *  Can we override?
         */
        if (set_by >= me->UCStages->s[which_stage].lock) {
+           int ohandle = me->UCStages->s[which_stage].LYhndl;
+
            me->UCStages->s[which_stage].lock = set_by;
            me->UCStages->s[which_stage].LYhndl = LYhndl;
            if (LYhndl >= 0) {
                memcpy(p, &LYCharSet_UC[LYhndl], sizeof(LYUCcharset));
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+               /* Allow a switch to a more suitable display charset */
+               if ( LYhndl != ohandle && which_stage == UCT_STAGE_PARSER )
+                   setup_switch_display_charset(me, LYhndl);
+#endif
            }
            else {
                p->UChndl = -1;
@@ -1433,10 +1454,18 @@ PUBLIC LYUCcharset * HTAnchor_resetUCInf
        int,                    which_stage,
        int,                    set_by)
 {
+    int ohandle;
+
     if (!me || !me->UCStages)
        return(NULL);
     me->UCStages->s[which_stage].lock = set_by;
+    ohandle = me->UCStages->s[which_stage].LYhndl;
     me->UCStages->s[which_stage].LYhndl = LYhndl;
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+    /* Allow a switch to a more suitable display charset */
+    if (LYhndl >= 0 && LYhndl != ohandle && which_stage == UCT_STAGE_PARSER)
+       setup_switch_display_charset(me, LYhndl);
+#endif
     return( &me->UCStages->s[which_stage].C);
 }
 
@@ -1463,9 +1492,19 @@ PUBLIC LYUCcharset * HTAnchor_copyUCInfo
        if (set_by == UCT_SETBY_NONE)
            set_by = UCT_SETBY_DEFAULT;
        if (set_by >= me->UCStages->s[to_stage].lock) {
+           int ohandle = me->UCStages->s[to_stage].LYhndl;
+
            me->UCStages->s[to_stage].lock = set_by;
            me->UCStages->s[to_stage].LYhndl =
                me->UCStages->s[from_stage].LYhndl;
+#ifdef CAN_SWITCH_DISPLAY_CHARSET
+           /* Allow a switch to a more suitable display charset */
+           if ( me->UCStages->s[to_stage].LYhndl >= 0
+                && me->UCStages->s[to_stage].LYhndl != ohandle
+                && to_stage == UCT_STAGE_PARSER )
+               setup_switch_display_charset(me, 
+                                            me->UCStages->s[to_stage].LYhndl);
+#endif
            if (p_to != p_from)
                memcpy(p_to, p_from, sizeof(LYUCcharset));
            return(p_to);

; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

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