diff options
Diffstat (limited to 'src')
128 files changed, 550 insertions, 338 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 65e58edb..71d9478a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,20 +138,24 @@ set(LEDGER_INCLUDES ${PROJECT_BINARY_DIR}/system.hh) if (CMAKE_BUILD_TYPE STREQUAL "Debug") - if ((CMAKE_CXX_COMPILER MATCHES "clang") OR (CMAKE_CXX_COMPILER MATCHES "cxx")) + if (CMAKE_CXX_COMPILER MATCHES "clang\\+\\+") add_definitions( - -Weverything - -Wno-disabled-macro-expansion - -Wno-padded - -Wno-weak-vtables - -Wno-exit-time-destructors - -Wno-global-constructors - -Wno-switch-enum - -Wno-missing-prototypes - -Wno-missing-noreturn - -Wno-unused-parameter - -Wno-c++98-compat - -fno-limit-debug-info) + # -Weverything + # -Wno-disabled-macro-expansion + # -Wno-padded + # -Wno-weak-vtables + # -Wno-exit-time-destructors + # -Wno-global-constructors + # -Wno-switch-enum + # -Wno-missing-prototypes + # -Wno-missing-noreturn + # -Wno-unused-parameter + # -Wno-c++98-compat + # -fno-limit-debug-info + -Wno-\#pragma-messages + -Wno-unused-local-typedef + --system-header-prefix=include/boost/ + --system-header-prefix=boost/) macro(ADD_PCH_RULE _header_filename _src_list _other_srcs) set(_pch_filename "${_header_filename}.pch") @@ -189,7 +193,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") DEPENDS ${_header_filename}) endmacro(ADD_PCH_RULE _header_filename _src_list _other_srcs) - elseif(CMAKE_CXX_COMPILER MATCHES "g\\+\\+") + elseif (CMAKE_CXX_COMPILER MATCHES "g\\+\\+") set(GXX_WARNING_FLAGS -pedantic -Wall @@ -237,7 +241,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") get_directory_property(DIRINC INCLUDE_DIRECTORIES) foreach(_inc ${DIRINC}) - list(APPEND _args "-isystem " ${_inc}) + list(APPEND _args "-I" ${_inc}) endforeach(_inc ${DIRINC}) separate_arguments(_args) diff --git a/src/account.cc b/src/account.cc index 2a48eaf5..29c28866 100644 --- a/src/account.cc +++ b/src/account.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -136,6 +136,19 @@ void account_t::add_post(post_t * post) xdata_->self_details.calculated = false; xdata_->family_details.gathered = false; xdata_->family_details.calculated = false; + if (! xdata_->family_details.total.is_null()) { + xdata_->family_details.total = ledger::value_t(); + } + account_t *ancestor = this; + while (ancestor->parent) { + ancestor = ancestor->parent; + if (ancestor->has_xdata()) { + xdata_t &xdata = ancestor->xdata(); + xdata.family_details.gathered = false; + xdata.family_details.calculated = false; + xdata.family_details.total = ledger::value_t(); + } + } } } @@ -296,6 +309,20 @@ namespace { return long(&account); } + value_t get_depth_parent(account_t& account) + { + std::size_t depth = 0; + for (const account_t * acct = account.parent; + acct && acct->parent; + acct = acct->parent) { + std::size_t count = acct->children_with_flags(ACCOUNT_EXT_TO_DISPLAY); + assert(count > 0); + if (count > 1 || acct->has_xflags(ACCOUNT_EXT_TO_DISPLAY)) + depth++; + } + return long(depth); + } + value_t get_depth_spacer(account_t& account) { std::size_t depth = 0; @@ -412,6 +439,8 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind, case 'd': if (fn_name == "depth") return WRAP_FUNCTOR(get_wrapper<&get_depth>); + else if (fn_name == "depth_parent") + return WRAP_FUNCTOR(get_wrapper<&get_depth_parent>); else if (fn_name == "depth_spacer") return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>); break; diff --git a/src/account.h b/src/account.h index 4a4e859d..0abbd87a 100644 --- a/src/account.h +++ b/src/account.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -205,7 +205,9 @@ public: posts_cleared_count(0), posts_last_7_count(0), posts_last_30_count(0), - posts_this_month_count(0) { + posts_this_month_count(0), + latest_checkout_cleared(false) + { TRACE_CTOR(account_t::xdata_t::details_t, ""); } // A copy copies nothing @@ -218,7 +220,8 @@ public: posts_cleared_count(0), posts_last_7_count(0), posts_last_30_count(0), - posts_this_month_count(0) + posts_this_month_count(0), + latest_checkout_cleared(false) { TRACE_CTOR(account_t::xdata_t::details_t, "copy"); } diff --git a/src/amount.cc b/src/amount.cc index 52ccbc88..05145f87 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1090,6 +1090,8 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags) bool no_more_commas = false; bool no_more_periods = false; + bool no_migrate_style + = commodity().has_flags(COMMODITY_STYLE_NO_MIGRATE); bool decimal_comma_style = (commodity_t::decimal_comma_by_default || commodity().has_flags(COMMODITY_STYLE_DECIMAL_COMMA)); @@ -1173,7 +1175,7 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags) // is non-NULL. new_quantity->add_flags(BIGINT_KEEP_PREC); } - else if (commodity_) { + else if (commodity_ && ! no_migrate_style) { commodity().add_flags(comm_flags); if (new_quantity->prec > commodity().precision()) diff --git a/src/amount.h b/src/amount.h index 8885a69d..fed9a467 100644 --- a/src/amount.h +++ b/src/amount.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/annotate.cc b/src/annotate.cc index e953f441..ab81d412 100644 --- a/src/annotate.cc +++ b/src/annotate.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/annotate.h b/src/annotate.h index 0ea2561b..75d42589 100644 --- a/src/annotate.h +++ b/src/annotate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/balance.cc b/src/balance.cc index ca14c7ff..fa1bc20c 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/balance.h b/src/balance.h index d68fccc8..8e773fc5 100644 --- a/src/balance.h +++ b/src/balance.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/chain.cc b/src/chain.cc index 94afc0fa..d508dd3e 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -186,9 +186,9 @@ post_handler_ptr chain_post_handlers(post_handler_ptr base_handler, // value expression. if (report.HANDLED(sort_)) { if (report.HANDLED(sort_xacts_)) - handler.reset(new sort_xacts(handler, report.HANDLER(sort_).str())); + handler.reset(new sort_xacts(handler, expr_t(report.HANDLER(sort_).str()), report)); else - handler.reset(new sort_posts(handler, report.HANDLER(sort_).str())); + handler.reset(new sort_posts(handler, report.HANDLER(sort_).str(), report)); } // collapse_posts causes xacts with multiple posts to appear as xacts diff --git a/src/chain.h b/src/chain.h index 16fb4400..ff891238 100644 --- a/src/chain.h +++ b/src/chain.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/commodity.cc b/src/commodity.cc index 1475f52e..a8520ca1 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/commodity.h b/src/commodity.h index 1741bfaf..c25ccaf2 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -95,6 +95,7 @@ protected: #define COMMODITY_SAW_ANN_PRICE_FLOAT 0x400 #define COMMODITY_SAW_ANN_PRICE_FIXATED 0x800 #define COMMODITY_STYLE_TIME_COLON 0x1000 +#define COMMODITY_STYLE_NO_MIGRATE 0x2000 string symbol; optional<std::size_t> graph_index; diff --git a/src/compare.cc b/src/compare.cc index 547acc18..63b85154 100644 --- a/src/compare.cc +++ b/src/compare.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -33,8 +33,10 @@ #include "compare.h" #include "op.h" +#include "scope.h" #include "post.h" #include "account.h" +#include "report.h" namespace ledger { @@ -65,6 +67,20 @@ void push_sort_value(std::list<sort_value_t>& sort_values, } template <> +void compare_items<post_t>::find_sort_values( + std::list<sort_value_t>& sort_values, scope_t& scope) { + bind_scope_t bound_scope(report, scope); + push_sort_value(sort_values, sort_order.get_op(), bound_scope); +} + +template <> +void compare_items<account_t>::find_sort_values( + std::list<sort_value_t>& sort_values, scope_t& scope) { + bind_scope_t bound_scope(report, scope); + push_sort_value(sort_values, sort_order.get_op(), bound_scope); +} + +template <> bool compare_items<post_t>::operator()(post_t * left, post_t * right) { assert(left); diff --git a/src/compare.h b/src/compare.h index baee6075..f1b6b9b3 100644 --- a/src/compare.h +++ b/src/compare.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -48,6 +48,7 @@ namespace ledger { class post_t; class account_t; +class report_t; void push_sort_value(std::list<sort_value_t>& sort_values, expr_t::ptr_op_t node, scope_t& scope); @@ -56,23 +57,24 @@ template <typename T> class compare_items { expr_t sort_order; + report_t& report; compare_items(); public: - compare_items(const compare_items& other) : sort_order(other.sort_order) { - TRACE_CTOR(compare_items, "copy"); + compare_items(const expr_t& _sort_order, report_t& _report) : + sort_order(_sort_order), report(_report) { + TRACE_CTOR(compare_items, "const value_expr&, report_t&"); } - compare_items(const expr_t& _sort_order) : sort_order(_sort_order) { - TRACE_CTOR(compare_items, "const value_expr&"); + compare_items(const compare_items& other) : + sort_order(other.sort_order), report(other.report) { + TRACE_CTOR(compare_items, "copy"); } ~compare_items() throw() { TRACE_DTOR(compare_items); } - void find_sort_values(std::list<sort_value_t>& sort_values, scope_t& scope) { - push_sort_value(sort_values, sort_order.get_op(), scope); - } + void find_sort_values(std::list<sort_value_t>& sort_values, scope_t& scope); bool operator()(T * left, T * right); }; diff --git a/src/context.h b/src/context.h index 603898f4..0af59930 100644 --- a/src/context.h +++ b/src/context.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/convert.cc b/src/convert.cc index d0a0dc39..cea2a130 100644 --- a/src/convert.cc +++ b/src/convert.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/convert.h b/src/convert.h index cb6bcd71..e27b5872 100644 --- a/src/convert.h +++ b/src/convert.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/draft.cc b/src/draft.cc index f7557373..424b7a9a 100644 --- a/src/draft.cc +++ b/src/draft.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/draft.h b/src/draft.h index f4c24c26..44c3bf3d 100644 --- a/src/draft.h +++ b/src/draft.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/emacs.cc b/src/emacs.cc index 9f2626a3..52389316 100644 --- a/src/emacs.cc +++ b/src/emacs.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/emacs.h b/src/emacs.h index 52b7bd37..6e428613 100644 --- a/src/emacs.h +++ b/src/emacs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/error.cc b/src/error.cc index 4b3565a3..7e49645b 100644 --- a/src/error.cc +++ b/src/error.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/error.h b/src/error.h index 26cbfafb..ba278519 100644 --- a/src/error.h +++ b/src/error.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/expr.cc b/src/expr.cc index bc877c1a..85818e4b 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/exprbase.h b/src/exprbase.h index 6d13c429..9c28dca3 100644 --- a/src/exprbase.h +++ b/src/exprbase.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/filters.cc b/src/filters.cc index 1d7832ca..3dfd2327 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -154,7 +154,7 @@ void truncate_xacts::operator()(post_t& post) void sort_posts::post_accumulated_posts() { std::stable_sort(posts.begin(), posts.end(), - compare_items<post_t>(sort_order)); + compare_items<post_t>(sort_order, report)); foreach (post_t * post, posts) { post->xdata().drop_flags(POST_EXT_SORT_CALC); @@ -982,10 +982,12 @@ void interval_posts::flush() std::stable_sort(all_posts.begin(), all_posts.end(), sort_posts_by_date()); - // Determine the beginning interval by using the earliest post - if (all_posts.size() > 0 && all_posts.front() && - ! interval.find_period(all_posts.front()->date())) - throw_(std::logic_error, _("Failed to find period for interval report")); + // only if the interval has no start use the earliest post + if (!(interval.begin() && interval.find_period(*interval.begin()))) + // Determine the beginning interval by using the earliest post + if (all_posts.size() > 0 && all_posts.front() + && !interval.find_period(all_posts.front()->date())) + throw_(std::logic_error, _("Failed to find period for interval report")); // Walk the interval forward reporting all posts within each one // before moving on, until we reach the end of all_posts @@ -1243,19 +1245,34 @@ void generate_posts::add_post(const date_interval_t& period, post_t& post) void budget_posts::report_budget_items(const date_t& date) { + { // Cleanup pending items that finished before date + // We have to keep them until the last day they apply because operator() needs them to see if a + // posting is budgeted or not + std::list<pending_posts_list::iterator> posts_to_erase; + for (pending_posts_list::iterator i = pending_posts.begin(); i != pending_posts.end(); i++) { + pending_posts_list::value_type& pair(*i); + if (pair.first.finish && ! pair.first.start && pair.first.finish < date) { + posts_to_erase.push_back(i); + } + } + foreach (pending_posts_list::iterator& i, posts_to_erase) + pending_posts.erase(i); + } + if (pending_posts.size() == 0) return; bool reported; do { - std::list<pending_posts_list::iterator> posts_to_erase; - reported = false; for (pending_posts_list::iterator i = pending_posts.begin(); i != pending_posts.end(); i++) { pending_posts_list::value_type& pair(*i); + if (pair.first.finish && ! pair.first.start) + continue; // skip expired posts + optional<date_t> begin = pair.first.start; if (! begin) { optional<date_t> range_begin; @@ -1283,9 +1300,6 @@ void budget_posts::report_budget_items(const date_t& date) post_t& post = *pair.second; ++pair.first; - if (! pair.first.start) - posts_to_erase.push_back(i); - DEBUG("budget.generate", "Reporting budget for " << post.reported_account()->fullname()); @@ -1310,9 +1324,6 @@ void budget_posts::report_budget_items(const date_t& date) reported = true; } } - - foreach (pending_posts_list::iterator& i, posts_to_erase) - pending_posts.erase(i); } while (reported); } diff --git a/src/filters.h b/src/filters.h index 4aa8af7a..c1dc2e04 100644 --- a/src/filters.h +++ b/src/filters.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -237,17 +237,20 @@ class sort_posts : public item_handler<post_t> posts_deque posts; expr_t sort_order; + report_t& report; sort_posts(); public: - sort_posts(post_handler_ptr handler, const expr_t& _sort_order) - : item_handler<post_t>(handler), sort_order(_sort_order) { - TRACE_CTOR(sort_posts, "post_handler_ptr, const value_expr&"); + sort_posts(post_handler_ptr handler, const expr_t& _sort_order, + report_t& _report) + : item_handler<post_t>(handler), sort_order(_sort_order), report(_report) { + TRACE_CTOR(sort_posts, "post_handler_ptr, const value_expr&, report_t&"); } - sort_posts(post_handler_ptr handler, const string& _sort_order) - : item_handler<post_t>(handler), sort_order(_sort_order) { - TRACE_CTOR(sort_posts, "post_handler_ptr, const string&"); + sort_posts(post_handler_ptr handler, const string& _sort_order, + report_t& _report) + : item_handler<post_t>(handler), sort_order(_sort_order), report(_report) { + TRACE_CTOR(sort_posts, "post_handler_ptr, const string&, report_t&"); } virtual ~sort_posts() { TRACE_DTOR(sort_posts); @@ -280,15 +283,17 @@ class sort_xacts : public item_handler<post_t> sort_xacts(); public: - sort_xacts(post_handler_ptr handler, const expr_t& _sort_order) - : sorter(handler, _sort_order) { + sort_xacts(post_handler_ptr handler, const expr_t& _sort_order, + report_t& _report) + : sorter(handler, _sort_order, _report) { TRACE_CTOR(sort_xacts, - "post_handler_ptr, const value_expr&"); + "post_handler_ptr, const value_expr&, report_t&"); } - sort_xacts(post_handler_ptr handler, const string& _sort_order) - : sorter(handler, _sort_order) { + sort_xacts(post_handler_ptr handler, const string& _sort_order, + report_t& _report) + : sorter(handler, _sort_order, _report) { TRACE_CTOR(sort_xacts, - "post_handler_ptr, const string&"); + "post_handler_ptr, const string&, report_t&"); } virtual ~sort_xacts() { TRACE_DTOR(sort_xacts); @@ -560,9 +565,9 @@ public: last_display_total = value_t(); temps.clear(); - create_accounts(); - item_handler<post_t>::clear(); + + create_accounts(); } }; @@ -622,9 +627,9 @@ public: last_total = value_t(); temps.clear(); - create_accounts(); - item_handler<post_t>::clear(); + + create_accounts(); } }; diff --git a/src/flags.h b/src/flags.h index e6b66470..42e2719a 100644 --- a/src/flags.h +++ b/src/flags.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/format.cc b/src/format.cc index b6f0d5ae..bb578141 100644 --- a/src/format.cc +++ b/src/format.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/format.h b/src/format.h index 8856905d..15431cf1 100644 --- a/src/format.h +++ b/src/format.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/generate.cc b/src/generate.cc index c1ecb007..95cdfa2e 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/generate.h b/src/generate.h index d4f13070..5272c7db 100644 --- a/src/generate.h +++ b/src/generate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/global.cc b/src/global.cc index 6edc69ca..32d3cc5a 100644 --- a/src/global.cc +++ b/src/global.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -136,9 +136,7 @@ void global_scope_t::read_init() path init_file; if (HANDLED(init_file_)) { init_file=HANDLER(init_file_).str(); - if (exists(init_file)) { - parse_init(init_file); - } else { + if (!exists(init_file)) { throw_(parse_error, _f("Could not find specified init file %1%") % init_file); } } else { @@ -451,7 +449,7 @@ expr_t::func_t global_scope_t::look_for_command(scope_t& scope, void global_scope_t::visit_man_page() const { -#ifndef WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) int pid = fork(); if (pid < 0) { throw std::logic_error(_("Failed to fork child process")); diff --git a/src/global.h b/src/global.h index 42464e35..8f8266ac 100644 --- a/src/global.h +++ b/src/global.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -129,7 +129,7 @@ public: out << '-' << Ledger_VERSION_DATE; out << _(", the command-line accounting tool"); out << - _("\n\nCopyright (c) 2003-2016, John Wiegley. All rights reserved.\n\n\ + _("\n\nCopyright (c) 2003-2018, John Wiegley. All rights reserved.\n\n\ This program is made available under the terms of the BSD Public License.\n\ See LICENSE file included with the distribution for details and disclaimer."); out << std::endl; diff --git a/src/history.cc b/src/history.cc index 25d42b06..7c98182c 100644 --- a/src/history.cc +++ b/src/history.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/history.h b/src/history.h index 37efb068..11e29bd7 100644 --- a/src/history.h +++ b/src/history.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/item.cc b/src/item.cc index 0402f467..bd025c52 100644 --- a/src/item.cc +++ b/src/item.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -92,7 +92,7 @@ public: typedef std::pair<optional<value_t>, bool> tag_data_t; typedef std::map<string, tag_data_t, - function<bool(string, string)> > string_map; + std::function<bool(string, string)> > string_map; state_t _state; optional<date_t> _date; diff --git a/src/iterators.cc b/src/iterators.cc index 88233ea1..0a20eac6 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -201,7 +201,7 @@ void sorted_accounts_iterator::push_back(account_t& account) std::stable_sort(accounts_list.back().begin(), accounts_list.back().end(), - compare_items<account_t>(sort_cmp)); + compare_items<account_t>(sort_cmp, report)); #if DEBUG_ON if (SHOW_DEBUG("account.sorted")) { @@ -234,7 +234,7 @@ void sorted_accounts_iterator::sort_accounts(account_t& account, deque.push_back(pair.second); std::stable_sort(deque.begin(), deque.end(), - compare_items<account_t>(sort_cmp)); + compare_items<account_t>(sort_cmp, report)); #if DEBUG_ON if (SHOW_DEBUG("account.sorted")) { diff --git a/src/iterators.h b/src/iterators.h index a3f535b1..0eaa3cc2 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -50,6 +50,7 @@ namespace ledger { class journal_t; +class report_t; template <typename Derived, typename Value, typename CategoryOrTraversal> class iterator_facade_base @@ -279,8 +280,9 @@ class sorted_accounts_iterator : public iterator_facade_base<sorted_accounts_iterator, account_t *, boost::forward_traversal_tag> { - expr_t sort_cmp; - bool flatten_all; + expr_t sort_cmp; + report_t& report; + bool flatten_all; typedef std::deque<account_t *> accounts_deque_t; @@ -290,16 +292,21 @@ class sorted_accounts_iterator public: sorted_accounts_iterator(account_t& account, - const expr_t& _sort_cmp, bool _flatten_all) - : sort_cmp(_sort_cmp), flatten_all(_flatten_all) { + const expr_t& _sort_cmp, + report_t& _report, + bool _flatten_all) + : sort_cmp(_sort_cmp), report(_report), + flatten_all(_flatten_all) { push_back(account); increment(); - TRACE_CTOR(sorted_accounts_iterator, "account_t&, expr_t, bool"); + TRACE_CTOR(sorted_accounts_iterator, + "account_t&, expr_t, report_t&, bool"); } sorted_accounts_iterator(const sorted_accounts_iterator& i) : iterator_facade_base<sorted_accounts_iterator, account_t *, boost::forward_traversal_tag>(i), - sort_cmp(i.sort_cmp), flatten_all(i.flatten_all), + sort_cmp(i.sort_cmp), report(i.report), + flatten_all(i.flatten_all), accounts_list(i.accounts_list), sorted_accounts_i(i.sorted_accounts_i), sorted_accounts_end(i.sorted_accounts_end) { diff --git a/src/journal.cc b/src/journal.cc index 36fe5fc0..1df7a114 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/journal.h b/src/journal.h index 76e1735d..3fefe4e1 100644 --- a/src/journal.h +++ b/src/journal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/lookup.cc b/src/lookup.cc index 11b7db61..a88752f5 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/lookup.h b/src/lookup.h index 2c4e6575..a357cafe 100644 --- a/src/lookup.h +++ b/src/lookup.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/main.cc b/src/main.cc index 3a36280a..c8b9ec3a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -74,7 +74,7 @@ int main(int argc, char * argv[], char * envp[]) #endif std::signal(SIGINT, sigint_handler); -#ifndef WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) std::signal(SIGPIPE, sigpipe_handler); #endif diff --git a/src/mask.cc b/src/mask.cc index c6868dde..434acad6 100644 --- a/src/mask.cc +++ b/src/mask.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/option.cc b/src/option.cc index 7c5c5e07..ab6c37e0 100644 --- a/src/option.cc +++ b/src/option.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/option.h b/src/option.h index b06c1754..c9759924 100644 --- a/src/option.h +++ b/src/option.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/output.cc b/src/output.cc index 77083450..c2fa83ac 100644 --- a/src/output.cc +++ b/src/output.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -34,6 +34,7 @@ #include "output.h" #include "xact.h" #include "post.h" +#include "item.h" #include "account.h" #include "session.h" #include "report.h" @@ -281,8 +282,23 @@ void format_accounts::operator()(account_t& account) void report_accounts::flush() { std::ostream& out(report.output_stream); + format_t prepend_format; + std::size_t prepend_width; + + if (report.HANDLED(prepend_format_)) { + prepend_format.parse_format(report.HANDLER(prepend_format_).str()); + prepend_width = report.HANDLED(prepend_width_) + ? lexical_cast<std::size_t>(report.HANDLER(prepend_width_).str()) + : 0; + } foreach (accounts_pair& entry, accounts) { + if (prepend_format) { + bind_scope_t bound_scope(report, *entry.first); + out.width(static_cast<std::streamsize>(prepend_width)); + out << prepend_format(bound_scope); + } + if (report.HANDLED(count)) out << entry.second << ' '; out << *entry.first << '\n'; @@ -329,23 +345,29 @@ void report_tags::flush() } } -void report_tags::operator()(post_t& post) +void report_tags::gather_metadata(item_t& item) { - if (post.metadata) { - foreach (const item_t::string_map::value_type& data, *post.metadata) { - string tag=data.first; - if (report.HANDLED(values) && (data.second).first) { - tag+=": "+ (data.second).first.get().to_string(); - } - std::map<string, std::size_t>::iterator i = tags.find(tag); - if (i == tags.end()) - tags.insert(tags_pair(tag, 1)); - else - (*i).second++; - } + if (! item.metadata) + return; + foreach (const item_t::string_map::value_type& data, *item.metadata) { + string tag(data.first); + if (report.HANDLED(values) && data.second.first) + tag += ": " + data.second.first.get().to_string(); + + std::map<string, std::size_t>::iterator i = tags.find(tag); + if (i == tags.end()) + tags.insert(tags_pair(tag, 1)); + else + (*i).second++; } } +void report_tags::operator()(post_t& post) +{ + gather_metadata(*post.xact); + gather_metadata(post); +} + void report_commodities::flush() { std::ostream& out(report.output_stream); diff --git a/src/output.h b/src/output.h index e8c45337..f7dd98b8 100644 --- a/src/output.h +++ b/src/output.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -51,6 +51,7 @@ namespace ledger { class xact_t; class post_t; +class item_t; class report_t; class format_posts : public item_handler<post_t> @@ -208,6 +209,7 @@ public: } virtual void flush(); + virtual void gather_metadata(item_t& item); virtual void operator()(post_t& post); virtual void clear() { diff --git a/src/parser.cc b/src/parser.cc index 53b03a0c..5675aef8 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/parser.h b/src/parser.h index 913179a1..5f5bfd2c 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pool.cc b/src/pool.cc index dff02df8..c04d00b7 100644 --- a/src/pool.cc +++ b/src/pool.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -262,6 +262,9 @@ commodity_pool_t::exchange(const amount_t& amount, if (! cost.has_commodity()) per_unit_cost.clear_commodity(); + if (cost.has_annotation()) + per_unit_cost = per_unit_cost.strip_annotations(keep_details_t()); + DEBUG("commodity.prices.add", "exchange: per-unit-cost = " << per_unit_cost); // Do not record commodity exchanges where amount's commodity has a @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/post.cc b/src/post.cc index 8d2693c7..97f6b6d4 100644 --- a/src/post.cc +++ b/src/post.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/precmd.cc b/src/precmd.cc index af8c5ee0..7c2a791d 100644 --- a/src/precmd.cc +++ b/src/precmd.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/precmd.h b/src/precmd.h index 365cc1ba..41fab617 100644 --- a/src/precmd.h +++ b/src/precmd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/predicate.h b/src/predicate.h index aca44452..cf41ffe6 100644 --- a/src/predicate.h +++ b/src/predicate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/print.cc b/src/print.cc index 0cc23275..92323777 100644 --- a/src/print.cc +++ b/src/print.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -103,11 +103,13 @@ namespace { void print_xact(report_t& report, std::ostream& out, xact_t& xact) { format_type_t format_type = FMT_WRITTEN; + string format_str; optional<const char *> format; if (report.HANDLED(date_format_)) { format_type = FMT_CUSTOM; - format = report.HANDLER(date_format_).str().c_str(); + format_str = report.HANDLER(date_format_).str(); + format = format_str.c_str(); } std::ostringstream buf; diff --git a/src/print.h b/src/print.h index 70b26d65..902fcd9a 100644 --- a/src/print.h +++ b/src/print.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pstream.h b/src/pstream.h index fc7fc8ca..6b12dcf0 100644 --- a/src/pstream.h +++ b/src/pstream.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/ptree.cc b/src/ptree.cc index 534db003..1be6dec5 100644 --- a/src/ptree.cc +++ b/src/ptree.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/ptree.h b/src/ptree.h index ca7b46e2..9044f13b 100644 --- a/src/ptree.h +++ b/src/ptree.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_account.cc b/src/py_account.cc index c4a9ae07..59680a23 100644 --- a/src/py_account.cc +++ b/src/py_account.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_amount.cc b/src/py_amount.cc index 8a8ea871..2d99ddec 100644 --- a/src/py_amount.cc +++ b/src/py_amount.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_balance.cc b/src/py_balance.cc index 6a6c59fb..dc9975cf 100644 --- a/src/py_balance.cc +++ b/src/py_balance.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_commodity.cc b/src/py_commodity.cc index 5aafa6ce..c98a0def 100644 --- a/src/py_commodity.cc +++ b/src/py_commodity.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -243,9 +243,6 @@ namespace { void export_commodity() { -#if BOOST_VERSION >= 106000 - python::register_ptr_to_python< shared_ptr<commodity_pool_t> >(); -#endif class_< commodity_pool_t, shared_ptr<commodity_pool_t>, boost::noncopyable > ("CommodityPool", no_init) .add_property("null_commodity", diff --git a/src/py_expr.cc b/src/py_expr.cc index de3ac925..c4891ac9 100644 --- a/src/py_expr.cc +++ b/src/py_expr.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_format.cc b/src/py_format.cc index 4dcd4ba3..57100290 100644 --- a/src/py_format.cc +++ b/src/py_format.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_item.cc b/src/py_item.cc index 644b11f1..6207f69c 100644 --- a/src/py_item.cc +++ b/src/py_item.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_journal.cc b/src/py_journal.cc index c1c38a90..08e9902e 100644 --- a/src/py_journal.cc +++ b/src/py_journal.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -135,6 +135,11 @@ namespace { return journal.find_account(name, auto_create); } + account_t * py_register_account(journal_t& journal, const string& name, post_t* post) + { + return journal.register_account(name, post, journal.master); + } + #if 0 std::size_t py_read(journal_t& journal, const string& pathname) { @@ -232,9 +237,6 @@ void export_journal() boost::noncopyable >("PostHandler") ; -#if BOOST_VERSION >= 106000 - python::register_ptr_to_python< shared_ptr<collector_wrapper> >(); -#endif class_< collector_wrapper, shared_ptr<collector_wrapper>, boost::noncopyable >("PostCollectorWrapper", no_init) .def("__len__", &collector_wrapper::length) @@ -289,6 +291,14 @@ void export_journal() return_internal_reference<1, with_custodian_and_ward_postcall<1, 0> >()) + .def("register_account", py_register_account, + return_internal_reference<1, + with_custodian_and_ward_postcall<1, 0> >()) + + .def("expand_aliases", &journal_t::expand_aliases, + return_internal_reference<1, + with_custodian_and_ward_postcall<1, 0> >()) + .def("add_xact", &journal_t::add_xact) .def("remove_xact", &journal_t::remove_xact) diff --git a/src/py_post.cc b/src/py_post.cc index 85d4701a..6195570b 100644 --- a/src/py_post.cc +++ b/src/py_post.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_session.cc b/src/py_session.cc index 0ddf66d2..1825fc14 100644 --- a/src/py_session.cc +++ b/src/py_session.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_times.cc b/src/py_times.cc index be3e4f31..bbd6f69a 100644 --- a/src/py_times.cc +++ b/src/py_times.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_utils.cc b/src/py_utils.cc index 731294b2..c2f84f55 100644 --- a/src/py_utils.cc +++ b/src/py_utils.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/py_value.cc b/src/py_value.cc index 60ba4cf2..f4f63946 100644 --- a/src/py_value.cc +++ b/src/py_value.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -325,7 +325,6 @@ void export_value() .def("to_mask", &value_t::to_mask) .def("to_sequence", &value_t::to_sequence) - .def("__unicode__", py_dump_relaxed) .def("__repr__", py_dump) .def("casted", &value_t::casted) @@ -372,6 +371,7 @@ void export_value() register_optional_to_python<value_t>(); + implicitly_convertible<bool, value_t>(); implicitly_convertible<long, value_t>(); implicitly_convertible<string, value_t>(); implicitly_convertible<amount_t, value_t>(); diff --git a/src/py_xact.cc b/src/py_xact.cc index f7283989..70dba5a0 100644 --- a/src/py_xact.cc +++ b/src/py_xact.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pyfstream.h b/src/pyfstream.h index a90b121c..5be3a1c4 100644 --- a/src/pyfstream.h +++ b/src/pyfstream.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pyinterp.cc b/src/pyinterp.cc index 81924c86..19430bef 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pyinterp.h b/src/pyinterp.h index 9c24b0cf..51d6c8ec 100644 --- a/src/pyinterp.h +++ b/src/pyinterp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pyledger.cc b/src/pyledger.cc index a516f66d..d8832220 100644 --- a/src/pyledger.cc +++ b/src/pyledger.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/pyutils.h b/src/pyutils.h index 07ce7bdd..641dbd3b 100644 --- a/src/pyutils.h +++ b/src/pyutils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/query.cc b/src/query.cc index a2117cfe..fc1d4ff0 100644 --- a/src/query.cc +++ b/src/query.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/query.h b/src/query.h index cbfac6bc..f7d48d32 100644 --- a/src/query.h +++ b/src/query.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/quotes.cc b/src/quotes.cc index 2777974e..50791560 100644 --- a/src/quotes.cc +++ b/src/quotes.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -62,7 +62,7 @@ commodity_quote_from_script(commodity_t& commodity, DEBUG("commodity.download", "invoking command: " << getquote_cmd); bool success = true; -#ifndef WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) if (FILE * fp = popen(getquote_cmd.c_str(), "r")) { if (std::feof(fp) || ! std::fgets(buf, 255, fp)) success = false; diff --git a/src/quotes.h b/src/quotes.h index b3978171..f1b347de 100644 --- a/src/quotes.h +++ b/src/quotes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/report.cc b/src/report.cc index 9e480ea5..13e6a61f 100644 --- a/src/report.cc +++ b/src/report.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -57,13 +57,16 @@ void report_t::normalize_options(const string& verb) // Patch up some of the reporting options based on what kind of // command it was. -#if HAVE_ISATTY +#ifdef HAVE_ISATTY if (! HANDLED(force_color)) { if (! HANDLED(no_color) && isatty(STDOUT_FILENO)) HANDLER(color).on("?normalize"); if (HANDLED(color) && ! isatty(STDOUT_FILENO)) HANDLER(color).off(); } + else { + HANDLER(color).on("?normalize"); + } if (! HANDLED(force_pager)) { if (HANDLED(pager_) && ! isatty(STDOUT_FILENO)) HANDLER(pager_).off(); @@ -181,14 +184,14 @@ void report_t::normalize_options(const string& verb) } long cols = 0; -#if HAVE_IOCTL +#ifdef HAVE_IOCTL struct winsize ws; #endif if (HANDLED(columns_)) cols = lexical_cast<long>(HANDLER(columns_).value); else if (const char * columns = std::getenv("COLUMNS")) cols = lexical_cast<long>(columns); -#if HAVE_IOCTL +#ifdef HAVE_IOCTL else if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) cols = ws.ws_col; #endif @@ -428,8 +431,9 @@ namespace { } else { expr_t sort_expr(report.HANDLER(sort_).str()); sort_expr.set_context(&report); - sorted_accounts_iterator iter(*report.session.journal->master, - sort_expr, report.HANDLED(flat)); + sorted_accounts_iterator iter( + *report.session.journal->master, sort_expr, report, + report.HANDLED(flat)); pass_down_accounts<sorted_accounts_iterator> (handler, iter, predicate_t(report.HANDLER(display_).str(), report.what_to_keep()), report); @@ -441,8 +445,9 @@ namespace { } else { expr_t sort_expr(report.HANDLER(sort_).str()); sort_expr.set_context(&report); - sorted_accounts_iterator iter(*report.session.journal->master, - sort_expr, report.HANDLED(flat)); + sorted_accounts_iterator iter( + *report.session.journal->master, sort_expr, report, + report.HANDLED(flat)); pass_down_accounts<sorted_accounts_iterator>(handler, iter); } } @@ -628,18 +633,15 @@ value_t report_t::fn_trim(call_scope_t& args) std::strcpy(buf.get(), temp.c_str()); const char * p = buf.get(); - while (*p && std::isspace(*p)) + const char * e = buf.get() + temp.length() - 1; + + while (p <= e && std::isspace(*p)) p++; - const char * e = buf.get() + temp.length() - 1; while (e > p && std::isspace(*e)) e--; - if (e == p) { - return string_value(empty_string); - } - else if (e < p) { - assert(false); + if (p > e) { return string_value(empty_string); } else { @@ -756,6 +758,23 @@ value_t report_t::fn_quoted(call_scope_t& args) return string_value(out.str()); } +value_t report_t::fn_quoted_rfc4180(call_scope_t& args) +{ + std::ostringstream out; + + out << '"'; + string arg(args.get<string>(0)); + foreach (const char ch, arg) { + if (ch == '"') + out << '"' << '"'; + else + out << ch; + } + out << '"'; + + return string_value(out.str()); +} + value_t report_t::fn_join(call_scope_t& args) { std::ostringstream out; @@ -822,6 +841,13 @@ value_t report_t::fn_commodity(call_scope_t& args) return string_value(args.get<amount_t>(0).commodity().symbol()); } +value_t report_t::fn_clear_commodity(call_scope_t& args) +{ + amount_t amt(args.get<amount_t>(0)); + amt.clear_commodity(); + return amt; +} + value_t report_t::fn_nail_down(call_scope_t& args) { value_t arg0(args[0]); @@ -1365,6 +1391,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, return MAKE_FUNCTOR(report_t::fn_commodity); else if (is_eq(p, "ceiling")) return MAKE_FUNCTOR(report_t::fn_ceiling); + else if (is_eq(p, "clear_commodity")) + return MAKE_FUNCTOR(report_t::fn_clear_commodity); break; case 'd': @@ -1439,6 +1467,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, case 'q': if (is_eq(p, "quoted")) return MAKE_FUNCTOR(report_t::fn_quoted); + else if (is_eq(p, "quoted_rfc4180")) + return MAKE_FUNCTOR(report_t::fn_quoted_rfc4180); else if (is_eq(p, "quantity")) return MAKE_FUNCTOR(report_t::fn_quantity); break; diff --git a/src/report.h b/src/report.h index 9110c5b0..1bda0407 100644 --- a/src/report.h +++ b/src/report.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -175,12 +175,14 @@ public: value_t fn_truncated(call_scope_t& scope); value_t fn_floor(call_scope_t& scope); value_t fn_ceiling(call_scope_t& scope); + value_t fn_clear_commodity(call_scope_t& scope); value_t fn_round(call_scope_t& scope); value_t fn_roundto(call_scope_t& scope); value_t fn_unround(call_scope_t& scope); value_t fn_abs(call_scope_t& scope); value_t fn_justify(call_scope_t& scope); value_t fn_quoted(call_scope_t& scope); + value_t fn_quoted_rfc4180(call_scope_t& scope); value_t fn_join(call_scope_t& scope); value_t fn_format_date(call_scope_t& scope); value_t fn_format_datetime(call_scope_t& scope); @@ -403,6 +405,7 @@ public: OPTION(report_t, auto_match); OPTION_(report_t, average, DO() { // -A + OTHER(empty).on(whence); OTHER(display_total_) .on(whence, "count>0?(display_total/count):0"); }); @@ -457,12 +460,12 @@ public: (report_t, budget_format_, CTOR(report_t, budget_format_) { on(none, - "%(justify(scrub(get_at(display_total, 0)), 12, -1, true, color))" - " %(justify(-scrub(get_at(display_total, 1)), 12, " - " 12 + 1 + 12, true, color))" - " %(justify(scrub(get_at(display_total, 1) + " - " get_at(display_total, 0)), 12, " - " 12 + 1 + 12 + 1 + 12, true, color))" + "%(justify(scrub(get_at(display_total, 0)), int(amount_width), -1, true, color))" + " %(justify(-scrub(get_at(display_total, 1)), int(amount_width), " + " int(amount_width) + 1 + int(amount_width), true, color))" + " %(justify(scrub((get_at(display_total, 1) || 0) + " + " (get_at(display_total, 0) || 0)), int(amount_width), " + " int(amount_width) + 1 + int(amount_width) + 1 + int(amount_width), true, color))" " %(ansify_if(" " justify((get_at(display_total, 1) ? " " (100% * quantity(scrub(get_at(display_total, 0)))) / " @@ -792,7 +795,8 @@ public: OPTION(report_t, output_); // -o -#if HAVE_ISATTY +// setenv() is not available on WIN32 +#if defined(HAVE_ISATTY) and !defined(_WIN32) and !defined(__CYGWIN__) OPTION__ (report_t, pager_, CTOR(report_t, pager_) { diff --git a/src/scope.cc b/src/scope.cc index 03387549..281d843b 100644 --- a/src/scope.cc +++ b/src/scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/scope.h b/src/scope.h index 147b400f..8ec1a44f 100644 --- a/src/scope.h +++ b/src/scope.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/select.cc b/src/select.cc index 1c69b2bf..187387d8 100644 --- a/src/select.cc +++ b/src/select.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -145,14 +145,14 @@ value_t select_command(call_scope_t& args) string thus_far = ""; std::size_t cols = 0; -#if HAVE_IOCTL +#ifdef HAVE_IOCTL struct winsize ws; #endif if (report.HANDLED(columns_)) cols = lexical_cast<std::size_t>(report.HANDLER(columns_).value); else if (const char * columns_env = std::getenv("COLUMNS")) cols = lexical_cast<std::size_t>(columns_env); -#if HAVE_IOCTL +#ifdef HAVE_IOCTL else if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) cols = ws.ws_col; #endif diff --git a/src/select.h b/src/select.h index 89d7c989..ea2e3708 100644 --- a/src/select.h +++ b/src/select.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/session.cc b/src/session.cc index 8d03431f..427850d9 100644 --- a/src/session.cc +++ b/src/session.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -284,7 +284,7 @@ value_t session_t::fn_str(call_scope_t& args) value_t session_t::fn_lot_price(call_scope_t& args) { - amount_t amt(args.get<amount_t>(1, false)); + amount_t amt(args.get<amount_t>(0, false)); if (amt.has_annotation() && amt.annotation().price) return *amt.annotation().price; else @@ -292,7 +292,7 @@ value_t session_t::fn_lot_price(call_scope_t& args) } value_t session_t::fn_lot_date(call_scope_t& args) { - amount_t amt(args.get<amount_t>(1, false)); + amount_t amt(args.get<amount_t>(0, false)); if (amt.has_annotation() && amt.annotation().date) return *amt.annotation().date; else @@ -300,7 +300,7 @@ value_t session_t::fn_lot_date(call_scope_t& args) } value_t session_t::fn_lot_tag(call_scope_t& args) { - amount_t amt(args.get<amount_t>(1, false)); + amount_t amt(args.get<amount_t>(0, false)); if (amt.has_annotation() && amt.annotation().tag) return string_value(*amt.annotation().tag); else diff --git a/src/session.h b/src/session.h index 3d35a93e..4dce3816 100644 --- a/src/session.h +++ b/src/session.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -52,6 +52,16 @@ namespace ledger { class xact_t; +struct ComparePaths +{ + bool operator()(const path& p1, const path& p2) const + { + return p1 < p2 && !boost::filesystem::equivalent(p1, p2); + } +}; + +#define COMMA , + class session_t : public symbol_scope_t { friend void set_session_context(session_t * session); diff --git a/src/stats.cc b/src/stats.cc index 2d1f8dc7..2c6d9069 100644 --- a/src/stats.cc +++ b/src/stats.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/stats.h b/src/stats.h index dfb9e796..c8d7ee4c 100644 --- a/src/stats.h +++ b/src/stats.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/stream.cc b/src/stream.cc index 60b0dc55..c4bbb42e 100644 --- a/src/stream.cc +++ b/src/stream.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -58,7 +58,7 @@ namespace { */ int do_fork(std::ostream ** os, const path& pager_path) { -#ifndef WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) int pfd[2]; int status = pipe(pfd); @@ -115,7 +115,7 @@ void output_stream_t::initialize(const optional<path>& output_file, void output_stream_t::close() { -#ifndef WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) if (os != &std::cout) { checked_delete(os); os = &std::cout; diff --git a/src/stream.h b/src/stream.h index 996cffb1..dd171284 100644 --- a/src/stream.h +++ b/src/stream.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/strptime.cc b/src/strptime.cc index b31954f4..069b9267 100644 --- a/src/strptime.cc +++ b/src/strptime.cc @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. - -#ifdef WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) // Implement strptime under windows #include "strptime.h" @@ -22,6 +21,22 @@ #include <ctype.h> #include <string.h> +#if defined(__CYGWIN__) +// Define strnicmp for Cygwin. +#ifndef strcmpi +#define strcmpi strcasecmp +#endif +#ifndef stricmp +#define stricmp strcasecmp +#endif +#ifndef strncmpi +#define strncmpi strncasecmp +#endif +#ifndef strnicmp +#define strnicmp strncasecmp +#endif +#endif + static const char* kWeekFull[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" @@ -70,14 +85,14 @@ static char* _strptime(const char *s, const char *format, struct tm *tm) { case 'A': tm->tm_wday = -1; for (int i = 0; i < 7; ++i) { - len = static_cast<int>(strlen(kWeekAbbr[i])); - if (strnicmp(kWeekAbbr[i], s, len) == 0) { + len = static_cast<int>(strlen(kWeekFull[i])); + if (strnicmp(kWeekFull[i], s, len) == 0) { tm->tm_wday = i; break; } - len = static_cast<int>(strlen(kWeekFull[i])); - if (strnicmp(kWeekFull[i], s, len) == 0) { + len = static_cast<int>(strlen(kWeekAbbr[i])); + if (strnicmp(kWeekAbbr[i], s, len) == 0) { tm->tm_wday = i; break; } @@ -92,14 +107,14 @@ static char* _strptime(const char *s, const char *format, struct tm *tm) { case 'h': tm->tm_mon = -1; for (int i = 0; i < 12; ++i) { - len = static_cast<int>(strlen(kMonthAbbr[i])); - if (strnicmp(kMonthAbbr[i], s, len) == 0) { + len = static_cast<int>(strlen(kMonthFull[i])); + if (strnicmp(kMonthFull[i], s, len) == 0) { tm->tm_mon = i; break; } - len = static_cast<int>(strlen(kMonthFull[i])); - if (strnicmp(kMonthFull[i], s, len) == 0) { + len = static_cast<int>(strlen(kMonthAbbr[i])); + if (strnicmp(kMonthAbbr[i], s, len) == 0) { tm->tm_mon = i; break; } @@ -186,4 +201,4 @@ char* strptime(const char *buf, const char *fmt, struct tm *tm) { return _strptime(buf, fmt, tm); } -#endif // WIN32 +#endif // _WIN32 diff --git a/src/system.hh.in b/src/system.hh.in index 54bcf7a9..38ac1e63 100644 --- a/src/system.hh.in +++ b/src/system.hh.in @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -60,12 +60,12 @@ #define HAVE_EDIT @HAVE_EDIT@ #define HAVE_GETTEXT @HAVE_GETTEXT@ -#define HAVE_ACCESS @HAVE_ACCESS@ -#define HAVE_REALPATH @HAVE_REALPATH@ -#define HAVE_GETPWUID @HAVE_GETPWUID@ -#define HAVE_GETPWNAM @HAVE_GETPWNAM@ -#define HAVE_IOCTL @HAVE_IOCTL@ -#define HAVE_ISATTY @HAVE_ISATTY@ +#cmakedefine HAVE_ACCESS +#cmakedefine HAVE_REALPATH +#cmakedefine HAVE_GETPWUID +#cmakedefine HAVE_GETPWNAM +#cmakedefine HAVE_IOCTL +#cmakedefine HAVE_ISATTY #define HAVE_UNIX_PIPES @HAVE_UNIX_PIPES@ @@ -144,16 +144,16 @@ typedef std::ostream::pos_type ostream_pos_type; #endif #include <sys/stat.h> -#if defined(WIN32) +#if defined(_WIN32) || defined(__CYGWIN__) #include <io.h> #else #include <unistd.h> #endif -#if HAVE_GETPWUID || HAVE_GETPWNAM +#if defined(HAVE_GETPWUID) || defined(HAVE_GETPWNAM) #include <pwd.h> #endif -#if HAVE_IOCTL +#ifdef HAVE_IOCTL #include <sys/ioctl.h> #endif diff --git a/src/temps.cc b/src/temps.cc index b8e7bfb6..7ff5ec94 100644 --- a/src/temps.cc +++ b/src/temps.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/temps.h b/src/temps.h index eb2b9b23..a28966fe 100644 --- a/src/temps.h +++ b/src/temps.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/textual.cc b/src/textual.cc index c97b8b01..3416073b 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -567,6 +567,9 @@ void instance_t::automated_xact_directive(char * line) expr_t::ptr_op_t expr = query.parse_args(string_value(skip_ws(line + 1)).to_sequence(), keeper, false, true); + if (!expr) { + throw parse_error(_("Expected predicate after '='")); + } unique_ptr<auto_xact_t> ae(new auto_xact_t(predicate_t(expr, keeper))); ae->pos = position_t(); @@ -725,15 +728,12 @@ void instance_t::include_directive(char * line) if (line[0] != '/' && line[0] != '\\' && line[0] != '~') { DEBUG("textual.include", "received a relative path"); DEBUG("textual.include", "parent file path: " << context.pathname); - string pathstr(context.pathname.string()); - string::size_type pos = pathstr.rfind('/'); - if (pos == string::npos) - pos = pathstr.rfind('\\'); - if (pos != string::npos) { - filename = path(string(pathstr, 0, pos + 1)) / line; - DEBUG("textual.include", "normalized path: " << filename.string()); - } else { + path parent_path = context.pathname.parent_path(); + if (parent_path.empty()) { filename = path(string(".")) / line; + } else { + filename = parent_path / line; + DEBUG("textual.include", "normalized path: " << filename.string()); } } else { filename = line; @@ -1132,6 +1132,7 @@ void instance_t::commodity_format_directive(commodity_t&, string format) trim(format); amount_t amt; amt.parse(format); + amt.commodity().add_flags(COMMODITY_STYLE_NO_MIGRATE); VERIFY(amt.valid()); } @@ -1647,53 +1648,84 @@ post_t * instance_t::parse_post(char * line, } DEBUG("textual.parse", "line " << context.linenum << ": " - << "POST assign: parsed amt = " << *post->assigned_amount); + << "POST assign: parsed balance amount = " << *post->assigned_amount); - amount_t& amt(*post->assigned_amount); + const amount_t& amt(*post->assigned_amount); value_t account_total (post->account->amount().strip_annotations(keep_details_t())); DEBUG("post.assign", "line " << context.linenum << ": " << "account balance = " << account_total); - DEBUG("post.assign", - "line " << context.linenum << ": " << "post amount = " << amt); + DEBUG("post.assign", "line " << context.linenum << ": " + << "post amount = " << amt << " (is_zero = " << amt.is_zero() << ")"); - amount_t diff = amt; + balance_t diff = amt; switch (account_total.type()) { case value_t::AMOUNT: diff -= account_total.as_amount(); + DEBUG("textual.parse", "line " << context.linenum << ": " + << "Subtracting amount " << account_total.as_amount() << " from diff, yielding " << diff); break; case value_t::BALANCE: - if (optional<amount_t> comm_bal = - account_total.as_balance().commodity_amount(amt.commodity())) - diff -= *comm_bal; + diff -= account_total.as_balance(); + DEBUG("textual.parse", "line " << context.linenum << ": " + << "Subtracting balance " << account_total.as_balance() << " from diff, yielding " << diff); break; default: break; } - amount_t tot = amt - diff; - DEBUG("post.assign", "line " << context.linenum << ": " << "diff = " << diff); DEBUG("textual.parse", "line " << context.linenum << ": " << "POST assign: diff = " << diff); - if (! diff.is_zero()) { - if (! post->amount.is_null()) { - diff -= post->amount; - if (! no_assertions && ! diff.is_zero()) - throw_(parse_error, - _f("Balance assertion off by %1% (expected to see %2%)") - % diff % tot); + // Subtract amounts from previous posts to this account in the xact. + for (post_t* p : xact->posts) { + if (p->account == post->account) { + diff -= p->amount; + DEBUG("textual.parse", "line " << context.linenum << ": " + << "Subtracting " << p->amount << ", diff = " << diff); + } + } + + // If amt has a commodity, restrict balancing to that. Otherwise, it's the blanket '0' and + // check that all of them are zero. + if (amt.has_commodity()) { + DEBUG("textual.parse", "line " << context.linenum << ": " + << "Finding commodity " << amt.commodity() << " (" << amt << ") in balance " << diff); + optional<amount_t> wanted_commodity = diff.commodity_amount(amt.commodity()); + if (!wanted_commodity) { + diff = amt - amt; // this is '0' with the correct commodity. } else { - post->amount = diff; + diff = *wanted_commodity; + } + DEBUG("textual.parse", "line " << context.linenum << ": " + << "Diff is now " << diff); + } + + if (post->amount.is_null()) { + // balance assignment + if (! diff.is_zero()) { + // This will fail if there are more than 1 commodity in diff, which is wanted, + // as amount cannot store more than 1 commodity. + post->amount = diff.to_amount(); DEBUG("textual.parse", "line " << context.linenum << ": " << "Overwrite null posting"); } + } else { + // balance assertion + diff -= post->amount; + if (! no_assertions && ! diff.is_zero()) { + balance_t tot = -diff + amt; + DEBUG("textual.parse", "Balance assertion: off by " << diff << " (expected to see " << tot << ")"); + throw_(parse_error, + _f("Balance assertion off by %1% (expected to see %2%)") + % diff.to_string() % tot.to_string()); + } } if (stream.eof()) diff --git a/src/timelog.cc b/src/timelog.cc index 870a4b4b..2a618afd 100644 --- a/src/timelog.cc +++ b/src/timelog.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/timelog.h b/src/timelog.h index 95a87eae..4e7d2bb4 100644 --- a/src/timelog.h +++ b/src/timelog.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/times.cc b/src/times.cc index b9c8fc01..eda71ae7 100644 --- a/src/times.cc +++ b/src/times.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -33,7 +33,7 @@ #include "times.h" -#ifdef WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) #include "strptime.h" #endif @@ -420,7 +420,6 @@ class date_parser_t TOK_DASH, TOK_DOT, - TOK_A_YEAR, TOK_A_MONTH, TOK_A_WDAY, @@ -512,9 +511,6 @@ class date_parser_t case TOK_SLASH: return "/"; case TOK_DASH: return "-"; case TOK_DOT: return "."; - case TOK_A_YEAR: - out << boost::get<date_specifier_t::year_type>(*value); - break; case TOK_A_MONTH: out << date_specifier_t::month_type (boost::get<date_time::months_of_year>(*value)); @@ -566,7 +562,6 @@ class date_parser_t case TOK_SLASH: out << "TOK_SLASH"; break; case TOK_DASH: out << "TOK_DASH"; break; case TOK_DOT: out << "TOK_DOT"; break; - case TOK_A_YEAR: out << "TOK_A_YEAR"; break; case TOK_A_MONTH: out << "TOK_A_MONTH"; break; case TOK_A_WDAY: out << "TOK_A_WDAY"; break; case TOK_AGO: out << "TOK_AGO"; break; @@ -727,7 +722,11 @@ void date_parser_t::determine_when(date_parser_t::lexer_t::token_t& tok, when += gregorian::days(amount * adjust); break; default: - specifier.day = date_specifier_t::day_type(amount); + if (amount > 31) { + specifier.year = date_specifier_t::year_type(amount); + } else { + specifier.day = date_specifier_t::day_type(amount); + } break; } @@ -832,16 +831,13 @@ void date_parser_t::determine_when(date_parser_t::lexer_t::token_t& tok, break; } - case lexer_t::token_t::TOK_A_YEAR: - specifier.year = boost::get<date_specifier_t::year_type>(*tok.value); - break; case lexer_t::token_t::TOK_A_MONTH: specifier.month = date_specifier_t::month_type (boost::get<date_time::months_of_year>(*tok.value)); tok = lexer.peek_token(); switch (tok.kind) { - case lexer_t::token_t::TOK_A_YEAR: + case lexer_t::token_t::TOK_INT: specifier.year = boost::get<date_specifier_t::year_type>(*tok.value); break; case lexer_t::token_t::END_REACHED: @@ -898,12 +894,6 @@ date_interval_t date_parser_t::parse() determine_when(tok, *inclusion_specifier); break; - case lexer_t::token_t::TOK_A_YEAR: - if (! inclusion_specifier) - inclusion_specifier = date_specifier_t(); - determine_when(tok, *inclusion_specifier); - break; - case lexer_t::token_t::TOK_A_MONTH: if (! inclusion_specifier) inclusion_specifier = date_specifier_t(); @@ -1304,21 +1294,35 @@ void date_interval_t::stabilize(const optional<date_t>& date) #endif date_t when = start ? *start : *date; - - if (duration->quantum == date_duration_t::MONTHS || - duration->quantum == date_duration_t::QUARTERS || - duration->quantum == date_duration_t::YEARS) { + switch (duration->quantum) { + case date_duration_t::MONTHS: + case date_duration_t::QUARTERS: + case date_duration_t::YEARS: + // These start on most recent period start quantum before when DEBUG("times.interval", - "stabilize: monthly, quarterly or yearly duration"); + "stabilize: monthly, quarterly or yearly duration"); start = date_duration_t::find_nearest(when, duration->quantum); - } else { - DEBUG("times.interval", "stabilize: daily or weekly duration"); - start = date_duration_t::find_nearest(when - gregorian::days(400), - duration->quantum); + break; + case date_duration_t::WEEKS: + // Weeks start on the beginning of week prior to 400 remainder period length + // Either the first quanta of the period or the last quanta of the period seems more sensible + // implies period is never less than 400 days not too unreasonable + DEBUG("times.interval", "stabilize: weekly duration"); + { + int period = duration->length * 7; + start = date_duration_t::find_nearest( + when - gregorian::days(period + 400 % period), duration->quantum); + } + break; + default: + // multiples of days have a quanta of 1 day so should not have the start date adjusted to a quanta + DEBUG("times.interval", + "stabilize: daily duration - stable by definition"); + start = when; + break; } - DEBUG("times.interval", - "stabilize: beginning start date = " << *start); + DEBUG("times.interval", "stabilize: beginning start date = " << *start); while (*start < *date) { date_interval_t next_interval(*this); @@ -1328,7 +1332,7 @@ void date_interval_t::stabilize(const optional<date_t>& date) *this = next_interval; } else { end_of_duration = none; - next = none; + next = none; break; } } @@ -1598,13 +1602,8 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token() if (! term.empty()) { if (std::isdigit(term[0])) { - if (term.length() == 4) - return token_t(token_t::TOK_A_YEAR, - token_t::content_t - (lexical_cast<date_specifier_t::year_type>(term))); - else - return token_t(token_t::TOK_INT, - token_t::content_t(lexical_cast<unsigned short>(term))); + return token_t(token_t::TOK_INT, + token_t::content_t(lexical_cast<unsigned short>(term))); } else if (std::isalpha(term[0])) { to_lower(term); diff --git a/src/times.h b/src/times.h index df833958..71ad6e3e 100644 --- a/src/times.h +++ b/src/times.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/token.cc b/src/token.cc index 0bbff6ea..1ec052ed 100644 --- a/src/token.cc +++ b/src/token.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -303,8 +303,8 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags) kind = SLASH; } else { // terminal context // Read in the regexp - char buf[256]; - READ_INTO_(in, buf, 255, c, length, c != '/'); + char buf[4096]; + READ_INTO_(in, buf, 4095, c, length, c != '/'); if (c != '/') expected('/', c); in.get(c); diff --git a/src/token.h b/src/token.h index b9ccde86..5d9f1fac 100644 --- a/src/token.h +++ b/src/token.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/unistring.h b/src/unistring.h index fc37c9f2..8cc4a9cd 100644 --- a/src/unistring.h +++ b/src/unistring.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/utils.cc b/src/utils.cc index 947f2408..23dc7205 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -807,7 +807,7 @@ path expand_path(const path& pathname) if (path_string.length() == 1 || pos == 1) { pfx = std::getenv("HOME"); -#if HAVE_GETPWUID +#ifdef HAVE_GETPWUID if (! pfx) { // Punt. We're trying to expand ~/, but HOME isn't set struct passwd * pw = getpwuid(getuid()); @@ -816,7 +816,7 @@ path expand_path(const path& pathname) } #endif } -#if HAVE_GETPWNAM +#ifdef HAVE_GETPWNAM else { string user(path_string, 1, pos == string::npos ? string::npos : pos - 1); diff --git a/src/utils.h b/src/utils.h index 42ea2ae9..857b8289 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -44,7 +44,11 @@ #ifndef _UTILS_H #define _UTILS_H +#if (BOOST_VERSION >= 106600) +#include <boost/uuid/detail/sha1.hpp> +#else #include <boost/uuid/sha1.hpp> +#endif /** * @name Default values @@ -496,7 +500,7 @@ inline T& downcast(U& object) { path resolve_path(const path& pathname); -#if HAVE_REALPATH +#ifdef HAVE_REALPATH extern "C" char * realpath(const char *, char resolved_path[]); #endif diff --git a/src/value.cc b/src/value.cc index 878d7349..1841505d 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/value.h b/src/value.h index eb0c7c76..35581bfb 100644 --- a/src/value.h +++ b/src/value.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/views.cc b/src/views.cc index 65d21a9a..85128307 100644 --- a/src/views.cc +++ b/src/views.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/views.h b/src/views.h index 070ac22d..61929dcf 100644 --- a/src/views.h +++ b/src/views.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/xact.cc b/src/xact.cc index 2524889d..5df9ebc5 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -145,7 +145,7 @@ namespace { first = false; } else { unique_ptr<post_t> p(new post_t(null_post->account, amount.negated(), - ITEM_GENERATED | POST_CALCULATED)); + null_post->flags() | ITEM_GENERATED | POST_CALCULATED)); p->set_state(null_post->state()); xact.add_post(p.release()); } @@ -396,9 +396,9 @@ bool xact_base_t::finalize() } if (post->has_flags(POST_DEFERRED)) - post->account->add_deferred_post(id(), post); - else - post->account->add_post(post); + post->account->add_deferred_post(id(), post); + else + post->account->add_post(post); post->xdata().add_flags(POST_EXT_VISITED); post->account->xdata().add_flags(ACCOUNT_EXT_VISITED); @@ -806,6 +806,10 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context) xact.add_post(new_post); new_post->account->add_post(new_post); + // Add flags so this post updates the account balance + new_post->xdata().add_flags(POST_EXT_VISITED); + new_post->account->xdata().add_flags(ACCOUNT_EXT_VISITED); + if (new_post->must_balance()) needs_further_verification = true; } @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2016, John Wiegley. All rights reserved. + * Copyright (c) 2003-2018, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are |