diff options
author | John Wiegley <johnw@newartisans.com> | 2005-02-03 05:08:30 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:40:53 -0400 |
commit | 38653c0166897fde8888a7e6bcd007d784e56249 (patch) | |
tree | 26ddaab4cb959cffb0c35cf039c8a85b16fa3942 | |
parent | 911c1783942e8421c76cd57a255425841552dff0 (diff) | |
download | fork-ledger-38653c0166897fde8888a7e6bcd007d784e56249.tar.gz fork-ledger-38653c0166897fde8888a7e6bcd007d784e56249.tar.bz2 fork-ledger-38653c0166897fde8888a7e6bcd007d784e56249.zip |
(endElement): Handle the <tr:virtual> and <tr:generated> tags, which
were being ignored. (parse): Corrected error reporting when it is a
Ledger error.
-rw-r--r-- | xml.cc | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -66,7 +66,7 @@ static void endElement(void *userData, const char *name) count++; } else { delete curr_entry; - have_error = "Entry does not balance"; + have_error = "Entry cannot be balanced"; } } curr_entry = NULL; @@ -89,6 +89,12 @@ static void endElement(void *userData, const char *name) else if (std::strcmp(name, "tr:account") == 0) { curr_entry->transactions.back()->account = curr_journal->find_account(data); } + else if (std::strcmp(name, "tr:virtual") == 0) { + curr_entry->transactions.back()->flags |= TRANSACTION_VIRTUAL; + } + else if (std::strcmp(name, "tr:generated") == 0) { + curr_entry->transactions.back()->flags |= TRANSACTION_AUTO; + } else if (std::strcmp(name, "commodity") == 0) { assert(! curr_comm); curr_comm = commodity_t::find_commodity(data, true); @@ -159,7 +165,8 @@ unsigned int xml_parser_t::parse(std::istream& in, curr_comm = NULL; ignore = false; - XML_Parser parser = XML_ParserCreate(NULL); + unsigned int offset = 2; + XML_Parser parser = XML_ParserCreate(NULL); current_parser = parser; XML_SetElementHandler(parser, startElement, endElement); @@ -167,26 +174,28 @@ unsigned int xml_parser_t::parse(std::istream& in, while (! in.eof()) { in.getline(buf, BUFSIZ - 1); + std::strcat(buf, "\n"); bool result; try { result = XML_Parse(parser, buf, std::strlen(buf), in.eof()); } catch (const std::exception& err) { - unsigned long line = XML_GetCurrentLineNumber(parser); + unsigned long line = XML_GetCurrentLineNumber(parser) - offset++; XML_ParserFree(parser); throw parse_error(original_file ? *original_file : "<xml>", line, err.what()); } if (! have_error.empty()) { - unsigned long line = XML_GetCurrentLineNumber(parser); + unsigned long line = XML_GetCurrentLineNumber(parser) - offset++; parse_error err(original_file ? *original_file : "<xml>", line, have_error); std::cerr << "Error: " << err.what() << std::endl; + have_error = ""; } if (! result) { - unsigned long line = XML_GetCurrentLineNumber(parser); + unsigned long line = XML_GetCurrentLineNumber(parser) - offset++; const char * err = XML_ErrorString(XML_GetErrorCode(parser)); XML_ParserFree(parser); throw parse_error(original_file ? *original_file : "<xml>", line, err); |