Enabled the --tail and --head options.

This commit is contained in:
John Wiegley 2008-08-13 02:58:49 -04:00
parent 3f8412f404
commit b134a98e1e
4 changed files with 30 additions and 17 deletions

View file

@ -46,6 +46,8 @@ pass_down_xacts::pass_down_xacts(xact_handler_ptr handler,
for (xact_t * xact = iter(); xact; xact = iter()) for (xact_t * xact = iter(); xact; xact = iter())
item_handler<xact_t>::operator()(*xact); item_handler<xact_t>::operator()(*xact);
item_handler<xact_t>::flush();
} }
void truncate_entries::flush() void truncate_entries::flush()
@ -749,6 +751,8 @@ pass_down_accounts::pass_down_accounts(acct_handler_ptr handler,
for (account_t * account = iter(); account; account = iter()) for (account_t * account = iter(); account; account = iter())
if (pred(*account)) if (pred(*account))
item_handler<account_t>::operator()(*account); item_handler<account_t>::operator()(*account);
item_handler<account_t>::flush();
} }
} // namespace ledger } // namespace ledger

View file

@ -111,11 +111,11 @@ public:
} }
virtual void flush(); virtual void flush();
virtual void operator()(xact_t& xact) { virtual void operator()(xact_t& xact) {
if (tail_count == 0 && head_count > 0 && if (! (tail_count == 0 && head_count > 0 &&
xacts.size() >= static_cast<unsigned int>(head_count)) static_cast<int>(xacts.size()) >= head_count))
return; xacts.push_back(&xact);
xacts.push_back(&xact);
} }
}; };

View file

@ -305,7 +305,6 @@ void report_t::xacts_report(xact_handler_ptr handler)
{ {
session_xacts_iterator walker(session); session_xacts_iterator walker(session);
pass_down_xacts(chain_xact_handlers(handler), walker); pass_down_xacts(chain_xact_handlers(handler), walker);
handler->flush();
if (DO_VERIFY()) if (DO_VERIFY())
session.clean_xacts(); session.clean_xacts();
@ -315,7 +314,6 @@ void report_t::entry_report(xact_handler_ptr handler, entry_t& entry)
{ {
entry_xacts_iterator walker(entry); entry_xacts_iterator walker(entry);
pass_down_xacts(chain_xact_handlers(handler), walker); pass_down_xacts(chain_xact_handlers(handler), walker);
handler->flush();
if (DO_VERIFY()) if (DO_VERIFY())
session.clean_xacts(entry); session.clean_xacts(entry);
@ -341,7 +339,6 @@ void report_t::accounts_report(acct_handler_ptr handler)
sorted_accounts_iterator walker(*session.master, sort_string); sorted_accounts_iterator walker(*session.master, sort_string);
pass_down_accounts(handler, walker, expr_t("total")); pass_down_accounts(handler, walker, expr_t("total"));
} }
handler->flush();
if (DO_VERIFY()) { if (DO_VERIFY()) {
session.clean_xacts(); session.clean_xacts();
@ -373,7 +370,7 @@ namespace {
#endif #endif
std::ostringstream out; std::ostringstream out;
args[0].dump(out, *first_width, *latter_width); args[0].strip_annotations().dump(out, *first_width, *latter_width);
return string_value(out.str()); return string_value(out.str());
} }
} }
@ -409,6 +406,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_format_); return MAKE_FUNCTOR(report_t::option_format_);
break; break;
case 'h':
if (std::strcmp(p, "head_") == 0)
return MAKE_FUNCTOR(report_t::option_head_);
break;
case 'j': case 'j':
if (! (*p + 1)) if (! (*p + 1))
return MAKE_FUNCTOR(report_t::option_amount_data); return MAKE_FUNCTOR(report_t::option_amount_data);
@ -420,19 +422,22 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break; break;
case 'l': case 'l':
if (std::strcmp(p, "l_") || std::strcmp(p, "limit_")) if (std::strcmp(p, "l_") == 0
|| std::strcmp(p, "limit_") == 0)
return MAKE_FUNCTOR(report_t::option_limit_); return MAKE_FUNCTOR(report_t::option_limit_);
break; break;
case 't': case 't':
if (std::strcmp(p, "t_")) if (std::strcmp(p, "t_") == 0)
return MAKE_FUNCTOR(report_t::option_amount_); return MAKE_FUNCTOR(report_t::option_amount_);
else if (std::strcmp(p, "total_") == 0) else if (std::strcmp(p, "total_") == 0)
return MAKE_FUNCTOR(report_t::option_total_); return MAKE_FUNCTOR(report_t::option_total_);
else if (std::strcmp(p, "tail_") == 0)
return MAKE_FUNCTOR(report_t::option_tail_);
break; break;
case 'T': case 'T':
if (std::strcmp(p, "T_")) if (std::strcmp(p, "T_") == 0)
return MAKE_FUNCTOR(report_t::option_total_); return MAKE_FUNCTOR(report_t::option_total_);
break; break;
} }

View file

@ -107,8 +107,8 @@ public:
unsigned long budget_flags; unsigned long budget_flags;
int head_entries; long head_entries;
int tail_entries; long tail_entries;
bool show_collapsed; bool show_collapsed;
bool show_subtotal; bool show_subtotal;
@ -424,15 +424,19 @@ public:
value_t option_wide(call_scope_t& args) { // w value_t option_wide(call_scope_t& args) { // w
config->register_format = config->wide_register_format; config->register_format = config->wide_register_format;
} }
#endif
value_t option_head(call_scope_t& args) { // : value_t option_head_(call_scope_t& args) { // :
report->head_entries = std::atoi(optarg); head_entries = *var_t<long>(args, 0);
return true;
} }
value_t option_tail(call_scope_t& args) { // : value_t option_tail_(call_scope_t& args) { // :
report->tail_entries = std::atoi(optarg); tail_entries = *var_t<long>(args, 0);
return true;
} }
#if 0
value_t option_pager(call_scope_t& args) { // : value_t option_pager(call_scope_t& args) { // :
config->pager = optarg; config->pager = optarg;
} }