X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmain.cpp;h=73a9f16fff877eb6ddc013e6cd3b2b4f7e2169ee;hb=8c8061a4f8b88410d6d93c039afe6affc4b69cf2;hp=bdde265098a54a10ab8881d1ff021d56a61c0716;hpb=0f30d8254ff8b9e63795960ec031577cf68fbf95;p=l2e.git diff --git a/src/main.cpp b/src/main.cpp index bdde265..73a9f16 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,8 +19,6 @@ #include "common/Script.h" #include "common/Spell.h" #include "common/Stats.h" -#include "math/Fixed.h" -#include "math/Vector.h" #include "graphics/CharSelect.h" #include "graphics/ComplexAnimation.h" #include "graphics/Font.h" @@ -31,6 +29,7 @@ #include "graphics/Sprite.h" #include "graphics/Texture.h" #include "loader/Caster.h" +#include "loader/Compiler.h" #include "loader/Interpreter.h" #include "loader/Loader.h" #include "loader/ParsedSource.h" @@ -42,6 +41,8 @@ #include "map/MapState.h" #include "map/Tile.h" #include "map/Trigger.h" +#include "math/Fixed.h" +#include "math/Vector.h" #include "menu/Resources.h" #include "sdl/InitImage.h" #include "sdl/InitScreen.h" @@ -67,10 +68,9 @@ using common::GameConfig; using common::GameState; using common::Hero; using common::Spell; -using math::Fixed; -using math::Vector; using graphics::Texture; using loader::Caster; +using loader::Compiler; using loader::Interpreter; using loader::Loader; using loader::ParsedSource; @@ -78,6 +78,8 @@ using loader::Parser; using loader::TypeDescription; using map::Entity; using map::MapState; +using math::Fixed; +using math::Vector; using sdl::InitImage; using sdl::InitScreen; using sdl::InitSDL; @@ -158,6 +160,9 @@ int main(int argc, char **argv) { } } + Interpreter intp(source); + intp.ReadSource(); + switch (args.GetRunLevel()) { case Arguments::WRITE: { @@ -169,9 +174,14 @@ int main(int argc, char **argv) { break; } case 'o': { - std::ofstream outstream(args.OutfilePath()); + std::fstream outstream(args.OutfilePath(), std::ios_base::out|std::ios_base::trunc); + outstream.flush(); + outstream.close(); + outstream.open(args.OutfilePath()); + outstream.exceptions(std::ios_base::badbit|std::ios_base::failbit); Compiler(intp).Write(outstream); break; + } default: { throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath()); } @@ -194,9 +204,6 @@ int main(int argc, char **argv) { break; } - Interpreter intp(source); - intp.ReadSource(); - if (intp.PostponedDefinitions().size() > 0) { for (vector::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) { std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;