diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/amount.cc | 46 | ||||
-rw-r--r-- | src/context.h | 32 | ||||
-rw-r--r-- | src/journal.cc | 30 | ||||
-rw-r--r-- | src/main.cc | 4 | ||||
-rw-r--r-- | src/mask.h | 2 | ||||
-rw-r--r-- | src/ofx.cc | 8 | ||||
-rw-r--r-- | src/pyinterp.cc | 9 | ||||
-rw-r--r-- | src/pyinterp.h | 8 | ||||
-rw-r--r-- | src/qif.cc | 8 | ||||
-rw-r--r-- | src/quotes.cc | 20 | ||||
-rw-r--r-- | src/session.cc | 8 | ||||
-rw-r--r-- | src/textual.cc | 65 | ||||
-rw-r--r-- | src/times.h | 8 | ||||
-rw-r--r-- | src/utils.cc | 10 | ||||
-rw-r--r-- | src/utils.h | 97 | ||||
-rw-r--r-- | src/value.cc | 8 | ||||
-rw-r--r-- | src/xml.cc | 10 | ||||
-rw-r--r-- | src/xpath.cc | 4 | ||||
-rw-r--r-- | src/xpath.h | 6 |
19 files changed, 202 insertions, 181 deletions
diff --git a/src/amount.cc b/src/amount.cc index ac7bbdb7..534e15a8 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -340,8 +340,8 @@ amount_t::amount_t(const double val) void amount_t::_release() { - DEBUG_("amounts.refs", - quantity << " ref--, now " << (quantity->ref - 1)); + DEBUG("amounts.refs", quantity << " ref--, now " << (quantity->ref - 1)); + if (--quantity->ref == 0) { if (! (quantity->flags & BIGINT_BULK_ALLOC)) delete quantity; @@ -382,7 +382,7 @@ void amount_t::_copy(const amount_t& amt) quantity = new bigint_t(*amt.quantity); } else { quantity = amt.quantity; - DEBUG_("amounts.refs", + DEBUG("amounts.refs", quantity << " ref++, now " << (quantity->ref + 1)); quantity->ref++; } @@ -1214,7 +1214,7 @@ bool parse_annotations(std::istream& in, amount_t& price, } } while (true); - DEBUG_("amounts.commodities", + DEBUG("amounts.commodities", "Parsed commodity annotations: " << " price " << price << " " << " date " << date << " " @@ -1473,7 +1473,7 @@ void amount_t::read_quantity(char *& data) data += sizeof(unsigned int); quantity = (bigint_t *) (bigints + (index - 1) * sizeof(bigint_t)); - DEBUG_("amounts.refs", + DEBUG("amounts.refs", quantity << " ref++, now " << (quantity->ref + 1)); quantity->ref++; } @@ -1562,12 +1562,12 @@ bool amount_t::valid() const { if (quantity) { if (quantity->ref == 0) { - DEBUG_("ledger.validate", "amount_t: quantity->ref == 0"); + DEBUG("ledger.validate", "amount_t: quantity->ref == 0"); return false; } } else if (commodity_) { - DEBUG_("ledger.validate", "amount_t: commodity_ != NULL"); + DEBUG("ledger.validate", "amount_t: commodity_ != NULL"); return false; } return true; @@ -1588,7 +1588,7 @@ void amount_t::annotate_commodity(const amount_t& tprice, } assert(this_base); - DEBUG_("amounts.commodities", "Annotating commodity for amount " + DEBUG("amounts.commodities", "Annotating commodity for amount " << *this << std::endl << " price " << tprice << " " << " date " << tdate << " " @@ -1602,7 +1602,7 @@ void amount_t::annotate_commodity(const amount_t& tprice, if (ann_comm) set_commodity(*ann_comm); - DEBUG_("amounts.commodities", " Annotated amount is " << *this); + DEBUG("amounts.commodities", " Annotated amount is " << *this); } amount_t amount_t::strip_annotations(const bool _keep_price, @@ -1613,7 +1613,7 @@ amount_t amount_t::strip_annotations(const bool _keep_price, (_keep_price && _keep_date && _keep_tag)) return *this; - DEBUG_("amounts.commodities", "Reducing commodity for amount " + DEBUG("amounts.commodities", "Reducing commodity for amount " << *this << std::endl << " keep price " << _keep_price << " " << " keep date " << _keep_date << " " @@ -1640,7 +1640,7 @@ amount_t amount_t::strip_annotations(const bool _keep_price, amount_t t(*this); t.set_commodity(*new_comm); - DEBUG_("amounts.commodities", " Reduced amount is " << t); + DEBUG("amounts.commodities", " Reduced amount is " << t); return t; } @@ -1650,7 +1650,7 @@ amount_t amount_t::price() const if (commodity_ && commodity_->annotated) { amount_t t(((annotated_commodity_t *)commodity_)->price); t *= number(); - DEBUG_("amounts.commodities", + DEBUG("amounts.commodities", "Returning price of " << *this << " = " << t); return t; } @@ -1660,7 +1660,7 @@ amount_t amount_t::price() const moment_t amount_t::date() const { if (commodity_ && commodity_->annotated) { - DEBUG_("amounts.commodities", + DEBUG("amounts.commodities", "Returning date of " << *this << " = " << ((annotated_commodity_t *)commodity_)->date); return ((annotated_commodity_t *)commodity_)->date; @@ -1702,7 +1702,7 @@ commodity_base_t * commodity_base_t::create(const string& symbol) { commodity_base_t * commodity = new commodity_base_t(symbol); - DEBUG_("amounts.commodities", "Creating base commodity " << symbol); + DEBUG("amounts.commodities", "Creating base commodity " << symbol); std::pair<base_commodities_map::iterator, bool> result = commodities.insert(base_commodities_pair(symbol, commodity)); @@ -1723,18 +1723,18 @@ bool commodity_t::needs_quotes(const string& symbol) bool commodity_t::valid() const { if (symbol().empty() && this != null_commodity) { - DEBUG_("ledger.validate", + DEBUG("ledger.validate", "commodity_t: symbol().empty() && this != null_commodity"); return false; } if (annotated && ! base) { - DEBUG_("ledger.validate", "commodity_t: annotated && ! base"); + DEBUG("ledger.validate", "commodity_t: annotated && ! base"); return false; } if (precision() > 16) { - DEBUG_("ledger.validate", "commodity_t: precision() > 16"); + DEBUG("ledger.validate", "commodity_t: precision() > 16"); return false; } @@ -1755,7 +1755,7 @@ commodity_t * commodity_t::create(const string& symbol) commodity->qualified_symbol = symbol; } - DEBUG_("amounts.commodities", + DEBUG("amounts.commodities", "Creating commodity " << commodity->qualified_symbol); std::pair<commodities_map::iterator, bool> result @@ -1777,7 +1777,7 @@ commodity_t * commodity_t::create(const string& symbol) commodity_t * commodity_t::find_or_create(const string& symbol) { - DEBUG_("amounts.commodities", "Find-or-create commodity " << symbol); + DEBUG("amounts.commodities", "Find-or-create commodity " << symbol); commodity_t * commodity = find(symbol); if (commodity) @@ -1787,7 +1787,7 @@ commodity_t * commodity_t::find_or_create(const string& symbol) commodity_t * commodity_t::find(const string& symbol) { - DEBUG_("amounts.commodities", "Find commodity " << symbol); + DEBUG("amounts.commodities", "Find commodity " << symbol); commodities_map::const_iterator i = commodities.find(symbol); if (i != commodities.end()) @@ -1899,7 +1899,7 @@ annotated_commodity_t::create(const commodity_t& comm, commodity->qualified_symbol = comm.symbol(); - DEBUG_("amounts.commodities", "Creating annotated commodity " + DEBUG("amounts.commodities", "Creating annotated commodity " << "symbol " << commodity->symbol() << " key " << mapping_key << std::endl << " price " << price << " " @@ -1934,13 +1934,13 @@ namespace { comm.write(name); annotated_commodity_t::write_annotations(name, price, date, tag); - DEBUG_("amounts.commodities", "make_qualified_name for " + DEBUG("amounts.commodities", "make_qualified_name for " << comm.qualified_symbol << std::endl << " price " << price << " " << " date " << date << " " << " tag " << tag); - DEBUG_("amounts.commodities", "qualified_name is " << name.str()); + DEBUG("amounts.commodities", "qualified_name is " << name.str()); return name.str(); } diff --git a/src/context.h b/src/context.h index 3851d073..899c9b88 100644 --- a/src/context.h +++ b/src/context.h @@ -7,20 +7,30 @@ class context { public: string context; // ex: 'While parsing file "%R" at line %L' +}; + +class file_context : public context +{ +public: + path pathname; // ex: ledger.dat - string resource; // ex: ledger.dat - long linenum_beg; // ex: 1010 - long linenum_end; // ex: 1010 - long colnum_beg; // ex: 8 - long colnum_end; // ex: 8 - long position_beg; - long position_end; + optional<long> linenum_beg; // ex: 1010 + optional<long> linenum_end; // ex: 1010 + optional<long> colnum_beg; // ex: 8 + optional<long> colnum_end; // ex: 8 + optional<long> position_beg; + optional<long> position_end; +}; +class string_context : public context +{ +public: string text; // ex: (The multi-line text of an entry) - long linenum_beg_off; // ex: 2 / -1 means start at beginning - long linenum_end_off; // ex: 2 / -1 means start at beginning - long colnum_beg_off; // ex: 8 / -1 means start - long colnum_end_off; // ex: 8 / -1 means start + + optional<long> linenum_beg_off; // ex: 2 / none means start at beginning + optional<long> linenum_end_off; // ex: 2 / none means start at beginning + optional<long> colnum_beg_off; // ex: 8 / none means start + optional<long> colnum_end_off; // ex: 8 / none means start }; } // namespace ledger diff --git a/src/journal.cc b/src/journal.cc index 1f643364..a8ad2807 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -35,12 +35,12 @@ moment_t transaction_t::effective_date() const bool transaction_t::valid() const { if (! entry) { - DEBUG_("ledger.validate", "transaction_t: ! entry"); + DEBUG("ledger.validate", "transaction_t: ! entry"); return false; } if (state != UNCLEARED && state != CLEARED && state != PENDING) { - DEBUG_("ledger.validate", "transaction_t: state is bad"); + DEBUG("ledger.validate", "transaction_t: state is bad"); return false; } @@ -53,27 +53,27 @@ bool transaction_t::valid() const break; } if (! found) { - DEBUG_("ledger.validate", "transaction_t: ! found"); + DEBUG("ledger.validate", "transaction_t: ! found"); return false; } if (! account) { - DEBUG_("ledger.validate", "transaction_t: ! account"); + DEBUG("ledger.validate", "transaction_t: ! account"); return false; } if (! amount.valid()) { - DEBUG_("ledger.validate", "transaction_t: ! amount.valid()"); + DEBUG("ledger.validate", "transaction_t: ! amount.valid()"); return false; } if (cost && ! cost->valid()) { - DEBUG_("ledger.validate", "transaction_t: cost && ! cost->valid()"); + DEBUG("ledger.validate", "transaction_t: cost && ! cost->valid()"); return false; } if (flags & ~0x003f) { - DEBUG_("ledger.validate", "transaction_t: flags are bad"); + DEBUG("ledger.validate", "transaction_t: flags are bad"); return false; } @@ -311,7 +311,7 @@ void entry_t::add_transaction(transaction_t * xact) bool entry_t::valid() const { if (! is_valid_moment(_date) || ! journal) { - DEBUG_("ledger.validate", "entry_t: ! _date || ! journal"); + DEBUG("ledger.validate", "entry_t: ! _date || ! journal"); return false; } @@ -319,7 +319,7 @@ bool entry_t::valid() const i != transactions.end(); i++) if ((*i)->entry != this || ! (*i)->valid()) { - DEBUG_("ledger.validate", "entry_t: transaction not valid"); + DEBUG("ledger.validate", "entry_t: transaction not valid"); return false; } @@ -470,7 +470,7 @@ std::ostream& operator<<(std::ostream& out, const account_t& account) bool account_t::valid() const { if (depth > 256 || ! journal) { - DEBUG_("ledger.validate", "account_t: depth > 256 || ! journal"); + DEBUG("ledger.validate", "account_t: depth > 256 || ! journal"); return false; } @@ -478,12 +478,12 @@ bool account_t::valid() const i != accounts.end(); i++) { if (this == (*i).second) { - DEBUG_("ledger.validate", "account_t: parent refers to itself!"); + DEBUG("ledger.validate", "account_t: parent refers to itself!"); return false; } if (! (*i).second->valid()) { - DEBUG_("ledger.validate", "account_t: child not valid"); + DEBUG("ledger.validate", "account_t: child not valid"); return false; } } @@ -579,7 +579,7 @@ bool journal_t::remove_entry(entry_t * entry) bool journal_t::valid() const { if (! master->valid()) { - DEBUG_("ledger.validate", "journal_t: master not valid"); + DEBUG("ledger.validate", "journal_t: master not valid"); return false; } @@ -587,7 +587,7 @@ bool journal_t::valid() const i != entries.end(); i++) if (! (*i)->valid()) { - DEBUG_("ledger.validate", "journal_t: entry not valid"); + DEBUG("ledger.validate", "journal_t: entry not valid"); return false; } @@ -595,7 +595,7 @@ bool journal_t::valid() const i != commodity_t::commodities.end(); i++) if (! (*i).second->valid()) { - DEBUG_("ledger.validate", "journal_t: commodity not valid"); + DEBUG("ledger.validate", "journal_t: commodity not valid"); return false; } diff --git a/src/main.cc b/src/main.cc index 0ca984c3..eb00bfb9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -46,7 +46,7 @@ static int read_and_report(report_t * report, int argc, char * argv[], else session.use_cache = session.data_file.empty() && session.price_db.empty(); - DEBUG_("ledger.session.cache", "1. use_cache = " << session.use_cache); + DEBUG("ledger.session.cache", "1. use_cache = " << session.use_cache); // Process the environment settings @@ -68,7 +68,7 @@ static int read_and_report(report_t * report, int argc, char * argv[], if (session.data_file == session.cache_file) session.use_cache = false; - DEBUG_("ledger.session.cache", "2. use_cache = " << session.use_cache); + DEBUG("ledger.session.cache", "2. use_cache = " << session.use_cache); INFO("Initialization file is " << session.init_file); INFO("Price database is " << session.price_db); @@ -3,8 +3,6 @@ #include "utils.h" -#include <boost/regex.hpp> - namespace ledger { class mask_t @@ -23,7 +23,7 @@ int ofx_proc_account_cb(struct OfxAccountData data, void * account_data) if (! data.account_id_valid) return -1; - DEBUG_("ledger.ofx.parse", "account " << data.account_name); + 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)); @@ -80,7 +80,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, xact->cost = new amount_t(stream.str()); } - DEBUG_("ofx.parse", "xact " << xact->amount << " from " << *xact->account); + DEBUG("ofx.parse", "xact " << xact->amount << " from " << *xact->account); if (data.date_initiated_valid) entry->_date = data.date_initiated; @@ -141,13 +141,13 @@ int ofx_proc_security_cb(struct OfxSecurityData data, void * security_data) commodities_map::iterator i = ofx_securities.find(data.unique_id); if (i == ofx_securities.end()) { - DEBUG_("ledger.ofx.parse", "security " << symbol); + 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); + DEBUG("ledger.ofx.parse", " price " << data.unitprice); commodity->add_price(data.date_unitprice, amount_t(data.unitprice)); } diff --git a/src/pyinterp.cc b/src/pyinterp.cc index b0cb166c..a08ec820 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -1,10 +1,14 @@ #include "pyinterp.h" +#include <boost/python/module_init.hpp> +#include <boost/python/exception_translator.hpp> + namespace ledger { struct python_run { object result; + python_run(python_interpreter_t * intepreter, const string& str, int input_mode) : result(handle<>(borrowed(PyRun_String(str.c_str(), input_mode, @@ -23,7 +27,7 @@ python_interpreter_t::python_interpreter_t(xml::xpath_t::scope_t * parent) nspace(handle<>(borrowed(PyModule_GetDict(mmodule.get())))) { Py_Initialize(); - detail::init_module("ledger", &initialize_for_python); + boost::python::detail::init_module("ledger", &initialize_for_python); } object python_interpreter_t::import(const string& str) @@ -121,7 +125,8 @@ void python_interpreter_t::functor_t::operator()(value_t& result, arglist.append(*i); if (PyObject * val = - PyObject_CallObject(func.ptr(), tuple(arglist).ptr())) { + PyObject_CallObject(func.ptr(), + boost::python::tuple(arglist).ptr())) { result = extract<value_t>(val)(); Py_DECREF(val); } diff --git a/src/pyinterp.h b/src/pyinterp.h index a75ef78b..9c801a48 100644 --- a/src/pyinterp.h +++ b/src/pyinterp.h @@ -6,18 +6,14 @@ #if defined(USE_BOOST_PYTHON) #include <boost/python.hpp> -#include <boost/python/detail/api_placeholder.hpp> -#include <boost/python/exception_translator.hpp> -#include <boost/python/suite/indexing/map_indexing_suite.hpp> - #include <Python.h> #include "pyfstream.h" -using namespace boost::python; - namespace ledger { +using namespace boost::python; + class python_interpreter_t : public xml::xpath_t::scope_t { handle<> mmodule; @@ -6,7 +6,7 @@ namespace ledger { #define MAX_LINE 1024 static char line[MAX_LINE + 1]; -static string path; +static string pathname; static unsigned int src_idx; static unsigned int linenum; @@ -52,9 +52,9 @@ unsigned int qif_parser_t::parse(std::istream& in, xact = new transaction_t(master); entry->add_transaction(xact); - path = journal->sources.back(); - src_idx = journal->sources.size() - 1; - linenum = 1; + pathname = journal->sources.back(); + src_idx = journal->sources.size() - 1; + linenum = 1; unsigned long beg_pos = 0; unsigned long beg_line = 0; diff --git a/src/quotes.cc b/src/quotes.cc index 1463c9bc..4b9eadae 100644 --- a/src/quotes.cc +++ b/src/quotes.cc @@ -10,15 +10,15 @@ void quotes_by_script::operator()(commodity_base_t& commodity, { LOGGER("quotes.download"); - DEBUG("commodity: " << commodity.symbol); - DEBUG(" now: " << now); - DEBUG(" moment: " << moment); - DEBUG(" date: " << date); - DEBUG(" last: " << last); + DEBUG_("commodity: " << commodity.symbol); + DEBUG_(" now: " << now); + DEBUG_(" moment: " << moment); + DEBUG_(" date: " << date); + DEBUG_(" last: " << last); - if (SHOW_DEBUG() && commodity.history) - DEBUG("last_lookup: " << commodity.history->last_lookup); - DEBUG("pricing_leeway is " << pricing_leeway); + if (SHOW_DEBUG_() && commodity.history) + DEBUG_("last_lookup: " << commodity.history->last_lookup); + DEBUG_("pricing_leeway is " << pricing_leeway); if ((commodity.history && (time_now - commodity.history->last_lookup) < pricing_leeway) || @@ -26,7 +26,7 @@ void quotes_by_script::operator()(commodity_base_t& commodity, (price && moment > date && (moment - date) <= pricing_leeway)) return; - DEBUG("downloading quote for symbol " << commodity.symbol); + DEBUG_("downloading quote for symbol " << commodity.symbol); char buf[256]; buf[0] = '\0'; @@ -47,7 +47,7 @@ void quotes_by_script::operator()(commodity_base_t& commodity, char * p = strchr(buf, '\n'); if (p) *p = '\0'; - DEBUG("downloaded quote: " << buf); + DEBUG_("downloaded quote: " << buf); price.parse(buf); commodity.add_price(now, price); diff --git a/src/session.cc b/src/session.cc index 78fc2596..b7b53c44 100644 --- a/src/session.cc +++ b/src/session.cc @@ -59,11 +59,11 @@ journal_t * session_t::read_data(const string& master_account) unsigned int entry_count = 0; - DEBUG_("ledger.cache", "3. use_cache = " << use_cache); + DEBUG("ledger.cache", "3. use_cache = " << use_cache); if (use_cache && ! cache_file.empty() && ! data_file.empty()) { - DEBUG_("ledger.cache", "using_cache " << cache_file); + DEBUG("ledger.cache", "using_cache " << cache_file); cache_dirty = true; if (access(cache_file.c_str(), R_OK) != -1) { std::ifstream stream(cache_file.c_str()); @@ -90,12 +90,12 @@ journal_t * session_t::read_data(const string& master_account) if (read_journal(journal->price_db, journal)) { throw_(exception, "Entries not allowed in price history file"); } else { - DEBUG_("ledger.cache", "read price database " << journal->price_db); + DEBUG("ledger.cache", "read price database " << journal->price_db); journal->sources.pop_back(); } } - DEBUG_("ledger.cache", "rejected cache, parsing " << data_file); + DEBUG("ledger.cache", "rejected cache, parsing " << data_file); if (data_file == "-") { use_cache = false; journal->sources.push_back("<stdin>"); diff --git a/src/textual.cc b/src/textual.cc index ab657898..f0918a26 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -7,7 +7,7 @@ namespace ledger { #define MAX_LINE 1024 -static string path; +static string pathname; static unsigned int linenum; static unsigned int src_idx; static accounts_map account_aliases; @@ -52,11 +52,11 @@ parse_amount_expr(std::istream& in, journal_t *, { xml::xpath_t xpath(in, flags | XPATH_PARSE_RELAXED | XPATH_PARSE_PARTIAL); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed an amount expression"); #if 0 - IF_DEBUG_("ledger.textual.parse") { + IF_DEBUG("ledger.textual.parse") { if (_debug_stream) { xpath.dump(*_debug_stream); *_debug_stream << std::endl; @@ -66,7 +66,7 @@ parse_amount_expr(std::istream& in, journal_t *, amount = xpath.calc(static_cast<xml::transaction_node_t *>(xact.data)).to_amount(); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "The transaction amount is " << amount); } @@ -124,12 +124,12 @@ transaction_t * parse_transaction(char * line, switch (*state) { case '*': xact->state = transaction_t::CLEARED; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed the CLEARED flag"); break; case '!': xact->state = transaction_t::PENDING; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed the PENDING flag"); break; } @@ -141,18 +141,18 @@ transaction_t * parse_transaction(char * line, if ((*b == '[' && *e == ']') || (*b == '(' && *e == ')')) { xact->flags |= TRANSACTION_VIRTUAL; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed a virtual account name"); if (*b == '[') { xact->flags |= TRANSACTION_BALANCE; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed a balanced virtual account name"); } *account_path++ = '\0'; *e = '\0'; } - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed account name " << account_path); if (account_aliases.size() > 0) { accounts_map::const_iterator i = account_aliases.find(account_path); @@ -214,14 +214,14 @@ transaction_t * parse_transaction(char * line, if (in.good() && ! in.eof()) { char c = peek_next_nonws(in); if (c == '@') { - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Found a price indicator"); bool per_unit = true; in.get(c); if (in.peek() == '@') { in.get(c); per_unit = false; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "And it's for a total price"); } @@ -262,13 +262,13 @@ transaction_t * parse_transaction(char * line, xact->entry->actual_date(), xact->entry->code); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Total cost is " << *xact->cost); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Per-unit cost is " << per_unit_cost); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Annotated amount is " << xact->amount); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Bare amount is " << xact->amount.number()); } } @@ -276,7 +276,7 @@ transaction_t * parse_transaction(char * line, xact->amount.in_place_reduce(); - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Reduced amount is " << xact->amount); } @@ -284,7 +284,7 @@ transaction_t * parse_transaction(char * line, if (note) { xact->note = note; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed a note '" << xact->note << "'"); if (char * b = std::strchr(xact->note.c_str(), '[')) @@ -293,7 +293,7 @@ transaction_t * parse_transaction(char * line, std::strncpy(buf, b + 1, e - b - 1); buf[e - b - 1] = '\0'; - DEBUG_("ledger.textual.parse", "line " << linenum << ": " << + DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed a transaction date " << buf); if (char * p = std::strchr(buf, '=')) { @@ -635,11 +635,11 @@ unsigned int textual_parser_t::parse(std::istream& in, account_stack.push_front(master); - path = journal ? journal->sources.back() : *original_file; - src_idx = journal ? journal->sources.size() - 1 : 0; - linenum = 1; + pathname = journal ? journal->sources.back() : *original_file; + src_idx = journal ? journal->sources.size() - 1 : 0; + linenum = 1; - INFO("Parsing file '" << path << "'"); + INFO("Parsing file '" << pathname << "'"); unsigned long beg_pos = in.tellg(); unsigned long end_pos; @@ -829,28 +829,29 @@ unsigned int textual_parser_t::parse(std::istream& in, char * p = next_element(line); string word(line + 1); if (word == "include") { - push_var<string> save_path(path); + push_var<string> save_path(pathname); push_var<unsigned int> save_src_idx(src_idx); push_var<unsigned long> save_beg_pos(beg_pos); push_var<unsigned long> save_end_pos(end_pos); push_var<unsigned int> save_linenum(linenum); - path = p; - if (path[0] != '/' && path[0] != '\\' && path[0] != '~') { + pathname = p; + if (pathname[0] != '/' && pathname[0] != '\\' && + pathname[0] != '~') { string::size_type pos = save_path.prev.rfind('/'); if (pos == string::npos) pos = save_path.prev.rfind('\\'); if (pos != string::npos) - path = string(save_path.prev, 0, pos + 1) + path; + pathname = string(save_path.prev, 0, pos + 1) + pathname; } - path = resolve_path(path); + pathname = resolve_path(pathname); - DEBUG_("ledger.textual.include", "line " << linenum << ": " << - "Including path '" << path << "'"); + DEBUG("ledger.textual.include", "line " << linenum << ": " << + "Including path '" << pathname << "'"); include_stack.push_back(std::pair<string, int> (journal->sources.back(), linenum - 1)); - count += journal->session->read_journal(path, journal, + count += journal->session->read_journal(pathname, journal, account_stack.front()); include_stack.pop_back(); } @@ -929,8 +930,8 @@ unsigned int textual_parser_t::parse(std::istream& in, i != include_stack.rend(); i++) err->context.push_back(new include_context((*i).first, (*i).second, - "In file included from")); - err->context.push_front(new file_context(path, linenum - 1)); + "In file included from")); + err->context.push_front(new file_context(pathname, linenum - 1)); std::cout.flush(); if (errors > 0 && err->context.size() > 1) diff --git a/src/times.h b/src/times.h index 2cc0d7e4..44b64102 100644 --- a/src/times.h +++ b/src/times.h @@ -3,16 +3,8 @@ #include "utils.h" -#include <boost/date_time/posix_time/posix_time.hpp> - namespace ledger { -typedef boost::posix_time::ptime ptime; -typedef ptime::time_duration_type time_duration; -typedef boost::gregorian::date date; -typedef boost::gregorian::date_duration date_duration; -typedef boost::posix_time::seconds seconds; - #define SUPPORT_DATE_AND_TIME 1 #ifdef SUPPORT_DATE_AND_TIME diff --git a/src/utils.cc b/src/utils.cc index 63c28c5c..afa0b7a8 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -77,10 +77,10 @@ void shutdown_memory_tracing() memory_tracing_active = false; if (live_objects) { - IF_DEBUG_("memory.counts") + IF_DEBUG("memory.counts") report_memory(std::cerr, true); else - IF_DEBUG_("memory.counts.live") + IF_DEBUG("memory.counts.live") report_memory(std::cerr); else if (live_objects->size() > 0) report_memory(std::cerr); @@ -253,7 +253,7 @@ void trace_ctor_func(void * ptr, const char * cls_name, const char * args, std::strcat(name, args); std::strcat(name, ")"); - DEBUG_("verify.memory", "TRACE_CTOR " << ptr << " " << name); + DEBUG("verify.memory", "TRACE_CTOR " << ptr << " " << name); live_objects->insert(live_objects_pair(ptr, allocation_pair(cls_name, cls_size))); @@ -271,7 +271,7 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size) if (! live_objects) return; - DEBUG_("ledger.trace.debug", "TRACE_DTOR " << ptr << " " << cls_name); + DEBUG("ledger.trace.debug", "TRACE_DTOR " << ptr << " " << cls_name); live_objects_map::iterator i = live_objects->find(ptr); VERIFY(i != live_objects->end()); @@ -494,8 +494,6 @@ bool logger_func(log_level_t level) #if defined(DEBUG_ON) -#include <boost/regex.hpp> - namespace ledger { std::string _log_category; diff --git a/src/utils.h b/src/utils.h index 79595c71..c8bd4c56 100644 --- a/src/utils.h +++ b/src/utils.h @@ -16,6 +16,27 @@ namespace ledger { #endif } +// jww (2007-04-30): These Boost includes can go into system.hh as +// soon as GCC fixes it's problem with pre-compiled headers and global +// variables defined in unnamed namespaces. + +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/filesystem/path.hpp> +#include <boost/optional.hpp> +#include <boost/regex.hpp> + +namespace ledger { + using namespace boost; + + typedef posix_time::ptime ptime; + typedef ptime::time_duration_type time_duration; + typedef gregorian::date date; + typedef gregorian::date_duration date_duration; + typedef posix_time::seconds seconds; + + typedef filesystem::path path; +} + /********************************************************************** * * Default values @@ -233,20 +254,20 @@ inline bool category_matches(const char * cat) { cat[_log_category.size()] == '.')); } -#define SHOW_DEBUG_(cat) \ +#define SHOW_DEBUG(cat) \ (_log_level >= LOG_DEBUG && category_matches(cat)) -#define SHOW_DEBUG() SHOW_DEBUG_(_this_category) +#define SHOW_DEBUG_() SHOW_DEBUG(_this_category) -#define DEBUG_(cat, msg) \ - (SHOW_DEBUG_(cat) ? ((_log_buffer << msg), logger_func(LOG_DEBUG)) : false) -#define DEBUG(msg) DEBUG_(_this_category, msg) +#define DEBUG(cat, msg) \ + (SHOW_DEBUG(cat) ? ((_log_buffer << msg), logger_func(LOG_DEBUG)) : false) +#define DEBUG_(msg) DEBUG(_this_category, msg) #else // DEBUG_ON -#define SHOW_DEBUG_(cat) false -#define SHOW_DEBUG() false -#define DEBUG_(cat, msg) -#define DEBUG(msg) +#define SHOW_DEBUG(cat) false +#define SHOW_DEBUG_() false +#define DEBUG(cat, msg) +#define DEBUG_(msg) #endif // DEBUG_ON @@ -273,18 +294,18 @@ inline bool category_matches(const char * cat) { #define LOGGER(cat) -#define SHOW_TRACE(lvl) false -#define SHOW_DEBUG_(cat) false -#define SHOW_DEBUG() false -#define SHOW_INFO() false -#define SHOW_WARN() false -#define SHOW_ERROR() false -#define SHOW_FATAL() false -#define SHOW_CRITICAL() false +#define SHOW_TRACE(lvl) false +#define SHOW_DEBUG(cat) false +#define SHOW_DEBUG_() false +#define SHOW_INFO() false +#define SHOW_WARN() false +#define SHOW_ERROR() false +#define SHOW_FATAL() false +#define SHOW_CRITICAL() false #define TRACE(lvl, msg) -#define DEBUG(msg) -#define DEBUG_(cat, msg) +#define DEBUG(cat, msg) +#define DEBUG_(msg) #define INFO(msg) #define WARN(msg) #define ERROR(msg) @@ -293,14 +314,14 @@ inline bool category_matches(const char * cat) { #endif // LOGGING_ON -#define IF_TRACE(lvl) if (SHOW_TRACE(lvl)) -#define IF_DEBUG_(cat) if (SHOW_DEBUG_(cat)) -#define IF_DEBUG() if (SHOW_DEBUG()) -#define IF_INFO() if (SHOW_INFO()) -#define IF_WARN() if (SHOW_WARN()) -#define IF_ERROR() if (SHOW_ERROR()) -#define IF_FATAL() if (SHOW_FATAL()) -#define IF_CRITICAL() if (SHOW_CRITICAL()) +#define IF_TRACE(lvl) if (SHOW_TRACE(lvl)) +#define IF_DEBUG(cat) if (SHOW_DEBUG(cat)) +#define IF_DEBUG_() if (SHOW_DEBUG_()) +#define IF_INFO() if (SHOW_INFO()) +#define IF_WARN() if (SHOW_WARN()) +#define IF_ERROR() if (SHOW_ERROR()) +#define IF_FATAL() if (SHOW_FATAL()) +#define IF_CRITICAL() if (SHOW_CRITICAL()) /********************************************************************** * @@ -330,22 +351,22 @@ void finish_timer(const char * name); #endif #if defined(DEBUG_ON) -#define DEBUG_START_(name, cat, msg) \ - (SHOW_DEBUG_(cat) ? \ +#define DEBUG_START(name, cat, msg) \ + (SHOW_DEBUG(cat) ? \ ((_log_buffer << msg), start_timer(#name, LOG_DEBUG)) : ((void)0)) -#define DEBUG_START(name, msg) \ +#define DEBUG_START_(name, msg) \ DEBUG_START_(name, _this_category, msg) -#define DEBUG_STOP_(name, cat) \ - (SHOW_DEBUG_(cat) ? stop_timer(#name) : ((void)0)) -#define DEBUG_STOP(name) \ +#define DEBUG_STOP(name, cat) \ + (SHOW_DEBUG(cat) ? stop_timer(#name) : ((void)0)) +#define DEBUG_STOP_(name) \ DEBUG_STOP_(name, _this_category) -#define DEBUG_FINISH_(name, cat) \ - (SHOW_DEBUG_(cat) ? finish_timer(#name) : ((void)0)) -#define DEBUG_FINISH(name) \ +#define DEBUG_FINISH(name, cat) \ + (SHOW_DEBUG(cat) ? finish_timer(#name) : ((void)0)) +#define DEBUG_FINISH_(name) \ DEBUG_FINISH_(name, _this_category) #else -#define DEBUG_START(name, msg) -#define DEBUG_START_(name, cat, msg) +#define DEBUG_START(name, cat, msg) +#define DEBUG_START_(name, msg) #define DEBUG_STOP(name) #define DEBUG_FINISH(name) #endif diff --git a/src/value.cc b/src/value.cc index 914a49e2..a8b4eab0 100644 --- a/src/value.cc +++ b/src/value.cc @@ -130,7 +130,7 @@ void value_t::destroy() void value_t::simplify() { if (realzero()) { - DEBUG_("amounts.values.simplify", "Zeroing type " << type); + DEBUG("amounts.values.simplify", "Zeroing type " << type); *this = 0L; return; } @@ -138,19 +138,19 @@ void value_t::simplify() if (type == BALANCE_PAIR && (! ((balance_pair_t *) data)->cost || ((balance_pair_t *) data)->cost->realzero())) { - DEBUG_("amounts.values.simplify", "Reducing balance pair to balance"); + DEBUG("amounts.values.simplify", "Reducing balance pair to balance"); in_place_cast(BALANCE); } if (type == BALANCE && ((balance_t *) data)->amounts.size() == 1) { - DEBUG_("amounts.values.simplify", "Reducing balance to amount"); + DEBUG("amounts.values.simplify", "Reducing balance to amount"); in_place_cast(AMOUNT); } if (type == AMOUNT && ! ((amount_t *) data)->commodity()) { - DEBUG_("amounts.values.simplify", "Reducing amount to integer"); + DEBUG("amounts.values.simplify", "Reducing amount to integer"); in_place_cast(INTEGER); } } @@ -48,7 +48,7 @@ int document_t::register_name(const string& name) names.push_back(name); index = names.size() - 1; - DEBUG_("xml.lookup", this << " Inserting name: " << names.back()); + DEBUG("xml.lookup", this << " Inserting name: " << names.back()); std::pair<names_map::iterator, bool> result = names_index.insert(names_pair(names.back(), index)); @@ -63,7 +63,7 @@ int document_t::lookup_name_id(const string& name) const if ((id = lookup_builtin_id(name)) != -1) return id; - DEBUG_("xml.lookup", this << " Finding name: " << name); + DEBUG("xml.lookup", this << " Finding name: " << name); names_map::const_iterator i = names_index.find(name); if (i != names_index.end()) @@ -268,7 +268,7 @@ static void startElement(void *userData, const char *name, const char **attrs) { document_t::parser_t * parser = static_cast<document_t::parser_t *>(userData); - DEBUG_("xml.parse", "startElement(" << name << ")"); + DEBUG("xml.parse", "startElement(" << name << ")"); if (parser->pending) { parent_node_t * node = create_node<parent_node_t>(parser); @@ -295,7 +295,7 @@ static void endElement(void *userData, const char *name) { document_t::parser_t * parser = static_cast<document_t::parser_t *>(userData); - DEBUG_("xml.parse", "endElement(" << name << ")"); + DEBUG("xml.parse", "endElement(" << name << ")"); if (parser->pending) { terminal_node_t * node = create_node<terminal_node_t>(parser); @@ -317,7 +317,7 @@ static void dataHandler(void *userData, const char *s, int len) { document_t::parser_t * parser = static_cast<document_t::parser_t *>(userData); - DEBUG_("xml.parse", "dataHandler(" << string(s, len) << ")"); + DEBUG("xml.parse", "dataHandler(" << string(s, len) << ")"); bool all_whitespace = true; for (int i = 0; i < len; i++) { diff --git a/src/xpath.cc b/src/xpath.cc index 6eb30d48..3facab60 100644 --- a/src/xpath.cc +++ b/src/xpath.cc @@ -475,7 +475,7 @@ xpath_t::op_t * xpath_t::wrap_mask(const string& pattern) void xpath_t::scope_t::define(const string& name, op_t * def) { - DEBUG_("ledger.xpath.syms", "Defining '" << name << "' = " << def); + DEBUG("ledger.xpath.syms", "Defining '" << name << "' = " << def); std::pair<symbol_map::iterator, bool> result = symbols.insert(symbol_pair(name, def)); @@ -548,7 +548,7 @@ xpath_t::op_t::~op_t() { TRACE_DTOR(xpath_t::op_t); - DEBUG_("ledger.xpath.memory", "Destroying " << this); + DEBUG("ledger.xpath.memory", "Destroying " << this); assert(refc == 0); switch (kind) { diff --git a/src/xpath.h b/src/xpath.h index 13966ffc..7056c74e 100644 --- a/src/xpath.h +++ b/src/xpath.h @@ -424,21 +424,21 @@ public: } void release() const { - DEBUG_("ledger.xpath.memory", + DEBUG("ledger.xpath.memory", "Releasing " << this << ", refc now " << refc - 1); assert(refc > 0); if (--refc == 0) delete this; } op_t * acquire() { - DEBUG_("ledger.xpath.memory", + DEBUG("ledger.xpath.memory", "Acquiring " << this << ", refc now " << refc + 1); assert(refc >= 0); refc++; return this; } const op_t * acquire() const { - DEBUG_("ledger.xpath.memory", + DEBUG("ledger.xpath.memory", "Acquiring " << this << ", refc now " << refc + 1); assert(refc >= 0); refc++; |