The register report has begun printing real data, although not all the pieces

are in place yet and the formatting is still off.
This commit is contained in:
John Wiegley 2008-07-29 21:38:20 -04:00
parent 42e1d725aa
commit 1bb29cdbb7
7 changed files with 52 additions and 54 deletions

View file

@ -102,8 +102,8 @@ struct amount_t::bigint_t : public supports_flags<>
DEBUG("ledger.validate", "amount_t::bigint_t: prec > 128"); DEBUG("ledger.validate", "amount_t::bigint_t: prec > 128");
return false; return false;
} }
if (ref > 128) { if (ref > 16535) {
DEBUG("ledger.validate", "amount_t::bigint_t: ref > 128"); DEBUG("ledger.validate", "amount_t::bigint_t: ref > 16535");
return false; return false;
} }
#if 0 #if 0

View file

@ -13,7 +13,7 @@ bool format_t::ansi_codes = false;
bool format_t::ansi_invert = false; bool format_t::ansi_invert = false;
string format_t::truncate(const string& str, unsigned int width, string format_t::truncate(const string& str, unsigned int width,
const bool is_account) const bool is_account)
{ {
const unsigned int len = str.length(); const unsigned int len = str.length();
if (len <= width) if (len <= width)
@ -735,10 +735,12 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
} }
break; break;
#endif
case element_t::SPACER: case element_t::SPACER:
out << " "; out << " ";
break; break;
#if 0
case element_t::DEPTH_SPACER: case element_t::DEPTH_SPACER:
for (const account_t * acct = details.account; for (const account_t * acct = details.account;
acct; acct;
@ -761,7 +763,7 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
string temp = out.str(); string temp = out.str();
if (! ignore_max_width && if (! ignore_max_width &&
elem->max_width > 0 && elem->max_width < temp.length()) elem->max_width > 0 && elem->max_width < temp.length())
temp.erase(elem->max_width); truncate(temp, elem->max_width);
out_str << temp; out_str << temp;
} }
} }

View file

