summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--textual.cc21
-rw-r--r--textual.h4
2 files changed, 22 insertions, 3 deletions
diff --git a/textual.cc b/textual.cc
index bffd56bd..39a5ae9f 100644
--- a/textual.cc
+++ b/textual.cc
@@ -304,6 +304,27 @@ static inline void parse_symbol(char *& p, std::string& symbol)
throw parse_error(path, linenum, "Failed to parse commodity");
}
+bool textual_parser_t::test(std::istream& in) const
+{
+ char buf[5];
+
+ assert(in.good());
+ in.read(buf, 5);
+ std::cerr << "buf (" << buf[0] << ")" << std::endl;
+ assert(in.good());
+ if (std::strncmp(buf, "<?xml", 5) == 0) {
+#ifdef HAVE_XMLPARSE
+ throw parse_error(path, linenum, "Ledger file contains XML data, but no XML support present");
+#else
+ throw parse_error(path, linenum, "Ledger file contains XML data, but format was not recognized");
+#endif
+ }
+
+ in.seekg(0, std::ios::beg);
+ assert(in.good());
+ return true;
+}
+
unsigned int textual_parser_t::parse(std::istream& in,
journal_t * journal,
account_t * master,
diff --git a/textual.h b/textual.h
index 5ea79d0c..741c21e8 100644
--- a/textual.h
+++ b/textual.h
@@ -9,9 +9,7 @@ namespace ledger {
class textual_parser_t : public parser_t
{
public:
- virtual bool test(std::istream& in) const {
- return true;
- }
+ virtual bool test(std::istream& in) const;
virtual unsigned int parse(std::istream& in,
journal_t * journal,