+++ /dev/null
-/* $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 <msp/core/error.h>
-
-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
--- /dev/null
+/* $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 <msp/core/except.h>
+
+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
#include <vector>
#include <msp/strings/lexicalcast.h>
-#include "error.h"
+#include "except.h"
namespace Msp {
namespace DataFile {
DataTool::DataTool(int argc, char **argv):
+ in_fn("-"),
out_fn("-")
{
GetOpt getopt;
getopt(argc, argv);
const vector<string> &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=="-")
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);