lynx-dev
[Top][All Lists]
Advanced

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

Re: lynx-dev extending the syntax of 'include' command in lynx.cfg


From: Vlad Harchev
Subject: Re: lynx-dev extending the syntax of 'include' command in lynx.cfg
Date: Thu, 15 Apr 1999 00:51:21 +0500 (SAMST)

On Wed, 14 Apr 1999, Vlad Harchev wrote:

>  IMO it would be good if the 'include' command had the list of settings that
> can be specified in included file. So admins can specify 
> 'include:~/.lynx/colors:COLOR' 
> 'include:~/.lynx/keymap:KEYMAP'
> 'include:~/.lynx/viewers:VIEWER'
> 
>  safely - and be sure that no critical options were altered by those files.
> The suggested syntax is 
> include:<filename>[:[<OPTNAME>* ] ]
> more samples:
> include:~/.lynx/rc:COLOR KEYMAP VIEWER SUFFIX
> include:/usr/local/lib/lynx-cfg.part: #all settings can be changed
> 
>  More brave approach:
>  Make ~/.lynxrc to be included by lynx.cfg (it's syntax must be changed to one
> of lynx.cfg), with a list of options it can contain in the 'include' line. As
> I understand, with  LP's patch lynx.cfg can be edited at runtime and reloaded
>  in the same session - such feature as editing options specified in .lynxrc
>  at runtime is not the major privelege (or feature) of .lynxrc. So, a huge
> section of code ~32KB can be removed when using this approach. 
>  In present state, users with paranoid sysadm were to live with colors s/he
  Here is a patch that implements this functionality (except brave approach).
 It works as described. Features:
*It prints warnings to stderr about unknown options specified in the list of
allowed options in include command. When 'o'->'lynx.cfg'->'RELOAD THE CHANGES'
is activated, these warnings are also printed on stderr - so the screen will
be corrupted if lynx.cfg and included are incorrect. 
* Only options, allowed for a given file are printed in 
  'o'->'lynx.cfg'->'RELOAD THE CHANGES'.
* Fully backward compatible - lines of the form
        include:filename
  will work as they did( ie if the list of allowed options is not specified,
  then the included file can use the same set of options, as the file that
  contained that 'include' command).
* A funny and may be powerful feature - if you wish to allow included file to
  include others, you must specify 'include' in the list of allowed options.
  Sample:
          include:~/.lynx/suffixes:INCLUDE SUFFIX
  so thet user will be able to use 'include' command in '~/.lynx/suffixes' 
  (otherwise included file will be unable to include anything)
* Option sets are ANDed. If file lynx.cfg contains:
        include:/usr/lib/lynx.cfg.0:COLOR SUFFIX VIEWER INCLUDE
 and /usr/lib/lynx.cfg.0 contains
        include:/usr/lib/lynx.cfg.1:SUFFIX VIEWER INCLUDE STARTFILE HELPFILE
 then /usr/lib/lynx.cfg.1 can use the following options:
        SUFFIX VIEWER INCLUDE

NOTE: May be it will be good if the new lynx distributions will use directory
~/.lynx as the place for .lynxrc (so it can be called simply 'rc' - ie
~/.lynx/rc) and all bookmarks, cookies are also placed in this dir. Also we
can provide as set of preconfigured keymaps (emacs,pc,etc), and add commented
lines that contain 'include' of each of such file - so sysadm have only to
uncomment the line s/he wishes (or the user have to copy the piece s/he likes
in the ~/.lynx under general name). Or we can insert the following lines in
lynx.cfg:

#the following line includes user keymap. To users: put the keymap
#(one of the distribution's keymap -  emacs-keymap, vi-keymap, foo-keymap, or
# composed by yourself) to the ~/.lynx/keymap
include:~/.lynx/keymap:KEYMAP INCLUDE

 Midnight Commander also uses approach of putting all cfg files and caches
in '~/.mc' . Here is a 'ls ~/.mc': history hotlist ini tree

