From fc84eeb358f13b7c2b2668917692da26af001901 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 25 Oct 2009 04:37:11 -0400 Subject: Rewrote the way date and time I/O is managed --- src/filters.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index 967e0843..5b087eea 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -531,15 +531,14 @@ void subtotal_posts::report_subtotal(const char * spec_fmt, std::ostringstream out_date; if (spec_fmt) { - out_date << format_date(*range_finish, string(spec_fmt)); + out_date << format_date(*range_finish, FMT_CUSTOM, spec_fmt); } else if (date_format) { - string fmt = "- "; - fmt += *date_format; - out_date << format_date(*range_finish, string(fmt)); + out_date << "- " << format_date(*range_finish, FMT_CUSTOM, + date_format->c_str()); } else { - out_date << format_date(*range_finish, std::string("- ") + output_date_format); + out_date << "- " << format_date(*range_finish); } xact_temps.push_back(xact_t()); -- cgit v1.2.3 From 26ae1fdfad62a15a0762c052ed9785f3c0d5be29 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 25 Oct 2009 04:38:43 -0400 Subject: New valexpr functions: id, idstring, magnitude id returns a unique SHA1 id of a transaction. idstring is the string that the SHA1 is based on. magnitude is the sum of the positive side of a transaction. --- src/filters.cc | 15 --------------- src/utils.h | 13 +++++++++++++ src/xact.cc | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 15 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index 5b087eea..08e7a22f 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -133,21 +133,6 @@ void sort_posts::post_accumulated_posts() posts.clear(); } -namespace { - string to_hex(uint_least32_t * message_digest) - { - std::ostringstream buf; - - for(int i = 0; i < 5 ; i++) { - buf.width(8); - buf.fill('0'); - buf << std::hex << message_digest[i]; - break; // only output the first dword - } - return buf.str(); - } -} - void anonymize_posts::operator()(post_t& post) { SHA1 sha; diff --git a/src/utils.h b/src/utils.h index 7042ddf6..7f5ca017 100644 --- a/src/utils.h +++ b/src/utils.h @@ -594,6 +594,19 @@ inline char peek_next_nonws(std::istream& in) { *_p = '\0'; \ } +inline string to_hex(uint_least32_t * message_digest) +{ + std::ostringstream buf; + + for(int i = 0; i < 5 ; i++) { + buf.width(8); + buf.fill('0'); + buf << std::hex << message_digest[i]; + break; // only output the first dword + } + return buf.str(); +} + extern const string version; } // namespace ledger diff --git a/src/xact.cc b/src/xact.cc index bd8a5955..175a1467 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -352,6 +352,33 @@ void xact_t::add_post(post_t * post) } namespace { + value_t get_magnitude(xact_t& xact) { + balance_t halfbal; + foreach (post_t * post, xact.posts) + if (post->amount.sign() > 0) + halfbal += post->amount.number(); + return halfbal; + } + + value_t get_idstring(xact_t& xact) { + std::ostringstream buf; + buf << *xact._date; + buf << xact.payee; + + get_magnitude(xact).print(buf); + + return string_value(buf.str()); + } + value_t get_id(xact_t& xact) { + SHA1 sha; + sha.Reset(); + sha << get_idstring(xact).as_string().c_str(); + + uint_least32_t message_digest[5]; + sha.Result(message_digest); + return string_value(to_hex(message_digest)); + } + value_t get_code(xact_t& xact) { if (xact.code) return string_value(*xact.code); @@ -377,6 +404,18 @@ expr_t::ptr_op_t xact_t::lookup(const string& name) return WRAP_FUNCTOR(get_wrapper<&get_code>); break; + case 'i': + if (name == "id") + return WRAP_FUNCTOR(get_wrapper<&get_id>); + else if (name == "idstring") + return WRAP_FUNCTOR(get_wrapper<&get_idstring>); + break; + + case 'm': + if (name == "magnitude") + return WRAP_FUNCTOR(get_wrapper<&get_magnitude>); + break; + case 'p': if (name[1] == '\0' || name == "payee") return WRAP_FUNCTOR(get_wrapper<&get_payee>); -- cgit v1.2.3