]> git.localhorst.tv Git - l2e.git/commitdiff
added dump option
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 15 Sep 2012 19:01:11 +0000 (21:01 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 15 Sep 2012 19:45:45 +0000 (21:45 +0200)
supply -d as an argument to dump read files

src/app/Arguments.cpp
src/app/Arguments.h
src/main.cpp

index bdfdf181579c17d934125cbc5b84c3f4c2706c12..d01cf2a4ba1b409d97cdfe5c1f0f890bf02a54f0 100644 (file)
@@ -13,7 +13,8 @@
 namespace app {
 
 Arguments::Arguments()
-: outfile(0) {
+: outfile(0)
+, dump(false) {
 
 }
 
@@ -23,6 +24,9 @@ void Arguments::Read(int argc, char **argv) {
                char *arg(argv[i]);
                if (arg[0] == '-') {
                        switch (arg[1]) {
+                               case 'd':
+                                       dump = true;
+                                       break;
                                case 'o':
                                        if (i + 1 >= argc) {
                                                throw std::runtime_error("missing argument to -o");
@@ -40,4 +44,14 @@ void Arguments::Read(int argc, char **argv) {
        }
 }
 
+Arguments::RunLevel Arguments::DetectRunLevel() const {
+       if (dump) {
+               return DUMP;
+       } else if (outfile) {
+               return COMPILE;
+       } else {
+               return PLAY;
+       }
+}
+
 }
index c7e37eee1419209d95cb2db9453982376de71c09..9bd35a93ad540c5a13c9ef95601ea6ed70969199 100644 (file)
@@ -18,9 +18,18 @@ public:
        Arguments();
        ~Arguments() { }
 
+public:
+       enum RunLevel {
+               COMPILE,
+               DUMP,
+               PLAY,
+       };
+
 public:
        void Read(int argc, char **argv);
 
+       RunLevel DetectRunLevel() const;
+
        const std::vector<char *> &Infiles() const { return infiles; }
 
        bool OutfileSet() const { return outfile; }
@@ -29,6 +38,7 @@ public:
 private:
        std::vector<char *> infiles;
        const char *outfile;
+       bool dump;
 
 };
 
index 97706269dcedf978f7ee12d9a90f79763ad6f67c..00fea98dfba5506231f60141c4763b902a024fb6 100644 (file)
@@ -135,10 +135,20 @@ int main(int argc, char **argv) {
                Interpreter intp(source);
                intp.ReadSource();
 
-               if (args.OutfileSet()) {
-                       std::ofstream testOut(args.OutfilePath());
-                       Compiler(intp).Write(testOut);
-                       return 0;
+               switch (args.DetectRunLevel()) {
+                       case Arguments::COMPILE:
+                       {
+                               std::ofstream testOut(args.OutfilePath());
+                               Compiler(intp).Write(testOut);
+                               return 0;
+                       }
+                       case Arguments::DUMP:
+                       {
+                               std::cout << source << std::endl;
+                               return 0;
+                       }
+                       case Arguments::PLAY:
+                               break;
                }
 
                int battleResId(TypeDescription::GetTypeId("BattleResources"));