]> git.localhorst.tv Git - l2e.git/blobdiff - src/main.cpp
generate header when output file ends with 'h'
[l2e.git] / src / main.cpp
index 00fea98dfba5506231f60141c4763b902a024fb6..edb0f1c8e47f28ca7361d32970a6e873e0b4f3ca 100644 (file)
@@ -36,6 +36,7 @@
 #include "sdl/InitSDL.h"
 
 #include <cstdlib>
+#include <cstring>
 #include <ctime>
 #include <exception>
 #include <iostream>
@@ -138,12 +139,23 @@ int main(int argc, char **argv) {
                switch (args.DetectRunLevel()) {
                        case Arguments::COMPILE:
                        {
-                               std::ofstream testOut(args.OutfilePath());
-                               Compiler(intp).Write(testOut);
+                               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:
-                       {
+                       case Arguments::DUMP: {
                                std::cout << source << std::endl;
                                return 0;
                        }