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
#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++ \

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,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;
// jww (2004-07-31): this should be handled differently
if (! details.xact->note.empty())
out << " ; " << details.xact->note;
}
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;
break;
}
case element_t::VALUE: {
balance_t value;

21
walk.h
View file

@ -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);
}