lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH 2.8.3.dev6] patch that allows user to define what charse


From: Vlad Harchev
Subject: lynx-dev [PATCH 2.8.3.dev6] patch that allows user to define what charsets will appear in "assumed doc chset" and "display chset" popups
Date: Thu, 12 Aug 1999 06:01:27 +0500 (SAMST)

 See diffs for lynx.cfg (5 lines lower than this) for more description.
 Seems this is useful for not-only-English-speaking people, that use
documents in languages for which several encodings exist - they have to
change "assumed doc chset" 'O'ption's field very often (since not all page
authors are worried about inserting proper charset info in the <HEAD>).
 Primitive pattern  matching will make the things even better (like
ASSUMED_DOC_CHSET_CHOICE:arabic* - only all arabic encodings - that have full
name begining with "arabic" - will be selected).

PS: Tested with '-form-options-' too. All wrapped in conditionals. No
commandling equivalent exists.

 Best regards,
  -Vlad

diff -ru lynx2-8-3dev6-orig/lynx.cfg lynx2-8-3dev6/lynx.cfg
--- lynx2-8-3dev6-orig/lynx.cfg Wed Aug 11 19:07:40 1999
+++ lynx2-8-3dev6/lynx.cfg      Thu Aug 12 05:46:03 1999
@@ -340,6 +340,35 @@
 #
 #ASSUME_CHARSET:iso-8859-1
 
+# It's possible to reduce the number of charset choices in the 'O'ptions menu
+# for "display charset" and "assumed document charset" fields via 
+# DISPLAY_CHSET_CHOICE and ASSUMED_DOC_CHSET_CHOICE settings correspondingly.
+# Each of these settings can be used several times to define the set of 
possible
+# choices for corresponding field. The syntax for the values is
+# string | prefix* | <ALL>
+#   Where
+#  * 'string' is either the MIME name of charset or it's full name (listed 
+# either in the left or in the right column of table of recognized charsets),
+# case-insensitive - e.g. 'Koi8-R' or 'Cyrillic (KOI8-R)' (both without 
quotes),
+#  * 'prefix' is any string, and such value will select all charsets having 
the 
+# name with prefix matching given (case insensitive), ie for the charsets 
+# listed in the table of recognized charsets, 
+# ASSUMED_DOC_CHSET_CHOICE:cyrillic* 
+#   will be equal to specifying
+# ASSUMED_DOC_CHSET_CHOICE:cp866
+# ASSUMED_DOC_CHSET_CHOICE:windows-1251
+# ASSUMED_DOC_CHSET_CHOICE:koi8-r
+# ASSUMED_DOC_CHSET_CHOICE:iso-8859-5
+#  or lines with full names of charsets.
+# * litteral string '<ALL>' (without quotes) will enable all charset choices in
+#   corresponding field. This is useful for overriding site defaults in private
+#   pieces of lynx.cfg included via INCLUDE directive.
+# Default values for both settings are <ALL>, but any occurance of settings 
with
+# values that denote any charsets will make only listed choices available for
+# corresponding field.
+#ASSUMED_DOC_CHSET_CHOICE:<ALL>
+#DISPLAY_CHSET_CHOICE:<ALL>
+
 # ASSUME_LOCAL_CHARSET is like ASSUME_CHARSET but only applies to local
 # files.  If no setting is given here or by an -assume_local_charset
 # command line option, the value for ASSUME_CHARSET or -assume_charset
diff -ru lynx2-8-3dev6-orig/src/LYCharSets.c lynx2-8-3dev6/src/LYCharSets.c
--- lynx2-8-3dev6-orig/src/LYCharSets.c Thu Jul 15 09:50:47 1999
+++ lynx2-8-3dev6/src/LYCharSets.c      Thu Aug 12 04:54:15 1999
@@ -30,7 +30,19 @@
 PUBLIC CONST char** p_entity_values = NULL; /* Pointer, for HTML_put_entity()*/
                              /* obsolete and probably not used(???)        */
                              /* will be initialized in HTMLUseCharacterSet */
-
+#ifndef ALL_CHSETS_IN_O_SCREEN
+PUBLIC chset_selectability_info_t chset_selectability_info[MAXCHARSETS];
+PUBLIC BOOL custom_display_chset=FALSE;
+PUBLIC BOOL custom_assumed_doc_chset=FALSE;
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+PUBLIC int displayed_display_chset_map[MAXCHARSETS];
+PUBLIC int displayed_assumed_doc_chset_map[MAXCHARSETS];
+
+PUBLIC char* displayed_display_chset_names[MAXCHARSETS+1];
+PUBLIC char* displayed_assumed_doc_chset_names[MAXCHARSETS+1];
+PUBLIC int displayed_display_chset_idx;
+#endif
+#endif
 /*
  *  New character sets now declared with UCInit() in UCdomap.c
  *
@@ -904,9 +916,41 @@
  *  Initializer, calls initialization function for the
  *  CHARTRANS handling. - KW
  */
-PUBLIC int LYCharSetsDeclared NOPARAMS
+PUBLIC int LYCharSetsDeclared NOARGS
 {
     UCInit();
 
     return UCInitialized;
 }
+
+#ifndef ALL_CHSETS_IN_O_SCREEN
+PUBLIC void init_selectable_chsets_lists NOARGS
+{
+    int i,n;
+    int cur_display_chset_choice=0;
+    int cur_assumed_chset_choice=0;
+
+    /*add them to displayed values*/
+    
chset_selectability_info[UCLYhndl_for_unspec].hide_in_assumed_doc_chsets=FALSE;
+    chset_selectability_info[current_char_set].hide_in_display_chsets=FALSE;
+    
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN    
+    /*all this stuff is for supporting old menu screen... */
+    for (i=0;i<LYNumCharsets;++i){
+       if (chset_selectability_info[i].hide_in_display_chsets==FALSE) {
+           n=cur_display_chset_choice++;
+           if (i==current_char_set)
+               displayed_display_chset_idx=n;
+           displayed_display_chset_map[n]=i;
+           displayed_display_chset_names[n]=LYchar_set_names[i];           
+       };
+       if (chset_selectability_info[i].hide_in_assumed_doc_chsets==FALSE) {
+           n=cur_assumed_chset_choice++;
+           displayed_assumed_doc_chset_map[n]=i;
+           displayed_assumed_doc_chset_names[n]=LYCharSet_UC[i].MIMEname;
+           chset_selectability_info[i].displayed_assumed_doc_chset_idx=n;
+       };
+    };
+#endif
+};
+#endif
\ No newline at end of file
diff -ru lynx2-8-3dev6-orig/src/LYCharSets.h lynx2-8-3dev6/src/LYCharSets.h
--- lynx2-8-3dev6-orig/src/LYCharSets.h Thu Jul 15 09:50:47 1999
+++ lynx2-8-3dev6/src/LYCharSets.h      Thu Aug 12 04:51:03 1999
@@ -54,4 +54,46 @@
 
 extern BOOL force_old_UCLYhndl_on_reload;
 extern int forced_UCLYhdnl;
+
+#ifdef  ALL_CHSETS_IN_O_SCREEN
+# define ALL_CHSETS_IN_O_MENU_SCREEN
+#endif
+
+#ifndef ALL_CHSETS_IN_O_SCREEN
+typedef struct chset_selectability_info_t_ {
+    BOOL hide_in_display_chsets; /*if FALSE, then chset is shown in menu */
+    BOOL hide_in_assumed_doc_chsets; /*if FALSE, then chset is shown in menu */
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+    int displayed_assumed_doc_chset_idx;/*only this field is needed.*/
+#endif    
+} chset_selectability_info_t;
+/*each elt correspond to chset in LYCharSets */
+extern chset_selectability_info_t chset_selectability_info[];
+/*all zeros by default - ie all chsets allowed */
+
+extern BOOL custom_display_chset;/*whether the chset choices for display 
+    chset were requested by user via lynx.cfg. It will remain FALSE if no
+    "display_chset_choice"  settings were encountered in lynx.cfg */
+extern BOOL custom_assumed_doc_chset;/*similar to custom_display_chset*/
+
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+/*this is done conditional to simplify removing enitre old-menu support later*/
+
+/*all this stuff is initialized after reading lynx.cfg and .lynxrc */
+
+/*these arrays maps index of chset shown in menu to the index in LYCharsets[]*/
+extern int displayed_display_chset_map[];
+extern int displayed_assumed_doc_chset_map[];
+
+/*these arrays are NULL terminated*/
+extern char* displayed_display_chset_names[];
+extern char* displayed_assumed_doc_chset_names[];
+
+extern int displayed_display_chset_idx;
+
+#endif
+/*this will be called after lynx.cfg and .lynxrc are read.*/
+extern void init_selectable_chsets_lists NOPARAMS;
+#endif
+
 #endif /* LYCHARSETS_H */
diff -ru lynx2-8-3dev6-orig/src/LYMain.c lynx2-8-3dev6/src/LYMain.c
--- lynx2-8-3dev6-orig/src/LYMain.c     Wed Aug 11 19:07:41 1999
+++ lynx2-8-3dev6/src/LYMain.c  Thu Aug 12 04:55:18 1999
@@ -780,6 +780,10 @@
     FixCharacters();
 #endif /* NOT_ASCII */
 
+#ifndef ALL_CHSETS_IN_O_SCREEN
+    
memset((char*)chset_selectability_info,0,sizeof(chset_selectability_info_t)*MAXCHARSETS);
+#endif
+
 #ifdef _WINDOWS
     WSADATA WSAData;
     {
@@ -2012,6 +2016,11 @@
            with_backspaces = FALSE;
        }
 #endif
+
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+       init_selectable_chsets_lists();
+#endif
+
        ena_csi((BOOLEAN)(LYlowest_eightbit[current_char_set] > 155));
        LYOpenCloset();
        status = mainloop();
diff -ru lynx2-8-3dev6-orig/src/LYOptions.c lynx2-8-3dev6/src/LYOptions.c
--- lynx2-8-3dev6-orig/src/LYOptions.c  Sat Jul 31 04:38:16 1999
+++ lynx2-8-3dev6/src/LYOptions.c       Thu Aug 12 04:56:49 1999
@@ -855,14 +855,29 @@
                    if (curval < 0)
                        curval = LYRawMode ? current_char_set : 0;
                    if (!LYSelectPopups) {
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+                       UCLYhndl_for_unspec = 
displayed_assumed_doc_chset_map[boolean_choice(
+                           
chset_selectability_info[curval].displayed_assumed_doc_chset_idx,
+                                                            L_ASSUME_CHARSET, 
-1,
+                                                            
displayed_assumed_doc_chset_names)];
+#else
                        UCLYhndl_for_unspec = boolean_choice(curval,
                                                             L_ASSUME_CHARSET, 
-1,
                                                             assume_list);
+#endif
                    } else {
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN                
+                       UCLYhndl_for_unspec = 
displayed_assumed_doc_chset_map[popup_choice(
+                           
chset_selectability_info[curval].displayed_assumed_doc_chset_idx,
+                                                          L_ASSUME_CHARSET, -1,
+                                                          
displayed_assumed_doc_chset_names,
+                                                          0, FALSE, FALSE)];
+#else
                        UCLYhndl_for_unspec = popup_choice(curval,
                                                           L_ASSUME_CHARSET, -1,
                                                           assume_list,
-                                                          0, FALSE, FALSE);
+                                                          0, FALSE, FALSE);
+#endif                                                    
 #if defined(VMS) || defined(USE_SLANG)
                        move(L_ASSUME_CHARSET, COL_OPTION_VALUES);
                        clrtoeol();
@@ -919,14 +934,30 @@
            case 'c':   /* Change display charset setting. */
            case 'C':
                if (!LYSelectPopups) {
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+                   
displayed_display_chset_idx=boolean_choice(displayed_display_chset_idx,
+                                                     L_Charset, -1,
+                                                     (char 
**)displayed_display_chset_names);
+                   
current_char_set=displayed_display_chset_map[displayed_display_chset_idx];
+#else
                    current_char_set = boolean_choice(current_char_set,
                                                      L_Charset, -1,
                                                      (char 
**)LYchar_set_names);
+#endif                                               
                } else {
+#ifndef ALL_CHSETS_IN_O_MENU_SCREEN
+                   
displayed_display_chset_idx=popup_choice(displayed_display_chset_idx,
+                                                   L_Charset, -1,
+                                                   (char 
**)displayed_display_chset_names,
+                                                   0, FALSE, FALSE);
+                   
current_char_set=displayed_display_chset_map[displayed_display_chset_idx];
+#else
                    current_char_set = popup_choice(current_char_set,
                                                    L_Charset, -1,
                                                    (char **)LYchar_set_names,
                                                    0, FALSE, FALSE);
+#endif
+                                                   
 #if defined(VMS) || defined(USE_SLANG)
                    move(L_Charset, COL_OPTION_VALUES);
                    clrtoeol();
@@ -4308,6 +4339,9 @@
        if (len > cset_len)
           cset_len = len;
        sprintf(temp, "%d", i);
+#ifndef ALL_CHSETS_IN_O_SCREEN 
+       if (!chset_selectability_info[i].hide_in_display_chsets)
+#endif
        PutOption(fp0, i==current_char_set, temp, LYchar_set_names[i]);
     }
     EndSelect(fp0);
@@ -4339,6 +4373,9 @@
        PutLabel(fp0, gettext("Assumed document character set"));
        BeginSelect(fp0, assume_char_set_string);
        for (i = 0; i < LYNumCharsets; i++) {
+#ifndef ALL_CHSETS_IN_O_SCREEN
+           if (!chset_selectability_info[i].hide_in_assumed_doc_chsets)
+#endif
            PutOption(fp0, i==curval,
                      LYCharSet_UC[i].MIMEname,
                      LYCharSet_UC[i].MIMEname);
diff -ru lynx2-8-3dev6-orig/src/LYReadCFG.c lynx2-8-3dev6/src/LYReadCFG.c
--- lynx2-8-3dev6-orig/src/LYReadCFG.c  Wed Aug 11 19:07:41 1999
+++ lynx2-8-3dev6/src/LYReadCFG.c       Thu Aug 12 05:11:27 1999
@@ -957,6 +957,93 @@
     return 0;
 }
 
