summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account.cc25
-rw-r--r--src/account.h9
-rw-r--r--src/amount.cc59
-rw-r--r--src/amount.h20
-rw-r--r--src/annotate.cc18
-rw-r--r--src/annotate.h2
-rw-r--r--src/archive.cc2
-rw-r--r--src/archive.h2
-rw-r--r--src/balance.cc8
-rw-r--r--src/balance.h24
-rw-r--r--src/chain.cc2
-rw-r--r--src/chain.h2
-rw-r--r--src/commodity.cc9
-rw-r--r--src/commodity.h11
-rw-r--r--src/compare.cc2
-rw-r--r--src/compare.h2
-rw-r--r--src/context.h16
-rw-r--r--src/convert.cc2
-rw-r--r--src/convert.h2
-rw-r--r--src/csv.cc4
-rw-r--r--src/csv.h2
-rw-r--r--src/draft.cc2
-rw-r--r--src/draft.h2
-rw-r--r--src/emacs.cc2
-rw-r--r--src/emacs.h2
-rw-r--r--src/error.cc4
-rw-r--r--src/error.h2
-rw-r--r--src/expr.cc2
-rw-r--r--src/expr.h2
-rw-r--r--src/exprbase.h2
-rw-r--r--src/filters.cc13
-rw-r--r--src/filters.h2
-rw-r--r--src/flags.h2
-rw-r--r--src/format.cc4
-rw-r--r--src/format.h2
-rw-r--r--src/generate.cc2
-rw-r--r--src/generate.h2
-rw-r--r--src/global.cc62
-rw-r--r--src/global.h14
-rw-r--r--src/history.cc6
-rw-r--r--src/history.h3
-rw-r--r--src/item.cc36
-rw-r--r--src/item.h2
-rw-r--r--src/iterators.cc2
-rw-r--r--src/iterators.h2
-rw-r--r--src/journal.cc15
-rw-r--r--src/journal.h2
-rw-r--r--src/lookup.cc2
-rw-r--r--src/lookup.h2
-rw-r--r--src/main.cc6
-rw-r--r--src/mask.cc2
-rw-r--r--src/mask.h4
-rw-r--r--src/op.cc2
-rw-r--r--src/op.h2
-rw-r--r--src/option.cc2
-rw-r--r--src/option.h2
-rw-r--r--src/org.cc2
-rw-r--r--src/org.h2
-rw-r--r--src/output.cc30
-rw-r--r--src/output.h33
-rw-r--r--src/parser.cc2
-rw-r--r--src/parser.h2
-rw-r--r--src/pool.cc2
-rw-r--r--src/pool.h2
-rw-r--r--src/post.cc45
-rw-r--r--src/post.h4
-rw-r--r--src/precmd.cc2
-rw-r--r--src/precmd.h2
-rw-r--r--src/predicate.h2
-rw-r--r--src/print.cc15
-rw-r--r--src/print.h2
-rw-r--r--src/pstream.h2
-rw-r--r--src/ptree.cc20
-rw-r--r--src/ptree.h5
-rw-r--r--src/py_account.cc2
-rw-r--r--src/py_amount.cc2
-rw-r--r--src/py_balance.cc2
-rw-r--r--src/py_commodity.cc2
-rw-r--r--src/py_expr.cc2
-rw-r--r--src/py_format.cc2
-rw-r--r--src/py_item.cc2
-rw-r--r--src/py_journal.cc2
-rw-r--r--src/py_post.cc2
-rw-r--r--src/py_session.cc2
-rw-r--r--src/py_times.cc2
-rw-r--r--src/py_utils.cc2
-rw-r--r--src/py_value.cc2
-rw-r--r--src/py_xact.cc8
-rw-r--r--src/pyfstream.h2
-rw-r--r--src/pyinterp.cc2
-rw-r--r--src/pyinterp.h2
-rw-r--r--src/pyledger.cc2
-rw-r--r--src/pyutils.h2
-rw-r--r--src/query.cc2
-rw-r--r--src/query.h2
-rw-r--r--src/quotes.cc2
-rw-r--r--src/quotes.h2
-rw-r--r--src/report.cc52
-rw-r--r--src/report.h8
-rw-r--r--src/scope.cc2
-rw-r--r--src/scope.h2
-rw-r--r--src/select.cc2
-rw-r--r--src/select.h2
-rw-r--r--src/session.cc27
-rw-r--r--src/session.h7
-rw-r--r--src/stats.cc2
-rw-r--r--src/stats.h2
-rw-r--r--src/stream.cc2
-rw-r--r--src/stream.h2
-rw-r--r--src/system.hh.in3
-rw-r--r--src/temps.cc2
-rw-r--r--src/temps.h2
-rw-r--r--src/textual.cc19
-rw-r--r--src/timelog.cc8
-rw-r--r--src/timelog.h2
-rw-r--r--src/times.cc2
-rw-r--r--src/times.h18
-rw-r--r--src/token.cc2
-rw-r--r--src/token.h2
-rw-r--r--src/unistring.h2
-rw-r--r--src/utils.cc10
-rw-r--r--src/utils.h2
-rw-r--r--src/value.cc68
-rw-r--r--src/value.h16
-rw-r--r--src/views.cc2
-rw-r--r--src/views.h2
-rw-r--r--src/xact.cc80
-rw-r--r--src/xact.h2
128 files changed, 669 insertions, 349 deletions
diff --git a/src/account.cc b/src/account.cc
index 72709f95..c3fc80f1 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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>);
@@ -690,12 +692,10 @@ void account_t::xdata_t::details_t::update(post_t& post,
}
}
-void put_account(property_tree::ptree& pt, const account_t& acct,
+void put_account(property_tree::ptree& st, const account_t& acct,
function<bool(const account_t&)> pred)
{
if (pred(acct)) {
- property_tree::ptree& st(pt.put("account", ""));
-
std::ostringstream buf;
buf.width(sizeof(unsigned long) * 2);
buf.fill('0');
@@ -707,18 +707,15 @@ void put_account(property_tree::ptree& pt, const account_t& acct,
st.put("fullname", acct.fullname());
value_t total = acct.amount();
- if (! total.is_null()) {
- property_tree::ptree& t(st.put("account-amount", ""));
- put_value(t, total);
- }
+ if (! total.is_null())
+ put_value(st.put("account-amount", ""), total);
+
total = acct.total();
- if (! total.is_null()) {
- property_tree::ptree& t(st.put("account-total", ""));
- put_value(t, total);
- }
+ if (! total.is_null())
+ put_value(st.put("account-total", ""), total);
foreach (const accounts_map::value_type& pair, acct.accounts)
- put_account(st, *pair.second, pred);
+ put_account(st.add("account", ""), *pair.second, pred);
}
}
diff --git a/src/account.h b/src/account.h
index a2fcb8de..7b53de15 100644
--- a/src/account.h
+++ b/src/account.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -308,6 +308,13 @@ std::ostream& operator<<(std::ostream& out, const account_t& account);
void put_account(property_tree::ptree& pt, const account_t& acct,
function<bool(const account_t&)> pred);
+//simple struct added to allow std::map to compare accounts in the accounts report
+struct account_compare {
+ bool operator() (const account_t& lhs, const account_t& rhs){
+ return (lhs.fullname().compare(rhs.fullname()) < 0);
+ }
+};
+
} // namespace ledger
#endif // _ACCOUNT_H
diff --git a/src/amount.cc b/src/amount.cc
index 6ecb3558..55cbabeb 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -30,6 +30,7 @@
*/
#include <system.hh>
+#include <math.h>
#include "amount.h"
#include "commodity.h"
@@ -195,7 +196,10 @@ namespace {
for (const char * p = buf; *p; p++) {
if (*p == '.') {
- if (commodity_t::decimal_comma_by_default ||
+ if (commodity_t::time_colon_by_default ||
+ (comm && comm->has_flags(COMMODITY_STYLE_TIME_COLON)))
+ out << ':';
+ else if (commodity_t::decimal_comma_by_default ||
(comm && comm->has_flags(COMMODITY_STYLE_DECIMAL_COMMA)))
out << ',';
else
@@ -209,7 +213,10 @@ namespace {
out << *p;
if (integer_digits > 3 && --integer_digits % 3 == 0) {
- if (commodity_t::decimal_comma_by_default ||
+ if (commodity_t::time_colon_by_default ||
+ (comm && comm->has_flags(COMMODITY_STYLE_TIME_COLON)))
+ out << ':';
+ else if (commodity_t::decimal_comma_by_default ||
(comm && comm->has_flags(COMMODITY_STYLE_DECIMAL_COMMA)))
out << '.';
else
@@ -666,14 +673,31 @@ void amount_t::in_place_truncate()
void amount_t::in_place_floor()
{
if (! quantity)
- throw_(amount_error, _("Cannot floor an uninitialized amount"));
+ throw_(amount_error, _("Cannot compute floor on an uninitialized amount"));
_dup();
- std::ostringstream out;
- stream_out_mpq(out, MP(quantity), precision_t(0), -1, GMP_RNDZ);
+ mpz_fdiv_q(temp, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_set_z(MP(quantity), temp);
+}
+
+void amount_t::in_place_ceiling()
+{
+ if (! quantity)
+ throw_(amount_error, _("Cannot compute ceiling on an uninitialized amount"));
+
+ _dup();
- mpq_set_str(MP(quantity), out.str().c_str(), 10);
+ mpz_cdiv_q(temp, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_set_z(MP(quantity), temp);
+}
+
+void amount_t::in_place_roundto(int places)
+{
+ if (! quantity)
+ throw_(amount_error, _("Cannot round an uninitialized amount"));
+ double x=ceil(mpq_get_d(MP(quantity))*pow(10, places) - 0.49999999) / pow(10, places);
+ mpq_set_d(MP(quantity), x);
}
void amount_t::in_place_unround()
@@ -720,6 +744,16 @@ void amount_t::in_place_unreduce()
}
if (shifted) {
+ if ("h" == comm->symbol() && commodity_t::time_colon_by_default) {
+ amount_t floored = tmp.floored();
+ amount_t precision = tmp - floored;
+ if (precision < 0.0) {
+ precision += 1.0;
+ floored -= 1.0;
+ }
+ tmp = floored + (precision * (comm->smaller()->number() / 100.0));
+ }
+
*this = tmp;
commodity_ = comm;
}
@@ -1073,6 +1107,9 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
bool decimal_comma_style
= (commodity_t::decimal_comma_by_default ||
commodity().has_flags(COMMODITY_STYLE_DECIMAL_COMMA));
+ bool time_colon_style
+ = (commodity_t::time_colon_by_default ||
+ commodity().has_flags(COMMODITY_STYLE_TIME_COLON));
new_quantity->prec = 0;
@@ -1283,13 +1320,11 @@ bool amount_t::valid() const
return true;
}
-void put_amount(property_tree::ptree& pt, const amount_t& amt,
- bool wrap, bool commodity_details)
+void put_amount(property_tree::ptree& st, const amount_t& amt,
+ bool commodity_details)
{
- property_tree::ptree& st(wrap ? pt.put("amount", "") : pt);
-
if (amt.has_commodity())
- put_commodity(st, amt.commodity(), commodity_details);
+ put_commodity(st.put("commodity", ""), amt.commodity(), commodity_details);
st.put("quantity", amt.quantity_string());
}
diff --git a/src/amount.h b/src/amount.h
index 49027bb7..938d4b7b 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -346,6 +346,13 @@ public:
}
void in_place_round();
+ amount_t roundto(int places) const {
+ amount_t temp(*this);
+ temp.in_place_round();
+ return temp;
+ }
+ void in_place_roundto(int places);
+
/** Yields an amount which has lost all of its extra precision, beyond what
the display precision of the commodity would have printed. */
amount_t truncated() const {
@@ -364,6 +371,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 {
@@ -777,7 +793,7 @@ inline std::istream& operator>>(std::istream& in, amount_t& amt) {
}
void put_amount(property_tree::ptree& pt, const amount_t& amt,
- bool wrap = true, bool commodity_details = false);
+ bool commodity_details = false);
} // namespace ledger
diff --git a/src/annotate.cc b/src/annotate.cc
index b7b6b5cb..8816a89c 100644
--- a/src/annotate.cc
+++ b/src/annotate.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -216,19 +216,13 @@ void annotation_t::print(std::ostream& out, bool keep_base,
out << " ((" << *value_expr << "))";
}
-void put_annotation(property_tree::ptree& pt, const annotation_t& details)
+void put_annotation(property_tree::ptree& st, const annotation_t& details)
{
- property_tree::ptree& st(pt.put("annotation", ""));
+ if (details.price)
+ put_amount(st.put("price", ""), *details.price);
- if (details.price) {
- property_tree::ptree& t(st.put("price", ""));
- put_amount(t, *details.price, false);
- }
-
- if (details.date) {
- property_tree::ptree& t(st.put("date", ""));
- put_date(t, *details.date, false);
- }
+ if (details.date)
+ put_date(st.put("date", ""), *details.date);
if (details.tag)
st.put("tag", *details.tag);
diff --git a/src/annotate.h b/src/annotate.h
index 27deaad3..998f7c83 100644
--- a/src/annotate.h
+++ b/src/annotate.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/archive.cc b/src/archive.cc
index caeaf965..6ac1c580 100644
--- a/src/archive.cc
+++ b/src/archive.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/archive.h b/src/archive.h
index ee4e9ccb..5c15a9fb 100644
--- a/src/archive.h
+++ b/src/archive.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 d9551670..b702cb7b 100644
--- a/src/balance.cc
+++ b/src/balance.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -336,12 +336,10 @@ void balance_t::print(std::ostream& out,
amount_printer.close();
}
-void put_balance(property_tree::ptree& pt, const balance_t& bal)
+void put_balance(property_tree::ptree& st, const balance_t& bal)
{
- property_tree::ptree& st(pt.put("balance", ""));
-
foreach (const balance_t::amounts_map::value_type& pair, bal.amounts)
- put_amount(st, pair.second);
+ put_amount(st.add("amount", ""), pair.second);
}
} // namespace ledger
diff --git a/src/balance.h b/src/balance.h
index 230a4e2c..a1ae51ef 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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,6 +325,17 @@ public:
pair.second.in_place_round();
}
+ balance_t roundto(int places) const {
+ balance_t temp(*this);
+ temp.in_place_roundto(places);
+ return temp;
+ }
+
+ void in_place_roundto(int places) {
+ foreach (amounts_map::value_type& pair, amounts)
+ pair.second.in_place_roundto(places);
+ }
+
balance_t truncated() const {
balance_t temp(*this);
temp.in_place_truncate();
@@ -345,6 +356,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/chain.cc b/src/chain.cc
index 52d52f14..b2f6f203 100644
--- a/src/chain.cc
+++ b/src/chain.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/chain.h
index 15ae12ba..de7f68c7 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 05d465ca..535b31c9 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -40,6 +40,7 @@
namespace ledger {
bool commodity_t::decimal_comma_by_default = false;
+bool commodity_t::time_colon_by_default = false;
void commodity_t::add_price(const datetime_t& date, const amount_t& price,
const bool reflexive)
@@ -496,11 +497,9 @@ bool commodity_t::compare_by_commodity::operator()(const amount_t * left,
}
}
-void put_commodity(property_tree::ptree& pt, const commodity_t& comm,
+void put_commodity(property_tree::ptree& st, const commodity_t& comm,
bool commodity_details)
{
- property_tree::ptree& st(pt.put("commodity", ""));
-
std::string flags;
if (! (comm.has_flags(COMMODITY_STYLE_SUFFIXED))) flags += 'P';
if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) flags += 'S';
@@ -511,7 +510,7 @@ void put_commodity(property_tree::ptree& pt, const commodity_t& comm,
st.put("symbol", comm.symbol());
if (commodity_details && comm.has_annotation())
- put_annotation(st, as_annotated_commodity(comm).details);
+ put_annotation(st.put("annotation", ""), as_annotated_commodity(comm).details);
}
} // namespace ledger
diff --git a/src/commodity.h b/src/commodity.h
index ab496850..a1988a3b 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -107,6 +107,7 @@ protected:
#define COMMODITY_SAW_ANNOTATED 0x200
#define COMMODITY_SAW_ANN_PRICE_FLOAT 0x400
#define COMMODITY_SAW_ANN_PRICE_FIXATED 0x800
+#define COMMODITY_STYLE_TIME_COLON 0x1000
string symbol;
optional<std::size_t> graph_index;
@@ -176,6 +177,7 @@ protected:
public:
static bool decimal_comma_by_default;
+ static bool time_colon_by_default;
virtual ~commodity_t() {
TRACE_DTOR(commodity_t);
@@ -349,6 +351,13 @@ inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
void put_commodity(property_tree::ptree& pt, const commodity_t& comm,
bool commodity_details = false);
+//simple struct to allow std::map to compare commodities names
+struct commodity_compare {
+ bool operator() (const commodity_t* lhs, const commodity_t* rhs){
+ return (lhs->symbol().compare(rhs->symbol()) < 0);
+ }
+};
+
} // namespace ledger
#endif // _COMMODITY_H
diff --git a/src/compare.cc b/src/compare.cc
index e2a298c2..946cd835 100644
--- a/src/compare.cc
+++ b/src/compare.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/compare.h b/src/compare.h
index e1abbca1..4a91f49f 100644
--- a/src/compare.h
+++ b/src/compare.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/context.h b/src/context.h
index 09734b3e..e5457641 100644
--- a/src/context.h
+++ b/src/context.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -112,16 +112,16 @@ inline parse_context_t open_for_reading(const path& pathname,
const path& cwd)
{
path filename = resolve_path(pathname);
-
- 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());
+ filename = filesystem::absolute(filename, cwd);
#else
- path parent(filesystem::complete(pathname, cwd).parent_path());
+ filename = filesystem::complete(filename, cwd);
#endif
+ if (! exists(filename) || is_directory(filename))
+ throw_(std::runtime_error,
+ _f("Cannot read journal file %1%") % filename);
+
+ 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/convert.cc b/src/convert.cc
index f0d8db06..38ef2c22 100644
--- a/src/convert.cc
+++ b/src/convert.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 de958108..17fb4505 100644
--- a/src/convert.h
+++ b/src/convert.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/csv.cc b/src/csv.cc
index 4992372a..2a3eb080 100644
--- a/src/csv.cc
+++ b/src/csv.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/csv.h b/src/csv.h
index 7d5098d2..94f7a328 100644
--- a/src/csv.h
+++ b/src/csv.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 a6f60520..6aef2f12 100644
--- a/src/draft.cc
+++ b/src/draft.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 9023e6da..1cc362ba 100644
--- a/src/draft.h
+++ b/src/draft.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 41c67cc6..9bfd1e4b 100644
--- a/src/emacs.cc
+++ b/src/emacs.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 a018ce68..368c4c4d 100644
--- a/src/emacs.h
+++ b/src/emacs.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 58339db7..acee85c9 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/error.h b/src/error.h
index 9837fa4d..93d92109 100644
--- a/src/error.h
+++ b/src/error.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 dbe860bf..aa1e07d2 100644
--- a/src/expr.cc
+++ b/src/expr.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/expr.h
index 798e5bec..a5119c0b 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 4edf2a7a..88d6f118 100644
--- a/src/exprbase.h
+++ b/src/exprbase.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 f5694133..9b8e4fc6 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/filters.h b/src/filters.h
index b765f630..42ff2e5c 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/flags.h b/src/flags.h
index 77a2c4dd..d584e2d0 100644
--- a/src/flags.h
+++ b/src/flags.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 d29c87b3..e0f74616 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
element_t * current = NULL;
- char buf[1024];
+ static char buf[65535];
char * q = buf;
for (const char * p = fmt.c_str(); *p; p++) {
diff --git a/src/format.h b/src/format.h
index cc48bdda..38f567bd 100644
--- a/src/format.h
+++ b/src/format.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 bcbde9f1..2b471c87 100644
--- a/src/generate.cc
+++ b/src/generate.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 1b22004b..f171605b 100644
--- a/src/generate.h
+++ b/src/generate.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 a718d6cb..a4da6ead 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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,6 +44,7 @@
namespace ledger {
static bool args_only = false;
+std::string _init_file;
global_scope_t::global_scope_t(char ** envp)
{
@@ -106,30 +107,53 @@ global_scope_t::~global_scope_t()
#endif
}
+void global_scope_t::parse_init(path init_file)
+{
+ TRACE_START(init, 1, "Read initialization file");
+
+ parse_context_stack_t parsing_context;
+ parsing_context.push(init_file);
+ parsing_context.get_current().journal = session().journal.get();
+ parsing_context.get_current().scope = &report();
+
+ if (session().journal->read(parsing_context) > 0 ||
+ session().journal->auto_xacts.size() > 0 ||
+ session().journal->period_xacts.size() > 0) {
+ throw_(parse_error, _f("Transactions found in initialization file '%1%'")
+ % init_file);
+ }
+
+ TRACE_FINISH(init, 1);
+}
+
void global_scope_t::read_init()
{
+ // if specified on the command line init_file_ is filled in
+ // global_scope_t::handle_debug_options. If it was specified on the command line
+ // fail is the file doesn't exist. If no init file was specified
+ // on the command-line then try the default values, but don't fail if there
+ // isn't one.
+ path init_file;
if (HANDLED(init_file_)) {
- path init_file(HANDLER(init_file_).str());
+ init_file=HANDLER(init_file_).str();
if (exists(init_file)) {
- TRACE_START(init, 1, "Read initialization file");
-
- parse_context_stack_t parsing_context;
- parsing_context.push(init_file);
- parsing_context.get_current().journal = session().journal.get();
- parsing_context.get_current().scope = &report();
-
- if (session().journal->read(parsing_context) > 0 ||
- session().journal->auto_xacts.size() > 0 ||
- session().journal->period_xacts.size() > 0) {
- throw_(parse_error, _f("Transactions found in initialization file '%1%'")
- % init_file);
- }
-
- TRACE_FINISH(init, 1);
+ parse_init(init_file);
+ } else {
+ throw_(parse_error, _f("Could not find specified init file %1%") % init_file);
}
+ } else {
+ if (const char * home_var = std::getenv("HOME")){
+ init_file = (path(home_var) / ".ledgerrc");
+ } else {
+ init_file = ("./.ledgerrc");
+ }
+ }
+ if(exists(init_file)){
+ parse_init(init_file);
}
}
+
char * global_scope_t::prompt_string()
{
static char prompt[32];
@@ -473,6 +497,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..c024dce2 100644
--- a/src/global.h
+++ b/src/global.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -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;
@@ -65,6 +67,7 @@ public:
return _("global scope");
}
+ void parse_init(path init_file);
void read_init();
void read_environment_settings(char * envp[]);
strings_list read_command_arguments(scope_t& scope, strings_list args);
@@ -124,7 +127,7 @@ public:
out << '-' << Ledger_VERSION_DATE;
out << _(", the command-line accounting tool");
out <<
- _("\n\nCopyright (c) 2003-2012, John Wiegley. All rights reserved.\n\n\
+ _("\n\nCopyright (c) 2003-2013, 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;
@@ -151,10 +154,9 @@ 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);
});
OPTION(global_scope_t, options);
diff --git a/src/history.cc b/src/history.cc
index 25335680..dde8c441 100644
--- a/src/history.cc
+++ b/src/history.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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,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..baefb333 100644
--- a/src/history.h
+++ b/src/history.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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..a29a3fd3 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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();
}
@@ -581,16 +600,15 @@ string item_context(const item_t& item, const string& desc)
return out.str();
}
-void put_metadata(property_tree::ptree& pt, const item_t::string_map& metadata)
+void put_metadata(property_tree::ptree& st, const item_t::string_map& metadata)
{
- property_tree::ptree& st(pt.put("metadata", ""));
foreach (const item_t::string_map::value_type& pair, metadata) {
if (pair.second.first) {
- property_tree::ptree& vt(st.put("pair", ""));
- vt.put("key", pair.first);
+ property_tree::ptree& vt(st.add("value", ""));
+ vt.put("<xmlattr>.key", pair.first);
put_value(vt, *pair.second.first);
} else {
- st.put("tag", pair.first);
+ st.add("tag", pair.first);
}
}
}
diff --git a/src/item.h b/src/item.h
index 8b0a5225..b0670ac5 100644
--- a/src/item.h
+++ b/src/item.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/iterators.cc b/src/iterators.cc
index 0a053031..738f33be 100644
--- a/src/iterators.cc
+++ b/src/iterators.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/iterators.h b/src/iterators.h
index 53814666..3ece313c 100644
--- a/src/iterators.h
+++ b/src/iterators.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.cc b/src/journal.cc
index e6c09125..c4c8fd98 100644
--- a/src/journal.cc
+++ b/src/journal.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/journal.h b/src/journal.h
index 5e0fa0e3..716e2910 100644
--- a/src/journal.h
+++ b/src/journal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 9edc3bbc..2a602569 100644
--- a/src/lookup.cc
+++ b/src/lookup.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 ba64b0b5..ee80faac 100644
--- a/src/lookup.h
+++ b/src/lookup.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 a1ac0339..accae197 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/mask.cc b/src/mask.cc
index 18d482ed..56ef02d1 100644
--- a/src/mask.cc
+++ b/src/mask.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/mask.h b/src/mask.h
index 06bd0141..877a0011 100644
--- a/src/mask.h
+++ b/src/mask.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -151,7 +151,7 @@ inline std::ostream& operator<<(std::ostream& out, const mask_t& mask) {
}
inline void put_mask(property_tree::ptree& pt, const mask_t& mask) {
- pt.put("mask", mask.str());
+ pt.put_value(mask.str());
}
} // namespace ledger
diff --git a/src/op.cc b/src/op.cc
index 87857049..15306f02 100644
--- a/src/op.cc
+++ b/src/op.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/op.h b/src/op.h
index 2a705ca0..bebfcbbd 100644
--- a/src/op.h
+++ b/src/op.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 7fcc9e4d..256ee45b 100644
--- a/src/option.cc
+++ b/src/option.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 642142aa..fe3e257b 100644
--- a/src/option.h
+++ b/src/option.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/org.cc b/src/org.cc
index 70427321..736260e6 100644
--- a/src/org.cc
+++ b/src/org.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/org.h b/src/org.h
index 0b34b610..8f9dcf81 100644
--- a/src/org.h
+++ b/src/org.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 f433f8d1..77d28eed 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -318,6 +318,34 @@ void report_payees::operator()(post_t& post)
(*i).second++;
}
+void report_tags::flush()
+{
+ std::ostream& out(report.output_stream);
+
+ foreach (tags_pair& entry, tags) {
+ if (report.HANDLED(count))
+ out << entry.second << ' ';
+ out << entry.first << '\n';
+ }
+}
+
+void report_tags::operator()(post_t& post)
+{
+ 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++;
+ }
+ }
+}
+
void report_commodities::flush()
{
std::ostream& out(report.output_stream);
diff --git a/src/output.h b/src/output.h
index 281f69b6..31afbd13 100644
--- a/src/output.h
+++ b/src/output.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -142,7 +142,7 @@ class report_accounts : public item_handler<post_t>
protected:
report_t& report;
- std::map<account_t *, std::size_t> accounts;
+ std::map<account_t *, std::size_t, account_compare> accounts;
typedef std::map<account_t *, std::size_t>::value_type accounts_pair;
@@ -189,12 +189,39 @@ public:
}
};
+class report_tags : public item_handler<post_t>
+{
+protected:
+ report_t& report;
+
+ std::map<string, std::size_t> tags;
+
+ typedef std::map<string, std::size_t>::value_type tags_pair;
+
+public:
+ report_tags(report_t& _report) : report(_report) {
+ TRACE_CTOR(report_tags, "report&");
+ }
+ virtual ~report_tags() {
+ TRACE_DTOR(report_tags);
+ }
+
+ virtual void flush();
+ virtual void operator()(post_t& post);
+
+ virtual void clear() {
+ tags.clear();
+ item_handler<post_t>::clear();
+ }
+};
+
+
class report_commodities : public item_handler<post_t>
{
protected:
report_t& report;
- std::map<commodity_t *, std::size_t> commodities;
+ std::map<commodity_t *, std::size_t, commodity_compare> commodities;
typedef std::map<commodity_t *, std::size_t>::value_type commodities_pair;
diff --git a/src/parser.cc b/src/parser.cc
index a17ad271..bcb23f48 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 9e6a59f4..8cc8027f 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 9f1aea9f..b9e64c4b 100644
--- a/src/pool.cc
+++ b/src/pool.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/pool.h
index 849b7a22..1bcb8b65 100644
--- a/src/pool.h
+++ b/src/pool.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 f23b81cb..1a24429b 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -696,10 +696,8 @@ void extend_post(post_t& post, journal_t& journal)
}
}
-void put_post(property_tree::ptree& pt, const post_t& post)
+void put_post(property_tree::ptree& st, const post_t& post)
{
- property_tree::ptree& st(pt.put("posting", ""));
-
if (post.state() == item_t::CLEARED)
st.put("<xmlattr>.state", "cleared");
else if (post.state() == item_t::PENDING)
@@ -710,14 +708,10 @@ void put_post(property_tree::ptree& pt, const post_t& post)
if (post.has_flags(ITEM_GENERATED))
st.put("<xmlattr>.generated", "true");
- if (post._date) {
- property_tree::ptree& t(st.put("date", ""));
- put_date(t, *post._date, false);
- }
- if (post._date_aux) {
- property_tree::ptree& t(st.put("aux-date", ""));
- put_date(t, *post._date_aux, false);
- }
+ if (post._date)
+ put_date(st.put("date", ""), *post._date);
+ if (post._date_aux)
+ put_date(st.put("aux-date", ""), *post._date_aux);
if (post.account) {
property_tree::ptree& t(st.put("account", ""));
@@ -736,34 +730,27 @@ void put_post(property_tree::ptree& pt, const post_t& post)
if (post.has_xdata() && post.xdata().has_flags(POST_EXT_COMPOUND))
put_value(t, post.xdata().compound_value);
else
- put_amount(t, post.amount);
+ put_amount(t.put("amount", ""), post.amount);
}
- if (post.cost) {
- property_tree::ptree& t(st.put("cost", ""));
- put_amount(t, *post.cost, false);
- }
+ if (post.cost)
+ put_amount(st.put("cost", ""), *post.cost);
if (post.assigned_amount) {
- if (post.has_flags(POST_CALCULATED)) {
- property_tree::ptree& t(st.put("balance-assertion", ""));
- put_amount(t, *post.assigned_amount, false);
- } else {
- property_tree::ptree& t(st.put("balance-assignment", ""));
- put_amount(t, *post.assigned_amount, false);
- }
+ if (post.has_flags(POST_CALCULATED))
+ put_amount(st.put("balance-assertion", ""), *post.assigned_amount);
+ else
+ put_amount(st.put("balance-assignment", ""), *post.assigned_amount);
}
if (post.note)
st.put("note", *post.note);
if (post.metadata)
- put_metadata(st, *post.metadata);
+ put_metadata(st.put("metadata", ""), *post.metadata);
- if (post.xdata_ && ! post.xdata_->total.is_null()) {
- property_tree::ptree& t(st.put("total", ""));
- put_value(t, post.xdata_->total);
- }
+ if (post.xdata_ && ! post.xdata_->total.is_null())
+ put_value(st.put("total", ""), post.xdata_->total);
}
} // namespace ledger
diff --git a/src/post.h b/src/post.h
index a9a44a79..3206afdd 100644
--- a/src/post.h
+++ b/src/post.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/precmd.cc b/src/precmd.cc
index fe0836bc..e9c966e9 100644
--- a/src/precmd.cc
+++ b/src/precmd.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 1c52d8a7..27925f42 100644
--- a/src/precmd.h
+++ b/src/precmd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 c670d6a4..6a1cc01c 100644
--- a/src/predicate.h
+++ b/src/predicate.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 79d83161..f04f59d5 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/print.h b/src/print.h
index 42bfc8b6..8d78e8cc 100644
--- a/src/print.h
+++ b/src/print.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 e9cddb4c..4886dc0b 100644
--- a/src/pstream.h
+++ b/src/pstream.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/ptree.cc b/src/ptree.cc
index 6fb840e0..e7afdcd1 100644
--- a/src/ptree.cc
+++ b/src/ptree.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -61,28 +61,28 @@ void format_ptree::flush()
property_tree::ptree& ct(pt.put("ledger.commodities", ""));
foreach (const commodities_pair& pair, commodities)
- put_commodity(ct, *pair.second, true);
+ put_commodity(ct.add("commodity", ""), *pair.second, true);
property_tree::ptree& at(pt.put("ledger.accounts", ""));
- put_account(at, *report.session.journal->master, account_visited_p);
+ put_account(at.add("account", ""), *report.session.journal->master, account_visited_p);
property_tree::ptree& tt(pt.put("ledger.transactions", ""));
foreach (const xact_t * xact, transactions) {
- put_xact(tt, *xact);
+ property_tree::ptree& t(tt.add("transaction", ""));
+ put_xact(t, *xact);
- property_tree::ptree& post_tree(tt.put("postings", ""));
+ property_tree::ptree& post_tree(t.put("postings", ""));
foreach (const post_t * post, xact->posts)
if (post->has_xdata() &&
post->xdata().has_flags(POST_EXT_VISITED))
- put_post(post_tree, *post);
+ put_post(post_tree.add("posting", ""), *post);
}
switch (format) {
case FORMAT_XML:
- property_tree::write_xml(out, pt);
- break;
- case FORMAT_JSON:
- property_tree::write_json(out, pt);
+ property_tree::xml_writer_settings<char> indented(' ', 2);
+ property_tree::write_xml(out, pt, indented);
+ out << std::endl;
break;
}
}
diff --git a/src/ptree.h b/src/ptree.h
index b28f97d5..154c8837 100644
--- a/src/ptree.h
+++ b/src/ptree.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -75,8 +75,7 @@ protected:
public:
enum format_t {
- FORMAT_XML,
- FORMAT_JSON
+ FORMAT_XML
} format;
format_ptree(report_t& _report, format_t _format = FORMAT_XML)
diff --git a/src/py_account.cc b/src/py_account.cc
index 64a7ae54..fbd68140 100644
--- a/src/py_account.cc
+++ b/src/py_account.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 0aa8fee8..50e16a70 100644
--- a/src/py_amount.cc
+++ b/src/py_amount.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 2ae546f1..65e3c401 100644
--- a/src/py_balance.cc
+++ b/src/py_balance.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 b283efcc..44a45e33 100644
--- a/src/py_commodity.cc
+++ b/src/py_commodity.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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_expr.cc b/src/py_expr.cc
index dd9df1f5..c680bab4 100644
--- a/src/py_expr.cc
+++ b/src/py_expr.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 482eaf5b..43266b29 100644
--- a/src/py_format.cc
+++ b/src/py_format.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 893ddcfa..02b978c5 100644
--- a/src/py_item.cc
+++ b/src/py_item.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 50a52be9..7cce6b11 100644
--- a/src/py_journal.cc
+++ b/src/py_journal.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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_post.cc b/src/py_post.cc
index 692542a0..6061d6ee 100644
--- a/src/py_post.cc
+++ b/src/py_post.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 f411d5e1..7e2f9e8a 100644
--- a/src/py_session.cc
+++ b/src/py_session.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 17f9ec7e..599aa60c 100644
--- a/src/py_times.cc
+++ b/src/py_times.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 45ffe545..dc572621 100644
--- a/src/py_utils.cc
+++ b/src/py_utils.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 b931f008..8b565661 100644
--- a/src/py_value.cc
+++ b/src/py_value.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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_xact.cc b/src/py_xact.cc
index 3d792c7b..0b07f582 100644
--- a/src/py_xact.cc
+++ b/src/py_xact.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/pyfstream.h b/src/pyfstream.h
index 18f28bc4..12bbecfd 100644
--- a/src/pyfstream.h
+++ b/src/pyfstream.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 135a088b..3354d3e9 100644
--- a/src/pyinterp.cc
+++ b/src/pyinterp.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 56f808c8..e961f4c0 100644
--- a/src/pyinterp.h
+++ b/src/pyinterp.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 cf5e362e..ee7b99c9 100644
--- a/src/pyledger.cc
+++ b/src/pyledger.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 406ca1ee..6bb9d0bd 100644
--- a/src/pyutils.h
+++ b/src/pyutils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 07f724fd..209205ae 100644
--- a/src/query.cc
+++ b/src/query.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 fe52eb35..10820a59 100644
--- a/src/query.h
+++ b/src/query.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 e92af236..2df51ec1 100644
--- a/src/quotes.cc
+++ b/src/quotes.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/quotes.h
index 56740e47..813bdfa3 100644
--- a/src/quotes.h
+++ b/src/quotes.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 662386a4..29077f10 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -681,11 +681,21 @@ 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();
}
+value_t report_t::fn_roundto(call_scope_t& args)
+{
+ return args[0].roundto(args.get<int>(1));
+}
+
value_t report_t::fn_unround(call_scope_t& args)
{
return args[0].unrounded();
@@ -1084,6 +1094,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 +1102,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 +1111,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 +1129,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 +1154,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 +1181,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 +1211,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 +1229,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 +1256,10 @@ 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);
+ else OPT(values);
+ break;
case 'w':
OPT(weekly);
else OPT_(wide);
@@ -1335,6 +1353,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':
@@ -1420,6 +1440,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(fn_red);
else if (is_eq(p, "round"))
return MAKE_FUNCTOR(report_t::fn_round);
+ else if (is_eq(p, "roundto"))
+ return MAKE_FUNCTOR(report_t::fn_roundto);
break;
case 's':
@@ -1585,7 +1607,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");
@@ -1602,12 +1628,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
}
break;
- case 'j':
- if (is_eq(p, "json"))
- return POSTS_REPORTER(new format_ptree(*this,
- format_ptree::FORMAT_JSON));
+ 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
@@ -1649,7 +1673,11 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
else if (is_eq(p, "select"))
return WRAP_FUNCTOR(select_command);
break;
-
+ case 't':
+ if (is_eq(p, "tags")) {
+ return POSTS_REPORTER(new report_tags(*this));
+ }
+ break;
case 'x':
if (is_eq(p, "xact"))
return WRAP_FUNCTOR(xact_command);
diff --git a/src/report.h b/src/report.h
index 0f4fc103..5897e8f6 100644
--- a/src/report.h
+++ b/src/report.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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,7 +174,9 @@ 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_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);
@@ -357,6 +359,7 @@ public:
HANDLER(account_width_).report(out);
HANDLER(amount_width_).report(out);
HANDLER(total_width_).report(out);
+ HANDLER(values).report(out);
}
option_t<report_t> * lookup_option(const char * p);
@@ -1042,6 +1045,7 @@ public:
OPTION(report_t, account_width_);
OPTION(report_t, amount_width_);
OPTION(report_t, total_width_);
+ OPTION(report_t, values);
};
template <class Type = post_t,
diff --git a/src/scope.cc b/src/scope.cc
index 9112040c..10ae45a9 100644
--- a/src/scope.cc
+++ b/src/scope.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 4190f5bb..d6291439 100644
--- a/src/scope.h
+++ b/src/scope.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 afcfb351..b7e4c920 100644
--- a/src/select.cc
+++ b/src/select.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/select.h
index 54883d22..346067a2 100644
--- a/src/select.h
+++ b/src/select.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 b6153203..e5425a50 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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,12 +62,7 @@ void set_session_context(session_t * session)
session_t::session_t()
: flush_on_next_data_file(false), journal(new journal_t)
{
- if (const char * home_var = std::getenv("HOME"))
- HANDLER(price_db_).on(none, (path(home_var) / ".pricedb").string());
- else
- HANDLER(price_db_).on(none, path("./.pricedb").string());
-
- parsing_context.push();
+ parsing_context.push();
TRACE_CTOR(session_t, "");
}
@@ -98,8 +93,18 @@ std::size_t session_t::read_data(const string& master_account)
acct = journal->find_account(master_account);
optional<path> price_db_path;
- if (HANDLED(price_db_))
+ if (HANDLED(price_db_)){
price_db_path = resolve_path(HANDLER(price_db_).str());
+ if (!exists(price_db_path.get())){
+ throw_(parse_error, _f("Could not find specified price-db file %1%") % price_db_path);
+ }
+ } else {
+ if (const char * home_var = std::getenv("HOME")){
+ price_db_path = (path(home_var) / ".pricedb");
+ } else {
+ price_db_path = ("./.ledgerrc");
+ }
+ }
if (HANDLED(explicit))
journal->force_checking = true;
@@ -143,7 +148,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.
@@ -348,9 +353,11 @@ option_t<session_t> * session_t::lookup_option(const char * p)
case 's':
OPT(strict);
break;
+ case 't':
+ OPT(time_colon);
+ break;
case 'v':
OPT(value_expr_);
- break;
}
return NULL;
}
diff --git a/src/session.h b/src/session.h
index a0aba91b..21be3cc7 100644
--- a/src/session.h
+++ b/src/session.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -100,6 +100,7 @@ public:
HANDLER(day_break).report(out);
HANDLER(download).report(out);
HANDLER(decimal_comma).report(out);
+ HANDLER(time_colon).report(out);
HANDLER(file_).report(out);
HANDLER(input_date_format_).report(out);
HANDLER(explicit).report(out);
@@ -130,6 +131,10 @@ public:
commodity_t::decimal_comma_by_default = true;
});
+ OPTION_(session_t, time_colon, DO() {
+ commodity_t::time_colon_by_default = true;
+ });
+
OPTION__
(session_t, price_exp_, // -Z
CTOR(session_t, price_exp_) { value = "24"; });
diff --git a/src/stats.cc b/src/stats.cc
index a12420b6..81d71a46 100644
--- a/src/stats.cc
+++ b/src/stats.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 7b00fec8..5583e704 100644
--- a/src/stats.h
+++ b/src/stats.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 ce40bfcc..ad03ab77 100644
--- a/src/stream.cc
+++ b/src/stream.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/stream.h
index c317ebdf..bb63873a 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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/system.hh.in b/src/system.hh.in
index e7411a5e..ff7ea75b 100644
--- a/src/system.hh.in
+++ b/src/system.hh.in
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -204,7 +204,6 @@ typedef std::ostream::pos_type ostream_pos_type;
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
-#include <boost/property_tree/json_parser.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
diff --git a/src/temps.cc b/src/temps.cc
index 881077f6..b4778b49 100644
--- a/src/temps.cc
+++ b/src/temps.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 daa1493b..99110496 100644
--- a/src/temps.h
+++ b/src/temps.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 a5ae2f68..932bde84 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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);
@@ -282,6 +282,10 @@ void instance_t::parse()
}
}
+#if defined(TIMELOG_SUPPORT)
+ timelog.close();
+#endif // TIMELOG_SUPPORT
+
TRACE_STOP(instance_parse, 1);
}
@@ -397,7 +401,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 +496,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 +536,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 +579,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/timelog.cc b/src/timelog.cc
index 9516ba17..64017d50 100644
--- a/src/timelog.cc
+++ b/src/timelog.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -169,10 +169,8 @@ void time_log_t::close()
foreach (account_t * account, accounts) {
DEBUG("timelog", "Clocking out from account " << account->fullname());
- clock_out_from_timelog(time_xacts,
- time_xact_t(none, CURRENT_TIME(), account),
- context);
- context.count++;
+ context.count += clock_out_from_timelog
+ (time_xacts, time_xact_t(none, CURRENT_TIME(), account), context);
}
assert(time_xacts.empty());
}
diff --git a/src/timelog.h b/src/timelog.h
index a902c084..1ce0be28 100644
--- a/src/timelog.h
+++ b/src/timelog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 167aac73..f9a6c279 100644
--- a/src/times.cc
+++ b/src/times.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/times.h
index 9a0f21ff..4b89cc0c 100644
--- a/src/times.h
+++ b/src/times.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -111,20 +111,12 @@ std::string format_date(const date_t& when,
void set_date_format(const char * format);
void set_input_date_format(const char * format);
-inline void put_datetime(property_tree::ptree& pt, const datetime_t& when,
- bool wrap = true) {
- if (wrap)
- pt.put("datetime", format_datetime(when, FMT_WRITTEN));
- else
- pt.put_value(format_datetime(when, FMT_WRITTEN));
+inline void put_datetime(property_tree::ptree& pt, const datetime_t& when) {
+ pt.put_value(format_datetime(when, FMT_WRITTEN));
}
-inline void put_date(property_tree::ptree& pt, const date_t& when,
- bool wrap = true) {
- if (wrap)
- pt.put("date", format_date(when, FMT_WRITTEN));
- else
- pt.put_value(format_date(when, FMT_WRITTEN));
+inline void put_date(property_tree::ptree& pt, const date_t& when) {
+ pt.put_value(format_date(when, FMT_WRITTEN));
}
struct date_traits_t
diff --git a/src/token.cc b/src/token.cc
index 1c43af32..d0ec185b 100644
--- a/src/token.cc
+++ b/src/token.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.h b/src/token.h
index 01ff7ee9..51fa1d78 100644
--- a/src/token.h
+++ b/src/token.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 b2278796..eb38f8b1 100644
--- a/src/unistring.h
+++ b/src/unistring.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 1a82787d..2f592325 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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/utils.h b/src/utils.h
index 1b356e7c..c4d11636 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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.cc b/src/value.cc
index 1921d5a3..98e48c2f 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -1612,6 +1612,27 @@ void value_t::in_place_round()
throw_(value_error, _f("Cannot set rounding for %1%") % label());
}
+void value_t::in_place_roundto(int places)
+{
+ DEBUG("amount.roundto", "=====> roundto places " << places);
+ switch (type()) {
+ case INTEGER:
+ return;
+ case AMOUNT:
+ as_amount_lval().in_place_roundto(places);
+ return;
+ case BALANCE:
+ as_balance_lval().in_place_roundto(places);
+ return;
+ case SEQUENCE:
+ foreach (value_t& value, as_sequence_lval())
+ value.in_place_roundto(places);
+ return;
+ default:
+ break;
+ }
+}
+
void value_t::in_place_truncate()
{
switch (type()) {
@@ -1658,6 +1679,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()) {
@@ -1803,7 +1847,7 @@ void value_t::print(std::ostream& _out,
switch (type()) {
case VOID:
- out << "(null)";
+ out << "";
break;
case BOOLEAN:
@@ -2018,35 +2062,35 @@ void put_value(property_tree::ptree& pt, const value_t& value)
{
switch (value.type()) {
case value_t::VOID:
- pt.put("void", "");
+ pt.add("void", "");
break;
case value_t::BOOLEAN:
- pt.put("bool", value.as_boolean() ? "true" : "false");
+ pt.add("bool", value.as_boolean() ? "true" : "false");
break;
case value_t::INTEGER:
- pt.put("int", value.to_string());
+ pt.add("int", value.to_string());
break;
case value_t::AMOUNT:
- put_amount(pt, value.as_amount());
+ put_amount(pt.add("amount", ""), value.as_amount());
break;
case value_t::BALANCE:
- put_balance(pt, value.as_balance());
+ put_balance(pt.add("balance", ""), value.as_balance());
break;
case value_t::DATETIME:
- put_datetime(pt, value.as_datetime());
+ put_datetime(pt.add("datetime", ""), value.as_datetime());
break;
case value_t::DATE:
- put_date(pt, value.as_date());
+ put_date(pt.add("date", ""), value.as_date());
break;
case value_t::STRING:
- pt.put("string", value.as_string());
+ pt.add("string", value.as_string());
break;
case value_t::MASK:
- put_mask(pt, value.as_mask());
+ put_mask(pt.add("mask", ""), value.as_mask());
break;
case value_t::SEQUENCE: {
- property_tree::ptree& st(pt.put("sequence", ""));
+ property_tree::ptree& st(pt.add("sequence", ""));
foreach (const value_t& member, value.as_sequence())
put_value(st, member);
break;
diff --git a/src/value.h b/src/value.h
index ee3d414d..93760234 100644
--- a/src/value.h
+++ b/src/value.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -443,6 +443,13 @@ public:
}
void in_place_round();
+ value_t roundto(int places) const {
+ value_t temp(*this);
+ temp.in_place_roundto(places);
+ return temp;
+ }
+ void in_place_roundto(int places);
+
value_t truncated() const {
value_t temp(*this);
temp.in_place_truncate();
@@ -457,6 +464,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/views.cc b/src/views.cc
index 76d06370..2646e84b 100644
--- a/src/views.cc
+++ b/src/views.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 7f769250..94bedda5 100644
--- a/src/views.h
+++ b/src/views.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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 b5cb2a38..8aecf5d6 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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
@@ -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);
+ }
}
}
@@ -813,10 +847,8 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
}
}
-void put_xact(property_tree::ptree& pt, const xact_t& xact)
+void put_xact(property_tree::ptree& st, const xact_t& xact)
{
- property_tree::ptree& st(pt.put("transaction", ""));
-
if (xact.state() == item_t::CLEARED)
st.put("<xmlattr>.state", "cleared");
else if (xact.state() == item_t::PENDING)
@@ -825,14 +857,10 @@ void put_xact(property_tree::ptree& pt, const xact_t& xact)
if (xact.has_flags(ITEM_GENERATED))
st.put("<xmlattr>.generated", "true");
- if (xact._date) {
- property_tree::ptree& t(st.put("date", ""));
- put_date(t, *xact._date, false);
- }
- if (xact._date_aux) {
- property_tree::ptree& t(st.put("aux-date", ""));
- put_date(t, *xact._date_aux, false);
- }
+ if (xact._date)
+ put_date(st.put("date", ""), *xact._date);
+ if (xact._date_aux)
+ put_date(st.put("aux-date", ""), *xact._date_aux);
if (xact.code)
st.put("code", *xact.code);
@@ -843,7 +871,7 @@ void put_xact(property_tree::ptree& pt, const xact_t& xact)
st.put("note", *xact.note);
if (xact.metadata)
- put_metadata(st, *xact.metadata);
+ put_metadata(st.put("metadata", ""), *xact.metadata);
}
} // namespace ledger
diff --git a/src/xact.h b/src/xact.h
index c5ad3ad6..e59ead75 100644
--- a/src/xact.h
+++ b/src/xact.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2013, 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