Restored --format, --date-format (-y), and --input-date-format options.

This commit is contained in:
John Wiegley 2008-09-14 19:41:20 -04:00
parent 6d020a9b0b
commit 53c6e826f1
4 changed files with 34 additions and 15 deletions

View file

@ -400,7 +400,10 @@ namespace ledger {
if (verb == "register" || verb == "reg" || verb == "r") { if (verb == "register" || verb == "reg" || verb == "r") {
verb = "register"; verb = "register";
command = reporter<>(new format_xacts(report, session.register_format)); command = reporter<>(new format_xacts(report,
report.format_string.empty() ?
session.register_format :
report.format_string));
} }
else if (verb == "print" || verb == "p") { else if (verb == "print" || verb == "p") {
verb = "print"; verb = "print";

View file

@ -322,9 +322,9 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
case 'c': case 'c':
if (std::strcmp(p, "collapse") == 0) if (std::strcmp(p, "collapse") == 0)
return MAKE_FUNCTOR(report_t::option_collapse); return MAKE_FUNCTOR(report_t::option_collapse);
else if (std::strcmp(p, "comm_as_payee") == 0) else if (std::strcmp(p, "comm-as-payee") == 0)
return MAKE_FUNCTOR(report_t::option_comm_as_payee); return MAKE_FUNCTOR(report_t::option_comm_as_payee);
else if (std::strcmp(p, "code_as_payee") == 0) else if (std::strcmp(p, "code-as-payee") == 0)
return MAKE_FUNCTOR(report_t::option_code_as_payee); return MAKE_FUNCTOR(report_t::option_code_as_payee);
break; break;
@ -333,6 +333,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_daily); return MAKE_FUNCTOR(report_t::option_daily);
else if (std::strcmp(p, "dow") == 0) else if (std::strcmp(p, "dow") == 0)
return MAKE_FUNCTOR(report_t::option_dow); return MAKE_FUNCTOR(report_t::option_dow);
else if (std::strcmp(p, "date-format_") == 0)
return MAKE_FUNCTOR(report_t::option_date_format_);
break; break;
case 'e': case 'e':
@ -344,8 +346,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break; break;
case 'f': case 'f':
if (std::strcmp(p, "F_") == 0 || if (std::strcmp(p, "format_") == 0)
std::strcmp(p, "format_") == 0)
return MAKE_FUNCTOR(report_t::option_format_); return MAKE_FUNCTOR(report_t::option_format_);
break; break;
@ -354,6 +355,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_head_); return MAKE_FUNCTOR(report_t::option_head_);
break; break;
case 'i':
if (std::strcmp(p, "input-date-format_") == 0)
return MAKE_FUNCTOR(report_t::option_input_date_format_);
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);
@ -430,6 +436,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
case 'y': case 'y':
if (std::strcmp(p, "yearly") == 0) if (std::strcmp(p, "yearly") == 0)
return MAKE_FUNCTOR(report_t::option_yearly); return MAKE_FUNCTOR(report_t::option_yearly);
else if (std::strcmp(p, "y_") == 0)
return MAKE_FUNCTOR(report_t::option_date_format_);
break; break;
case 'E': case 'E':
@ -437,6 +445,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_empty); return MAKE_FUNCTOR(report_t::option_empty);
break; break;
case 'F':
if (std::strcmp(p, "F_") == 0)
return MAKE_FUNCTOR(report_t::option_format_);
break;
case 'J': case 'J':
if (! (*p + 1)) if (! (*p + 1))
return MAKE_FUNCTOR(report_t::option_total_data); return MAKE_FUNCTOR(report_t::option_total_data);

View file

@ -353,15 +353,17 @@ public:
return true; return true;
} }
value_t option_date_format_(call_scope_t& args) { // y:
ledger::output_date_format = args[0].as_string();
return true;
}
value_t option_input_date_format_(call_scope_t& args) { // :
ledger::input_date_format = args[0].as_string();
return true;
}
#if 0 #if 0
value_t option_date_format(call_scope_t& args) { // y:
report->date_output_format = optarg;
}
value_t option_input_date_format(call_scope_t& args) { // :
config->date_input_format = optarg;
}
value_t option_balance_format(call_scope_t& args) { // : value_t option_balance_format(call_scope_t& args) { // :
config->balance_format = optarg; config->balance_format = optarg;
} }

View file

@ -89,10 +89,11 @@ inline string format_datetime(const datetime_t& when)
inline string format_date(const date_t& when, inline string format_date(const date_t& when,
const optional<string>& format = none) const optional<string>& format = none)
{ {
if (format) { if (format || ! output_date_format.empty()) {
char buf[256]; char buf[256];
std::tm moment = gregorian::to_tm(when); std::tm moment = gregorian::to_tm(when);
std::strftime(buf, 255, format->c_str(), &moment); std::strftime(buf, 255, format ?
format->c_str() : output_date_format.c_str(), &moment);
return buf; return buf;
} else { } else {
return to_simple_string(when).substr(2); return to_simple_string(when).substr(2);