PS: It will be good if someone documented the 'include' command. As I
remember, even the description of the plain 'include' is absent in the docs.
PS2: I checked this patch with original dev22 with 'enable' and 'disable' of 
config-info.

 Best regards,
  -Vlad


diff -ruP dev22-orig/src/LYReadCFG.c lynx-2.8.2dev22-fixed/src/LYReadCFG.c
--- lynx-2.8.2dev22-orig/src/LYReadCFG.c        Tue Apr 13 15:01:15 1999
+++ lynx-2.8.2dev22-fixed/src/LYReadCFG.c       Thu Apr 15 00:15:27 1999
@@ -443,7 +443,7 @@
 }
 #endif /* USE_COLOR_TABLE */
 
-#define MAX_LINE_BUFFER_LEN    501
+#define MAX_LINE_BUFFER_LEN    1501
 
 typedef int (*ParseFunc) PARAMS((char *));
 
@@ -1214,14 +1214,32 @@
     }
 }
 
+#define NOPTS_ ( (sizeof Config_Table)/(sizeof Config_Table[0]) - 1 )
+typedef BOOL (optidx_set_t) [ NOPTS_ ];   
+ /* if elt is FALSE, then it's allowed in the current file*/
+
+#define optidx_set_AND(r,a,b) \
+    {\
+        int i1;\
+        for (i1=0;i1<NOPTS_;++i1) \
+            (r)[i1]= (a)[i1] || (b)[i1]; \
+    }
+        
+
 /*
  * Process the configuration file (lynx.cfg).
+ *
+ * opts_allowed is ptr to HTList of allowed options. Since included file can
+ *         also include other file with a list of acceptable options, these 
+ *         lists are ANDed. The 'object' member of the HTList is casted to 
+ *         'short' - it's an index of the  
  */
-PUBLIC void read_cfg ARGS4(
+PRIVATE void do_read_cfg ARGS5(
        char *, cfg_filename,
        char *, parent_filename,
        int,    nesting_level,
-       FILE *, fp0)
+       FILE *, fp0,
+        optidx_set_t*, allowed)        
 {
     FILE *fp;
     char mypath[LY_MAXPATH];
@@ -1326,6 +1344,17 @@
            /* fprintf (stderr, "%s not found in config file */
            continue;
        }
+        
+        if ( allowed && (*allowed)[ tbl-Config_Table ] ) { 
+            if (fp0 == NULL)
+                fprintf (stderr, "%s is not allowed in the %s\n",
+                    name,cfg_filename); 
+            /*FIXME: we can do something wiser if we are generating 
+            the html representation of lynx.cfg - say include this line 
+            in bold, or something...*/
+            
+            continue;
+        };
 
 #ifdef PARSE_DEBUG
        q = tbl;
@@ -1386,12 +1415,21 @@
            }
            break;
 
