lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev lynx-2.8.2dev19 commandline patch


From: Vlad Harchev
Subject: lynx-dev lynx-2.8.2dev19 commandline patch
Date: Wed, 10 Mar 1999 18:00:06 +0400 (SAMT)

  Here is a patch that allows the use of '--' prefix for commandline options
 ( '-' can also be used ), same for options redirected to stdin. This means 
 that '-localhost' and '--localhost' mean the same thing for lynx. 
 
 If EXTENDED_OPTION_LOGIC is defined and ==1 (it will be defined to 1 if 
 it wasn't defined ) then the extended commandline option logic 
 will be used. It means that '--' will be accepted and will be treated as an
 end of options. Anything after it will be treated as URL even if begins with 
 '-' or '--'. Also the number of URLs passed will be counted and stored in 
 variable 'url_count'. Search for a symbol FILLTHIS in this patch and fill 
 in actions lynx should take when it encounters several URLs passed - I don't
 know how to put and what to put in message catalogue ( or disable the 
 execution of the branch ). This works for both regular commandline options
 and for ones redirected to stdin.
 
 May be lynx help message should be modified to accomodate the changes.

  Best regards, 
  -Vlad

diff -ru lynx-2.8.2dev19-orig/src/LYMain.c lynx-2.8.2dev19-fixed/src/LYMain.c
--- lynx-2.8.2dev19-orig/src/LYMain.c   Tue Mar  9 22:45:05 1999
+++ lynx-2.8.2dev19-fixed/src/LYMain.c  Wed Mar 10 17:42:45 1999
@@ -393,6 +393,18 @@
 PRIVATE BOOLEAN LYPrependBase = FALSE;
 PRIVATE HTList *LYStdinArgs = NULL;
 
+#ifndef EXTENDED_OPTION_LOGIC
+  /* if ==1, then '--' will be recognized as the end of options, and
+     the number of URLs passed will be counted.
+  */
+# define EXTENDED_OPTION_LOGIC 1
+#endif
+#if EXTENDED_OPTION_LOGIC
+PRIVATE BOOLEAN no_options_further=FALSE; /* set to TRUE after '--' argument */
+PRIVATE int url_count=0;/* counts URLs passed via command line. If >1, then
+        error message is printed. */
+#endif
+
 PRIVATE void parse_arg PARAMS((char **arg, int *i));
 PRIVATE void print_help_and_exit PARAMS((int exit_status));
 
@@ -598,6 +610,24 @@
 }
 #endif /* EBCDIC */
 
+/*these two are used for matching commanline options. */
+PRIVATE int argcmp ARGS2(
+       char*,          str,
+       char*,          what)
+{
+ if (str[0] == '-' && str[1] == '-' ) ++str;
+ return strcmp(str,what);
+};        
+
+PRIVATE int argncmp ARGS3(
+       char*,          str,
+       char*,          what,
+        int  ,          len )
+{
+ if (str[0] == '-' && str[1] == '-' ) ++str;
+ return strncmp(str,what,len);
+};        
+
 /*
  * Wow!  Someone wants to start up Lynx.
  */
@@ -673,7 +703,7 @@
      * Act on -help NOW, so we only output the help and exit. - FM
      */
     for (i = 1; i < argc; i++) {
-       if (strncmp(argv[i], "-help", 5) == 0) {
+       if (argncmp(argv[i], "-help", 5) == 0) {
            parse_arg(&argv[i], &i);
        }
     }
@@ -873,28 +903,28 @@
      * the help menu, output that and exit. - FM
      */
     for (i = 1; i < argc; i++) {
-       if (strncmp(argv[i], "-trace", 6) == 0) {
+       if (argncmp(argv[i], "-trace", 6) == 0) {
            WWW_TraceFlag = TRUE;
-       } else if (strncmp(argv[i], "-tlog", 5) == 0) {
+       } else if (argncmp(argv[i], "-tlog", 5) == 0) {
            if (LYUseTraceLog) {
                LYUseTraceLog = FALSE;
            } else {
                LYUseTraceLog = TRUE;
            }
-       } else if (strncmp(argv[i], "-anonymous", 10) == 0) {
+       } else if (argncmp(argv[i], "-anonymous", 10) == 0) {
            if (!LYValidate)
                parse_restrictions("default");
            LYRestricted = TRUE;
-       } else if (strcmp(argv[i], "-validate") == 0) {
+       } else if (argcmp(argv[i], "-validate") == 0) {
            /*
             *  Follow only http URLs.
             */
            LYValidate = TRUE;
 #ifdef SOCKS
-       } else if (strncmp(argv[i], "-nosocks", 8) == 0) {
+       } else if (argncmp(argv[i], "-nosocks", 8) == 0) {
            socks_flag = FALSE;
 #endif /* SOCKS */
-       } else if (strncmp(argv[i], "-cfg", 4) == 0) {
+       } else if (argncmp(argv[i], "-cfg", 4) == 0) {
            if ((cp=strchr(argv[i],'=')) != NULL)
                StrAllocCopy(lynx_cfg_file, cp+1);
            else {
@@ -903,7 +933,7 @@
            }
 
 #if defined(USE_HASH)
-       } else if (strncmp(argv[i], "-lss", 4) == 0) {
+       } else if (argncmp(argv[i], "-lss", 4) == 0) {
            if ((cp=strchr(argv[i],'=')) != NULL)
                StrAllocCopy(lynx_lss_file, cp+1);
            else {
@@ -947,28 +977,28 @@
                buf[j] = '\0';
            }
 
-           if (strncmp(buf, "-trace", 6) == 0) {
+           if (argncmp(buf, "-trace", 6) == 0) {
                WWW_TraceFlag = TRUE;
-           } else if (strncmp(buf, "-tlog", 5) == 0) {
+           } else if (argncmp(buf, "-tlog", 5) == 0) {
                if (LYUseTraceLog) {
                    LYUseTraceLog = FALSE;
                } else {
                    LYUseTraceLog = TRUE;
                }
-           } else if (strncmp(buf, "-anonymous", 10) == 0) {
+           } else if (argncmp(buf, "-anonymous", 10) == 0) {
                if (!LYValidate && !LYRestricted)
                    parse_restrictions("default");
                LYRestricted = TRUE;
-           } else if (strcmp(buf, "-validate") == 0) {
+           } else if (argcmp(buf, "-validate") == 0) {
                /*
                 *  Follow only http URLs.
                 */
                LYValidate = TRUE;
 #ifdef SOCKS
-           } else if (strncmp(buf, "-nosocks", 8) == 0) {
+           } else if (argncmp(buf, "-nosocks", 8) == 0) {
                socks_flag = FALSE;
 #endif /* SOCKS */
-           } else if (strncmp(buf, "-cfg", 4) == 0) {
+           } else if (argncmp(buf, "-cfg", 4) == 0) {
                if ((cp = strchr(buf,'=')) != NULL) {
                    StrAllocCopy(lynx_cfg_file, cp+1);
                } else {
@@ -978,7 +1008,7 @@
                        StrAllocCopy(lynx_cfg_file, cp);
                }
 #if defined(USE_HASH)
-           } else if (strncmp(buf, "-lss", 4) == 0) {
+           } else if (argncmp(buf, "-lss", 4) == 0) {
                if ((cp = strchr(buf,'=')) != NULL) {
                    StrAllocCopy(lynx_lss_file, cp+1);
                } else {
@@ -990,7 +1020,7 @@
                CTRACE(tfp, "LYMain found -lss flag, lss file is %s\n",
                        lynx_lss_file ? lynx_lss_file : "<NONE>");
 #endif
-           } else if (strcmp(buf, "-get_data") == 0) {
+           } else if (argcmp(buf, "-get_data") == 0) {
                /*
                 *  User data for GET form.
                 */
@@ -1029,7 +1059,7 @@
                    }
                    StrAllocCat(*get_data, buf);
                }
-           } else if (strcmp(buf, "-post_data") == 0) {
+           } else if (argcmp(buf, "-post_data") == 0) {
                /*
                 *  User data for POST form.
                 */
@@ -3118,7 +3148,20 @@
     /*
      * Check for a command line startfile. - FM
      */
+#if !EXTENDED_OPTION_LOGIC    
     if (*arg_name != '-') {
+#else
+    if (*arg_name != '-' || no_options_further==TRUE ) 
+      if (url_count>1) {
+        /* here we've encountered excessive url - this seems to be an 
+            ill-formed  command-line */
+           /*FILLTHIS or remove this branch if you don't consider this an
+            error*/
+        }
+      else            
+      {
+        url_count++;
+#endif    
        StrAllocCopy(startfile, arg_name);
        LYTrimHead(startfile);
        if (!strncasecomp(startfile, "lynxexec:", 9) ||
@@ -3135,6 +3178,11 @@
        }
        return;
     }
+#if EXTENDED_OPTION_LOGIC        
+    if (strcmp(arg_name,"--")==0) {
+        no_options_further=TRUE; return;
+    }    
+#endif
 
     /* lose the first '-' character */
     arg_name++;
@@ -3146,6 +3194,10 @@
      */
     if (*arg_name == 0)
        return;
+    
+    /* allow GNU-style options with -- prefix*/    
+    if (*arg_name == '-') ++arg_name; 
+    
 
     p = Arg_Table;
     while (p->name != 0) {




reply via email to

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