diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-03 18:50:19 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-03 19:06:56 -0400 |
commit | 71642d98de7e55b235f45feb8e68199ff3c357aa (patch) | |
tree | fda45579cc5439661c6a3ffc00a11e1c5658b37d | |
parent | 2ce7ae376c1e3de0b952d6bb8125f68fc99813d0 (diff) | |
download | fork-ledger-71642d98de7e55b235f45feb8e68199ff3c357aa.tar.gz fork-ledger-71642d98de7e55b235f45feb8e68199ff3c357aa.tar.bz2 fork-ledger-71642d98de7e55b235f45feb8e68199ff3c357aa.zip |
Deleted unused source files: gnucash, ofx, qif.
-rw-r--r-- | src/gnucash.cc | 453 | ||||
-rw-r--r-- | src/gnucash.h | 72 | ||||
-rw-r--r-- | src/ofx.cc | 267 | ||||
-rw-r--r-- | src/ofx.h | 72 | ||||
-rw-r--r-- | src/qif.cc | 276 | ||||
-rw-r--r-- | src/qif.h | 72 |
6 files changed, 0 insertions, 1212 deletions
diff --git a/src/gnucash.cc b/src/gnucash.cc deleted file mode 100644 index 805be514..00000000 --- a/src/gnucash.cc +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "gnucash.h" -#include "session.h" -#include "account.h" - -namespace ledger { - -typedef std::map<const string, account_t *> accounts_map; -typedef std::pair<const string, account_t *> accounts_pair; - -typedef std::map<account_t *, commodity_t *> account_comm_map; -typedef std::pair<account_t *, commodity_t *> account_comm_pair; - -#if 0 - -static journal_t * curr_journal; -static account_t * master_account; -static account_t * curr_account; -static string curr_account_id; -static entry_t * curr_entry; -static commodity_t * entry_comm; -static commodity_t * curr_comm; -static amount_t curr_value; -static amount_t curr_quant; -static XML_Parser current_parser; -static accounts_map accounts_by_id; -static account_comm_map account_comms; -static std::size_t count; -static string have_error; - -static std::istream * instreamp; -static std::size_t offset; -static XML_Parser parser; -static path pathname; -static std::size_t src_idx; -static istream_pos_type beg_pos; -static std::size_t beg_line; - -static xact_t::state_t curr_state; - -static enum action_t { - NO_ACTION, - ACCOUNT_NAME, - ACCOUNT_ID, - ACCOUNT_PARENT, - COMM_SYM, - COMM_NAME, - COMM_PREC, - ENTRY_NUM, - ALMOST_ENTRY_DATE, - ENTRY_DATE, - ENTRY_DESC, - XACT_STATE, - XACT_AMOUNT, - XACT_VALUE, - XACT_QUANTITY, - XACT_ACCOUNT, - XACT_NOTE -} action; - -static void startElement(void *, const char *name, const char **) -{ - if (std::strcmp(name, "gnc:account") == 0) { - curr_account = new account_t(master_account); - } - else if (std::strcmp(name, "act:name") == 0) - action = ACCOUNT_NAME; - else if (std::strcmp(name, "act:id") == 0) - action = ACCOUNT_ID; - else if (std::strcmp(name, "act:parent") == 0) - action = ACCOUNT_PARENT; - else if (std::strcmp(name, "gnc:commodity") == 0) - curr_comm = NULL; - else if (std::strcmp(name, "cmdty:id") == 0) - action = COMM_SYM; - else if (std::strcmp(name, "cmdty:name") == 0) - action = COMM_NAME; - else if (std::strcmp(name, "cmdty:fraction") == 0) - action = COMM_PREC; - else if (std::strcmp(name, "gnc:xact") == 0) { - assert(! curr_entry); - curr_entry = new entry_t; - } - else if (std::strcmp(name, "trn:num") == 0) - action = ENTRY_NUM; - else if (std::strcmp(name, "trn:date-posted") == 0) - action = ALMOST_ENTRY_DATE; - else if (action == ALMOST_ENTRY_DATE && std::strcmp(name, "ts:date") == 0) - action = ENTRY_DATE; - else if (std::strcmp(name, "trn:description") == 0) - action = ENTRY_DESC; - else if (std::strcmp(name, "trn:split") == 0) { - assert(curr_entry); - curr_entry->add_xact(new xact_t(curr_account)); - } - else if (std::strcmp(name, "split:reconciled-state") == 0) - action = XACT_STATE; - else if (std::strcmp(name, "split:amount") == 0) - action = XACT_AMOUNT; - else if (std::strcmp(name, "split:value") == 0) - action = XACT_VALUE; - else if (std::strcmp(name, "split:quantity") == 0) - action = XACT_QUANTITY; - else if (std::strcmp(name, "split:account") == 0) - action = XACT_ACCOUNT; - else if (std::strcmp(name, "split:memo") == 0) - action = XACT_NOTE; -} - -static void endElement(void *, const char *name) -{ - if (std::strcmp(name, "gnc:account") == 0) { - assert(curr_account); - if (curr_account->parent == master_account) - curr_journal->add_account(curr_account); - accounts_by_id.insert(accounts_pair(curr_account_id, curr_account)); - curr_account = NULL; - } - else if (std::strcmp(name, "gnc:commodity") == 0) { - curr_comm = NULL; - } - else if (std::strcmp(name, "gnc:xact") == 0) { - assert(curr_entry); - - // Add the new entry (what gnucash calls a 'xact') to the - // journal - if (! curr_journal->add_entry(curr_entry)) { -#if 0 - print_entry(std::cerr, *curr_entry); -#endif - have_error = "The above entry does not balance"; - checked_delete(curr_entry); - } else { - curr_entry->src_idx = src_idx; - curr_entry->beg_pos = beg_pos; - curr_entry->beg_line = beg_line; - curr_entry->end_pos = instreamp->tellg(); - curr_entry->end_line = XML_GetCurrentLineNumber(parser) - offset; - count++; - } - - // Clear the relevant variables for the next run - curr_entry = NULL; - entry_comm = NULL; - } - else if (std::strcmp(name, "trn:split") == 0) { - xact_t * xact = curr_entry->xacts.back(); - - // Identify the commodity to use for the value of this - // xact. The quantity indicates how many times that value - // the xact is worth. - amount_t value; - commodity_t * default_commodity = NULL; - account_comm_map::iterator ac = account_comms.find(xact->account); - if (ac != account_comms.end()) - default_commodity = (*ac).second; - - if (default_commodity) { - curr_quant.set_commodity(*default_commodity); - value = curr_quant.rounded(); - - if (curr_value.commodity() == *default_commodity) - curr_value = value; - } else { - value = curr_quant; - } - - xact->set_state(curr_state); - xact->amount = value; - if (value != curr_value) - xact->cost = curr_value; - - xact->beg_pos = beg_pos; - xact->beg_line = beg_line; - xact->end_pos = instreamp->tellg(); - xact->end_line = XML_GetCurrentLineNumber(parser) - offset; - - // Clear the relevant variables for the next run - curr_state = xact_t::UNCLEARED; - curr_value = amount_t(); - curr_quant = amount_t(); - } - - action = NO_ACTION; -} - - -static amount_t convert_number(const string& number, - int * precision = NULL) -{ - const char * num = number.c_str(); - - if (char * p = std::strchr(num, '/')) { - string numer_str(num, p - num); - string denom_str(p + 1); - - amount_t amt(numer_str); - amount_t den(denom_str); - - if (precision) - *precision = denom_str.length() - 1; - - if (! den) { - have_error = "Denominator in entry is zero!"; - return amt; - } else { - return amt / den; - } - } else { - return amount_t(number); - } -} - -static void dataHandler(void *, const char *s, int len) -{ - switch (action) { - case ACCOUNT_NAME: - curr_account->name = string(s, len); - break; - - case ACCOUNT_ID: - curr_account_id = string(s, len); - break; - - case ACCOUNT_PARENT: { - accounts_map::iterator i = accounts_by_id.find(string(s, len)); - assert(i != accounts_by_id.end()); - curr_account->parent = (*i).second; - curr_account->depth = curr_account->parent->depth + 1; - (*i).second->add_account(curr_account); - break; - } - - case COMM_SYM: { - string symbol(s, len); - if (symbol == "USD") symbol = "$"; - - curr_comm = amount_t::current_pool->find_or_create(symbol); - assert(curr_comm); - - if (symbol != "$") - curr_comm->add_flags(COMMODITY_STYLE_SEPARATED); - - if (curr_account) - account_comms.insert(account_comm_pair(curr_account, curr_comm)); - else if (curr_entry) - entry_comm = curr_comm; - break; - } - - case COMM_NAME: - curr_comm->set_name(string(s, len)); - break; - - case COMM_PREC: - curr_comm->set_precision(len - 1); - break; - - case ENTRY_NUM: - curr_entry->code = string(s, len); - break; - - case ENTRY_DATE: - curr_entry->_date = parse_date(string(s, len)); - break; - - case ENTRY_DESC: - curr_entry->payee = string(s, len); - break; - - case XACT_STATE: - if (*s == 'y') - curr_state = xact_t::CLEARED; - else if (*s == 'n') - curr_state = xact_t::UNCLEARED; - else - curr_state = xact_t::PENDING; - break; - - case XACT_VALUE: { - int precision; - assert(entry_comm); - curr_value = convert_number(string(s, len), &precision); - curr_value.set_commodity(*entry_comm); - - if (precision > entry_comm->precision()) - entry_comm->set_precision(precision); - break; - } - - case XACT_QUANTITY: - curr_quant = convert_number(string(s, len)); - break; - - case XACT_ACCOUNT: { - xact_t * xact = curr_entry->xacts.back(); - - accounts_map::iterator i = accounts_by_id.find(string(s, len)); - if (i != accounts_by_id.end()) { - xact->account = (*i).second; - } else { - xact->account = curr_journal->find_account("<Unknown>"); - - have_error = (string("Could not find account ") + - string(s, len)); - } - break; - } - - case XACT_NOTE: - curr_entry->xacts.back()->note = string(s, len); - break; - - case NO_ACTION: - case ALMOST_ENTRY_DATE: - case XACT_AMOUNT: - break; - - default: - assert(false); - break; - } -} - -#endif - -bool gnucash_parser_t::test(std::istream& in) const -{ - char buf[80]; - char * p; - - in.read(buf, 11); - if (utf8::is_bom(buf)) - p = &buf[3]; - else - p = buf; - - if (std::strncmp(p, "<?xml", 5) != 0) { - in.clear(); - in.seekg(0, std::ios::beg); - return false; - } - - in.clear(); - in.seekg(0, std::ios::beg); - return true; -} - -std::size_t gnucash_parser_t::parse(std::istream& in, - session_t& session, - journal_t& journal, - account_t * master, - const path * original_file) -{ -#if 0 - char buf[BUFSIZ]; - -#if 0 - // jww (2008-05-08): Replace this - // This is the date format used by Gnucash, so override whatever the - // user specified. - date_t::input_format = "%Y-%m-%d %H:%M:%S %z"; -#endif - - count = 0; - action = NO_ACTION; - curr_journal = &journal; - master_account = master ? master : session.master.get(); - curr_account = NULL; - curr_entry = NULL; - curr_comm = NULL; - entry_comm = NULL; - curr_state = xact_t::UNCLEARED; - - instreamp = ∈ - pathname = original_file ? *original_file : "<gnucash>"; - src_idx = journal.sources.size() - 1; - - // GnuCash uses the USD commodity without defining it, which really - // means $. - commodity_t * usd = amount_t::current_pool->find_or_create("$"); - usd->set_precision(2); - usd->add_flags(COMMODITY_STYLE_THOUSANDS); - - offset = 2; - parser = current_parser = XML_ParserCreate(NULL); - - XML_SetElementHandler(parser, startElement, endElement); - XML_SetCharacterDataHandler(parser, dataHandler); - - while (in.good() && ! in.eof()) { - beg_pos = in.tellg(); - beg_line = (XML_GetCurrentLineNumber(parser) - offset) + 1; - - in.getline(buf, BUFSIZ - 1); - std::strcat(buf, "\n"); - if (! XML_Parse(parser, buf, std::strlen(buf), in.eof())) { - //std::size_t line = XML_GetCurrentLineNumber(parser) - offset++; - const char * msg = XML_ErrorString(XML_GetErrorCode(parser)); - XML_ParserFree(parser); - throw parse_error(msg); - } - - if (! have_error.empty()) { - //std::size_t line = XML_GetCurrentLineNumber(parser) - offset++; - parse_error err(have_error); - std::cerr << "Error: " << err.what() << std::endl; - have_error = ""; - } - } - - XML_ParserFree(parser); - - accounts_by_id.clear(); - curr_account_id.clear(); - - return count; -#else - return 0; -#endif -} - -} // namespace ledger diff --git a/src/gnucash.h b/src/gnucash.h deleted file mode 100644 index e813be40..00000000 --- a/src/gnucash.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @addtogroup parse - */ - -/** - * @file gnucash.h - * @author John Wiegley - * - * @ingroup pares - * - * @brief Brief - * - * Long. - */ -#ifndef _GNUCASH_H -#define _GNUCASH_H - -#include "journal.h" - -namespace ledger { - -/** - * @brief Brief - * - * Long. - */ -class gnucash_parser_t : public journal_t::parser_t -{ - public: - virtual bool test(std::istream& in) const; - - virtual std::size_t parse(std::istream& in, - session_t& session, - journal_t& journal, - account_t * master = NULL, - const path * original_file = NULL); -}; - -} // namespace ledger - -#endif // _GNUCASH_H diff --git a/src/ofx.cc b/src/ofx.cc deleted file mode 100644 index 2e4a9d5d..00000000 --- a/src/ofx.cc +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "ofx.h" -#include "amount.h" -#include "account.h" -#include "session.h" - -#if defined(HAVE_LIBOFX) - -#include <libofx.h> - -namespace ledger { - -typedef std::map<const string, account_t *> accounts_map; -typedef std::pair<const string, account_t *> accounts_pair; - -typedef std::map<const string, commodity_t *> commodities_map; -typedef std::pair<const string, commodity_t *> commodities_pair; - -journal_t * curr_journal; -accounts_map ofx_accounts; -commodities_map ofx_account_currencies; -commodities_map ofx_securities; -account_t * master_account; - -int ofx_proc_statement_cb(struct OfxStatementData, void *) -{ - return 0; -} - -int ofx_proc_account_cb(struct OfxAccountData data, void *) -{ - if (! data.account_id_valid) - return -1; - - DEBUG("ledger.ofx.parse", "account " << data.account_name); - account_t * account = new account_t(master_account, data.account_name); - curr_journal->add_account(account); - ofx_accounts.insert(accounts_pair(data.account_id, account)); - - if (data.currency_valid) { - commodity_t * commodity = amount_t::current_pool->find_or_create(data.currency); - commodity->add_flags(COMMODITY_STYLE_SUFFIXED | COMMODITY_STYLE_SEPARATED); - - commodities_map::iterator i = ofx_account_currencies.find(data.account_id); - if (i == ofx_account_currencies.end()) - ofx_account_currencies.insert(commodities_pair(data.account_id, - commodity)); - } - - return 0; -} - -int ofx_proc_transaction_cb(struct OfxTransactionData data, void *) -{ - if (! data.account_id_valid || ! data.units_valid) - return -1; - - accounts_map::iterator i = ofx_accounts.find(data.account_id); - assert(i != ofx_accounts.end()); - account_t * account = (*i).second; - - entry_t * entry = new entry_t; - - entry->add_xact(new xact_t(account)); - xact_t * xact = entry->xacts.back(); - - // get the account's default currency - commodities_map::iterator ac = ofx_account_currencies.find(data.account_id); - assert(ac != ofx_account_currencies.end()); - commodity_t * default_commodity = (*ac).second; - - std::ostringstream stream; - stream << - data.units; - - // jww (2005-02-09): what if the amount contains fees? - - if (data.unique_id_valid) { - commodities_map::iterator s = ofx_securities.find(data.unique_id); - assert(s != ofx_securities.end()); - xact->amount = string(stream.str()) + " " + (*s).second->base_symbol(); - } else { - xact->amount = string(stream.str()) + " " + default_commodity->base_symbol(); - } - - if (data.unitprice_valid && (data.unitprice < 1.0 || data.unitprice > 1.0)) { - std::ostringstream cstream; - stream << - data.unitprice; - xact->cost = amount_t(string(stream.str()) + " " + default_commodity->base_symbol()); - } - - DEBUG("ledger.ofx.parse", "xact " << xact->amount - << " from " << *xact->account); - -#if 0 - if (data.date_initiated_valid) - entry->_date = gregorian::from_time_t(data.date_initiated); - else if (data.date_posted_valid) - entry->_date = from_time_t(data.date_posted); -#endif - - if (data.check_number_valid) - entry->code = data.check_number; - else if (data.reference_number_valid) - entry->code = data.reference_number; - - if (data.name_valid) - entry->payee = data.name; - - if (data.memo_valid) - xact->note = data.memo; - - // jww (2005-02-09): check for fi_id_corrected? or is this handled - // by the library? - - // Balance all entries into <Unknown>, since it is not specified. - account = curr_journal->find_account("<Unknown>"); - entry->add_xact(new xact_t(account)); - - if (! curr_journal->add_entry(entry)) { -#if 0 - print_entry(std::cerr, *entry); -#endif - // jww (2005-02-09): uncomment - //have_error = "The above entry does not balance"; - checked_delete(entry); - return -1; - } - return 0; -} - -int ofx_proc_security_cb(struct OfxSecurityData data, void *) -{ - if (! data.unique_id_valid) - return -1; - - string symbol; - if (data.ticker_valid) - symbol = data.ticker; - else if (data.currency_valid) - symbol = data.currency; - else - return -1; - - commodity_t * commodity = amount_t::current_pool->find_or_create(symbol); - commodity->add_flags(COMMODITY_STYLE_SUFFIXED | COMMODITY_STYLE_SEPARATED); - - if (data.secname_valid) - commodity->set_name(string(data.secname)); - - if (data.memo_valid) - commodity->set_note(string(data.memo)); - - commodities_map::iterator i = ofx_securities.find(data.unique_id); - if (i == ofx_securities.end()) { - DEBUG("ledger.ofx.parse", "security " << symbol); - ofx_securities.insert(commodities_pair(data.unique_id, commodity)); - } - - // jww (2005-02-09): What is the commodity for data.unitprice? - if (data.date_unitprice_valid && data.unitprice_valid) { - DEBUG("ledger.ofx.parse", " price " << data.unitprice); -#if 0 - // jww (2008-08-07): Need to convert from double here - commodity->add_price(data.date_unitprice, amount_t(data.unitprice)); -#endif - } - - return 0; -} - -int ofx_proc_status_cb(struct OfxStatusData, void *) -{ - return 0; -} - -bool ofx_parser_t::test(std::istream& in) const -{ - char buf[80]; - - in.getline(buf, 79); - if (std::strncmp(buf, "OFXHEADER", 9) == 0) { - in.clear(); - in.seekg(0, std::ios::beg); - return true; - } - else if (std::strncmp(buf, "<?xml", 5) != 0) { - in.clear(); - in.seekg(0, std::ios::beg); - return false; - } - - in.getline(buf, 79); - if (std::strncmp(buf, "<?OFX", 5) != 0 && - std::strncmp(buf, "<?ofx", 5) != 0) { - in.clear(); - in.seekg(0, std::ios::beg); - return false; - } - - in.clear(); - in.seekg(0, std::ios::beg); - return true; -} - -std::size_t ofx_parser_t::parse(std::istream& in, - session_t& session, - journal_t& journal, - account_t * master, - const path * original_file) -{ - if (! original_file) - return 0; - - curr_journal = &journal; - master_account = master ? master : session.master.get(); - - LibofxContextPtr libofx_context = libofx_get_new_context(); - - ofx_set_statement_cb (libofx_context, ofx_proc_statement_cb, 0); - ofx_set_account_cb (libofx_context, ofx_proc_account_cb, 0); - ofx_set_transaction_cb (libofx_context, ofx_proc_transaction_cb, 0); - ofx_set_security_cb (libofx_context, ofx_proc_security_cb, 0); - ofx_set_status_cb (libofx_context, ofx_proc_status_cb, 0); - - // The processing is done by way of callbacks, which are all defined - // above. - libofx_proc_file(libofx_context, original_file->string().c_str(), - AUTODETECT); - - libofx_free_context(libofx_context); - - return 1; // jww (2005-02-09): count; -} - -} // namespace ledger - -#endif HAVE_LIBOFX diff --git a/src/ofx.h b/src/ofx.h deleted file mode 100644 index e8bac7dd..00000000 --- a/src/ofx.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @addtogroup parse - */ - -/** - * @file ofx.h - * @author John Wiegley - * - * @ingroup parse - * - * @brief Brief - * - * Long. - */ -#ifndef _OFX_H -#define _OFX_H - -#include "journal.h" - -namespace ledger { - -/** - * @brief Brief - * - * Long. - */ -class ofx_parser_t : public journal_t::parser_t -{ -public: - virtual bool test(std::istream& in) const; - - virtual std::size_t parse(std::istream& in, - session_t& session, - journal_t& journal, - account_t * master = NULL, - const path * original_file = NULL); -}; - -} // namespace ledger - -#endif // _OFX_H diff --git a/src/qif.cc b/src/qif.cc deleted file mode 100644 index 07a29ca1..00000000 --- a/src/qif.cc +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "journal.h" -#include "qif.h" -#include "utils.h" - -namespace ledger { - -#define MAX_LINE 1024 - -static char line[MAX_LINE + 1]; -static path pathname; -static std::size_t src_idx; -static std::size_t linenum; - -static inline char * get_line(std::istream& in) { - in.getline(line, MAX_LINE); - int len = std::strlen(line); - if (line[len - 1] == '\r') - line[len - 1] = '\0'; - linenum++; - return line; -} - -bool qif_parser_t::test(std::istream& in) const -{ - char magic[sizeof(uint32_t) + 1]; - in.read(magic, sizeof(uint32_t)); - magic[sizeof(uint32_t)] = '\0'; - in.clear(); - in.seekg(0, std::ios::beg); - - return (std::strcmp(magic, "!Typ") == 0 || - std::strcmp(magic, "\n!Ty") == 0 || - std::strcmp(magic, "\r\n!T") == 0); -} - -std::size_t qif_parser_t::parse(std::istream& in, - session_t& session, - journal_t& journal, - account_t * master, - const path * original_file) -{ - std::auto_ptr<entry_t> entry; - std::auto_ptr<amount_t> amount; - - xact_t * xact; - std::size_t count = 0; - account_t * misc = NULL; - commodity_t * def_commodity = NULL; - bool saw_splits = false; - bool saw_category = false; - xact_t * total = NULL; - - entry.reset(new entry_t); - xact = new xact_t(master); - entry->add_xact(xact); - - pathname = journal.sources.back(); - src_idx = journal.sources.size() - 1; - linenum = 1; - - istream_pos_type beg_pos = 0; - std::size_t beg_line = 0; - -#define SET_BEG_POS_AND_LINE() \ - if (! beg_line) { \ - beg_pos = in.tellg(); \ - beg_line = linenum; \ - } - - while (in.good() && ! in.eof()) { - char c; - in.get(c); - switch (c) { - case ' ': - case '\t': - if (peek_next_nonws(in) != '\n') { - get_line(in); - throw parse_error("Line begins with whitespace"); - } - // fall through... - - case '\n': - linenum++; - case '\r': // skip blank lines - break; - - case '!': - get_line(in); - - if (std::strcmp(line, "Type:Invst") == 0 || - std::strcmp(line, "Account") == 0 || - std::strcmp(line, "Type:Cat") == 0 || - std::strcmp(line, "Type:Class") == 0 || - std::strcmp(line, "Type:Memorized") == 0) - throw_(parse_error, "QIF files of type " << line << " are not supported."); - break; - - case 'D': - SET_BEG_POS_AND_LINE(); - get_line(in); - // jww (2008-08-01): Is this just a date? - entry->_date = parse_date(line); - break; - - case 'T': - case '$': { - SET_BEG_POS_AND_LINE(); - get_line(in); - xact->amount.parse(line); - - unsigned char flags = xact->amount.commodity().flags(); - unsigned char prec = xact->amount.commodity().precision(); - - if (! def_commodity) { - def_commodity = amount_t::current_pool->find_or_create("$"); - assert(def_commodity); - } - xact->amount.set_commodity(*def_commodity); - - def_commodity->add_flags(flags); - if (prec > def_commodity->precision()) - def_commodity->set_precision(prec); - - if (c == '$') { - saw_splits = true; - xact->amount.negate(); - } else { - total = xact; - } - break; - } - - case 'C': - SET_BEG_POS_AND_LINE(); - c = in.peek(); - if (c == '*' || c == 'X') { - in.get(c); - xact->set_state(item_t::CLEARED); - } - break; - - case 'N': - SET_BEG_POS_AND_LINE(); - get_line(in); - entry->code = line; - break; - - case 'P': - case 'M': - case 'L': - case 'S': - case 'E': { - SET_BEG_POS_AND_LINE(); - get_line(in); - - switch (c) { - case 'P': - entry->payee = line; - break; - - case 'S': - xact = new xact_t(NULL); - entry->add_xact(xact); - // fall through... - case 'L': { - int len = std::strlen(line); - if (line[len - 1] == ']') - line[len - 1] = '\0'; - xact->account = journal.find_account(line[0] == '[' ? - line + 1 : line); - if (c == 'L') - saw_category = true; - break; - } - - case 'M': - case 'E': - xact->note = line; - break; - } - break; - } - - case 'A': - SET_BEG_POS_AND_LINE(); - // jww (2004-08-19): these are ignored right now - get_line(in); - break; - - case '^': { - account_t * other; - if (xact->account == master) { - if (! misc) - misc = journal.find_account("Miscellaneous"); - other = misc; - } else { - other = master; - } - - if (total && saw_category) { - if (! saw_splits) - total->amount.negate(); // negate, to show correct flow - else - total->account = other; - } - - if (! saw_splits) { - xact_t * nxact = new xact_t(other); - // The amount doesn't need to be set because the code below - // will balance this xact against the other. - entry->add_xact(nxact); - } - - if (journal.add_entry(entry.get())) { - entry->src_idx = src_idx; - entry->beg_pos = beg_pos; - entry->beg_line = beg_line; - entry->end_pos = in.tellg(); - entry->end_line = linenum; - entry.release(); - count++; - } - - // reset things for the next entry - entry.reset(new entry_t); - xact = new xact_t(master); - entry->add_xact(xact); - - saw_splits = false; - saw_category = false; - total = NULL; - beg_line = 0; - break; - } - - default: - get_line(in); - break; - } - } - - return count; -} - -} // namespace ledger diff --git a/src/qif.h b/src/qif.h deleted file mode 100644 index ad016601..00000000 --- a/src/qif.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @addtogroup parse - */ - -/** - * @file qif.h - * @author John Wiegley - * - * @ingroup parse - * - * @brief Brief - * - * Long. - */ -#ifndef _QIF_H -#define _QIF_H - -#include "journal.h" - -namespace ledger { - -/** - * @brief Brief - * - * Long. - */ -class qif_parser_t : public journal_t::parser_t -{ - public: - virtual bool test(std::istream& in) const; - - virtual std::size_t parse(std::istream& in, - session_t& session, - journal_t& journal, - account_t * master = NULL, - const path * original_file = NULL); -}; - -} // namespace ledger - -#endif // _QIF_H |