diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-05 02:26:06 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-05 02:27:42 -0500 |
commit | 34ee358f5e16d4018adf3db5dac31d2d9c16b9f5 (patch) | |
tree | 5f2db02f896b2e50edb4fa1b143960286f6c1991 /src/session.cc | |
parent | 817f1ae1619df06f06f79f772f075041bb70f751 (diff) | |
download | fork-ledger-34ee358f5e16d4018adf3db5dac31d2d9c16b9f5.tar.gz fork-ledger-34ee358f5e16d4018adf3db5dac31d2d9c16b9f5.tar.bz2 fork-ledger-34ee358f5e16d4018adf3db5dac31d2d9c16b9f5.zip |
Moved journal reading code into journal_t
Diffstat (limited to 'src/session.cc')
-rw-r--r-- | src/session.cc | 46 |
1 files changed, 5 insertions, 41 deletions
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); } } |