diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | error.cc | 12 | ||||
-rw-r--r-- | format.cc | 59 | ||||
-rw-r--r-- | walk.h | 21 |
4 files changed, 52 insertions, 42 deletions
@@ -19,7 +19,7 @@ CXX = g++ CFLAGS = -Wall -ansi -pedantic #DFLAGS = -O3 -fomit-frame-pointer DFLAGS = -g -DDEBUG=1 -#DFLAGS = -g -pg +#DFLAGS = -g -DDEBUG=1 -pg INCS = -I/sw/include \ -I/usr/include/gcc/darwin/3.3/c++ \ diff --git a/error.cc b/error.cc new file mode 100644 index 00000000..13955c66 --- /dev/null +++ b/error.cc @@ -0,0 +1,12 @@ +#include "error.h" + +namespace ledger { + +const char* parse_error::what() const throw() +{ + std::ostringstream msg; + msg << file << ", line " << line << ": " << error::what(); + return msg.str().c_str(); +} + +} // namespace ledger @@ -226,43 +226,48 @@ void format_t::format_elements(std::ostream& out, } break; - case element_t::OPT_AMOUNT: { - if (! details.entry || ! details.xact) - break; + case element_t::OPT_AMOUNT: + if (details.xact) { + std::string disp; + bool use_disp = false; - std::string disp; - bool use_disp = false; - - if (std::find(details.entry->transactions.begin(), - details.entry->transactions.end(), details.xact) != - details.entry->transactions.end()) { - if (details.entry->transactions.size() == 2 && - details.xact == details.entry->transactions.back() && - (details.entry->transactions.front()->amount == - details.entry->transactions.front()->cost) && - (details.entry->transactions.front()->amount == - - details.entry->transactions.back()->amount)) { - use_disp = true; - } - else if (details.entry->transactions.size() != 2 && - details.xact->amount != details.xact->cost) { + if (details.xact->amount != details.xact->cost) { amount_t unit_cost = details.xact->cost / details.xact->amount; std::ostringstream stream; stream << details.xact->amount << " @ " << unit_cost; disp = stream.str(); use_disp = true; + } else { + unsigned int xacts_real_count = 0; + transaction_t * first = NULL; + transaction_t * last = NULL; + + for (transactions_list::const_iterator i + = details.entry->transactions.begin(); + i != details.entry->transactions.end(); + i++) + if (! ((*i)->flags & TRANSACTION_AUTO)) { + xacts_real_count++; + + if (! first) + first = *i; + last = *i; + } + + use_disp = (xacts_real_count == 2 && + details.xact == last && + first->amount == - last->amount); } - } - if (! use_disp) - disp = std::string(details.xact->amount); - out << disp; + if (! use_disp) + disp = std::string(details.xact->amount); + out << disp; - // jww (2004-07-31): this should be handled differently - if (! details.xact->note.empty()) - out << " ; " << details.xact->note; + // jww (2004-07-31): this should be handled differently + if (! details.xact->note.empty()) + out << " ; " << details.xact->note; + } break; - } case element_t::VALUE: { balance_t value; @@ -66,20 +66,13 @@ void handle_transaction(transaction_t * xact, const Function& functor, unsigned int flags) { - if ((flags & MATCHING_TRANSACTIONS) && - ! (xact->flags & TRANSACTION_HANDLED)) { - xact->flags |= TRANSACTION_HANDLED; - functor(xact); - } - - if (flags & OTHER_TRANSACTIONS) - for (transactions_list::iterator i = xact->entry->transactions.begin(); - i != xact->entry->transactions.end(); - i++) { - if (*i == xact || ((*i)->flags & (TRANSACTION_AUTO | - TRANSACTION_HANDLED))) - continue; - + for (transactions_list::iterator i = xact->entry->transactions.begin(); + i != xact->entry->transactions.end(); + i++) + if (! ((*i)->flags & (TRANSACTION_AUTO | TRANSACTION_HANDLED)) && + (*i == xact ? + (flags & MATCHING_TRANSACTIONS) : + (flags & OTHER_TRANSACTIONS))) { (*i)->flags |= TRANSACTION_HANDLED; functor(*i); } |