lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH 2.8.4dev.16] Allow manual/auto-switch of display charset


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.4dev.16] Allow manual/auto-switch of display charset
Date: Tue, 23 Jan 2001 01:15:57 -0500
User-agent: Mutt/1.2.5i

Currently the only way to switch the display charset is via obscure
manipulation with 'O'ptions.  (.lynxrc is not viable if you have
different charsets in different windows.)

This patch allows -display_chars cmdline option, and additionally
allows autodetection of the charset on the system which allow it.

The logic:

  first autodetect;

  then read cfg file, and if it is not "AutoDetect ..." (as the saved
  version says), grant the cfg file charset;

  then read the cmdline, if it is present, but not "auto", then
  grant it, otherwise switch back to the autodetected one.

Enjoy,
Ilya

--- ./src/UCdomap.c~    Wed Oct 25 11:35:28 2000
+++ ./src/UCdomap.c     Tue Jan 23 00:34:08 2001
@@ -73,6 +73,16 @@
 #include <mnem_suni.h>
 #endif /* NOTDEFINED */
 
+#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
+
 /*
  *  Some of the code below, and some of the comments, are left in for
  *  historical reasons.  Not all those tables below are currently
@@ -2226,6 +2236,43 @@ PUBLIC void UCInit NOARGS
 #ifdef NOTDEFINED
     UC_CHARSET_SETUP_mnem;
 #endif /* NOTDEFINED */
+
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+#  ifdef __EMX__
+    {
+       unsigned long lst[3];
+       unsigned long len;
+
+       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);
+           }
+       }
+    }
+#  endif
+#endif
 
 /*
  *  To add synonyms for any charset name
--- ./src/LYReadCFG.c~  Thu Dec 21 21:44:10 2000
+++ ./src/LYReadCFG.c   Tue Jan 23 00:07:50 2001
@@ -588,8 +588,14 @@ static int character_set_fun ARGS1(
        char *,         value)
 {
     int i = UCGetLYhndl_byAnyName(value); /* by MIME or full name */
-    if (i < 0)
-       ; /* do nothing here: so fallback to userdefs.h */
+
+    if (i < 0) {
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+       if (auto_display_charset >= 0 && !strnicmp(value,"AutoDetect ",11))
+           current_char_set = auto_display_charset;
+#endif
+       /* do nothing here: so fallback to userdefs.h */
+    }    
     else
        current_char_set = i;
 
--- ./src/LYMain.c~     Mon Jan  1 20:39:50 2001
+++ ./src/LYMain.c      Tue Jan 23 00:28:04 2001
@@ -1355,6 +1355,11 @@ PUBLIC int main ARGS2(
     /*
      * Set up the compilation default character set. - FM
      */
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+    if (auto_display_charset >= 0)
+       current_char_set = auto_display_charset;
+    else
+#endif
     current_char_set = safeUCGetLYhndl_byMIME(CHARACTER_SET);
     /*
      * Set up HTTP default for unlabeled charset (iso-8859-1).
@@ -2511,6 +2516,25 @@ PRIVATE int display_fun ARGS1(
     return 0;
 }
 
+/* -display_charset */
+PRIVATE int display_charset_fun ARGS1(
+       char *,                 next_arg)
+{
+    int i = UCGetLYhndl_byMIME(next_arg);
+
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+    if (i < 0 && !stricmp(next_arg,"auto"))
+       i = auto_display_charset;
+#endif
+    if (i < 0) {       /* do nothing here: so fallback to lynx.cfg */
+       fprintf(stderr,
+               gettext("Lynx: ignoring unrecognized charset=%s\n"), next_arg);
+    }    
+    else
+       current_char_set = i;
+    return 0;
+}
+
 /* -dump */
 PRIVATE int dump_output_fun ARGS1(
        char *,                 next_arg GCC_UNUSED)
@@ -3163,6 +3187,10 @@ with -dump, format output as with -trave
       "=NNN\nset the NNN msec delay at statusline message"
    ),
 #endif
+   PARSE_FUN(                  /* Does not work if put after 'display' */
+      "display_charset", 4|NEED_FUNCTION_ARG,  display_charset_fun,
+      "=MIMEname\ncharset for the terminal output"
+   ),
    PARSE_FUN(
       "display",       4|NEED_FUNCTION_ARG,    display_fun,
       "=DISPLAY\nset the display variable for X exec'ed programs"
--- ./src/LYCharSets.h~ Thu Aug 26 06:31:18 1999
+++ ./src/LYCharSets.h  Tue Jan 23 00:35:24 2001
@@ -93,4 +93,14 @@ extern int displayed_display_charset_idx
 extern void init_charset_subsets NOPARAMS;
 #endif /* EXP_CHARSET_CHOICE */
 
+#if !defined(NO_AUTODETECT_DISPLAY_CHARSET)
+#  ifdef __EMX__
+#    define CAN_AUTODETECT_DISPLAY_CHARSET
+#  endif
+#endif
+
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+extern int auto_display_charset;    
+#endif
+
 #endif /* LYCHARSETS_H */

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

reply via email to

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