X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tool%2Ftool.cpp;h=02fba07fa022cd758722fa81e4e4ec78caf50d1c;hb=cbd0ddd6ee033e46646bfb85d19232c816ea1eda;hp=ca415d30a0d9dc7d996d84b62021be90bc054f9e;hpb=db9c49893c2a9475cb5efa4a53bc481a5f66231f;p=libs%2Fdatafile.git diff --git a/tool/tool.cpp b/tool/tool.cpp index ca415d3..02fba07 100644 --- a/tool/tool.cpp +++ b/tool/tool.cpp @@ -12,6 +12,7 @@ Distributed under the LGPL #include #include #include +#include "compiler.h" #include "tool.h" using namespace std; @@ -19,31 +20,34 @@ using namespace Msp; DataTool::DataTool(int argc, char **argv): in_fn("-"), - out_fn("-") + out_fn("-"), + binary(false), + compile(false) { GetOpt getopt; - getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG); getopt.add_option('b', "binary", binary, GetOpt::NO_ARG); + getopt.add_option('c', "compile", compile, GetOpt::NO_ARG); + getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG); getopt(argc, argv); - const vector &args=getopt.get_args(); + const vector &args = getopt.get_args(); if(!args.empty()) - in_fn=args[0]; + in_fn = args[0]; } int DataTool::main() { IO::Base *in; if(in_fn=="-") - in=&IO::cin; + in = &IO::cin; else - in=new IO::File(in_fn); + in = new IO::File(in_fn); IO::Base *out; if(out_fn=="-") - out=&IO::cout; + out = &IO::cout; else - out=new IO::File(out_fn, IO::M_WRITE); + out = new IO::File(out_fn, IO::M_WRITE); { IO::Buffered in_buf(*in); @@ -53,13 +57,21 @@ int DataTool::main() if(binary) writer.set_binary(true); - while(parser) + if(compile) + { + Compiler compiler(writer); + compiler.load(parser); + } + else { - DataFile::Statement st=parser.parse(); - if(st.valid) + while(parser) { - writer.write(st); - out_buf.flush(); + DataFile::Statement st = parser.parse(); + if(st.valid) + { + writer.write(st); + out_buf.flush(); + } } } }