From eda733a56eae156044a879ab2ce1a15a0cf0eef8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 24 Sep 2004 23:11:50 -0400 Subject: improved error checking in parser, in case parts of an amount are missing --- main.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'main.cc') diff --git a/main.cc b/main.cc index f1dbeff4..cc26d433 100644 --- a/main.cc +++ b/main.cc @@ -137,6 +137,36 @@ chain_formatters(const std::string& command, return formatter; } +void walk_commodities(commodities_map& commodities, + item_handler& handler) +{ + std::list xact_temps; + std::list entry_temps; + std::list acct_temps; + + for (commodities_map::iterator i = commodities.begin(); + i != commodities.end(); + i++) { + if ((*i).second->flags & COMMODITY_STYLE_NOMARKET) + continue; + + entry_temps.push_back(entry_t()); + acct_temps.push_back(account_t(NULL, (*i).second->symbol)); + + for (history_map::iterator j = (*i).second->history.begin(); + j != (*i).second->history.end(); + j++) { + entry_temps.back().date = (*j).first; + + xact_temps.push_back(transaction_t(&acct_temps.back())); + xact_temps.back().entry = &entry_temps.back(); + xact_temps.back().amount = (*j).second; + + handler(xact_temps.back()); + } + } +} + int parse_and_report(int argc, char * argv[], char * envp[]) { std::auto_ptr journal(new journal_t); @@ -186,6 +216,8 @@ int parse_and_report(int argc, char * argv[], char * envp[]) command = "e"; else if (command == "equity") command = "E"; + else if (command == "prices") + command = "P"; else throw error(std::string("Unrecognized command '") + command + "'"); @@ -240,6 +272,8 @@ int parse_and_report(int argc, char * argv[], char * envp[]) format = &config.register_format; else if (command == "E") format = &config.equity_format; + else if (command == "P") + format = &config.prices_format; else format = &config.print_format; @@ -259,6 +293,8 @@ int parse_and_report(int argc, char * argv[], char * envp[]) if (command == "e") walk_transactions(new_entry->transactions, *formatter); + else if (command == "P") + walk_commodities(commodity_t::commodities, *formatter); else walk_entries(journal->entries, *formatter); -- cgit v1.2.3