-/* $Id$ */
-#include <iostream>
-#include <msp/core/application.h>
-#include <msp/core/getopt.h>
-#include <msp/io/buffered.h>
-#include <msp/io/console.h>
-#include <msp/io/file.h>
-#include "source/parser.h"
-#include "source/statement.h"
-#include "source/writer.h"
-
-using namespace std;
-using namespace Msp;
-
-class DataTool: public Application
-{
-private:
- string in_fn;
- string out_fn;
- bool binary;
-public:
- DataTool(int argc, char **argv);
- int main();
-
- static Application::RegApp<DataTool> reg;
-};
-
-
-DataTool::DataTool(int argc, char **argv):
- in_fn("-"),
- out_fn("-")
-{
- GetOpt getopt;
- getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG);
- getopt.add_option('b', "binary", binary, GetOpt::NO_ARG);
- getopt(argc, argv);
-
- const vector<string> &args=getopt.get_args();
- if(!args.empty())
- in_fn=args[0];
-}
-
-int DataTool::main()
-{
- IO::Base *in;
- if(in_fn=="-")
- in=&IO::cin;
- else
- in=new IO::File(in_fn);
-
- IO::Base *out;
- if(out_fn=="-")
- 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);
- out_buf.flush();
- }
- }
- }
-
- if(in!=&IO::cin)
- delete in;
- if(out!=&IO::cout)
- delete out;
-
- return 0;
-}
-
-Application::RegApp<DataTool> DataTool::reg;