From: Mikko Rasa Date: Thu, 26 Jun 2008 10:51:27 +0000 (+0000) Subject: Add back support for stdin/out to datatool X-Git-Tag: 1.0~6 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d9f7b5d126827f9e08328bc3044bf7dba017f458;p=libs%2Fdatafile.git Add back support for stdin/out to datatool Make sure the buffers won't outlive their underlying objects --- 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;