Made several fixes to commodity parsing, which were preventing Gnucash files

from being parsed altogether.
This commit is contained in:
John Wiegley 2008-04-13 05:02:38 -04:00
parent c7b4370ff9
commit 91234e40ab

View file

@ -82,13 +82,8 @@ static void startElement(void *userData, const char *name, const char **atts)
action = ACCOUNT_ID; action = ACCOUNT_ID;
else if (std::strcmp(name, "act:parent") == 0) else if (std::strcmp(name, "act:parent") == 0)
action = ACCOUNT_PARENT; action = ACCOUNT_PARENT;
else if (std::strcmp(name, "gnc:commodity") == 0) { else if (std::strcmp(name, "gnc:commodity") == 0)
assert(! curr_comm); curr_comm = NULL;
#if 0
// jww (2006-03-02): !!!
curr_comm = new commodity_t("");
#endif
}
else if (std::strcmp(name, "cmdty:id") == 0) else if (std::strcmp(name, "cmdty:id") == 0)
action = COMM_SYM; action = COMM_SYM;
else if (std::strcmp(name, "cmdty:name") == 0) else if (std::strcmp(name, "cmdty:name") == 0)
@ -135,11 +130,6 @@ static void endElement(void *userData, const char *name)
curr_account = NULL; curr_account = NULL;
} }
else if (std::strcmp(name, "gnc:commodity") == 0) { else if (std::strcmp(name, "gnc:commodity") == 0) {
assert(curr_comm);
#if 0
// jww (2006-03-02): !!!
commodity_t::add_commodity(curr_comm);
#endif
curr_comm = NULL; curr_comm = NULL;
} }
else if (std::strcmp(name, "gnc:transaction") == 0) { else if (std::strcmp(name, "gnc:transaction") == 0) {
@ -256,32 +246,25 @@ static void dataHandler(void *userData, const char *s, int len)
break; break;
} }
case COMM_SYM: case COMM_SYM: {
if (curr_comm) {
#if 0
// jww (2006-03-02): !!!
curr_comm->set_symbol(std::string(s, len));
#endif
}
else if (curr_account) {
std::string symbol(s, len); std::string symbol(s, len);
commodity_t * comm = commodity_t::find_or_create(symbol); if (symbol == "USD") symbol = "$";
assert(comm);
if (symbol != "$" && symbol != "USD") curr_comm = commodity_t::find_or_create(symbol);
comm->add_flags(COMMODITY_STYLE_SEPARATED); assert(curr_comm);
account_comms.insert(account_comm_pair(curr_account, comm));
} if (symbol != "$")
else if (curr_entry) { curr_comm->add_flags(COMMODITY_STYLE_SEPARATED);
std::string symbol(s, len);
entry_comm = commodity_t::find_or_create(symbol); if (curr_account)
assert(entry_comm); account_comms.insert(account_comm_pair(curr_account, curr_comm));
if (symbol != "$" && symbol != "USD") else if (curr_entry)
entry_comm->add_flags(COMMODITY_STYLE_SEPARATED); entry_comm = curr_comm;
}
break; break;
}
case COMM_NAME: case COMM_NAME:
curr_comm->name() = std::string(s, len); curr_comm->set_name(std::string(s, len));
break; break;
case COMM_PREC: case COMM_PREC:
@ -395,10 +378,6 @@ unsigned int gnucash_parser_t::parse(std::istream& in,
commodity_t * usd = commodity_t::find_or_create("$"); commodity_t * usd = commodity_t::find_or_create("$");
usd->set_precision(2); usd->set_precision(2);
usd->add_flags(COMMODITY_STYLE_THOUSANDS); usd->add_flags(COMMODITY_STYLE_THOUSANDS);
#if 0
//jww (2006-03-02): !!! make an alias here
commodity_t::add_commodity(usd, "USD");
#endif
offset = 2; offset = 2;
parser = current_parser = XML_ParserCreate(NULL); parser = current_parser = XML_ParserCreate(NULL);