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:
parent
42e1d725aa
commit
1bb29cdbb7
7 changed files with 52 additions and 54 deletions
|
|
@ -102,8 +102,8 @@ struct amount_t::bigint_t : public supports_flags<>
|
|||
DEBUG("ledger.validate", "amount_t::bigint_t: prec > 128");
|
||||
return false;
|
||||
}
|
||||
if (ref > 128) {
|
||||
DEBUG("ledger.validate", "amount_t::bigint_t: ref > 128");
|
||||
if (ref > 16535) {
|
||||
DEBUG("ledger.validate", "amount_t::bigint_t: ref > 16535");
|
||||
return false;
|
||||
}
|
||||
#if 0
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ bool format_t::ansi_codes = false;
|
|||
bool format_t::ansi_invert = false;
|
||||
|
||||
string format_t::truncate(const string& str, unsigned int width,
|
||||
const bool is_account)
|
||||
const bool is_account)
|
||||
{
|
||||
const unsigned int len = str.length();
|
||||
if (len <= width)
|
||||
|
|
@ -735,10 +735,12 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
|
|||
}
|
||||
break;
|
||||
|
||||
#endif
|
||||
case element_t::SPACER:
|
||||
out << " ";
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case element_t::DEPTH_SPACER:
|
||||
for (const account_t * acct = details.account;
|
||||
acct;
|
||||
|
|
@ -761,7 +763,7 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
|
|||
string temp = out.str();
|
||||
if (! ignore_max_width &&
|
||||
elem->max_width > 0 && elem->max_width < temp.length())
|
||||
temp.erase(elem->max_width);
|
||||
truncate(temp, elem->max_width);
|
||||
out_str << temp;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
main.cc
2
main.cc
|
|
@ -51,8 +51,6 @@ namespace ledger {
|
|||
var_t<report_t> report(args, 0);
|
||||
var_t<std::ostream> ostream(args, 1);
|
||||
|
||||
std::cout << "Hello, world!" << std::endl;
|
||||
|
||||
report->xacts_report
|
||||
(xact_handler_ptr(new format_xacts
|
||||
(*ostream, report->session.register_format)));
|
||||
|
|
|
|||
60
textual.cc
60
textual.cc
|
|
@ -68,20 +68,10 @@ namespace {
|
|||
#endif
|
||||
|
||||
if (expr) {
|
||||
expr.compile(*xact);
|
||||
|
||||
if (expr.is_constant()) {
|
||||
amount = expr.constant_value().as_amount();
|
||||
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;
|
||||
}
|
||||
amount = expr.calc(*xact).as_amount();
|
||||
DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
|
||||
"The transaction amount is " << amount);
|
||||
return expr;
|
||||
}
|
||||
return none;
|
||||
}
|
||||
|
|
@ -189,9 +179,12 @@ xact_t * parse_xact(char * line, account_t * account,
|
|||
"Reduced amount is " << xact->amount);
|
||||
}
|
||||
|
||||
// jww (2008-07-24): I don't think this is right, since amount_expr is
|
||||
// always NULL right now
|
||||
// We don't need to store the actual expression that resulted in the
|
||||
// amount if it's constant
|
||||
if (xact->amount_expr) {
|
||||
if (xact->amount_expr->is_constant())
|
||||
xact->amount_expr = expr_t();
|
||||
|
||||
unsigned long end = (long)in.tellg();
|
||||
xact->amount_expr->set_text(string(line, beg, end - beg));
|
||||
}
|
||||
|
|
@ -228,28 +221,19 @@ xact_t * parse_xact(char * line, account_t * account,
|
|||
try {
|
||||
unsigned long beg = (long)in.tellg();
|
||||
|
||||
if (optional<expr_t> cost_expr =
|
||||
parse_amount_expr(in, *xact->cost, xact.get(),
|
||||
EXPR_PARSE_NO_MIGRATE |
|
||||
EXPR_PARSE_NO_ASSIGN)) {
|
||||
try {
|
||||
*xact->cost = cost_expr->calc(*xact).as_amount();
|
||||
assert(xact->cost->valid());
|
||||
xact->cost_expr =
|
||||
parse_amount_expr(in, *xact->cost, xact.get(),
|
||||
EXPR_PARSE_NO_MIGRATE |
|
||||
EXPR_PARSE_NO_ASSIGN);
|
||||
|
||||
xact->cost_expr = cost_expr;
|
||||
|
||||
unsigned long end = (long)in.tellg();
|
||||
if (per_unit)
|
||||
xact->cost_expr->set_text(string("@") +
|
||||
string(line, beg, end - beg));
|
||||
else
|
||||
xact->cost_expr->set_text(string("@@") +
|
||||
string(line, beg, end - beg));
|
||||
}
|
||||
catch (...) {
|
||||
throw new parse_error
|
||||
("A transaction's cost must evaluate to a constant value");
|
||||
}
|
||||
if (xact->cost_expr) {
|
||||
unsigned long end = (long)in.tellg();
|
||||
if (per_unit)
|
||||
xact->cost_expr->set_text(string("@") +
|
||||
string(line, beg, end - beg));
|
||||
else
|
||||
xact->cost_expr->set_text(string("@@") +
|
||||
string(line, beg, end - beg));
|
||||
}
|
||||
}
|
||||
catch (error * err) {
|
||||
|
|
@ -290,7 +274,7 @@ xact_t * parse_xact(char * line, account_t * account,
|
|||
|
||||
account_xdata_t& xdata(account_xdata(*xact->account));
|
||||
|
||||
if (xact->amount) {
|
||||
if (! xact->amount.is_null()) {
|
||||
if (xdata.value.is_null())
|
||||
xdata.value = xact->amount;
|
||||
else
|
||||
|
|
|
|||
16
times.h
16
times.h
|
|
@ -152,8 +152,22 @@ inline datetime_t parse_datetime(const string& 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) {
|
||||
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;
|
||||
|
|
|
|||
10
value.cc
10
value.cc
|
|
@ -67,7 +67,7 @@ value_t::storage_t& value_t::storage_t::operator=(const value_t::storage_t& rhs)
|
|||
break;
|
||||
|
||||
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));
|
||||
break;
|
||||
}
|
||||
|
|
@ -1458,20 +1458,18 @@ value_t& value_t::add(const amount_t& amount, const optional<amount_t>& tcost)
|
|||
else if (! is_amount()) {
|
||||
in_place_cast(AMOUNT);
|
||||
}
|
||||
*this += amount;
|
||||
break;
|
||||
return *this += amount;
|
||||
|
||||
case BALANCE:
|
||||
if (tcost) {
|
||||
in_place_cast(BALANCE_PAIR);
|
||||
return add(amount, tcost);
|
||||
}
|
||||
*this += amount;
|
||||
break;
|
||||
return *this += amount;
|
||||
|
||||
case BALANCE_PAIR:
|
||||
as_balance_pair_lval().add(amount, tcost);
|
||||
break;
|
||||
return *this;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
8
walk.cc
8
walk.cc
|
|
@ -54,8 +54,7 @@ void add_xact_to(const xact_t& xact, value_t& value)
|
|||
value += xact_xdata_(xact).value;
|
||||
}
|
||||
else if (xact.cost || (! value.is_null() && ! value.is_realzero())) {
|
||||
// jww (2008-04-24): Is this costly?
|
||||
value.add(xact.amount, xact.cost ? optional<amount_t>(*xact.cost) : none);
|
||||
value.add(xact.amount, xact.cost);
|
||||
}
|
||||
else {
|
||||
value = xact.amount;
|
||||
|
|
@ -201,7 +200,10 @@ void calc_xacts::operator()(xact_t& xact)
|
|||
xact_xdata_t& xdata(xact_xdata(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;
|
||||
} else {
|
||||
xdata.index = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue