diff options
-rw-r--r-- | gnucash.cc | 14 | ||||
-rw-r--r-- | gnucash.h | 21 | ||||
-rw-r--r-- | main.cc | 6 | ||||
-rw-r--r-- | valexpr.cc | 6 |
4 files changed, 42 insertions, 5 deletions
@@ -255,7 +255,19 @@ static void dataHandler(void *userData, const char *s, int len) } } -int parse_gnucash(std::istream& in, journal_t * journal, account_t * master) +bool gnucash_parser_t::test(std::istream& in) const +{ + char buf[23]; + in.get(buf, 22); + in.seekg(0); + + return std::strncmp(buf, "<?xml version=\"1.0\"?>", 21) == 0; +} + +unsigned int gnucash_parser_t::parse(std::istream& in, + journal_t * journal, + account_t * master, + const std::string * original_file) { char buf[BUFSIZ]; diff --git a/gnucash.h b/gnucash.h new file mode 100644 index 00000000..6b71fffa --- /dev/null +++ b/gnucash.h @@ -0,0 +1,21 @@ +#ifndef _GNUCASH_H +#define _GNUCASH_H + +#include "parser.h" + +namespace ledger { + +class gnucash_parser_t : public parser_t +{ + public: + virtual bool test(std::istream& in) const; + + virtual unsigned int parse(std::istream& in, + journal_t * journal, + account_t * master = NULL, + const std::string * original_file = NULL); +}; + +} // namespace ledger + +#endif // _GNUCASH_H @@ -3,6 +3,9 @@ #include "textual.h" #include "binary.h" #include "qif.h" +#ifdef READ_GNUCASH +#include "gnucash.h" +#endif #include "valexpr.h" #include "format.h" #include "walk.h" @@ -188,6 +191,9 @@ int main(int argc, char * argv[], char * envp[]) std::auto_ptr<textual_parser_t> text_parser(new textual_parser_t); parser_t::parsers.push_back(bin_parser.get()); +#ifdef READ_GNUCASH + parser_t::parsers.push_back(gnucash_parser.get()); +#endif parser_t::parsers.push_back(qif_parser.get()); parser_t::parsers.push_back(text_parser.get()); @@ -187,8 +187,8 @@ void value_expr_t::compute(value_t& result, const details_t& details, case INDEX: if (details.xact) result = details.xact->index + 1; - else - result = 0U; + else if (details.account) + result = details.account->count; break; case DEPTH: @@ -424,8 +424,6 @@ value_expr_t * parse_value_term(std::istream& in) case 'V': node.reset(parse_value_term("P(O,d)")); break; case 'g': node.reset(parse_value_expr("v-c")); break; case 'G': node.reset(parse_value_expr("V-C")); break; - case 'o': node.reset(parse_value_expr("d-b")); break; - case 'w': node.reset(parse_value_expr("e-d")); break; // Functions case '-': |