From b14c814fec11ab450c552bccf5fe7d96dc2c4e18 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 4 Nov 2009 20:07:32 -0500 Subject: Whitespace fix --- src/journal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/journal.h') diff --git a/src/journal.h b/src/journal.h index 88a225c5..7a7c4ec9 100644 --- a/src/journal.h +++ b/src/journal.h @@ -105,7 +105,7 @@ public: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int /* version */) { + void serialize(Archive& ar, const unsigned int /* version */) { ar & filename; ar & size; ar & modtime; @@ -160,7 +160,7 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int /* version */) { + void serialize(Archive& ar, const unsigned int /* version */) { ar & master; ar & basket; ar & xacts; -- cgit v1.2.3 From 40a430139edd12d9f580f5616571bc3ed8709d73 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 5 Nov 2009 02:22:17 -0500 Subject: Transactions, etc., are now accessed by iterators --- src/account.h | 20 ++++++++++++++++++++ src/journal.h | 26 ++++++++++++++++++++++++++ src/py_account.cc | 9 +++++++-- src/py_journal.cc | 12 +++++++++++- src/py_xact.cc | 9 ++++++--- src/system.hh.in | 1 + src/xact.h | 7 +++++++ 7 files changed, 78 insertions(+), 6 deletions(-) (limited to 'src/journal.h') diff --git a/src/account.h b/src/account.h index 7d51a08e..3452bba7 100644 --- a/src/account.h +++ b/src/account.h @@ -114,11 +114,31 @@ public: account_t * find_account(const string& name, bool auto_create = true); account_t * find_account_re(const string& regexp); + typedef transform_iterator, + accounts_map::iterator> + accounts_map_seconds_iterator; + + accounts_map_seconds_iterator accounts_begin() { + return make_transform_iterator + (accounts.begin(), bind(&accounts_map::value_type::second, _1)); + } + accounts_map_seconds_iterator accounts_end() { + return make_transform_iterator + (accounts.end(), bind(&accounts_map::value_type::second, _1)); + } + void add_post(post_t * post) { posts.push_back(post); } bool remove_post(post_t * post); + posts_list::iterator posts_begin() { + return posts.begin(); + } + posts_list::iterator posts_end() { + return posts.end(); + } + virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, const string& name); diff --git a/src/journal.h b/src/journal.h index 7a7c4ec9..551f9142 100644 --- a/src/journal.h +++ b/src/journal.h @@ -128,6 +128,13 @@ public: journal_t(); ~journal_t(); + std::list::iterator sources_begin() { + return sources.begin(); + } + std::list::iterator sources_end() { + return sources.end(); + } + // These four methods are delegated to the current session, since all // accounts processed are gathered together at the session level. void add_account(account_t * acct); @@ -138,6 +145,25 @@ public: bool add_xact(xact_t * xact); bool remove_xact(xact_t * xact); + xacts_list::iterator xacts_begin() { + return xacts.begin(); + } + xacts_list::iterator xacts_end() { + return xacts.end(); + } + auto_xacts_list::iterator auto_xacts_begin() { + return auto_xacts.begin(); + } + auto_xacts_list::iterator auto_xacts_end() { + return auto_xacts.end(); + } + period_xacts_list::iterator period_xacts_begin() { + return period_xacts.begin(); + } + period_xacts_list::iterator period_xacts_end() { + return period_xacts.end(); + } + void add_xact_finalizer(xact_finalizer_t * finalizer) { xact_finalize_hooks.add_hook(finalizer); } diff --git a/src/py_account.cc b/src/py_account.cc index 7fa30d0a..3341c948 100644 --- a/src/py_account.cc +++ b/src/py_account.cc @@ -177,8 +177,6 @@ void export_account() .def_readwrite("name", &account_t::name) .def_readwrite("note", &account_t::note) .def_readonly("depth", &account_t::depth) - .def_readonly("accounts", &account_t::accounts) - .def_readonly("posts", &account_t::posts) .def(self_ns::str(self)) @@ -201,6 +199,13 @@ void export_account() .def("__len__", accounts_len) .def("__getitem__", accounts_getitem, return_internal_reference<1>()) + .def("__iter__", range > + (&account_t::accounts_begin, &account_t::accounts_end)) + .def("accounts", range > + (&account_t::accounts_begin, &account_t::accounts_end)) + .def("posts", range > + (&account_t::posts_begin, &account_t::posts_end)) + .def("has_xdata", &account_t::has_xdata) .def("clear_xdata", &account_t::clear_xdata) .def("xdata", py_xdata, diff --git a/src/py_journal.cc b/src/py_journal.cc index 873645d3..0f800077 100644 --- a/src/py_journal.cc +++ b/src/py_journal.cc @@ -192,7 +192,6 @@ void export_journal() make_getter(&journal_t::basket, return_internal_reference<1>()), make_setter(&journal_t::basket)) - .add_property("sources", make_getter(&journal_t::sources)) .add_property("was_loaded", make_getter(&journal_t::was_loaded)) .add_property("commodity_pool", make_getter(&journal_t::commodity_pool, @@ -221,6 +220,17 @@ void export_journal() .def("__len__", xacts_len) .def("__getitem__", xacts_getitem, return_internal_reference<1>()) + .def("__iter__", range > + (&journal_t::xacts_begin, &journal_t::xacts_end)) + .def("xacts", range > + (&journal_t::xacts_begin, &journal_t::xacts_end)) + .def("auto_xacts", range > + (&journal_t::auto_xacts_begin, &journal_t::auto_xacts_end)) + .def("period_xacts", range > + (&journal_t::period_xacts_begin, &journal_t::period_xacts_end)) + .def("sources", range > + (&journal_t::sources_begin, &journal_t::sources_end)) + .def("valid", &journal_t::valid) ; } diff --git a/src/py_xact.cc b/src/py_xact.cc index d98d226c..3755dcd1 100644 --- a/src/py_xact.cc +++ b/src/py_xact.cc @@ -88,9 +88,6 @@ void export_xact() return_value_policy()), make_setter(&xact_base_t::journal, with_custodian_and_ward<1, 2>())) - .add_property("posts", - make_getter(&xact_base_t::posts), - make_setter(&xact_base_t::posts)) .def("__len__", posts_len) .def("__getitem__", posts_getitem, @@ -100,6 +97,12 @@ void export_xact() .def("remove_post", &xact_base_t::add_post) .def("finalize", &xact_base_t::finalize) + + .def("__iter__", range > + (&xact_t::posts_begin, &xact_t::posts_end)) + .def("posts", range > + (&xact_t::posts_begin, &xact_t::posts_end)) + .def("valid", &xact_base_t::valid) ; diff --git a/src/system.hh.in b/src/system.hh.in index 4a7dc55f..96febb22 100644 --- a/src/system.hh.in +++ b/src/system.hh.in @@ -155,6 +155,7 @@ typedef std::ostream::pos_type ostream_pos_type; #include #include #include +#include #include #include #include diff --git a/src/xact.h b/src/xact.h index 07fc68f5..337abce8 100644 --- a/src/xact.h +++ b/src/xact.h @@ -77,6 +77,13 @@ public: virtual void add_post(post_t * post); virtual bool remove_post(post_t * post); + posts_list::iterator posts_begin() { + return posts.begin(); + } + posts_list::iterator posts_end() { + return posts.end(); + } + virtual bool finalize(); virtual bool valid() const { return true; -- cgit v1.2.3 From 3dc200983d5057a7760aeb9e864479c902d7e1d7 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 5 Nov 2009 02:23:49 -0500 Subject: Moved xdata clearing code into each type proper --- src/account.cc | 9 +++++++++ src/account.h | 4 +--- src/filters.h | 26 -------------------------- src/journal.cc | 17 +++++++++++++++++ src/journal.h | 2 ++ src/precmd.cc | 2 +- src/py_journal.cc | 2 ++ src/py_xact.cc | 2 ++ src/report.cc | 9 ++++----- src/session.cc | 19 ------------------- src/session.h | 8 -------- src/xact.cc | 7 +++++++ src/xact.h | 3 +++ 13 files changed, 48 insertions(+), 62 deletions(-) (limited to 'src/journal.h') diff --git a/src/account.cc b/src/account.cc index 2a75a6ac..43b7cd56 100644 --- a/src/account.cc +++ b/src/account.cc @@ -382,6 +382,15 @@ account_t::xdata_t::details_t::operator+=(const details_t& other) return *this; } +void account_t::clear_xdata() +{ + xdata_ = none; + + foreach (accounts_map::value_type& pair, accounts) + if (! pair.second->has_flags(ACCOUNT_TEMP)) + pair.second->clear_xdata(); +} + value_t account_t::amount(const optional& expr) const { if (xdata_ && xdata_->has_flags(ACCOUNT_EXT_VISITED)) { diff --git a/src/account.h b/src/account.h index 3452bba7..dc1d6c9a 100644 --- a/src/account.h +++ b/src/account.h @@ -230,9 +230,7 @@ public: bool has_xdata() const { return xdata_; } - void clear_xdata() { - xdata_ = none; - } + void clear_xdata(); xdata_t& xdata() { if (! xdata_) xdata_ = xdata_t(); diff --git a/src/filters.h b/src/filters.h index 0dcf5e41..42503945 100644 --- a/src/filters.h +++ b/src/filters.h @@ -70,19 +70,6 @@ public: virtual void operator()(post_t&) {} }; -/** - * @brief Brief - * - * Long. - */ -class clear_post_xdata : public item_handler -{ -public: - virtual void operator()(post_t& post) { - post.clear_xdata(); - } -}; - class posts_iterator; /** @@ -790,19 +777,6 @@ class forecast_posts : public generate_posts // Account filters // -/** - * @brief Brief - * - * Long. - */ -class clear_account_xdata : public item_handler -{ -public: - virtual void operator()(account_t& acct) { - acct.clear_xdata(); - } -}; - class accounts_iterator; /** diff --git a/src/journal.cc b/src/journal.cc index 4b5172f5..4d6e084e 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -134,6 +134,23 @@ bool journal_t::remove_xact(xact_t * xact) return true; } +void journal_t::clear_xdata() +{ + foreach (xact_t * xact, xacts) + if (! xact->has_flags(ITEM_TEMP)) + xact->clear_xdata(); + + foreach (auto_xact_t * xact, auto_xacts) + if (! xact->has_flags(ITEM_TEMP)) + xact->clear_xdata(); + + foreach (period_xact_t * xact, period_xacts) + if (! xact->has_flags(ITEM_TEMP)) + xact->clear_xdata(); + + master->clear_xdata(); +} + bool journal_t::valid() const { if (! master->valid()) { diff --git a/src/journal.h b/src/journal.h index 551f9142..60d703e6 100644 --- a/src/journal.h +++ b/src/journal.h @@ -177,6 +177,8 @@ public: const path * original_file = NULL, bool strict = false); + void clear_xdata(); + bool valid() const; #if defined(HAVE_BOOST_SERIALIZATION) diff --git a/src/precmd.cc b/src/precmd.cc index 479d7c2d..4cf541f4 100644 --- a/src/precmd.cc +++ b/src/precmd.cc @@ -67,7 +67,7 @@ namespace { { std::istringstream in(str); report.session.journal->parse(in, report.session); - report.session.clean_accounts(); + report.session.journal->clear_xdata(); } } xact_t * first = report.session.journal->xacts.front(); diff --git a/src/py_journal.cc b/src/py_journal.cc index 0f800077..bc79101b 100644 --- a/src/py_journal.cc +++ b/src/py_journal.cc @@ -231,6 +231,8 @@ void export_journal() .def("sources", range > (&journal_t::sources_begin, &journal_t::sources_end)) + .def("clear_xdata", &journal_t::clear_xdata) + .def("valid", &journal_t::valid) ; } diff --git a/src/py_xact.cc b/src/py_xact.cc index 3755dcd1..86e2e067 100644 --- a/src/py_xact.cc +++ b/src/py_xact.cc @@ -122,6 +122,8 @@ void export_xact() .def("lookup", &xact_t::lookup) + .def("clear_xdata", &xact_t::clear_xdata) + .def("valid", &xact_t::valid) ; diff --git a/src/report.cc b/src/report.cc index 883b324a..e6f3ccb4 100644 --- a/src/report.cc +++ b/src/report.cc @@ -50,7 +50,7 @@ void report_t::posts_report(post_handler_ptr handler) { journal_posts_iterator walker(*session.journal.get()); pass_down_posts(chain_post_handlers(*this, handler), walker); - session.clean_posts(); + session.journal->clear_xdata(); } void report_t::generate_report(post_handler_ptr handler) @@ -70,7 +70,7 @@ void report_t::xact_report(post_handler_ptr handler, xact_t& xact) { xact_posts_iterator walker(xact); pass_down_posts(chain_post_handlers(*this, handler), walker); - session.clean_posts(xact); + xact.clear_xdata(); } void report_t::accounts_report(acct_handler_ptr handler) @@ -101,15 +101,14 @@ void report_t::accounts_report(acct_handler_ptr handler) else pass_down_accounts(handler, *iter.get()); - session.clean_posts(); - session.clean_accounts(); + session.journal->clear_xdata(); } void report_t::commodities_report(post_handler_ptr handler) { posts_commodities_iterator walker(*session.journal.get()); pass_down_posts(chain_post_handlers(*this, handler), walker); - session.clean_posts(); + session.journal->clear_xdata(); } value_t report_t::fn_amount_expr(call_scope_t& scope) diff --git a/src/session.cc b/src/session.cc index 67f19ca9..8cbef1e6 100644 --- a/src/session.cc +++ b/src/session.cc @@ -224,25 +224,6 @@ void session_t::close_journal_files() amount_t::initialize(journal->commodity_pool); } -void session_t::clean_posts() -{ - journal_posts_iterator walker(*journal.get()); - pass_down_posts(post_handler_ptr(new clear_post_xdata), walker); -} - -void session_t::clean_posts(xact_t& xact) -{ - xact_posts_iterator walker(xact); - pass_down_posts(post_handler_ptr(new clear_post_xdata), walker); -} - -void session_t::clean_accounts() -{ - basic_accounts_iterator acct_walker(*journal->master); - pass_down_accounts(acct_handler_ptr(new clear_account_xdata), acct_walker); - journal->master->clear_xdata(); -} - option_t * session_t::lookup_option(const char * p) { switch (*p) { diff --git a/src/session.h b/src/session.h index 972a97ba..8e73b660 100644 --- a/src/session.h +++ b/src/session.h @@ -93,14 +93,6 @@ public: void read_journal_files(); void close_journal_files(); - void clean_posts(); - void clean_posts(xact_t& xact); - void clean_accounts(); - void clean_all() { - clean_posts(); - clean_accounts(); - } - void report_options(std::ostream& out) { HANDLER(account_).report(out); diff --git a/src/xact.cc b/src/xact.cc index 473837b6..9e5f504e 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -76,6 +76,13 @@ bool xact_base_t::remove_post(post_t * post) return true; } +void xact_base_t::clear_xdata() +{ + foreach (post_t * post, posts) + if (! post->has_flags(ITEM_TEMP)) + post->clear_xdata(); +} + bool xact_base_t::finalize() { // Scan through and compute the total balance for the xact. This is used diff --git a/src/xact.h b/src/xact.h index 337abce8..8c5c21ce 100644 --- a/src/xact.h +++ b/src/xact.h @@ -85,6 +85,9 @@ public: } virtual bool finalize(); + + void clear_xdata(); + virtual bool valid() const { return true; } -- cgit v1.2.3 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/global.cc | 3 +- src/global.h | 8 +++-- src/journal.cc | 97 +++++++++++++++++++++++++++++++++++++++++++++++-------- src/journal.h | 12 +++++++ src/py_journal.cc | 5 +++ src/scope.cc | 2 ++ src/scope.h | 2 ++ src/session.cc | 46 +++----------------------- src/session.h | 8 ----- 9 files changed, 118 insertions(+), 65 deletions(-) (limited to 'src/journal.h') diff --git a/src/global.cc b/src/global.cc index 97a46cce..2103e32c 100644 --- a/src/global.cc +++ b/src/global.cc @@ -67,6 +67,7 @@ global_scope_t::global_scope_t(char ** envp) // open document, with a separate report_t object for each report it // generated. report_stack.push_front(new report_t(session())); + scope_t::default_scope = &report(); // Read the user's options, in the following order: // @@ -111,7 +112,7 @@ void global_scope_t::read_init() ifstream init(init_file); - if (session().read_journal(init_file, NULL, &report()) > 0 || + if (session().journal->read(init_file, NULL, &report()) > 0 || session().journal->auto_xacts.size() > 0 || session().journal->period_xacts.size() > 0) { throw_(parse_error, _("Transactions found in initialization file '%1'") diff --git a/src/global.h b/src/global.h index 34577656..31a0a480 100644 --- a/src/global.h +++ b/src/global.h @@ -75,10 +75,14 @@ public: void push_report() { report_stack.push_front(new report_t(report_stack.front())); + scope_t::default_scope = &report(); } void pop_report() { - if (! report_stack.empty()) - report_stack.pop_front(); + assert(! report_stack.empty()); + report_stack.pop_front(); + // There should always be the "default report" waiting on the stack. + assert(! report_stack.empty()); + scope_t::default_scope = &report(); } void report_error(const std::exception& err); diff --git a/src/journal.cc b/src/journal.cc index 4d6e084e..31557635 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -41,23 +41,23 @@ namespace ledger { journal_t::journal_t() - : master(new account_t), basket(NULL), was_loaded(false), - commodity_pool(new commodity_pool_t) { TRACE_CTOR(journal_t, ""); + initialize(); +} - // Add time commodity conversions, so that timelog's may be parsed - // in terms of seconds, but reported as minutes or hours. - if (commodity_t * commodity = commodity_pool->create("s")) - commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); - else - assert(false); +journal_t::journal_t(const path& pathname) +{ + TRACE_CTOR(journal_t, "path"); + initialize(); + read(pathname); +} - // Add a "percentile" commodity - if (commodity_t * commodity = commodity_pool->create("%")) - commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); - else - assert(false); +journal_t::journal_t(const string& str) +{ + TRACE_CTOR(journal_t, "string"); + initialize(); + read(str); } journal_t::~journal_t() @@ -80,6 +80,28 @@ journal_t::~journal_t() commodity_pool.reset(); } +void journal_t::initialize() +{ + master = new account_t; + basket = NULL; + was_loaded = false; + + commodity_pool.reset(new commodity_pool_t); + + // Add time commodity conversions, so that timelog's may be parsed + // in terms of seconds, but reported as minutes or hours. + if (commodity_t * commodity = commodity_pool->create("s")) + commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); + else + assert(false); + + // Add a "percentile" commodity + if (commodity_t * commodity = commodity_pool->create("%")) + commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET); + else + assert(false); +} + void journal_t::add_account(account_t * acct) { master->add_account(acct); @@ -134,6 +156,55 @@ bool journal_t::remove_xact(xact_t * xact) return true; } +std::size_t journal_t::read(std::istream& in, + const path& pathname, + account_t * master_alt, + scope_t * scope) +{ + std::size_t count = 0; + try { + if (! scope) + scope = scope_t::default_scope; + + if (! scope) + throw_(std::runtime_error, + _("No default scope in which to read journal file '%1'") + << pathname); + + value_t strict = expr_t("strict").calc(*scope); + + count = parse(in, *scope, master_alt ? master_alt : master, + &pathname, strict.to_boolean()); + } + catch (...) { + clear_xdata(); + throw; + } + + // xdata may have been set for some accounts and transaction due to the use + // of balance assertions or other calculations performed in valexpr-based + // posting amounts. + clear_xdata(); + + return count; +} + +std::size_t journal_t::read(const path& pathname, + account_t * master, + scope_t * scope) +{ + path filename = resolve_path(pathname); + + if (! exists(filename)) + throw_(std::runtime_error, + _("Cannot read journal file '%1'") << filename); + + ifstream stream(filename); + std::size_t count = read(stream, filename, master, scope); + sources.push_back(fileinfo_t(filename)); + return count; +} + void journal_t::clear_xdata() { foreach (xact_t * xact, xacts) diff --git a/src/journal.h b/src/journal.h index 60d703e6..e2af0dde 100644 --- a/src/journal.h +++ b/src/journal.h @@ -126,8 +126,12 @@ public: hooks_t xact_finalize_hooks; journal_t(); + journal_t(const path& pathname); + journal_t(const string& str); ~journal_t(); + void initialize(); + std::list::iterator sources_begin() { return sources.begin(); } @@ -171,6 +175,14 @@ public: xact_finalize_hooks.remove_hook(finalizer); } + std::size_t read(std::istream& in, + const path& pathname, + account_t * master = NULL, + scope_t * scope = NULL); + std::size_t read(const path& pathname, + account_t * master = NULL, + scope_t * scope = NULL); + std::size_t parse(std::istream& in, scope_t& session_scope, account_t * master = NULL, diff --git a/src/py_journal.cc b/src/py_journal.cc index bc79101b..a9789840 100644 --- a/src/py_journal.cc +++ b/src/py_journal.cc @@ -171,6 +171,8 @@ namespace { void export_journal() { class_< journal_t::fileinfo_t > ("FileInfo") + .def(init()) + .add_property("filename", make_getter(&journal_t::fileinfo_t::filename), make_setter(&journal_t::fileinfo_t::filename)) @@ -186,6 +188,9 @@ void export_journal() ; class_< journal_t, boost::noncopyable > ("Journal") + .def(init()) + .def(init()) + .add_property("master", make_getter(&journal_t::master, return_internal_reference<1>())) .add_property("basket", diff --git a/src/scope.cc b/src/scope.cc index 998eac64..99f6b669 100644 --- a/src/scope.cc +++ b/src/scope.cc @@ -35,6 +35,8 @@ namespace ledger { +scope_t * scope_t::default_scope = NULL; + void symbol_scope_t::define(const symbol_t::kind_t kind, const string& name, expr_t::ptr_op_t def) { diff --git a/src/scope.h b/src/scope.h index 7cf89c3e..c2c9df20 100644 --- a/src/scope.h +++ b/src/scope.h @@ -113,6 +113,8 @@ private: class scope_t { public: + static scope_t * default_scope; + explicit scope_t() { TRACE_CTOR(scope_t, ""); } 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); } } diff --git a/src/session.h b/src/session.h index 8e73b660..7c5d47dd 100644 --- a/src/session.h +++ b/src/session.h @@ -80,14 +80,6 @@ public: flush_on_next_data_file = truth; } - std::size_t read_journal(std::istream& in, - const path& pathname, - account_t * master = NULL, - scope_t * scope = NULL); - std::size_t read_journal(const path& pathname, - account_t * master = NULL, - scope_t * scope = NULL); - std::size_t read_data(const string& master_account = ""); void read_journal_files(); -- cgit v1.2.3