From aa8bfd3c13848dc27947d3947038bd66c258d288 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Oct 2007 20:16:17 +0000 Subject: [PATCH] Rename error.h to except.h Make datatool support reading from stdin --- source/{error.h => except.h} | 2 +- source/value.h | 2 +- tool.cpp | 20 +++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) rename source/{error.h => except.h} (96%) diff --git a/source/error.h b/source/except.h similarity index 96% rename from source/error.h rename to source/except.h index 11bccd8..4573e94 100644 --- a/source/error.h +++ b/source/except.h @@ -7,7 +7,7 @@ Distributed under the LGPL #ifndef MSP_DATAFILE_ERROR_H_ #define MSP_DATAFILE_ERROR_H_ -#include +#include namespace Msp { namespace DataFile { diff --git a/source/value.h b/source/value.h index fda83e4..4b3ac41 100644 --- a/source/value.h +++ b/source/value.h @@ -9,7 +9,7 @@ Distributed under the LGPL #include #include -#include "error.h" +#include "except.h" namespace Msp { namespace DataFile { diff --git a/tool.cpp b/tool.cpp index 533abb0..8ca4f74 100644 --- a/tool.cpp +++ b/tool.cpp @@ -25,6 +25,7 @@ public: DataTool::DataTool(int argc, char **argv): + in_fn("-"), out_fn("-") { GetOpt getopt; @@ -33,20 +34,17 @@ DataTool::DataTool(int argc, char **argv): getopt(argc, argv); const vector &args=getopt.get_args(); - if(args.empty()) - throw UsageError("Must give input filename"); - - in_fn=args[0]; + if(!args.empty()) + in_fn=args[0]; } int DataTool::main() { - ifstream in(in_fn.c_str()); - if(!in) - { - cerr<<"Couldn't open input file\n"; - return 1; - } + istream *in; + if(in_fn=="-") + in=&cin; + else + in=new ifstream(in_fn.c_str()); ostream *out; if(out_fn=="-") @@ -54,7 +52,7 @@ int DataTool::main() else out=new ofstream(out_fn.c_str()); - DataFile::Parser parser(in, in_fn); + DataFile::Parser parser(*in, in_fn); DataFile::Writer writer(*out); if(binary) writer.set_binary(true); -- 2.43.0