X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=tool.cpp;h=1e4da9a67e2bc897e12e2e778f7fa19662f89455;hp=68c0fdccff40fada878072df672d55a212db0238;hb=d9f7b5d126827f9e08328bc3044bf7dba017f458;hpb=08576b49c8bfb6cd841724dc5124d40af9475eb8 diff --git a/tool.cpp b/tool.cpp index 68c0fdc..1e4da9a 100644 --- a/tool.cpp +++ b/tool.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "source/parser.h" #include "source/statement.h" @@ -43,31 +44,38 @@ int DataTool::main() { IO::Base *in; if(in_fn=="-") - throw Exception("stdin/out not supported at the moment"); + in=&IO::cin; else in=new IO::File(in_fn); IO::Base *out; if(out_fn=="-") - throw Exception("stdin/out not supported at the moment"); + out=&IO::cout; else out=new IO::File(out_fn, IO::M_WRITE); - IO::Buffered in_buf(*in); - DataFile::Parser parser(in_buf, in_fn); - IO::Buffered out_buf(*out); - DataFile::Writer writer(out_buf); - if(binary) - writer.set_binary(true); - - while(parser) { - DataFile::Statement st=parser.parse(); - if(st.valid) - writer.write(st); + IO::Buffered in_buf(*in); + DataFile::Parser parser(in_buf, in_fn); + IO::Buffered out_buf(*out); + DataFile::Writer writer(out_buf); + if(binary) + writer.set_binary(true); + + while(parser) + { + DataFile::Statement st=parser.parse(); + if(st.valid) + { + writer.write(st); + out_buf.flush(); + } + } } - //if(out!=&cout) + if(in!=&IO::cin) + delete in; + if(out!=&IO::cout) delete out; return 0;