print is working again

This commit is contained in:
John Wiegley 2004-08-07 21:46:05 -04:00
parent c6c0179545
commit 38e9c6c76c
4 changed files with 53 additions and 43 deletions

View file

@ -19,7 +19,7 @@ CXX = g++
CFLAGS = -Wall -ansi -pedantic CFLAGS = -Wall -ansi -pedantic
#DFLAGS = -O3 -fomit-frame-pointer #DFLAGS = -O3 -fomit-frame-pointer
DFLAGS = -g -DDEBUG=1 DFLAGS = -g -DDEBUG=1
#DFLAGS = -g -pg #DFLAGS = -g -DDEBUG=1 -pg
INCS = -I/sw/include \ INCS = -I/sw/include \
-I/usr/include/gcc/darwin/3.3/c++ \ -I/usr/include/gcc/darwin/3.3/c++ \

12
error.cc Normal file
View file

@ -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

View file

@ -226,32 +226,37 @@ void format_t::format_elements(std::ostream& out,
} }
break; break;
case element_t::OPT_AMOUNT: { case element_t::OPT_AMOUNT:
if (! details.entry || ! details.xact) if (details.xact) {
break;
std::string disp; std::string disp;
bool use_disp = false; bool use_disp = false;
if (std::find(details.entry->transactions.begin(), if (details.xact->amount != details.xact->cost) {
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) {
amount_t unit_cost = details.xact->cost / details.xact->amount; amount_t unit_cost = details.xact->cost / details.xact->amount;
std::ostringstream stream; std::ostringstream stream;
stream << details.xact->amount << " @ " << unit_cost; stream << details.xact->amount << " @ " << unit_cost;
disp = stream.str(); disp = stream.str();
use_disp = true; 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) if (! use_disp)
@ -261,8 +266,8 @@ void format_t::format_elements(std::ostream& out,
// jww (2004-07-31): this should be handled differently // jww (2004-07-31): this should be handled differently
if (! details.xact->note.empty()) if (! details.xact->note.empty())
out << " ; " << details.xact->note; out << " ; " << details.xact->note;
break;
} }
break;
case element_t::VALUE: { case element_t::VALUE: {
balance_t value; balance_t value;

17
walk.h
View file

@ -66,20 +66,13 @@ void handle_transaction(transaction_t * xact,
const Function& functor, const Function& functor,
unsigned int flags) 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(); for (transactions_list::iterator i = xact->entry->transactions.begin();
i != xact->entry->transactions.end(); i != xact->entry->transactions.end();
i++) { i++)
if (*i == xact || ((*i)->flags & (TRANSACTION_AUTO | if (! ((*i)->flags & (TRANSACTION_AUTO | TRANSACTION_HANDLED)) &&
TRANSACTION_HANDLED))) (*i == xact ?
continue; (flags & MATCHING_TRANSACTIONS) :
(flags & OTHER_TRANSACTIONS))) {
(*i)->flags |= TRANSACTION_HANDLED; (*i)->flags |= TRANSACTION_HANDLED;
functor(*i); functor(*i);
} }