]> granicus.if.org Git - re2c/commitdiff
Fixed re2c behaviour with "--" command line option.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 21 Jul 2015 12:47:31 +0000 (13:47 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 21 Jul 2015 12:47:31 +0000 (13:47 +0100)
All arguments after "--" are treated as non-options. This can be
used to handle option-like filenames (those starting with "-" and "--").

re2c/bootstrap/src/conf/parse_opts.cc
re2c/src/conf/parse_opts.re

index 70ecf3f64bddeb0d9f9bc44467a8412b91f02f47..8c7612f7c1b524ed8cc2d034e3116c58328d2c03 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.14.3 on Tue Jul 21 12:00:08 2015 */
+/* Generated by re2c 0.14.3 on Tue Jul 21 13:43:41 2015 */
 #include <stdio.h>
 
 #include "src/conf/msg.h"
@@ -92,7 +92,19 @@ yy9:
        { if (!opts.source ("<stdin>")) return EXIT_FAIL; goto opt; }
 yy11:
        ++YYCURSOR;
-       { goto end; }
+       {
+               // all remaining arguments are non-options
+               // so they must be input files
+               // re2c expects exactly one input file
+               if (const char * f = *++argv)
+               {
+                       if (!opts.source (f) || *++argv)
+                       {
+                               return EXIT_FAIL;
+                       }
+               }
+               goto end;
+       }
 yy13:
        ++YYCURSOR;
        yych = *YYCURSOR;
index dc62c025c539d4f15f769fdc1f54e59fea132241..087c272169b98fd913f8038b40222fb34355c8cd 100644 (file)
@@ -38,7 +38,20 @@ opt:
                return EXIT_FAIL;
        }
 
-       "--" end { goto end; }
+       "--" end
+       {
+               // all remaining arguments are non-options
+               // so they must be input files
+               // re2c expects exactly one input file
+               if (const char * f = *++argv)
+               {
+                       if (!opts.source (f) || *++argv)
+                       {
+                               return EXIT_FAIL;
+                       }
+               }
+               goto end;
+       }
 
        "-"      end { if (!opts.source ("<stdin>")) return EXIT_FAIL; goto opt; }
        filename end { if (!opts.source (*argv))     return EXIT_FAIL; goto opt; }