@ -51,8 +51,6 @@ namespace ledger {
var_t<report_t> report(args, 0); var_t<report_t> report(args, 0);
var_t<std::ostream> ostream(args, 1); var_t<std::ostream> ostream(args, 1);
std::cout << "Hello, world!" << std::endl;
report->xacts_report report->xacts_report
(xact_handler_ptr(new format_xacts (xact_handler_ptr(new format_xacts
(*ostream, report->session.register_format))); (*ostream, report->session.register_format)));

View file

@ -68,20 +68,10 @@ namespace {
#endif #endif
if (expr) { if (expr) {
expr.compile(*xact); amount = expr.calc(*xact).as_amount();
DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
if (expr.is_constant()) { "The transaction amount is " << amount);
amount = expr.constant_value().as_amount(); return expr;
DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
"The transaction amount is " << amount);
return expr_t(); // we will fill this in with text
} else {
if (SHOW_DEBUG("ledger.textual.parse")) {
std::cout << "Value expression tree:" << std::endl;
expr.dump(std::cout);
}
return expr;
}
} }
return none; return none;
} }
@ -189,9 +179,12 @@ xact_t * parse_xact(char * line, account_t * account,
"Reduced amount is " << xact->amount); "Reduced amount is " << xact->amount);
} }
// jww (2008-07-24): I don't think this is right, since amount_expr is // We don't need to store the actual expression that resulted in the
// always NULL right now // amount if it's constant
if (xact->amount_expr) { if (xact->amount_expr) {
if (xact->amount_expr->is_constant())
xact->amount_expr = expr_t();
unsigned long end = (long)in.tellg(); unsigned long end = (long)in.tellg();
xact->amount_expr->set_text(string(line, beg, end - beg)); xact->amount_expr->set_text(string(line, beg, end - beg));
} }
@ -228,28 +221,19 @@ xact_t * parse_xact(char * line, account_t * account,
try { try {
unsigned long beg = (long)in.tellg(); unsigned long beg = (long)in.tellg();
if (optional<expr_t> cost_expr = xact->cost_expr =
parse_amount_expr(in, *xact->cost, xact.get(), parse_amount_expr(in, *xact->cost, xact.get(),
EXPR_PARSE_NO_MIGRATE | EXPR_PARSE_NO_MIGRATE |
EXPR_PARSE_NO_ASSIGN)) { EXPR_PARSE_NO_ASSIGN);
try {
*xact->cost = cost_expr->calc(*xact).as_amount();
assert(xact->cost->valid());
xact->cost_expr = cost_expr; if (xact->cost_expr) {
unsigned long end = (long)in.tellg();
unsigned long end = (long)in.tellg(); if (per_unit)
if (per_unit) xact->cost_expr->set_text(string("@") +
xact->cost_expr->set_text(string("@") + string(line, beg, end - beg));
string(line, beg, end - beg)); else
else xact->cost_expr->set_text(string("@@") +
xact->cost_expr->set_text(string("@@") + string(line, beg, end - beg));
string(line, beg, end - beg));
}
catch (...) {
throw new parse_error
("A transaction's cost must evaluate to a constant value");
}
} }
} }
catch (error * err) { catch (error * err) {
@ -290,7 +274,7 @@ xact_t * parse_xact(char * line, account_t * account,
account_xdata_t& xdata(account_xdata(*xact->account)); account_xdata_t& xdata(account_xdata(*xact->account));
if (xact->amount) { if (! xact->amount.is_null()) {
if (xdata.value.is_null()) if (xdata.value.is_null())
xdata.value = xact->amount; xdata.value = xact->amount;
else else

16
times.h
View file

@ -152,8 +152,22 @@ inline datetime_t parse_datetime(const string& str) {
return parse_datetime(str.c_str()); return parse_datetime(str.c_str());
} }
inline std::time_t to_time_t(const ptime& t)
{
if( t == posix_time::neg_infin )
return 0;
else if( t == posix_time::pos_infin )
return LONG_MAX;
ptime start(date(1970,1,1));
return (t-start).total_seconds();
}
inline string format_datetime(const datetime_t& when) { inline string format_datetime(const datetime_t& when) {
return ""; // jww (2008-07-19): NYI char buf[64];
time_t moment = to_time_t(when);
// jww (2008-07-29): Need to make the output format configurable
std::strftime(buf, 63, "%Y/%m/%d", std::localtime(&moment));
return buf;
} }
extern const ptime time_now; extern const ptime time_now;

View file

@ -67,7 +67,7 @@ value_t::storage_t& value_t::storage_t::operator=(const value_t::storage_t& rhs)
break; break;
default: default:
// The rest are fundamental types, which can copy using std::memcpy // The rest are fundamental types, which can be copied using std::memcpy
std::memcpy(data, rhs.data, sizeof(data)); std::memcpy(data, rhs.data, sizeof(data));
break; break;
} }
@ -1458,20 +1458,18 @@ value_t& value_t::add(const amount_t& amount, const optional<amount_t>& tcost)
else if (! is_amount()) { else if (! is_amount()) {
in_place_cast(AMOUNT); in_place_cast(AMOUNT);
} }
*this += amount; return *this += amount;
break;
case BALANCE: case BALANCE:
if (tcost) { if (tcost) {
in_place_cast(BALANCE_PAIR); in_place_cast(BALANCE_PAIR);
return add(amount, tcost); return add(amount, tcost);
} }
*this += amount; return *this += amount;
break;
case BALANCE_PAIR: case BALANCE_PAIR:
as_balance_pair_lval().add(amount, tcost); as_balance_pair_lval().add(amount, tcost);
break; return *this;
default: default:
break; break;

View file

@ -54,8 +54,7 @@ void add_xact_to(const xact_t& xact, value_t& value)
value += xact_xdata_(xact).value; value += xact_xdata_(xact).value;
} }
else if (xact.cost || (! value.is_null() && ! value.is_realzero())) { else if (xact.cost || (! value.is_null() && ! value.is_realzero())) {
// jww (2008-04-24): Is this costly? value.add(xact.amount, xact.cost);
value.add(xact.amount, xact.cost ? optional<amount_t>(*xact.cost) : none);
} }
else { else {
value = xact.amount; value = xact.amount;
@ -201,7 +200,10 @@ void calc_xacts::operator()(xact_t& xact)
xact_xdata_t& xdata(xact_xdata(xact)); xact_xdata_t& xdata(xact_xdata(xact));
if (last_xact && xact_has_xdata(*last_xact)) { if (last_xact && xact_has_xdata(*last_xact)) {
xdata.total += xact_xdata_(*last_xact).total; if (xdata.total.is_null())
xdata.total = xact_xdata_(*last_xact).total;
else
xdata.total += xact_xdata_(*last_xact).total;
xdata.index = xact_xdata_(*last_xact).index + 1; xdata.index = xact_xdata_(*last_xact).index + 1;
} else { } else {
xdata.index = 0; xdata.index = 0;