]> granicus.if.org Git - re2c/commitdiff
Allow to specify exacly one input file and at most one output and header file.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 21 Jul 2015 11:15:01 +0000 (12:15 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 21 Jul 2015 11:15:01 +0000 (12:15 +0100)
re2c/bootstrap/src/conf/parse_opts.cc
re2c/src/codegen/output.cc
re2c/src/conf/opt.cc
re2c/src/conf/opt.h
re2c/src/conf/parse_opts.re

index f0707db053a3823e6e055673436c08a14cfb8004..70ecf3f64bddeb0d9f9bc44467a8412b91f02f47 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.14.3 on Sun Jul 19 12:06:48 2015 */
+/* Generated by re2c 0.14.3 on Tue Jul 21 12:00:08 2015 */
 #include <stdio.h>
 
 #include "src/conf/msg.h"
@@ -89,7 +89,7 @@ yy7:
        { goto opt_long; }
 yy9:
        ++YYCURSOR;
-       { opts.source ("<stdin>"); goto opt; }
+       { if (!opts.source ("<stdin>")) return EXIT_FAIL; goto opt; }
 yy11:
        ++YYCURSOR;
        { goto end; }
@@ -101,7 +101,7 @@ yy14:
                goto yy13;
        }
        ++YYCURSOR;
-       { opts.source (*argv);     goto opt; }
+       { if (!opts.source (*argv))     return EXIT_FAIL; goto opt; }
 }
 
 
@@ -466,7 +466,7 @@ yy131:
        yych = *++YYCURSOR;
        if (yych >= 0x01) goto yy89;
        ++YYCURSOR;
-       { goto opt_header; }
+       { YYCURSOR = *++argv; goto opt_header; }
 yy143:
        yych = *++YYCURSOR;
        if (yych == 'n') goto yy184;
@@ -605,7 +605,7 @@ yy204:
        yych = *++YYCURSOR;
        if (yych >= 0x01) goto yy89;
        ++YYCURSOR;
-       { goto opt_output; }
+       { YYCURSOR = *++argv; goto opt_output; }
 yy211:
        yych = *++YYCURSOR;
        if (yych == '-') goto yy223;
@@ -1009,7 +1009,7 @@ yy387:
                goto yy386;
        }
        ++YYCURSOR;
-       { opts.output (*argv); goto opt; }
+       { if (!opts.output (*argv)) return EXIT_FAIL; goto opt; }
 }
 
 
@@ -1071,7 +1071,7 @@ yy396:
                goto yy395;
        }
        ++YYCURSOR;
-       { opts.type_header (*argv); goto opt; }
+       { if (!opts.type_header (*argv)) return EXIT_FAIL; goto opt; }
 }
 
 
@@ -1288,6 +1288,11 @@ yy477:
 
 
 end:
