From: Daniel Karbach Date: Sat, 15 Sep 2012 19:01:11 +0000 (+0200) Subject: added dump option X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=d557b3422756e3492b60cf545fd956a2fbf18af1;p=l2e.git added dump option supply -d as an argument to dump read files --- diff --git a/src/app/Arguments.cpp b/src/app/Arguments.cpp index bdfdf18..d01cf2a 100644 --- a/src/app/Arguments.cpp +++ b/src/app/Arguments.cpp @@ -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; + } +} + } diff --git a/src/app/Arguments.h b/src/app/Arguments.h index c7e37ee..9bd35a9 100644 --- a/src/app/Arguments.h +++ b/src/app/Arguments.h @@ -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 &Infiles() const { return infiles; } bool OutfileSet() const { return outfile; } @@ -29,6 +38,7 @@ public: private: std::vector infiles; const char *outfile; + bool dump; }; diff --git a/src/main.cpp b/src/main.cpp index 9770626..00fea98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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"));