supply -d as an argument to dump read files
namespace app {
Arguments::Arguments()
-: outfile(0) {
+: outfile(0)
+, dump(false) {
}
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");
}
}
+Arguments::RunLevel Arguments::DetectRunLevel() const {
+ if (dump) {
+ return DUMP;
+ } else if (outfile) {
+ return COMPILE;
+ } else {
+ return PLAY;
+ }
+}
+
}
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; }
private:
std::vector<char *> infiles;
const char *outfile;
+ bool dump;
};
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"));