From: Mikko Rasa Date: Thu, 4 Oct 2007 20:16:17 +0000 (+0000) Subject: Rename error.h to except.h X-Git-Tag: 1.0~18 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aa8bfd3c13848dc27947d3947038bd66c258d288;p=libs%2Fdatafile.git Rename error.h to except.h Make datatool support reading from stdin --- diff --git a/source/error.h b/source/error.h deleted file mode 100644 index 11bccd8..0000000 --- a/source/error.h +++ /dev/null @@ -1,36 +0,0 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2006 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ -#ifndef MSP_DATAFILE_ERROR_H_ -#define MSP_DATAFILE_ERROR_H_ - -#include - -namespace Msp { -namespace DataFile { - -class TypeError: public Exception -{ -public: - TypeError(const std::string &w_): Exception(w_) { } -}; - -class ParseError: public Exception -{ -public: - ParseError(const std::string &w_, const std::string &s, unsigned l): Exception(w_), source(s), line(l) { } - const std::string &get_source() const { return source; } - unsigned get_line() const { return line; } - ~ParseError() throw() { } -private: - std::string source; - unsigned line; -}; - -} // namespace DataFile -} // namespace Msp - -#endif diff --git a/source/except.h b/source/except.h new file mode 100644 index 0000000..4573e94 --- /dev/null +++ b/source/except.h @@ -0,0 +1,36 @@ +/* $Id$ + +This file is part of libmspdatafile +Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ +#ifndef MSP_DATAFILE_ERROR_H_ +#define MSP_DATAFILE_ERROR_H_ + +#include + +namespace Msp { +namespace DataFile { + +class TypeError: public Exception +{ +public: + TypeError(const std::string &w_): Exception(w_) { } +}; + +class ParseError: public Exception +{ +public: + ParseError(const std::string &w_, const std::string &s, unsigned l): Exception(w_), source(s), line(l) { } + const std::string &get_source() const { return source; } + unsigned get_line() const { return line; } + ~ParseError() throw() { } +private: + std::string source; + unsigned line; +}; + +} // namespace DataFile +} // namespace Msp + +#endif 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);