-       case CONF_INCLUDE:
-           /* include another file */
+       case CONF_INCLUDE: {
+           /* include another file */                          
+            optidx_set_t cur_set,anded_set;
+            optidx_set_t* resultant_set=NULL; 
+            char* p1,*p2,savechar,ch;
+            BOOL any_optname_found=FALSE;
+            
+            char *url = NULL;
+            char *cp1 = NULL;            
+            
+            if (p1=strchr(value,':')) 
+                *p1++ ='\0';
+                
 #ifndef NO_CONFIG_INFO
            if (fp0 != 0  &&  !LYRestricted) {
-               char *url = 0;
-               char *cp1 = NULL;
                LYLocalFileToURL(&url, value);
                StrAllocCopy(cp1, value);
                if (strchr(value, '&') || strchr(value, '<')) {
@@ -1400,17 +1438,101 @@
 
                fprintf(fp0, "%s:<a href=\"%s\">%s</a>\n\n", name, url, cp1);
                fprintf(fp0, "    #&lt;begin  %s&gt;\n", cp1);
+            };
+#endif
+            
+            if (p1) {    
+                while (1) {    
+                    Config_Type *tbl;
+                    char ch;
+                    char* name;
+                    
+                    while (*p1 && isspace(*p1)) ++p1;
+                    if (!*p1) break;
+                    name=p1;
+                    p2=p1+1;
+                    while (*p2 && !isspace(*p2)) ++p2;
+                    savechar=*p2;                    
+                    *p2=0;
+
+                   tbl = Config_Table;
+                   ch = TOUPPER(*name);
+                    
+                   while (tbl->name != 0) {
+                       char ch1 = tbl->name[0];
+
+                       if ((ch == TOUPPER(ch1))
+                           && (0 == strcasecomp (name, tbl->name)))
+                       break;
+
+                       tbl++;
+                   };
+
+                   if (tbl->name == 0) {
+                        if (fp0 == NULL)
+                           fprintf (stderr, "unknow option name %s in the list 
of"
+                            " allowed optnames in %s\n",name,cfg_filename);
+                        /*FIXME - can do something wiser if generating the 
+                        html from lynx.cfg */    
+                   } else {
+                        int i;
+                        if (!any_optname_found) {                            
+                            any_optname_found=TRUE;
+                            for(i=0;i<NOPTS_;++i)
+                                cur_set[i]=TRUE; 
+                        };    
+                        cur_set[tbl-Config_Table]=FALSE;
+                    };    
+                    if (savechar && *(p2+1) ) 
+                        p1=p2+1;
+                    else 
+                        break;                    
+                };    
+            };
+            if (!allowed)
+                if (!any_optname_found) 
+                    resultant_set=NULL;
+                else
+                    resultant_set=&cur_set;    
+            else 
+                if (!any_optname_found)  
+                    resultant_set=allowed;
+                else {
+                    optidx_set_AND(anded_set,*allowed,cur_set);
+                    resultant_set=&anded_set;
+                };
+
+#ifndef NO_CONFIG_INFO                
+            /*now list the opts that are allowed in included file. If all opts
+            are allowed, then emit nothing, else emit an effective set of 
+            allowed options in <ul>. Option names will be and uppercased. 
+            FIXME: uppercasing option names can be considered redundant. */
+            
+            if (fp0 != 0  &&  !LYRestricted && resultant_set) {
+                char buf[2000];
+                int i;
+                
+                fprintf(fp0,"    Options allowed in this file:\n");
+                for (i=0;i<NOPTS_;++i) {
+                    if ((*resultant_set)[i]) 
+                        continue;
+                    strcpy(buf,Config_Table[i].name);
+                    LYUpperCase(buf);
+                    fprintf(fp0,"        * %s\n",buf);
+                };
+                /*fprintf(fp0,"\n");*/
+            };       
+#endif                    
+           do_read_cfg (value, cfg_filename, nesting_level + 1, 
fp0,resultant_set);            
 
-               read_cfg (value, cfg_filename, nesting_level + 1, fp0);
-
+#ifndef NO_CONFIG_INFO            
+            if (fp0 != 0  &&  !LYRestricted) {
                fprintf(fp0, "    #&lt;end of %s&gt;\n\n", cp1);
                FREE(url);
                FREE(cp1);
-           } else
-#endif /* !NO_CONFIG_INFO */
-
-           read_cfg (value, cfg_filename, nesting_level + 1, fp0);
-
+            };
+#endif
+            };
            break;
 
        case CONF_ADD_ITEM:
@@ -1514,6 +1636,17 @@
     }
 
 }
+/* this is a public interface to do_read_cfg */        
+PUBLIC void read_cfg ARGS4(
+       char *, cfg_filename,
+       char *, parent_filename,
+       int,    nesting_level,
+       FILE *, fp0)
+{
+    do_read_cfg(cfg_filename,parent_filename,nesting_level,fp0,
+        NULL);
+};
+
 
 /*
  *  Show rendered lynx.cfg data without comments, LYNXCFG:/ internal page.


reply via email to

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