(parse): Accept CX as well as C*. Also, general improvements to Bank

type parser.
This commit is contained in:
John Wiegley 2005-06-20 00:31:48 +00:00
parent 6d14952e1e
commit fdf73faff7

27
qif.cc
View file

@ -113,7 +113,8 @@ unsigned int qif_parser_t::parse(std::istream& in,
} }
case 'C': case 'C':
if (in.peek() == '*') { c = in.peek();
if (c == '*' || c == 'X') {
in.get(c); in.get(c);
entry->state = entry_t::CLEARED; entry->state = entry_t::CLEARED;
} }
@ -131,13 +132,9 @@ unsigned int qif_parser_t::parse(std::istream& in,
case 'L': case 'L':
case 'S': case 'S':
case 'E': { case 'E': {
char b = c;
int len;
c = in.peek();
if (! std::isspace(c) && c != '\n') {
get_line(in); get_line(in);
switch (b) { switch (c) {
case 'P': case 'P':
entry->payee = line; entry->payee = line;
break; break;
@ -146,20 +143,20 @@ unsigned int qif_parser_t::parse(std::istream& in,
xact = new transaction_t(NULL); xact = new transaction_t(NULL);
entry->add_transaction(xact); entry->add_transaction(xact);
// fall through... // fall through...
case 'L': case 'L': {
len = std::strlen(line); int len = std::strlen(line);
if (line[len - 1] == ']') if (line[len - 1] == ']')
line[len - 1] = '\0'; line[len - 1] = '\0';
xact->account = journal->find_account(line[0] == '[' ? xact->account = journal->find_account(line[0] == '[' ?
line + 1 : line); line + 1 : line);
break; break;
}
case 'M': case 'M':
case 'E': case 'E':
xact->note = line; xact->note = line;
break; break;
} }
}
break; break;
} }
@ -168,14 +165,19 @@ unsigned int qif_parser_t::parse(std::istream& in,
get_line(in); get_line(in);
break; break;
case '^': case '^': {
account_t * other;
if (xact->account == master) { if (xact->account == master) {
if (! misc) if (! misc)
misc = journal->find_account("Miscellaneous"); misc = journal->find_account("Miscellaneous");
transaction_t * nxact = new transaction_t(misc); other = misc;
} else {
other = master;
}
transaction_t * nxact = new transaction_t(other);
entry->add_transaction(nxact); entry->add_transaction(nxact);
nxact->amount.negate(); nxact->amount.negate();
}
if (journal->add_entry(entry.get())) { if (journal->add_entry(entry.get())) {
entry.release(); entry.release();
@ -188,6 +190,7 @@ unsigned int qif_parser_t::parse(std::istream& in,
break; break;
} }
} }
}
return count; return count;
} }