diff options
author | John Wiegley <johnw@newartisans.com> | 2012-05-18 01:38:39 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-05-18 01:38:39 -0600 |
commit | 7e8ba51cd0fc94776b8f687736202a25ddc39f15 (patch) | |
tree | 373ec4d59af7a14d3519f0c18063e61e41cf8ec9 | |
parent | a38ed141c1f33ecdad99b322acb1ae07b30a5da2 (diff) | |
download | fork-ledger-7e8ba51cd0fc94776b8f687736202a25ddc39f15.tar.gz fork-ledger-7e8ba51cd0fc94776b8f687736202a25ddc39f15.tar.bz2 fork-ledger-7e8ba51cd0fc94776b8f687736202a25ddc39f15.zip |
Added a "json" report command
-rw-r--r-- | src/ptree.cc | 9 | ||||
-rw-r--r-- | src/ptree.h | 10 | ||||
-rw-r--r-- | src/report.cc | 12 | ||||
-rw-r--r-- | src/select.cc | 2 |
4 files changed, 27 insertions, 6 deletions
diff --git a/src/ptree.cc b/src/ptree.cc index 5f7b5766..ca343072 100644 --- a/src/ptree.cc +++ b/src/ptree.cc @@ -74,7 +74,14 @@ void format_ptree::flush() put_post(pt, *post); } - property_tree::write_xml(out, pt); + switch (format) { + case FORMAT_XML: + property_tree::write_xml(out, pt); + break; + case FORMAT_JSON: + property_tree::write_json(out, pt); + break; + } } void format_ptree::operator()(post_t& post) diff --git a/src/ptree.h b/src/ptree.h index d3fecc88..b28f97d5 100644 --- a/src/ptree.h +++ b/src/ptree.h @@ -74,8 +74,14 @@ protected: std::deque<xact_t *> transactions; public: - format_ptree(report_t& _report) : report(_report) { - TRACE_CTOR(format_ptree, "report&"); + enum format_t { + FORMAT_XML, + FORMAT_JSON + } format; + + format_ptree(report_t& _report, format_t _format = FORMAT_XML) + : report(_report), format(_format) { + TRACE_CTOR(format_ptree, "report&, format_t"); } virtual ~format_ptree() { TRACE_DTOR(format_ptree); diff --git a/src/report.cc b/src/report.cc index 9d417b93..d6e6f150 100644 --- a/src/report.cc +++ b/src/report.cc @@ -1602,11 +1602,16 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, } break; + case 'j': + if (is_eq(p, "json")) + return POSTS_REPORTER(new format_ptree(*this, + format_ptree::FORMAT_JSON)); + break; + case 'o': - if (is_eq(p, "org")) { + if (is_eq(p, "org")) return POSTS_REPORTER(new posts_to_org_table (*this, maybe_format(HANDLER(prepend_format_)))); - } break; case 'p': @@ -1649,7 +1654,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (is_eq(p, "xact")) return WRAP_FUNCTOR(xact_command); else if (is_eq(p, "xml")) - return POSTS_REPORTER(new format_ptree(*this)); + return POSTS_REPORTER(new format_ptree(*this, + format_ptree::FORMAT_XML)); break; } break; diff --git a/src/select.cc b/src/select.cc index 56bd3f2d..20a78701 100644 --- a/src/select.cc +++ b/src/select.cc @@ -419,6 +419,8 @@ value_t select_command(call_scope_t& args) } else if (arg == "xml") { } + else if (arg == "json") { + } else if (arg == "emacs") { } else if (arg == "org") { |