+#ifndef ALL_CHSETS_IN_O_SCREEN
+PRIVATE int parse_chset_choise ARGS2(
+       char*,p,
+       BOOL,display_chset) /*if FALSE, then assumed doc chset*/
+{
+    int len,i,j;
+    int matches = 0;    
+    /*only one chset choice is allowed per line!*/
+    LYTrimHead(p);
+    LYTrimTail(p);
+    CTRACE(tfp,"parsing chset choice for %s:\"%s\"",
+       (display_chset?"display chset":"assumed doc chset"),p);
+    len=strlen(p);
+    if (!len) {
+       CTRACE(tfp," - EMPTY STRING\n");
+       return 1;
+    };
+    if (!strcasecmp(p,"<ALL>")) {
+       if (display_chset)
+           for (custom_display_chset=TRUE,i=0;i<LYNumCharsets;++i)
+               chset_selectability_info[i].hide_in_display_chsets = FALSE;
+       else
+           for(custom_assumed_doc_chset=TRUE,i=0;i<LYNumCharsets;++i)
+               chset_selectability_info[i].hide_in_assumed_doc_chsets = FALSE; 
+       CTRACE(tfp," - all unhidden\n");
+       return 0;
+    };
+    if (p[len-1] == '*') {             
+       --len;
+       for (i=0;i<LYNumCharsets;++i){
+           if ( (!strncasecmp(p,LYchar_set_names[i],len)) ||
+               (!strncasecmp(p,LYCharSet_UC[i].MIMEname,len)) )
+           {
+               ++matches;
+               if (display_chset && !custom_display_chset)
+                   for(custom_display_chset=TRUE,j=0;j<LYNumCharsets;++j)
+                       chset_selectability_info[j].hide_in_display_chsets = 
TRUE;
+               else if (!display_chset && !custom_assumed_doc_chset)
+                   for(custom_assumed_doc_chset=TRUE,j=0;j<LYNumCharsets;++j)
+                       chset_selectability_info[j].hide_in_assumed_doc_chsets 
= TRUE;
+               if (display_chset)
+                   chset_selectability_info[i].hide_in_display_chsets = FALSE;
+               else
+                   chset_selectability_info[i].hide_in_assumed_doc_chsets = 
FALSE;
+           }
+       }
+       CTRACE(tfp," - %d matches\n",matches);
+       return 0;
+    } else {
+       for (i=0;i<LYNumCharsets;++i)
+           if ( (!strcasecmp(p,LYchar_set_names[i])) ||
+               (!strcasecmp(p,LYCharSet_UC[i].MIMEname)) )
+           {
+               if (display_chset && !custom_display_chset)
+                   for(custom_display_chset=TRUE,j=0;j<LYNumCharsets;++j)
+                       chset_selectability_info[j].hide_in_display_chsets = 
TRUE;                  
+               else if (!display_chset && !custom_assumed_doc_chset)
+                   for(custom_assumed_doc_chset=TRUE,j=0;j<LYNumCharsets;++j)
+                       chset_selectability_info[j].hide_in_assumed_doc_chsets 
= TRUE;
+               if (display_chset)
+                   chset_selectability_info[i].hide_in_display_chsets = FALSE;
+               else
+                   chset_selectability_info[i].hide_in_assumed_doc_chsets = 
FALSE;
+                   
+               CTRACE(tfp," - OK\n");
+               ++matches;
+               return 0;
+           }
+       if (!matches) {
+           CTRACE(tfp," - NOT RECOGNISED\n");
+           return 1;
+       };
+    };
+};
+
+PRIVATE int parse_display_chset_choise ARGS1(char*,p)
+{
+    return parse_chset_choise(p,1);
+};
+
+PRIVATE int parse_assumed_doc_chset_choise ARGS1(char*,p)
+{
+    return parse_chset_choise(p,0);
+};
+
+#endif
+
 #if defined(__STDC__) || defined(_WIN_CC)
 #define defHTSRC_parse_fun(x) static int html_src_set_##x ARGS1( char*,str) \
  { parse_html_src_spec(HTL_##x,str,#x); return 0; }
@@ -1035,6 +1122,9 @@
      PARSE_FUN("assume_charset", CONF_FUN, assume_charset_fun),
      PARSE_FUN("assume_local_charset", CONF_FUN, assume_local_charset_fun),
      PARSE_FUN("assume_unrec_charset", CONF_FUN, assume_unrec_charset_fun),
+#ifndef ALL_CHSETS_IN_O_SCREEN
+     
PARSE_FUN("assumed_doc_chset_choice",CONF_FUN,parse_assumed_doc_chset_choise),  
   
+#endif
      PARSE_SET("block_multi_bookmarks", CONF_BOOL, &LYMBMBlocked),
      PARSE_SET("bold_h1", CONF_BOOL, &bold_H1),
      PARSE_SET("bold_headers", CONF_BOOL, &bold_headers),
@@ -1069,6 +1159,9 @@
 #endif
 #ifdef DIRED_SUPPORT
      PARSE_FUN("dired_menu", CONF_FUN, dired_menu_fun),
+#endif
+#ifndef ALL_CHSETS_IN_O_SCREEN
+     PARSE_FUN("display_chset_choice",CONF_FUN,parse_display_chset_choise),    
    
 #endif
      PARSE_ADD("downloader", CONF_ADD_ITEM, downloaders),
      PARSE_SET("emacs_keys_always_on", CONF_BOOL, &emacs_keys),


reply via email to

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