summaryrefslogtreecommitdiff
path: root/parser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'parser.cc')
-rw-r--r--parser.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/parser.cc b/parser.cc
new file mode 100644
index 00000000..6a97caa2
--- /dev/null
+++ b/parser.cc
@@ -0,0 +1,35 @@
+#include "parser.h"
+
+#include <fstream>
+
+namespace ledger {
+
+parsers_list parser_t::parsers;
+
+unsigned int parser_t::parse_file(const std::string& path,
+ journal_t * journal,
+ account_t * master,
+ const std::string * original_file)
+{
+ journal->sources.push_back(path);
+
+ if (access(path.c_str(), R_OK) == -1)
+ return 0;
+
+ std::ifstream stream(path.c_str());
+
+ if (! master)
+ master = journal->master;
+ if (! original_file)
+ original_file = &path;
+
+ for (parsers_list::iterator i = parser_t::parsers.begin();
+ i != parser_t::parsers.end();
+ i++)
+ if ((*i)->test(stream))
+ return (*i)->parse(stream, journal, master, original_file);
+
+ return 0;
+}
+
+} // namespace ledger