Formatting now relies exclusively on value expressions.
What this means is that the utility code, basic math, value expressions, string formatting and option handling are now entirely decoupled from the rest of the code. This decoupling not only greatly simplifies the more basic parts of Ledger, but makes it much easier to test and verify its completeness. For example, when the formatting code %X is seen by the format parser, it turns into a call to the expression function fmt_X, which must be defined when the format string is first compiled against an object. If that object is a transaction, the transaction's scope will be the first to have a chance at providing a definition. If an account is being reported, it will. If neither does, the next scope in sequence -- soon to be the current report -- will, and then the session object that "owns" the current Ledger session. In 2.6, the formatting code new everything about transaction and accounts, and relied on flags to communicate special details between them. Now the transaction will offer the details for its own reporting, while the formatter worries only about strings and how to output them.
This commit is contained in:
parent
5bf3f536b3
commit
9a9e06554e
18 changed files with 133 additions and 136 deletions
10
expr.cc
10
expr.cc
|
|
@ -125,11 +125,6 @@ value_t expr_t::calc(scope_t& scope)
|
||||||
return NULL_VALUE;
|
return NULL_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
value_t expr_t::calc(scope_t& scope) const
|
|
||||||
{
|
|
||||||
return ptr.get() ? ptr->calc(scope) : NULL_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool expr_t::is_constant() const
|
bool expr_t::is_constant() const
|
||||||
{
|
{
|
||||||
return ptr.get() && ptr->is_value();
|
return ptr.get() && ptr->is_value();
|
||||||
|
|
@ -165,11 +160,6 @@ void expr_t::dump(std::ostream& out) const
|
||||||
if (ptr) ptr->dump(out, 0);
|
if (ptr) ptr->dump(out, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expr_t::read(std::ostream& in)
|
|
||||||
{
|
|
||||||
if (ptr) ptr->read(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
void expr_t::read(const char *& data)
|
void expr_t::read(const char *& data)
|
||||||
{
|
{
|
||||||
if (ptr) ptr->read(data);
|
if (ptr) ptr->read(data);
|
||||||
|
|
|
||||||
2
expr.h
2
expr.h
|
|
@ -107,8 +107,6 @@ public:
|
||||||
|
|
||||||
void print(std::ostream& out, scope_t& scope) const;
|
void print(std::ostream& out, scope_t& scope) const;
|
||||||
void dump(std::ostream& out) const;
|
void dump(std::ostream& out) const;
|
||||||
|
|
||||||
void read(std::ostream& in);
|
|
||||||
void read(const char *& data);
|
void read(const char *& data);
|
||||||
void write(std::ostream& out) const;
|
void write(std::ostream& out) const;
|
||||||
|
|
||||||
|
|
|
||||||
32
format.cc
32
format.cc
|
|
@ -90,7 +90,6 @@ format_t::element_t * format_t::parse_elements(const string& fmt)
|
||||||
// T: TOTAL
|
// T: TOTAL
|
||||||
// N: NOTE
|
// N: NOTE
|
||||||
// n: OPT_NOTE
|
// n: OPT_NOTE
|
||||||
// |: SPACER
|
|
||||||
// _: DEPTH_SPACER
|
// _: DEPTH_SPACER
|
||||||
//
|
//
|
||||||
// xB: XACT_BEG_POS
|
// xB: XACT_BEG_POS
|
||||||
|
|
@ -173,6 +172,11 @@ format_t::element_t * format_t::parse_elements(const string& fmt)
|
||||||
current->chars = "%";
|
current->chars = "%";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '|':
|
||||||
|
current->type = element_t::STRING;
|
||||||
|
current->chars = " ";
|
||||||
|
break;
|
||||||
|
|
||||||
case '(':
|
case '(':
|
||||||
case '[': {
|
case '[': {
|
||||||
std::istringstream str(p);
|
std::istringstream str(p);
|
||||||
|
|
@ -183,12 +187,17 @@ format_t::element_t * format_t::parse_elements(const string& fmt)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
current->type = element_t::EXPR;
|
current->type = element_t::EXPR;
|
||||||
|
char buf[2];
|
||||||
|
buf[0] = *p;
|
||||||
|
buf[1] = '\0';
|
||||||
|
current->chars = buf;
|
||||||
current->expr.parse(string("fmt_") + *p);
|
current->expr.parse(string("fmt_") + *p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (q != buf) {
|
if (q != buf) {
|
||||||
if (! result.get()) {
|
if (! result.get()) {
|
||||||
|
|
@ -211,9 +220,9 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_t::format(std::ostream& out_str, scope_t& scope) const
|
void format_t::format(std::ostream& out_str, scope_t& scope)
|
||||||
{
|
{
|
||||||
for (const element_t * elem = elements.get(); elem; elem = elem->next.get()) {
|
for (element_t * elem = elements.get(); elem; elem = elem->next.get()) {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
string name;
|
string name;
|
||||||
bool ignore_max_width = false;
|
bool ignore_max_width = false;
|
||||||
|
|
@ -232,7 +241,16 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case element_t::EXPR:
|
case element_t::EXPR:
|
||||||
out << elem->expr.calc(scope);
|
try {
|
||||||
|
if (elem->max_width == 0)
|
||||||
|
elem->expr.calc(scope).dump(out, elem->min_width);
|
||||||
|
else
|
||||||
|
out << truncate(elem->expr.calc(scope).as_string(),
|
||||||
|
elem->max_width);
|
||||||
|
}
|
||||||
|
catch (const calc_error&) {
|
||||||
|
out << (string("%") + elem->chars);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -622,10 +640,6 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case element_t::SPACER:
|
|
||||||
out << " ";
|
|
||||||
break;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
||||||
3
format.h
3
format.h
|
|
@ -20,7 +20,6 @@ class format_t : public noncopyable
|
||||||
STRING,
|
STRING,
|
||||||
EXPR,
|
EXPR,
|
||||||
#if 0
|
#if 0
|
||||||
SPACER,
|
|
||||||
DEPTH_SPACER
|
DEPTH_SPACER
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
@ -92,7 +91,7 @@ public:
|
||||||
format_string = _format;
|
format_string = _format;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(std::ostream& out, scope_t& scope) const;
|
void format(std::ostream& out, scope_t& scope);
|
||||||
|
|
||||||
void dump(std::ostream& out) const {
|
void dump(std::ostream& out) const {
|
||||||
for (const element_t * elem = elements.get();
|
for (const element_t * elem = elements.get();
|
||||||
|
|
|
||||||
33
op.cc
33
op.cc
|
|
@ -640,8 +640,8 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope)
|
||||||
#if 1
|
#if 1
|
||||||
return def;
|
return def;
|
||||||
#else
|
#else
|
||||||
// Aren't definitions compiled when they go in? Would
|
// jww (2008-08-02): Aren't definitions compiled when they go in?
|
||||||
// recompiling here really add any benefit?
|
// Would recompiling here really add any benefit?
|
||||||
return def->compile(scope);
|
return def->compile(scope);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -655,7 +655,7 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope)
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
ptr_op_t lhs(left()->compile(scope));
|
ptr_op_t lhs(left()->compile(scope));
|
||||||
ptr_op_t rhs(right() ? right()->compile(scope) : ptr_op_t());
|
ptr_op_t rhs(kind > UNARY_OPERATORS ? right()->compile(scope) : ptr_op_t());
|
||||||
|
|
||||||
if (lhs == left() && (! rhs || rhs == right()))
|
if (lhs == left() && (! rhs || rhs == right()))
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -675,10 +675,12 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
||||||
return as_value();
|
return as_value();
|
||||||
|
|
||||||
case IDENT:
|
case IDENT:
|
||||||
|
#if 0
|
||||||
if (ptr_op_t reference = compile(scope)) {
|
if (ptr_op_t reference = compile(scope)) {
|
||||||
if (reference != this)
|
if (reference != this)
|
||||||
return reference->calc(scope);
|
return reference->calc(scope);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
throw_(calc_error, "Unknown identifier '" << as_ident() << "'");
|
throw_(calc_error, "Unknown identifier '" << as_ident() << "'");
|
||||||
|
|
||||||
case FUNCTION: {
|
case FUNCTION: {
|
||||||
|
|
@ -698,6 +700,9 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
||||||
ptr_op_t func = left();
|
ptr_op_t func = left();
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// The expression must be compiled beforehand in order to resolve this
|
||||||
|
// into a function.
|
||||||
if (func->kind == IDENT) {
|
if (func->kind == IDENT) {
|
||||||
name = func->as_ident();
|
name = func->as_ident();
|
||||||
ptr_op_t def = func->compile(scope);
|
ptr_op_t def = func->compile(scope);
|
||||||
|
|
@ -706,6 +711,7 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
||||||
"Calling unknown function '" << name << "'");
|
"Calling unknown function '" << name << "'");
|
||||||
func = def;
|
func = def;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (func->kind != FUNCTION)
|
if (func->kind != FUNCTION)
|
||||||
throw_(calc_error, "Calling non-function");
|
throw_(calc_error, "Calling non-function");
|
||||||
|
|
@ -713,8 +719,12 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
||||||
return func->as_function()(call_args);
|
return func->as_function()(call_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case O_MATCH:
|
||||||
|
assert(left()->is_mask());
|
||||||
|
return left()->as_mask().match(right()->calc(scope).to_string());
|
||||||
|
|
||||||
case INDEX: {
|
case INDEX: {
|
||||||
call_scope_t args(scope);
|
const call_scope_t& args(downcast<const call_scope_t>(scope));
|
||||||
|
|
||||||
if (as_index() < args.size())
|
if (as_index() < args.size())
|
||||||
return args[as_index()];
|
return args[as_index()];
|
||||||
|
|
@ -755,6 +765,7 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
||||||
|
|
||||||
case O_AND:
|
case O_AND:
|
||||||
return ! left()->calc(scope) ? value_t(false) : right()->calc(scope);
|
return ! left()->calc(scope) ? value_t(false) : right()->calc(scope);
|
||||||
|
|
||||||
case O_OR:
|
case O_OR:
|
||||||
if (value_t temp = left()->calc(scope))
|
if (value_t temp = left()->calc(scope))
|
||||||
return temp;
|
return temp;
|
||||||
|
|
@ -957,6 +968,15 @@ bool expr_t::op_t::print(std::ostream& out, print_context_t& context) const
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case O_MATCH:
|
||||||
|
out << '/';
|
||||||
|
if (left() && left()->print(out, context))
|
||||||
|
found = true;
|
||||||
|
out << "/ =~ ";
|
||||||
|
if (right() && right()->print(out, context))
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case LAST:
|
case LAST:
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
@ -1002,6 +1022,7 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_CALL: out << "O_CALL"; break;
|
case O_CALL: out << "O_CALL"; break;
|
||||||
|
case O_MATCH: out << "O_MATCH"; break;
|
||||||
|
|
||||||
case O_NOT: out << "O_NOT"; break;
|
case O_NOT: out << "O_NOT"; break;
|
||||||
case O_NEG: out << "O_NEG"; break;
|
case O_NEG: out << "O_NEG"; break;
|
||||||
|
|
@ -1042,10 +1063,6 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void expr_t::op_t::read(std::ostream& in)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void expr_t::op_t::read(const char *& data)
|
void expr_t::op_t::read(const char *& data)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
||||||
9
op.h
9
op.h
|
|
@ -75,6 +75,10 @@ public:
|
||||||
|
|
||||||
// Binary operators
|
// Binary operators
|
||||||
O_NOT,
|
O_NOT,
|
||||||
|
O_NEG,
|
||||||
|
|
||||||
|
UNARY_OPERATORS,
|
||||||
|
|
||||||
O_EQ,
|
O_EQ,
|
||||||
O_NEQ,
|
O_NEQ,
|
||||||
O_LT,
|
O_LT,
|
||||||
|
|
@ -85,7 +89,6 @@ public:
|
||||||
O_AND,
|
O_AND,
|
||||||
O_OR,
|
O_OR,
|
||||||
|
|
||||||
O_NEG,
|
|
||||||
O_ADD,
|
O_ADD,
|
||||||
O_SUB,
|
O_SUB,
|
||||||
O_MUL,
|
O_MUL,
|
||||||
|
|
@ -97,6 +100,9 @@ public:
|
||||||
O_COMMA,
|
O_COMMA,
|
||||||
|
|
||||||
O_CALL,
|
O_CALL,
|
||||||
|
O_MATCH,
|
||||||
|
|
||||||
|
BINARY_OPERATORS,
|
||||||
|
|
||||||
OPERATORS,
|
OPERATORS,
|
||||||
|
|
||||||
|
|
@ -288,7 +294,6 @@ public:
|
||||||
bool print(std::ostream& out, print_context_t& context) const;
|
bool print(std::ostream& out, print_context_t& context) const;
|
||||||
void dump(std::ostream& out, const int depth) const;
|
void dump(std::ostream& out, const int depth) const;
|
||||||
|
|
||||||
void read(std::ostream& in);
|
|
||||||
void read(const char *& data);
|
void read(const char *& data);
|
||||||
void write(std::ostream& out) const;
|
void write(std::ostream& out) const;
|
||||||
|
|
||||||
|
|
|
||||||
10
option.cc
10
option.cc
|
|
@ -62,16 +62,16 @@ namespace {
|
||||||
op_bool_tuple find_option(scope_t& scope, const char letter)
|
op_bool_tuple find_option(scope_t& scope, const char letter)
|
||||||
{
|
{
|
||||||
char buf[10];
|
char buf[10];
|
||||||
std::strcpy(buf, "option_");
|
std::strcpy(buf, "opt_");
|
||||||
buf[7] = letter;
|
buf[4] = letter;
|
||||||
buf[8] = '\0';
|
buf[5] = '\0';
|
||||||
|
|
||||||
expr_t::ptr_op_t op = scope.lookup(buf);
|
expr_t::ptr_op_t op = scope.lookup(buf);
|
||||||
if (op)
|
if (op)
|
||||||
return op_bool_tuple(op, false);
|
return op_bool_tuple(op, false);
|
||||||
|
|
||||||
buf[8] = '_';
|
buf[5] = '_';
|
||||||
buf[9] = '\0';
|
buf[6] = '\0';
|
||||||
|
|
||||||
return op_bool_tuple(scope.lookup(buf), true);
|
return op_bool_tuple(scope.lookup(buf), true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
parser.cc
21
parser.cc
|
|
@ -49,22 +49,15 @@ expr_t::parser_t::parse_value_term(std::istream& in,
|
||||||
|
|
||||||
case token_t::MASK: {
|
case token_t::MASK: {
|
||||||
// A /mask/ is just a shorthand for calling match().
|
// A /mask/ is just a shorthand for calling match().
|
||||||
node = new op_t(op_t::O_CALL);
|
node = new op_t(op_t::O_MATCH);
|
||||||
|
|
||||||
ptr_op_t ident = new op_t(op_t::IDENT);
|
|
||||||
ident->set_ident("match");
|
|
||||||
node->set_left(ident);
|
|
||||||
|
|
||||||
ptr_op_t args = new op_t(op_t::O_COMMA);
|
|
||||||
node->set_right(args);
|
|
||||||
|
|
||||||
ptr_op_t mask = new op_t(op_t::MASK);
|
ptr_op_t mask = new op_t(op_t::MASK);
|
||||||
mask->set_mask(tok.value.as_string());
|
mask->set_mask(tok.value.as_string());
|
||||||
|
|
||||||
ident = new op_t(op_t::IDENT);
|
ptr_op_t ident = new op_t(op_t::IDENT);
|
||||||
|
|
||||||
args->set_left(mask);
|
node->set_left(mask);
|
||||||
args->set_right(ident);
|
node->set_right(ident);
|
||||||
|
|
||||||
switch (tok.flags()) {
|
switch (tok.flags()) {
|
||||||
case TOKEN_SHORT_ACCOUNT_MASK:
|
case TOKEN_SHORT_ACCOUNT_MASK:
|
||||||
|
|
@ -301,6 +294,12 @@ expr_t::parser_t::parse_logic_expr(std::istream& in,
|
||||||
case token_t::NEQUAL:
|
case token_t::NEQUAL:
|
||||||
kind = op_t::O_NEQ;
|
kind = op_t::O_NEQ;
|
||||||
break;
|
break;
|
||||||
|
case token_t::MATCH:
|
||||||
|
kind = op_t::O_MATCH;
|
||||||
|
assert(node->kind == op_t::O_MATCH);
|
||||||
|
node = node->left();
|
||||||
|
assert(node->kind == op_t::MASK);
|
||||||
|
break;
|
||||||
case token_t::LESS:
|
case token_t::LESS:
|
||||||
kind = op_t::O_LT;
|
kind = op_t::O_LT;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ public:
|
||||||
TRACE_DTOR(item_predicate);
|
TRACE_DTOR(item_predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator()(T& item) const {
|
bool operator()(T& item) {
|
||||||
return ! predicate || predicate.calc(item).strip_annotations();
|
return ! predicate || predicate.calc(item).strip_annotations();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -558,7 +558,7 @@ void print_entry(std::ostream& out, const entry_base_t& entry_base,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disp_subaccounts_p(const account_t& account,
|
bool disp_subaccounts_p(const account_t& account,
|
||||||
const optional<item_predicate<account_t> >& disp_pred,
|
item_predicate<account_t>& disp_pred,
|
||||||
const account_t *& to_show)
|
const account_t *& to_show)
|
||||||
{
|
{
|
||||||
bool display = false;
|
bool display = false;
|
||||||
|
|
@ -596,7 +596,7 @@ bool disp_subaccounts_p(const account_t& account,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool display_account(const account_t& account,
|
bool display_account(const account_t& account,
|
||||||
const optional<item_predicate<account_t> >& disp_pred)
|
item_predicate<account_t>& disp_pred)
|
||||||
{
|
{
|
||||||
// Never display an account that has already been displayed.
|
// Never display an account that has already been displayed.
|
||||||
if (account_has_xdata(account) &&
|
if (account_has_xdata(account) &&
|
||||||
|
|
@ -615,7 +615,7 @@ bool display_account(const account_t& account,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return (! account_to_show &&
|
return (! account_to_show &&
|
||||||
(! disp_pred || (*disp_pred)(const_cast<account_t&>(account))));
|
disp_pred(const_cast<account_t&>(account)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_accounts::operator()(account_t& account)
|
void format_accounts::operator()(account_t& account)
|
||||||
|
|
|
||||||
9
report.h
9
report.h
|
|
@ -352,16 +352,11 @@ void print_entry(std::ostream& out, const entry_base_t& entry,
|
||||||
const string& prefix = "");
|
const string& prefix = "");
|
||||||
|
|
||||||
bool disp_subaccounts_p(const account_t& account,
|
bool disp_subaccounts_p(const account_t& account,
|
||||||
const optional<item_predicate<account_t> >& disp_pred,
|
item_predicate<account_t>& disp_pred,
|
||||||
const account_t *& to_show);
|
const account_t *& to_show);
|
||||||
|
|
||||||
inline bool disp_subaccounts_p(const account_t& account) {
|
|
||||||
const account_t * temp;
|
|
||||||
return disp_subaccounts_p(account, none, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool display_account(const account_t& account,
|
bool display_account(const account_t& account,
|
||||||
const optional<item_predicate<account_t> >& disp_pred);
|
item_predicate<account_t>& disp_pred);
|
||||||
|
|
||||||
class format_accounts : public item_handler<account_t>
|
class format_accounts : public item_handler<account_t>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,10 @@ void release_session_context()
|
||||||
|
|
||||||
session_t::session_t()
|
session_t::session_t()
|
||||||
: register_format
|
: register_format
|
||||||
("%D %-.20P %-.22A %12.67t %!12.80T\n%/"
|
("%-.10D %-.20P %-.22A %12.67t %!12.80T\n%/"
|
||||||
"%32|%-.22A %12.67t %!12.80T\n"),
|
"%32|%-.22A %12.67t %!12.80T\n"),
|
||||||
wide_register_format
|
wide_register_format
|
||||||
("%D %-.35P %-.38A %22.108t %!22.132T\n%/"
|
("%-.10D %-.35P %-.38A %22.108t %!22.132T\n%/"
|
||||||
"%48|%-.38A %22.108t %!22.132T\n"),
|
"%48|%-.38A %22.108t %!22.132T\n"),
|
||||||
print_format
|
print_format
|
||||||
("\n%d %Y%C%P\n %-34W %12o%n\n%/ %-34W %12o%n\n"),
|
("\n%d %Y%C%P\n %-34W %12o%n\n%/ %-34W %12o%n\n"),
|
||||||
|
|
|
||||||
19
textual.cc
19
textual.cc
|
|
@ -5,6 +5,8 @@
|
||||||
#include "textual.h"
|
#include "textual.h"
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include "session.h"
|
||||||
|
#include "option.h"
|
||||||
#include "acconf.h"
|
#include "acconf.h"
|
||||||
|
|
||||||
#define TIMELOG_SUPPORT 1
|
#define TIMELOG_SUPPORT 1
|
||||||
|
|
@ -298,6 +300,8 @@ xact_t * parse_xact(char * line, account_t * account,
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#if 0
|
#if 0
|
||||||
|
// jww (2008-08-02): This data must be saved so that it can be
|
||||||
|
// restored on "print".
|
||||||
unsigned long beg = static_cast<unsigned long>(in.tellg());
|
unsigned long beg = static_cast<unsigned long>(in.tellg());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -825,9 +829,7 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
if (p)
|
if (p)
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
}
|
}
|
||||||
#if 0
|
process_option(line + 2, session, p);
|
||||||
process_option(config_options, line + 2, p);
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -932,11 +934,8 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (word == "def") {
|
else if (word == "def") {
|
||||||
#if 0
|
expr_t def(p);
|
||||||
if (! expr_t::global_scope.get())
|
def.compile(session); // causes definitions to be established
|
||||||
init_value_expr();
|
|
||||||
parse_value_definition(p);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1064,9 +1063,7 @@ void write_textual_journal(journal_t& journal,
|
||||||
while (! in.eof()) {
|
while (! in.eof()) {
|
||||||
entry_base_t * base = NULL;
|
entry_base_t * base = NULL;
|
||||||
if (el != journal.entries.end() && pos == (*el)->beg_pos) {
|
if (el != journal.entries.end() && pos == (*el)->beg_pos) {
|
||||||
#if 0
|
hdr_fmt.format(out, **el);
|
||||||
hdr_fmt.format(out, details_t(**el));
|
|
||||||
#endif
|
|
||||||
base = *el++;
|
base = *el++;
|
||||||
}
|
}
|
||||||
else if (al != journal.auto_entries.end() && pos == (*al)->beg_pos) {
|
else if (al != journal.auto_entries.end() && pos == (*al)->beg_pos) {
|
||||||
|
|
|
||||||
13
token.cc
13
token.cc
|
|
@ -148,6 +148,10 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
|
||||||
in.get(c);
|
in.get(c);
|
||||||
kind = KW_AND;
|
kind = KW_AND;
|
||||||
break;
|
break;
|
||||||
|
case '|':
|
||||||
|
in.get(c);
|
||||||
|
kind = KW_OR;
|
||||||
|
break;
|
||||||
|
|
||||||
case '(':
|
case '(':
|
||||||
in.get(c);
|
in.get(c);
|
||||||
|
|
@ -300,6 +304,15 @@ void expr_t::token_t::next(std::istream& in, const unsigned int pflags)
|
||||||
|
|
||||||
case '=':
|
case '=':
|
||||||
in.get(c);
|
in.get(c);
|
||||||
|
c = in.peek();
|
||||||
|
if (c == '~') {
|
||||||
|
in.get(c);
|
||||||
|
symbol[1] = c;
|
||||||
|
symbol[2] = '\0';
|
||||||
|
kind = MATCH;
|
||||||
|
length = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
kind = EQUAL;
|
kind = EQUAL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
1
token.h
1
token.h
|
|
@ -61,6 +61,7 @@ struct expr_t::token_t : public noncopyable, public supports_flags<>
|
||||||
GREATEREQ, // >=
|
GREATEREQ, // >=
|
||||||
|
|
||||||
ASSIGN, // =
|
ASSIGN, // =
|
||||||
|
MATCH, // =~
|
||||||
MINUS, // -
|
MINUS, // -
|
||||||
PLUS, // +
|
PLUS, // +
|
||||||
STAR, // *
|
STAR, // *
|
||||||
|
|
|
||||||
35
walk.cc
35
walk.cc
|
|
@ -14,17 +14,16 @@ bool compare_items<xact_t>::operator()(const xact_t * left,
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
|
|
||||||
#if 0
|
|
||||||
xact_xdata_t& lxdata(xact_xdata(*left));
|
xact_xdata_t& lxdata(xact_xdata(*left));
|
||||||
if (! (lxdata.dflags & XACT_SORT_CALC)) {
|
if (! (lxdata.dflags & XACT_SORT_CALC)) {
|
||||||
sort_order.compute(lxdata.sort_value, details_t(*left));
|
lxdata.sort_value = sort_order.calc(const_cast<xact_t&>(*left));
|
||||||
lxdata.sort_value.reduce();
|
lxdata.sort_value.reduce();
|
||||||
lxdata.dflags |= XACT_SORT_CALC;
|
lxdata.dflags |= XACT_SORT_CALC;
|
||||||
}
|
}
|
||||||
|
|
||||||
xact_xdata_t& rxdata(xact_xdata(*right));
|
xact_xdata_t& rxdata(xact_xdata(*right));
|
||||||
if (! (rxdata.dflags & XACT_SORT_CALC)) {
|
if (! (rxdata.dflags & XACT_SORT_CALC)) {
|
||||||
sort_order.compute(rxdata.sort_value, details_t(*right));
|
rxdata.sort_value = sort_order.calc(const_cast<xact_t&>(*right));
|
||||||
rxdata.sort_value.reduce();
|
rxdata.sort_value.reduce();
|
||||||
rxdata.dflags |= XACT_SORT_CALC;
|
rxdata.dflags |= XACT_SORT_CALC;
|
||||||
}
|
}
|
||||||
|
|
@ -35,9 +34,6 @@ bool compare_items<xact_t>::operator()(const xact_t * left,
|
||||||
"rxdata.sort_value = " << rxdata.sort_value);
|
"rxdata.sort_value = " << rxdata.sort_value);
|
||||||
|
|
||||||
return lxdata.sort_value < rxdata.sort_value;
|
return lxdata.sort_value < rxdata.sort_value;
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xact_xdata_t& xact_xdata(const xact_t& xact)
|
xact_xdata_t& xact_xdata(const xact_t& xact)
|
||||||
|
|
@ -382,8 +378,9 @@ void changed_value_xacts::output_diff(const date_t& date)
|
||||||
compute_total(cur_bal, details_t(*last_xact));
|
compute_total(cur_bal, details_t(*last_xact));
|
||||||
#endif
|
#endif
|
||||||
cur_bal.round();
|
cur_bal.round();
|
||||||
// jww (2008-04-24): What does this do?
|
|
||||||
#if 0
|
#if 0
|
||||||
|
// jww (2008-04-24): What does this do?
|
||||||
xact_xdata(*last_xact).date = 0;
|
xact_xdata(*last_xact).date = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -634,10 +631,7 @@ void set_code_as_payee::operator()(xact_t& xact)
|
||||||
void dow_xacts::flush()
|
void dow_xacts::flush()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
// jww (2008-04-24): What to use here?
|
start = finish = date_t();
|
||||||
#if 0
|
|
||||||
start = finish = 0;
|
|
||||||
#endif
|
|
||||||
foreach (xact_t * xact, days_of_the_week[i])
|
foreach (xact_t * xact, days_of_the_week[i])
|
||||||
subtotal_xacts::operator()(*xact);
|
subtotal_xacts::operator()(*xact);
|
||||||
subtotal_xacts::report_subtotal("%As");
|
subtotal_xacts::report_subtotal("%As");
|
||||||
|
|
@ -682,11 +676,6 @@ void budget_xacts::report_budget_items(const date_t& date)
|
||||||
|
|
||||||
DEBUG("ledger.walk.budget", "Reporting budget for "
|
DEBUG("ledger.walk.budget", "Reporting budget for "
|
||||||
<< xact_account(xact)->fullname());
|
<< xact_account(xact)->fullname());
|
||||||
#if 0
|
|
||||||
// jww (2008-04-24): Need a new debug macro here
|
|
||||||
DEBUG_TIME("ledger.walk.budget", begin);
|
|
||||||
DEBUG_TIME("ledger.walk.budget", date);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
entry_temps.push_back(entry_t());
|
entry_temps.push_back(entry_t());
|
||||||
entry_t& entry = entry_temps.back();
|
entry_t& entry = entry_temps.back();
|
||||||
|
|
@ -787,12 +776,8 @@ void forecast_xacts::flush()
|
||||||
entry.add_xact(&temp);
|
entry.add_xact(&temp);
|
||||||
|
|
||||||
date_t next = (*least).first.increment(begin);
|
date_t next = (*least).first.increment(begin);
|
||||||
#if 0
|
if (next < begin || (is_valid(last) && (next - last).days() > 365 * 5))
|
||||||
// jww (2008-04-24): Does seconds() here give the total seconds?
|
|
||||||
if (next < begin || // wraparound
|
|
||||||
(is_valid(last) && (next - last).seconds() > 365 * 5 * 24 * 3600))
|
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
begin = next;
|
begin = next;
|
||||||
|
|
||||||
item_handler<xact_t>::operator()(temp);
|
item_handler<xact_t>::operator()(temp);
|
||||||
|
|
@ -829,23 +814,19 @@ bool compare_items<account_t>::operator()(const account_t * left,
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
|
|
||||||
#if 0
|
|
||||||
account_xdata_t& lxdata(account_xdata(*left));
|
account_xdata_t& lxdata(account_xdata(*left));
|
||||||
if (! (lxdata.dflags & ACCOUNT_SORT_CALC)) {
|
if (! (lxdata.dflags & ACCOUNT_SORT_CALC)) {
|
||||||
sort_order.compute(lxdata.sort_value, details_t(*left));
|
lxdata.sort_value = sort_order.calc(const_cast<account_t&>(*left));
|
||||||
lxdata.dflags |= ACCOUNT_SORT_CALC;
|
lxdata.dflags |= ACCOUNT_SORT_CALC;
|
||||||
}
|
}
|
||||||
|
|
||||||
account_xdata_t& rxdata(account_xdata(*right));
|
account_xdata_t& rxdata(account_xdata(*right));
|
||||||
if (! (rxdata.dflags & ACCOUNT_SORT_CALC)) {
|
if (! (rxdata.dflags & ACCOUNT_SORT_CALC)) {
|
||||||
sort_order.compute(rxdata.sort_value, details_t(*right));
|
rxdata.sort_value = sort_order.calc(const_cast<account_t&>(*right));
|
||||||
rxdata.dflags |= ACCOUNT_SORT_CALC;
|
rxdata.dflags |= ACCOUNT_SORT_CALC;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lxdata.sort_value < rxdata.sort_value;
|
return lxdata.sort_value < rxdata.sort_value;
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
account_xdata_t& account_xdata(const account_t& account)
|
account_xdata_t& account_xdata(const account_t& account)
|
||||||
|
|
|
||||||
22
walk.h
22
walk.h
|
|
@ -59,15 +59,7 @@ bool compare_items<T>::operator()(const T * left, const T * right)
|
||||||
{
|
{
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
|
return sort_order.calc(*left) < sort_order.calc(*right);
|
||||||
value_t left_result;
|
|
||||||
value_t right_result;
|
|
||||||
#if 0
|
|
||||||
sort_order.compute(left_result, details_t(*left));
|
|
||||||
sort_order.compute(right_result, details_t(*right));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return left_result < right_result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
@ -1031,18 +1023,6 @@ public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if 0
|
|
||||||
inline void clear_journal_xdata(journal_t& journal) {
|
|
||||||
clear_xact_xdata xact_cleaner;
|
|
||||||
walk_entries(journal.entries, xact_cleaner);
|
|
||||||
|
|
||||||
clear_account_xdata acct_cleaner;
|
|
||||||
walk_accounts(*journal.master, acct_cleaner);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class journals_iterator : public noncopyable
|
class journals_iterator : public noncopyable
|
||||||
{
|
{
|
||||||
ptr_list<journal_t>::iterator journals_i;
|
ptr_list<journal_t>::iterator journals_i;
|
||||||
|
|
|
||||||
18
xact.cc
18
xact.cc
|
|
@ -79,6 +79,8 @@ namespace {
|
||||||
{
|
{
|
||||||
xact_t& xact(downcast<xact_t>(*scope.parent));
|
xact_t& xact(downcast<xact_t>(*scope.parent));
|
||||||
|
|
||||||
|
// jww (2008-08-02): Accept a width here so that we can abbreviate the
|
||||||
|
// string.
|
||||||
string name = xact.account->fullname();
|
string name = xact.account->fullname();
|
||||||
|
|
||||||
if (xact.has_flags(XACT_VIRTUAL)) {
|
if (xact.has_flags(XACT_VIRTUAL)) {
|
||||||
|
|
@ -102,19 +104,25 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
|
||||||
switch (name[0]) {
|
switch (name[0]) {
|
||||||
case 'a':
|
case 'a':
|
||||||
if (name[1] == '\0' || name == "amount")
|
if (name[1] == '\0' || name == "amount")
|
||||||
return WRAP_FUNCTOR(bind(get_amount, _1));
|
return WRAP_FUNCTOR(get_amount);
|
||||||
else if (name == "account")
|
else if (name == "account")
|
||||||
return WRAP_FUNCTOR(bind(get_account, _1));
|
return WRAP_FUNCTOR(get_account);
|
||||||
else if (name == "account_base")
|
else if (name == "account_base")
|
||||||
return WRAP_FUNCTOR(bind(get_account_base, _1));
|
return WRAP_FUNCTOR(get_account_base);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (name[1] == '\0' || name == "date")
|
if (name[1] == '\0' || name == "date")
|
||||||
return WRAP_FUNCTOR(bind(get_date, _1));
|
return WRAP_FUNCTOR(get_date);
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
if (name.find("fmt_") == 0) {
|
||||||
|
if (name == "fmt_A")
|
||||||
|
return WRAP_FUNCTOR(get_account);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (name[1] == '\0' || name == "payee")
|
if (name[1] == '\0' || name == "payee")
|
||||||
return WRAP_FUNCTOR(bind(get_payee, _1));
|
return WRAP_FUNCTOR(get_payee);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return entry->lookup(name);
|
return entry->lookup(name);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue