]> git.localhorst.tv Git - l2e.git/blobdiff - src/main.cpp
generate header when output file ends with 'h'
[l2e.git] / src / main.cpp
index 97706269dcedf978f7ee12d9a90f79763ad6f67c..edb0f1c8e47f28ca7361d32970a6e873e0b4f3ca 100644 (file)
@@ -36,6 +36,7 @@
 #include "sdl/InitSDL.h"
 
 #include <cstdlib>
+#include <cstring>
 #include <ctime>
 #include <exception>
 #include <iostream>
@@ -135,10 +136,31 @@ 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:
+                       {
+                               int length(std::strlen(args.OutfilePath()));
+                               switch (args.OutfilePath()[length - 1]) {
+                                       case 'h': {
+                                               std::ofstream outstream(args.OutfilePath());
+                                               source.WriteHeader(outstream);
+                                               break;
+                                       }
+                                       default:
+                                       case 'o': {
+                                               std::ofstream outstream(args.OutfilePath());
+                                               Compiler(intp).Write(outstream);
+                                               break;
+                                       }
+                               }
+                               return 0;
+                       }
+                       case Arguments::DUMP: {
+                               std::cout << source << std::endl;
+                               return 0;
+                       }
+                       case Arguments::PLAY:
+                               break;
                }
 
                int battleResId(TypeDescription::GetTypeId("BattleResources"));