summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account.cc4
-rw-r--r--src/amount.cc23
-rw-r--r--src/amount.h9
-rw-r--r--src/balance.h11
-rw-r--r--src/context.h12
-rw-r--r--src/csv.cc2
-rw-r--r--src/error.cc2
-rw-r--r--src/filters.cc11
-rw-r--r--src/global.cc7
-rw-r--r--src/global.h14
-rw-r--r--src/history.cc4
-rw-r--r--src/history.h1
-rw-r--r--src/item.cc25
-rw-r--r--src/journal.cc13
-rw-r--r--src/main.cc4
-rw-r--r--src/post.h2
-rw-r--r--src/print.cc13
-rw-r--r--src/py_xact.cc6
-rw-r--r--src/report.cc33
-rw-r--r--src/report.h3
-rw-r--r--src/session.cc2
-rw-r--r--src/textual.cc13
-rw-r--r--src/utils.cc8
-rw-r--r--src/value.cc23
-rw-r--r--src/value.h7
-rw-r--r--src/xact.cc60
26 files changed, 250 insertions, 62 deletions
diff --git a/src/account.cc b/src/account.cc
index 72709f95..8a5cdffa 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -380,7 +380,9 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
break;
case 'd':
- if (fn_name == "depth")
+ if (fn_name == "date")
+ return WRAP_FUNCTOR(get_wrapper<&get_latest>);
+ else if (fn_name == "depth")
return WRAP_FUNCTOR(get_wrapper<&get_depth>);
else if (fn_name == "depth_spacer")
return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>);
diff --git a/src/amount.cc b/src/amount.cc
index 6ecb3558..cba9a282 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -670,10 +670,27 @@ void amount_t::in_place_floor()
_dup();
- std::ostringstream out;
- stream_out_mpq(out, MP(quantity), precision_t(0), -1, GMP_RNDZ);
+ mpz_t quot;
+ mpz_init(quot);
+ mpz_fdiv_q(quot, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_clear(MP(quantity));
+ mpq_init(MP(quantity));
+ mpq_set_num(MP(quantity), quot);
+}
+
+void amount_t::in_place_ceiling()
+{
+ if (! quantity)
+ throw_(amount_error, _("Cannot ceiling an uninitialized amount"));
+
+ _dup();
- mpq_set_str(MP(quantity), out.str().c_str(), 10);
+ mpz_t quot;
+ mpz_init(quot);
+ mpz_cdiv_q(quot, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_clear(MP(quantity));
+ mpq_init(MP(quantity));
+ mpq_set_num(MP(quantity), quot);
}
void amount_t::in_place_unround()
diff --git a/src/amount.h b/src/amount.h
index 49027bb7..1b7d2101 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -364,6 +364,15 @@ public:
}
void in_place_floor();
+ /** Yields an amount which has lost all of its extra precision, beyond what
+ the display precision of the commodity would have printed. */
+ amount_t ceilinged() const {
+ amount_t temp(*this);
+ temp.in_place_ceiling();
+ return temp;
+ }
+ void in_place_ceiling();
+
/** Yields an amount whose display precision is never truncated, even
though its commodity normally displays only rounded values. */
amount_t unrounded() const {
diff --git a/src/balance.h b/src/balance.h
index 230a4e2c..9635742d 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -345,6 +345,17 @@ public:
pair.second.in_place_floor();
}
+ balance_t ceilinged() const {
+ balance_t temp(*this);
+ temp.in_place_ceiling();
+ return temp;
+ }
+ void in_place_ceiling() {
+ foreach (amounts_map::value_type& pair, amounts)
+ pair.second.in_place_ceiling();
+ }
+
+
balance_t unrounded() const {
balance_t temp(*this);
temp.in_place_unround();
diff --git a/src/context.h b/src/context.h
index 09734b3e..9fe0613b 100644
--- a/src/context.h
+++ b/src/context.h
@@ -112,16 +112,16 @@ inline parse_context_t open_for_reading(const path& pathname,
const path& cwd)
{
path filename = resolve_path(pathname);
-
+#if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
+ filename = filesystem::absolute(filename, cwd);
+#else
+ filename = filesystem::complete(filename, cwd);
+#endif
if (! exists(filename))
throw_(std::runtime_error,
_f("Cannot read journal file %1%") % filename);
-#if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
- path parent(filesystem::absolute(pathname, cwd).parent_path());
-#else
- path parent(filesystem::complete(pathname, cwd).parent_path());
-#endif
+ path parent(filename.parent_path());
shared_ptr<std::istream> stream(new ifstream(filename));
parse_context_t context(stream, parent);
context.pathname = filename;
diff --git a/src/csv.cc b/src/csv.cc
index 4992372a..c7b75712 100644
--- a/src/csv.cc
+++ b/src/csv.cc
@@ -245,7 +245,7 @@ xact_t * csv_reader::read_xact(bool rich_data)
// Translate the account name, if we have enough information to do so
- foreach (account_mapping_t& value, context.journal->account_mappings) {
+ foreach (account_mapping_t& value, context.journal->payees_for_unknown_accounts) {
if (value.first.match(xact->payee)) {
post->account = value.second;
break;
diff --git a/src/error.cc b/src/error.cc
index 58339db7..8aa1d3d6 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -84,7 +84,7 @@ string source_context(const path& file,
const string& prefix)
{
const std::streamoff len = end_pos - pos;
- if (! len || file == path("/dev/stdin"))
+ if (! len || file.empty())
return _("<no source context>");
assert(len > 0);
diff --git a/src/filters.cc b/src/filters.cc
index f5694133..7570809a 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -530,9 +530,11 @@ bool display_filter_posts::output_rounding(post_t& post)
}
// Allow the posting to be displayed if:
- // 1. It's display_amount would display as non-zero
- // 2. The --empty option was specified
- // 3. The account of the posting is <Revalued>
+ // 1. Its display_amount would display as non-zero, or
+ // 2. The --empty option was specified, or
+ // 3. a) The account of the posting is <Revalued>, and
+ // b) the revalued option is specified, and
+ // c) the --no-rounding option is not specified.
if (post.account == revalued_account) {
if (show_rounding)
@@ -981,7 +983,8 @@ void interval_posts::flush()
sort_posts_by_date());
// Determine the beginning interval by using the earliest post
- if (! interval.find_period(all_posts.front()->date()))
+ if (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
diff --git a/src/global.cc b/src/global.cc
index a718d6cb..bc172075 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -44,6 +44,7 @@
namespace ledger {
static bool args_only = false;
+std::string _init_file;
global_scope_t::global_scope_t(char ** envp)
{
@@ -126,6 +127,8 @@ void global_scope_t::read_init()
}
TRACE_FINISH(init, 1);
+ } else {
+ throw_(parse_error, _f("Could not find specified init file %1%") % init_file);
}
}
}
@@ -473,6 +476,10 @@ void handle_debug_options(int argc, char * argv[])
_log_level = LOG_INFO;
#endif
}
+ else if (i + 1 < argc && std::strcmp(argv[i], "--init-file") == 0) {
+ _init_file = argv[i + 1];
+ i++;
+ }
else if (i + 1 < argc && std::strcmp(argv[i], "--debug") == 0) {
#if DEBUG_ON
_log_level = LOG_DEBUG;
diff --git a/src/global.h b/src/global.h
index f797ba01..dc6abd78 100644
--- a/src/global.h
+++ b/src/global.h
@@ -46,6 +46,8 @@ namespace ledger {
class session_t;
class report_t;
+extern std::string _init_file;
+
class global_scope_t : public noncopyable, public scope_t
{
shared_ptr<session_t> session_ptr;
@@ -151,10 +153,14 @@ See LICENSE file included with the distribution for details and disclaimer.");
OPTION__
(global_scope_t, init_file_, // -i
CTOR(global_scope_t, init_file_) {
- if (const char * home_var = std::getenv("HOME"))
- on(none, (path(home_var) / ".ledgerrc").string());
- else
- on(none, path("./.ledgerrc").string());
+ if (!_init_file.empty())
+ // _init_file is filled during handle_debug_options
+ on(none, _init_file);
+ else
+ if (const char * home_var = std::getenv("HOME"))
+ on(none, (path(home_var) / ".ledgerrc").string());
+ else
+ on(none, path("./.ledgerrc").string());
});
OPTION(global_scope_t, options);
diff --git a/src/history.cc b/src/history.cc
index 25335680..414fc15d 100644
--- a/src/history.cc
+++ b/src/history.cc
@@ -129,6 +129,10 @@ commodity_history_t::commodity_history_t()
p_impl.reset(new commodity_history_impl_t);
}
+commodity_history_t::~commodity_history_t()
+{
+}
+
void commodity_history_t::add_commodity(commodity_t& comm)
{
p_impl->add_commodity(comm);
diff --git a/src/history.h b/src/history.h
index 4362c9f9..b763cb0b 100644
--- a/src/history.h
+++ b/src/history.h
@@ -88,6 +88,7 @@ public:
const datetime_t& oldest = datetime_t());
void print_map(std::ostream& out, const datetime_t& moment = datetime_t());
+ ~commodity_history_t();
};
} // namespace ledger
diff --git a/src/item.cc b/src/item.cc
index 0630043b..4e2a487c 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -330,6 +330,21 @@ namespace {
return NULL_VALUE;
}
+ value_t get_filebase(item_t& item) {
+ if (item.pos)
+ return string_value(item.pos->pathname.filename().string());
+ else
+ return NULL_VALUE;
+ }
+
+ value_t get_filepath(item_t& item) {
+ if (item.pos)
+ return string_value(item.pos->pathname.parent_path().string());
+ else
+ return NULL_VALUE;
+ }
+
+
value_t get_beg_pos(item_t& item) {
return item.pos ? long(item.pos->beg_pos) : 0L;
}
@@ -456,7 +471,11 @@ expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind,
case 'f':
if (name == "filename")
return WRAP_FUNCTOR(get_wrapper<&get_pathname>);
- break;
+ else if (name == "filebase")
+ return WRAP_FUNCTOR(get_wrapper<&get_filebase>);
+ else if (name == "filepath")
+ return WRAP_FUNCTOR(get_wrapper<&get_filepath>);
+ break;
case 'h':
if (name == "has_tag")
@@ -563,8 +582,8 @@ string item_context(const item_t& item, const string& desc)
std::ostringstream out;
- if (item.pos->pathname == path("/dev/stdin")) {
- out << desc << _(" from standard input:");
+ if (item.pos->pathname.empty()) {
+ out << desc << _(" from streamed input:");
return out.str();
}
diff --git a/src/journal.cc b/src/journal.cc
index e6c09125..68939be6 100644
--- a/src/journal.cc
+++ b/src/journal.cc
@@ -127,8 +127,19 @@ account_t * journal_t::register_account(const string& name, post_t * post,
// object.
if (account_aliases.size() > 0) {
accounts_map::const_iterator i = account_aliases.find(name);
- if (i != account_aliases.end())
+ if (i != account_aliases.end()) {
result = (*i).second;
+ } else {
+ // only check the very first account for alias expansion, in case
+ // that can be expanded successfully
+ size_t colon = name.find(':');
+ if(colon != string::npos) {
+ accounts_map::const_iterator i = account_aliases.find(name.substr(0, colon));
+ if (i != account_aliases.end()) {
+ result = find_account((*i).second->fullname() + name.substr(colon));
+ }
+ }
+ }
}
// Create the account object and associate it with the journal; this
diff --git a/src/main.cc b/src/main.cc
index a1ac0339..a44506c9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -59,6 +59,7 @@ int main(int argc, char * argv[], char * envp[])
// --debug CATEGORY ; turns on debug logging
// --trace LEVEL ; turns on trace logging
// --memory ; turns on memory usage tracing
+ // --init-file ; directs ledger to use a different init file
handle_debug_options(argc, argv);
#if VERIFY_ON
IF_VERIFY() initialize_memory_tracing();
@@ -213,7 +214,8 @@ int main(int argc, char * argv[], char * envp[])
} else
#endif
{
- global_scope->quick_close();
+ if (global_scope)
+ global_scope->quick_close();
INFO("Ledger ended"); // let global_scope leak!
}
diff --git a/src/post.h b/src/post.h
index a9a44a79..c9aec6b2 100644
--- a/src/post.h
+++ b/src/post.h
@@ -83,7 +83,7 @@ public:
const optional<string>& _note = none)
: item_t(_flags, _note), xact(NULL), account(_account), amount(_amount)
{
- TRACE_CTOR(post_t, "account_t *, const amount_t&, flags_t, const optional<string>&");
+ TRACE_CTOR(post_t, "account_t *, amount_t, flags_t, optional<string>");
}
post_t(const post_t& post)
: item_t(post),
diff --git a/src/print.cc b/src/print.cc
index 79d83161..a4a0bc6f 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -203,9 +203,15 @@ namespace {
(static_cast<std::string::size_type>(account_width) -
static_cast<std::string::size_type>(name.length()));
+ std::size_t amount_width =
+ (report.HANDLED(amount_width_) ?
+ lexical_cast<std::size_t>(report.HANDLER(amount_width_).str()) :
+ 12);
string amt;
if (post->amount_expr) {
- amt = post->amount_expr->text();
+ std::ostringstream amt_str;
+ justify(amt_str, post->amount_expr->text(), amount_width, true);
+ amt = amt_str.str();
}
else if (count == 2 && index == 2 &&
post_has_simple_amount(*post) &&
@@ -218,11 +224,6 @@ namespace {
// first.
}
else {
- std::size_t amount_width =
- (report.HANDLED(amount_width_) ?
- lexical_cast<std::size_t>(report.HANDLER(amount_width_).str()) :
- 12);
-
std::ostringstream amt_str;
value_t(post->amount).print(amt_str, static_cast<int>(amount_width),
-1, AMOUNT_PRINT_RIGHT_JUSTIFY |
diff --git a/src/py_xact.cc b/src/py_xact.cc
index 3d792c7b..96674207 100644
--- a/src/py_xact.cc
+++ b/src/py_xact.cc
@@ -119,8 +119,8 @@ void export_xact()
.def("__str__", py_xact_to_string)
.add_property("code",
- make_getter(&xact_t::code),
- make_setter(&xact_t::code))
+ make_getter(&xact_t::code, return_value_policy<return_by_value>()),
+ make_setter(&xact_t::code, return_value_policy<return_by_value>()))
.add_property("payee",
make_getter(&xact_t::payee),
make_setter(&xact_t::payee))
@@ -157,6 +157,8 @@ void export_xact()
make_getter(&period_xact_t::period_string),
make_setter(&period_xact_t::period_string))
;
+
+ register_optional_to_python<std::string>();
}
} // namespace ledger
diff --git a/src/report.cc b/src/report.cc
index 662386a4..d4beaf2a 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -681,6 +681,11 @@ value_t report_t::fn_floor(call_scope_t& args)
return args[0].floored();
}
+value_t report_t::fn_ceiling(call_scope_t& args)
+{
+ return args[0].ceilinged();
+}
+
value_t report_t::fn_round(call_scope_t& args)
{
return args[0].rounded();
@@ -1084,6 +1089,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(anon);
else OPT_ALT(color, ansi);
else OPT(auto_match);
+ else OPT(aux_date);
else OPT(average);
else OPT(account_width_);
else OPT(amount_width_);
@@ -1091,7 +1097,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
case 'b':
OPT(balance_format_);
else OPT(base);
- else OPT_ALT(basis, cost);
+ else OPT(basis);
else OPT_(begin_);
else OPT(bold_if_);
else OPT(budget);
@@ -1100,6 +1106,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
break;
case 'c':
OPT(csv_format_);
+ else OPT_ALT(gain, change);
else OPT(cleared);
else OPT(collapse);
else OPT(collapse_if_zero);
@@ -1117,6 +1124,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(dc);
else OPT(depth_);
else OPT(deviation);
+ else OPT_ALT(rich_data, detail);
else OPT_(display_);
else OPT(display_amount_);
else OPT(display_total_);
@@ -1141,7 +1149,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT_ALT(head_, first_);
break;
case 'g':
- OPT_ALT(gain, change);
+ OPT(gain);
else OPT(group_by_);
else OPT(group_title_format_);
else OPT(generated);
@@ -1168,7 +1176,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT_ALT(tail_, last_);
break;
case 'm':
- OPT_ALT(market, value);
+ OPT(market);
else OPT(monthly);
else OPT(meta_);
else OPT(meta_width_);
@@ -1198,6 +1206,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(price);
else OPT(prices_format_);
else OPT(pricedb_format_);
+ else OPT(primary_date);
else OPT(payee_width_);
else OPT(prepend_format_);
else OPT(prepend_width_);
@@ -1215,7 +1224,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(revalued);
else OPT(revalued_only);
else OPT(revalued_total_);
- else OPT_ALT(rich_data, detail);
+ else OPT(rich_data);
break;
case 's':
OPT(sort_);
@@ -1242,6 +1251,9 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(unrealized_losses_);
else OPT(unround);
break;
+ case 'v':
+ OPT_ALT(market, value);
+ break;
case 'w':
OPT(weekly);
else OPT_(wide);
@@ -1335,6 +1347,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(fn_cyan);
else if (is_eq(p, "commodity"))
return MAKE_FUNCTOR(report_t::fn_commodity);
+ else if (is_eq(p, "ceiling"))
+ return MAKE_FUNCTOR(report_t::fn_ceiling);
break;
case 'd':
@@ -1585,7 +1599,11 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return POSTS_REPORTER(new report_commodities(*this));
}
break;
-
+ case 'd':
+ if (is_eq(p, "draft")) {
+ return WRAP_FUNCTOR(xact_command);
+ }
+ break;
case 'e':
if (is_eq(p, "equity")) {
HANDLER(generated).on("#equity");
@@ -1607,7 +1625,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return POSTS_REPORTER(new format_ptree(*this,
format_ptree::FORMAT_JSON));
break;
-
+ case 'l':
+ if (is_eq(p, "lisp"))
+ return POSTS_REPORTER(new format_emacs_posts(output_stream));
+ break;
case 'o':
if (is_eq(p, "org"))
return POSTS_REPORTER(new posts_to_org_table
diff --git a/src/report.h b/src/report.h
index 0f4fc103..2eac61fe 100644
--- a/src/report.h
+++ b/src/report.h
@@ -123,7 +123,7 @@ public:
TRACE_CTOR(report_t, "session_t&");
}
report_t(const report_t& report)
- : session(report.session),
+ : scope_t(report), session(report.session),
output_stream(report.output_stream),
terminus(report.terminus),
budget_flags(report.budget_flags) {
@@ -174,6 +174,7 @@ public:
value_t fn_unrounded(call_scope_t& scope);
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_round(call_scope_t& scope);
value_t fn_unround(call_scope_t& scope);
value_t fn_abs(call_scope_t& scope);
diff --git a/src/session.cc b/src/session.cc
index b6153203..f047a540 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -143,7 +143,7 @@ std::size_t session_t::read_data(const string& master_account)
}
foreach (const path& pathname, HANDLER(file_).data_files) {
- if (pathname == "-") {
+ if (pathname == "-" || pathname == "/dev/stdin") {
// To avoid problems with stdin and pipes, etc., we read the entire
// file in beforehand into a memory buffer, and then parcel it out
// from there.
diff --git a/src/textual.cc b/src/textual.cc
index a5ae2f68..6106914f 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -148,7 +148,7 @@ namespace {
void account_value_directive(account_t * account, string expr_str);
void account_default_directive(account_t * account);
- void default_account_directive(char * line);
+ void default_account_directive(char * args);
void alias_directive(char * line);
void payee_directive(char * line);
@@ -397,7 +397,7 @@ void instance_t::read_next_directive(bool& error_flag)
#endif // TIMELOG_SUPPORT
case 'A': // a default account for unbalanced posts
- default_account_directive(line);
+ default_account_directive(line + 1);
break;
case 'C': // a set of conversions
price_conversion_directive(line);
@@ -492,7 +492,7 @@ void instance_t::default_commodity_directive(char * line)
void instance_t::default_account_directive(char * line)
{
- context.journal->bucket = top_account()->find_account(skip_ws(line + 1));
+ context.journal->bucket = top_account()->find_account(skip_ws(line));
context.journal->bucket->add_flags(ACCOUNT_KNOWN);
}
@@ -532,9 +532,8 @@ void instance_t::option_directive(char * line)
*p++ = '\0';
}
- path abs_path(filesystem::absolute(context.pathname,
- context.current_directory));
- if (! process_option(abs_path.string(), line + 2, *context.scope, p, line))
+ if (! process_option(context.pathname.string(), line + 2, *context.scope,
+ p, line))
throw_(option_error, _f("Illegal option --%1%") % (line + 2));
}
@@ -576,7 +575,7 @@ void instance_t::automated_xact_directive(char * line)
item = ae.get();
// This is a trailing note, and possibly a metadata info tag
- item->append_note(p + 1, *context.scope, true);
+ ae->append_note(p + 1, *context.scope, true);
item->add_flags(ITEM_NOTE_ON_NEXT_LINE);
item->pos->end_pos = context.curr_pos;
item->pos->end_line++;
diff --git a/src/utils.cc b/src/utils.cc
index 1a82787d..e5faf184 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -153,6 +153,8 @@ std::size_t current_memory_size()
return memory_size;
}
+//#if !defined(__has_feature) || !__has_feature(address_sanitizer)
+
static void trace_new_func(void * ptr, const char * which, std::size_t size)
{
if (! live_memory || ! memory_tracing_active) return;
@@ -221,8 +223,12 @@ static void trace_delete_func(void * ptr, const char * which)
memory_tracing_active = true;
}
+//#endif // !defined(__has_feature) || !__has_feature(address_sanitizer)
+
} // namespace ledger
+//#if !defined(__has_feature) || !__has_feature(address_sanitizer)
+
void * operator new(std::size_t size) throw (std::bad_alloc) {
void * ptr = std::malloc(size);
if (DO_VERIFY() && ledger::memory_tracing_active)
@@ -268,6 +274,8 @@ void operator delete[](void * ptr, const std::nothrow_t&) throw() {
std::free(ptr);
}
+//#endif // !defined(__has_feature) || !__has_feature(address_sanitizer)
+
namespace ledger {
namespace {
diff --git a/src/value.cc b/src/value.cc
index 1921d5a3..c57cff78 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1658,6 +1658,29 @@ void value_t::in_place_floor()
throw_(value_error, _f("Cannot floor %1%") % label());
}
+void value_t::in_place_ceiling()
+{
+ switch (type()) {
+ case INTEGER:
+ return;
+ case AMOUNT:
+ as_amount_lval().in_place_ceiling();
+ return;
+ case BALANCE:
+ as_balance_lval().in_place_ceiling();
+ return;
+ case SEQUENCE:
+ foreach (value_t& value, as_sequence_lval())
+ value.in_place_ceiling();
+ return;
+ default:
+ break;
+ }
+
+ add_error_context(_f("While ceiling %1%:") % *this);
+ throw_(value_error, _f("Cannot ceiling %1%") % label());
+}
+
void value_t::in_place_unround()
{
switch (type()) {
diff --git a/src/value.h b/src/value.h
index ee3d414d..249f3d7f 100644
--- a/src/value.h
+++ b/src/value.h
@@ -457,6 +457,13 @@ public:
}
void in_place_floor();
+ value_t ceilinged() const {
+ value_t temp(*this);
+ temp.in_place_ceiling();
+ return temp;
+ }
+ void in_place_ceiling();
+
value_t unrounded() const {
value_t temp(*this);
temp.in_place_unround();
diff --git a/src/xact.cc b/src/xact.cc
index b5cb2a38..7ac7a9e9 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -36,6 +36,7 @@
#include "account.h"
#include "journal.h"
#include "context.h"
+#include "format.h"
#include "pool.h"
namespace ledger {
@@ -355,14 +356,16 @@ bool xact_base_t::finalize()
}
}
} else {
- if (post->amount.has_annotation()) {
- if (breakdown.amount.has_annotation())
- breakdown.amount.annotation().tag = post->amount.annotation().tag;
- else
- breakdown.amount.annotate
- (annotation_t(none, none, post->amount.annotation().tag));
- }
- post->amount = breakdown.amount;
+ post->amount =
+ breakdown.amount.has_annotation() ?
+ amount_t(breakdown.amount,
+ annotation_t(breakdown.amount.annotation().price,
+ breakdown.amount.annotation().date,
+ post->amount.has_annotation() ?
+ post->amount.annotation().tag :
+ breakdown.amount.annotation().tag,
+ breakdown.amount.annotation().value_expr)) :
+ breakdown.amount;
DEBUG("xact.finalize", "added breakdown, balance = " << balance);
}
@@ -642,6 +645,18 @@ namespace {
}
}
+static string apply_format(const string& str, scope_t& scope)
+{
+ if (contains(str, "%(")) {
+ format_t str_format(str);
+ std::ostringstream buf;
+ buf << str_format(scope);
+ return buf.str();
+ } else {
+ return str;
+ }
+}
+
void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
{
posts_list initial_posts(xact.posts.begin(), xact.posts.end());
@@ -693,8 +708,9 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
if (deferred_notes) {
foreach (deferred_tag_data_t& data, *deferred_notes) {
if (data.apply_to_post == NULL)
- initial_post->parse_tags(data.tag_data.c_str(), bound_scope,
- data.overwrite_existing);
+ initial_post->append_note(
+ apply_format(data.tag_data, bound_scope).c_str(),
+ bound_scope, data.overwrite_existing);
}
}
@@ -773,11 +789,27 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
account = account->parent;
account = account->find_account(fullname);
}
+ else if (contains(fullname, "%(")) {
+ format_t account_name(fullname);
+ std::ostringstream buf;
+ buf << account_name(bound_scope);
+ while (account->parent)
+ account = account->parent;
+ account = account->find_account(buf.str());
+ }
// Copy over details so that the resulting post is a mirror of
// the automated xact's one.
post_t * new_post = new post_t(account, amt);
new_post->copy_details(*post);
+
+ // A Cleared transaction implies all of its automatic posting are cleared
+ // CPR 2012/10/23
+ if (xact.state() == item_t::CLEARED) {
+ DEBUG("xact.extend.cleared", "CLEARED");
+ new_post->set_state(item_t::CLEARED);
+ }
+
new_post->add_flags(ITEM_GENERATED);
new_post->account =
journal->register_account(account->fullname(), new_post,
@@ -785,9 +817,11 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
if (deferred_notes) {
foreach (deferred_tag_data_t& data, *deferred_notes) {
- if (! data.apply_to_post || data.apply_to_post == post)
- new_post->parse_tags(data.tag_data.c_str(), bound_scope,
- data.overwrite_existing);
+ if (! data.apply_to_post || data.apply_to_post == post) {
+ new_post->append_note(
+ apply_format(data.tag_data, bound_scope).c_str(),
+ bound_scope, data.overwrite_existing);
+ }
}
}