diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/format.cc | 6 | ||||
-rw-r--r-- | src/precmd.cc | 64 |
2 files changed, 46 insertions, 24 deletions
diff --git a/src/format.cc b/src/format.cc index 3bbb2b13..f881cf37 100644 --- a/src/format.cc +++ b/src/format.cc @@ -43,15 +43,15 @@ void format_t::element_t::dump(std::ostream& out) const case EXPR: out << " EXPR"; break; } - out << " flags: " << flags(); + out << " flags: 0x" << std::hex << int(flags()); out << " min: "; out << std::right; out.width(2); - out << int(min_width); + out << std::dec << int(min_width); out << " max: "; out << std::right; out.width(2); - out << int(max_width); + out << std::dec << int(max_width); switch (type) { case STRING: out << " str: '" << chars << "'" << std::endl; break; diff --git a/src/precmd.cc b/src/precmd.cc index 5ec6c7c6..274b77e2 100644 --- a/src/precmd.cc +++ b/src/precmd.cc @@ -34,6 +34,36 @@ namespace ledger { +namespace { + xact_t * get_sample_xact(report_t& report) + { + { + string str; + { + std::ostringstream buf; + + buf << "2004/05/27 Book Store\n" + << " Expenses:Books 20 BOOK @ $10\n" + << " Liabilities:MasterCard $-200.00\n"; + + str = buf.str(); + } + + std::ostream& out(report.output_stream); + + out << "--- Context is first transaction of the following entry ---" + << std::endl << str << std::endl; + { + std::istringstream in(str); + report.session.journal->parse(in, report.session, NULL, NULL); + report.session.clean_accounts(); + } + } + entry_t * first = report.session.journal->entries.front(); + return first->xacts.front(); + } +} + value_t parse_command(call_scope_t& args) { string arg = join_args(args); @@ -45,27 +75,7 @@ value_t parse_command(call_scope_t& args) report_t& report(find_scope<report_t>(args)); std::ostream& out(report.output_stream); - { - string str; - { - std::ostringstream buf; - - buf << "2004/05/27 Book Store\n" - << " Expenses:Books 20 BOOK @ $10\n" - << " Liabilities:MasterCard $-200.00\n"; - - str = buf.str(); - } - out << "--- Context is first transaction of the following entry ---" - << std::endl << str << std::endl; - { - std::istringstream in(str); - report.session.journal->parse(in, report.session, NULL, NULL); - report.session.clean_accounts(); - } - } - entry_t * first = report.session.journal->entries.front(); - xact_t * xact = first->xacts.front(); + xact_t * xact = get_sample_xact(report); out << "--- Input expression ---" << std::endl; out << arg << std::endl; @@ -114,9 +124,21 @@ value_t format_command(call_scope_t& args) report_t& report(find_scope<report_t>(args)); std::ostream& out(report.output_stream); + xact_t * xact = get_sample_xact(report); + + out << "--- Input format string ---" << std::endl; + out << arg << std::endl << std::endl; + + out << "--- Format elements ---" << std::endl; format_t fmt(arg); fmt.dump(out); + out << std::endl << "--- Formatted string ---" << std::endl; + bind_scope_t bound_scope(args, *xact); + out << '"'; + fmt.format(out, bound_scope); + out << "\"\n"; + return 0L; } |