+       if (!opts.source_file)
+       {
+               error ("no source file\n");
+               return EXIT_FAIL;
+       }
        if (!cFlag && opts.header_file)
        {
                error ("can only output a header file when using -c switch\n");
index 30adfa58ae4facefab943cb2d9aa65a855c0a44d..b2461531b0abd0a0475b16e8e490f698c9d007d5 100644 (file)
@@ -60,8 +60,9 @@ OutputFile::OutputFile (const char * fn)
 
 bool OutputFile::open ()
 {
-       if (strcmp (file_name, "<stdout>") == 0)
+       if (file_name == NULL)
        {
+               file_name = "<stdout>";
                file = stdout;
        }
        else
index 561a51be02b32893a6727669d17737ac80c53be3..9773fbf62cb768521c43ebd6e84aa262a5af57e9 100644 (file)
@@ -1,3 +1,4 @@
+#include "src/conf/msg.h"
 #include "src/conf/opt.h"
 
 namespace re2c
@@ -129,22 +130,6 @@ void Opt::skeleton ()
        flag_skeleton = true;
 }
 
-void Opt::source (const char * s)
-{
-       source_file = s;
-}
-
-void Opt::output (const char * s)
-{
-       output_file = s;
-}
-
-void Opt::type_header (const char * s)
-{
-       tFlag = true;
-       header_file = s;
-}
-
 void Opt::encoding_policy (Enc::policy_t p)
 {
        encoding.setPolicy (p);
@@ -160,6 +145,49 @@ void Opt::empty_class (empty_class_policy_t p)
        empty_class_policy = p;
 }
 
+bool Opt::source (const char * s)
+{
+       if (source_file)
+       {
+               error ("multiple source files: %s, %s\n", source_file, s);
+               return false;
+       }
+       else
+       {
+               source_file = s;
+               return true;
+       }
+}
+
+bool Opt::output (const char * s)
+{
+       if (output_file)
+       {
+               error ("multiple output files: %s, %s\n", output_file, s);
+               return false;
+       }
+       else
+       {
+               output_file = s;
+               return true;
+       }
+}
+
+bool Opt::type_header (const char * s)
+{
+       if (header_file)
+       {
+               error ("multiple header files: %s, %s\n", header_file, s);
+               return false;
+       }
+       else
+       {
+               tFlag = true;
+               header_file = s;
+               return true;
+       }
+}
+
 bool Opt::ecb ()
 {
        return encoding.set (Enc::EBCDIC);
index 6bc202f3605e73ddb89f564deae020473fc598a2..95409a6eb92e7251bcb3fe2e710fdd36013f85a3 100644 (file)
@@ -19,7 +19,7 @@ struct Opt
 
        Opt ()
                : source_file (NULL)
-               , output_file ("<stdout>")
+               , output_file (NULL)
                , header_file (NULL)
        {}
 
@@ -37,12 +37,12 @@ struct Opt
        void case_insensitive ();
        void case_inverted ();
        void skeleton ();
-       void source (const char * s);
-       void output (const char * s);
-       void type_header (const char * s);
        void encoding_policy (Enc::policy_t);
        void input (InputAPI::type_t);
        void empty_class (empty_class_policy_t);
+       bool source (const char * s);
+       bool output (const char * s);
+       bool type_header (const char * s);
        bool ecb ();
        bool unicode ();
        bool wide_chars ();
index dadbe819ea19ee1c1c08e81b7045988eed55aa98..dc62c025c539d4f15f769fdc1f54e59fea132241 100644 (file)
@@ -40,8 +40,8 @@ opt:
 
        "--" end { goto end; }
 
-       "-"      end { opts.source ("<stdin>"); goto opt; }
-       filename end { opts.source (*argv);     goto opt; }
+       "-"      end { if (!opts.source ("<stdin>")) return EXIT_FAIL; goto opt; }
+       filename end { if (!opts.source (*argv))     return EXIT_FAIL; goto opt; }
 
        "-"  { goto opt_short; }
        "--" { goto opt_long; }
@@ -109,8 +109,8 @@ opt_long:
        "wide-chars"         end { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt; }
        "utf-16"             end { if (!opts.utf_16 ())     { error_encoding (); return EXIT_FAIL; } goto opt; }
        "utf-8"              end { if (!opts.utf_8 ())      { error_encoding (); return EXIT_FAIL; } goto opt; }
-       "output"             end { goto opt_output; }
-       "type-header"        end { goto opt_header; }
+       "output"             end { YYCURSOR = *++argv; goto opt_output; }
+       "type-header"        end { YYCURSOR = *++argv; goto opt_header; }
        "encoding-policy"    end { goto opt_encoding_policy; }
        "input"              end { goto opt_input; }
        "empty-class"        end { goto opt_empty_class; }
@@ -124,7 +124,7 @@ opt_output:
                error ("bad argument to option -o, --output: %s\n", *argv);
                return EXIT_FAIL;
        }
-       filename end { opts.output (*argv); goto opt; }
+       filename end { if (!opts.output (*argv)) return EXIT_FAIL; goto opt; }
 */
 
 opt_header:
@@ -134,7 +134,7 @@ opt_header:
                error ("bad argument to option -t, --type-header: %s\n", *argv);
                return EXIT_FAIL;
        }
-       filename end { opts.type_header (*argv); goto opt; }
+       filename end { if (!opts.type_header (*argv)) return EXIT_FAIL; goto opt; }
 */
 
 opt_encoding_policy:
@@ -176,6 +176,11 @@ opt_empty_class:
 */
 
 end:
+       if (!opts.source_file)
+       {
+               error ("no source file\n");
+               return EXIT_FAIL;
+       }
        if (!cFlag && opts.header_file)
        {
                error ("can only output a header file when using -c switch\n");