From 34ee358f5e16d4018adf3db5dac31d2d9c16b9f5 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 5 Nov 2009 02:26:06 -0500 Subject: Moved journal reading code into journal_t --- src/session.cc | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) (limited to 'src/session.cc') diff --git a/src/session.cc b/src/session.cc index 8cbef1e6..afc092f1 100644 --- a/src/session.cc +++ b/src/session.cc @@ -72,35 +72,6 @@ session_t::session_t() HANDLER(price_db_).on(none, path("./.pricedb").string()); } -std::size_t session_t::read_journal(std::istream& in, - const path& pathname, - account_t * master, - scope_t * scope) -{ - if (! master) - master = journal->master; - - std::size_t count = journal->parse(in, scope ? *scope : *this, - master, &pathname, HANDLED(strict)); - - // remove calculated totals and flags - clean_posts(); - clean_accounts(); - - return count; -} - -std::size_t session_t::read_journal(const path& pathname, - account_t * master, - scope_t * scope) -{ - if (! exists(pathname)) - throw_(std::logic_error, _("Cannot read file '%1'") << pathname); - - ifstream stream(pathname); - return read_journal(stream, pathname, master, scope); -} - std::size_t session_t::read_data(const string& master_account) { bool populated_data_files = false; @@ -144,16 +115,14 @@ std::size_t session_t::read_data(const string& master_account) cache->load(journal))) { if (price_db_path) { if (exists(*price_db_path)) { - if (read_journal(*price_db_path) > 0) + if (journal->read(*price_db_path) > 0) throw_(parse_error, _("Transactions not allowed in price history file")); - journal->sources.push_back(journal_t::fileinfo_t(*price_db_path)); } HANDLER(file_).data_files.remove(*price_db_path); } foreach (const path& pathname, HANDLER(file_).data_files) { - path filename = resolve_path(pathname); - if (filename == "-") { + if (pathname == "-") { // To avoid problems with stdin and pipes, etc., we read the entire // file in beforehand into a memory buffer, and then parcel it out // from there. @@ -169,15 +138,10 @@ std::size_t session_t::read_data(const string& master_account) std::istringstream buf_in(buffer.str()); - xact_count += read_journal(buf_in, "/dev/stdin", acct); + xact_count += journal->read(buf_in, "/dev/stdin", acct); journal->sources.push_back(journal_t::fileinfo_t()); - } - else if (exists(filename)) { - xact_count += read_journal(filename, acct); - journal->sources.push_back(journal_t::fileinfo_t(filename)); - } - else { - throw_(parse_error, _("Could not read journal file '%1'") << filename); + } else { + xact_count += journal->read(pathname, acct); } } -- cgit v1.2.3