From a2f805ef73010de7f136eba5682a909cdae3e09b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 29 Jul 2004 01:56:53 -0400 Subject: Exit if parsing errors are encountered --- textual.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'textual.cc') diff --git a/textual.cc b/textual.cc index fa49cc23..95506e99 100644 --- a/textual.cc +++ b/textual.cc @@ -504,20 +504,18 @@ entry_t * parse_entry(std::istream& in, ledger_t * ledger, // Textual ledger parser // -unsigned int parse_textual_ledger(std::istream& in, ledger_t *& ledger, +unsigned int parse_textual_ledger(std::istream& in, ledger_t * ledger, account_t * master) { static char line[MAX_LINE + 1]; char c; - int count = 0; + unsigned int count = 0; + unsigned int errors = 0; commodity_t * time_commodity = NULL; std::list account_stack; automated_transactions_t auto_xacts; - if (! ledger) - ledger = new ledger_t; - if (! master) master = ledger->master; @@ -761,7 +759,8 @@ unsigned int parse_textual_ledger(std::istream& in, ledger_t *& ledger, } } catch (const parse_error& err) { - std::cerr << err.what() << std::endl; + std::cerr << "Error: " << err.what() << std::endl; + errors++; } } @@ -772,6 +771,12 @@ unsigned int parse_textual_ledger(std::istream& in, ledger_t *& ledger, COMMODITY_STYLE_NOMARKET); } + if (errors > 0) { + std::ostringstream msg; + msg << "Errors parsing file '" << path << "'"; + throw error(msg.str()); + } + return count; } -- cgit v1.2.3