summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account.h7
-rw-r--r--src/amount.cc46
-rw-r--r--src/amount.h9
-rw-r--r--src/balance.h11
-rw-r--r--src/commodity.cc1
-rw-r--r--src/commodity.h9
-rw-r--r--src/context.h2
-rw-r--r--src/csv.cc10
-rw-r--r--src/error.cc2
-rw-r--r--src/filters.cc11
-rw-r--r--src/global.cc60
-rw-r--r--src/global.h10
-rw-r--r--src/item.cc25
-rw-r--r--src/journal.cc13
-rw-r--r--src/main.cc4
-rw-r--r--src/output.cc28
-rw-r--r--src/output.h31
-rw-r--r--src/post.h2
-rw-r--r--src/print.cc13
-rw-r--r--src/py_xact.cc6
-rw-r--r--src/report.cc40
-rw-r--r--src/report.h3
-rw-r--r--src/session.cc12
-rw-r--r--src/session.h5
-rw-r--r--src/textual.cc8
-rw-r--r--src/value.cc23
-rw-r--r--src/value.h7
-rw-r--r--src/xact.cc42
28 files changed, 370 insertions, 70 deletions
diff --git a/src/account.h b/src/account.h
index a2fcb8de..3642ada0 100644
--- a/src/account.h
+++ b/src/account.h
@@ -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..ee03827e 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -195,7 +195,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 +212,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
@@ -670,10 +676,27 @@ void amount_t::in_place_floor()
_dup();
- std::ostringstream out;
- stream_out_mpq(out, MP(quantity), precision_t(0), -1, GMP_RNDZ);
+ mpz_t quot;
+ mpz_init(quot);
+ mpz_fdiv_q(quot, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_clear(MP(quantity));
+ mpq_init(MP(quantity));
+ mpq_set_num(MP(quantity), quot);
+}
+
+void amount_t::in_place_ceiling()
+{
+ if (! quantity)
+ throw_(amount_error, _("Cannot ceiling an uninitialized amount"));
- mpq_set_str(MP(quantity), out.str().c_str(), 10);
+ _dup();
+
+ mpz_t quot;
+ mpz_init(quot);
+ mpz_cdiv_q(quot, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_clear(MP(quantity));
+ mpq_init(MP(quantity));
+ mpq_set_num(MP(quantity), quot);
}
void amount_t::in_place_unround()
@@ -720,6 +743,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 +1106,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;
diff --git a/src/amount.h b/src/amount.h
index 49027bb7..1b7d2101 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -364,6 +364,15 @@ public:
}
void in_place_floor();
+ /** Yields an amount which has lost all of its extra precision, beyond what
+ the display precision of the commodity would have printed. */
+ amount_t ceilinged() const {
+ amount_t temp(*this);
+ temp.in_place_ceiling();
+ return temp;
+ }
+ void in_place_ceiling();
+
/** Yields an amount whose display precision is never truncated, even
though its commodity normally displays only rounded values. */
amount_t unrounded() const {
diff --git a/src/balance.h b/src/balance.h
index 230a4e2c..9635742d 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -345,6 +345,17 @@ public:
pair.second.in_place_floor();
}
+ balance_t ceilinged() const {
+ balance_t temp(*this);
+ temp.in_place_ceiling();
+ return temp;
+ }
+ void in_place_ceiling() {
+ foreach (amounts_map::value_type& pair, amounts)
+ pair.second.in_place_ceiling();
+ }
+
+
balance_t unrounded() const {
balance_t temp(*this);
temp.in_place_unround();
diff --git a/src/commodity.cc b/src/commodity.cc
index 05d465ca..ffeac10d 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -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)
diff --git a/src/commodity.h b/src/commodity.h
index ab496850..82efac6a 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -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/context.h b/src/context.h
index 7373be39..9fe0613b 100644
--- a/src/context.h
+++ b/src/context.h
@@ -121,7 +121,7 @@ inline parse_context_t open_for_reading(const path& pathname,
throw_(std::runtime_error,
_f("Cannot read journal file %1%") % filename);
- path parent(pathname.parent_path());
+ path parent(filename.parent_path());
shared_ptr<std::istream> stream(new ifstream(filename));
parse_context_t context(stream, parent);
context.pathname = filename;
diff --git a/src/csv.cc b/src/csv.cc
index 71b6516a..c7b75712 100644
--- a/src/csv.cc
+++ b/src/csv.cc
@@ -166,7 +166,7 @@ xact_t * csv_reader::read_xact(bool rich_data)
string total;
string field;
- while (instr.good() && ! instr.eof()) {
+ while (instr.good() && ! instr.eof() && n < index.size()) {
field = read_field(instr);
switch (index[n]) {
@@ -175,7 +175,8 @@ xact_t * csv_reader::read_xact(bool rich_data)
break;
case FIELD_DATE_AUX:
- xact->_date_aux = parse_date(field);
+ if (! field.empty())
+ xact->_date_aux = parse_date(field);
break;
case FIELD_CODE:
@@ -224,7 +225,8 @@ xact_t * csv_reader::read_xact(bool rich_data)
break;
case FIELD_NOTE:
- xact->note = field;
+ if (! field.empty())
+ xact->note = field;
break;
case FIELD_UNKNOWN:
@@ -243,7 +245,7 @@ xact_t * csv_reader::read_xact(bool rich_data)
// Translate the account name, if we have enough information to do so
- foreach (account_mapping_t& value, context.journal->account_mappings) {
+ foreach (account_mapping_t& value, context.journal->payees_for_unknown_accounts) {
if (value.first.match(xact->payee)) {
post->account = value.second;
break;
diff --git a/src/error.cc b/src/error.cc
index 58339db7..8aa1d3d6 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -84,7 +84,7 @@ string source_context(const path& file,
const string& prefix)
{
const std::streamoff len = end_pos - pos;
- if (! len || file == path("/dev/stdin"))
+ if (! len || file.empty())
return _("<no source context>");
assert(len > 0);
diff --git a/src/filters.cc b/src/filters.cc
index f5694133..7570809a 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -530,9 +530,11 @@ bool display_filter_posts::output_rounding(post_t& post)
}
// Allow the posting to be displayed if:
- // 1. It's display_amount would display as non-zero
- // 2. The --empty option was specified
- // 3. The account of the posting is <Revalued>
+ // 1. Its display_amount would display as non-zero, or
+ // 2. The --empty option was specified, or
+ // 3. a) The account of the posting is <Revalued>, and
+ // b) the revalued option is specified, and
+ // c) the --no-rounding option is not specified.
if (post.account == revalued_account) {
if (show_rounding)
@@ -981,7 +983,8 @@ void interval_posts::flush()
sort_posts_by_date());
// Determine the beginning interval by using the earliest post
- if (! interval.find_period(all_posts.front()->date()))
+ if (all_posts.front() &&
+ ! interval.find_period(all_posts.front()->date()))
throw_(std::logic_error, _("Failed to find period for interval report"));
// Walk the interval forward reporting all posts within each one
diff --git a/src/global.cc b/src/global.cc
index a718d6cb..5fc10f02 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -44,6 +44,7 @@
namespace ledger {
static bool args_only = false;
+std::string _init_file;
global_scope_t::global_scope_t(char ** envp)
{
@@ -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..11459529 100644
--- a/src/global.h
+++ b/src/global.h
@@ -46,6 +46,8 @@ namespace ledger {
class session_t;
class report_t;
+extern std::string _init_file;
+
class global_scope_t : public noncopyable, public scope_t
{
shared_ptr<session_t> session_ptr;
@@ -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);
@@ -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/item.cc b/src/item.cc
index 0630043b..4e2a487c 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -330,6 +330,21 @@ namespace {
return NULL_VALUE;
}
+ value_t get_filebase(item_t& item) {
+ if (item.pos)
+ return string_value(item.pos->pathname.filename().string());
+ else
+ return NULL_VALUE;
+ }
+
+ value_t get_filepath(item_t& item) {
+ if (item.pos)
+ return string_value(item.pos->pathname.parent_path().string());
+ else
+ return NULL_VALUE;
+ }
+
+
value_t get_beg_pos(item_t& item) {
return item.pos ? long(item.pos->beg_pos) : 0L;
}
@@ -456,7 +471,11 @@ expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind,
case 'f':
if (name == "filename")
return WRAP_FUNCTOR(get_wrapper<&get_pathname>);
- break;
+ else if (name == "filebase")
+ return WRAP_FUNCTOR(get_wrapper<&get_filebase>);
+ else if (name == "filepath")
+ return WRAP_FUNCTOR(get_wrapper<&get_filepath>);
+ break;
case 'h':
if (name == "has_tag")
@@ -563,8 +582,8 @@ string item_context(const item_t& item, const string& desc)
std::ostringstream out;
- if (item.pos->pathname == path("/dev/stdin")) {
- out << desc << _(" from standard input:");
+ if (item.pos->pathname.empty()) {
+ out << desc << _(" from streamed input:");
return out.str();
}
diff --git a/src/journal.cc b/src/journal.cc
index e6c09125..68939be6 100644
--- a/src/journal.cc
+++ b/src/journal.cc
@@ -127,8 +127,19 @@ account_t * journal_t::register_account(const string& name, post_t * post,
// object.
if (account_aliases.size() > 0) {
accounts_map::const_iterator i = account_aliases.find(name);
- if (i != account_aliases.end())
+ if (i != account_aliases.end()) {
result = (*i).second;
+ } else {
+ // only check the very first account for alias expansion, in case
+ // that can be expanded successfully
+ size_t colon = name.find(':');
+ if(colon != string::npos) {
+ accounts_map::const_iterator i = account_aliases.find(name.substr(0, colon));
+ if (i != account_aliases.end()) {
+ result = find_account((*i).second->fullname() + name.substr(colon));
+ }
+ }
+ }
}
// Create the account object and associate it with the journal; this
diff --git a/src/main.cc b/src/main.cc
index a1ac0339..a44506c9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -59,6 +59,7 @@ int main(int argc, char * argv[], char * envp[])
// --debug CATEGORY ; turns on debug logging
// --trace LEVEL ; turns on trace logging
// --memory ; turns on memory usage tracing
+ // --init-file ; directs ledger to use a different init file
handle_debug_options(argc, argv);
#if VERIFY_ON
IF_VERIFY() initialize_memory_tracing();
@@ -213,7 +214,8 @@ int main(int argc, char * argv[], char * envp[])
} else
#endif
{
- global_scope->quick_close();
+ if (global_scope)
+ global_scope->quick_close();
INFO("Ledger ended"); // let global_scope leak!
}
diff --git a/src/output.cc b/src/output.cc
index f433f8d1..6ed7f861 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -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..44eca2d2 100644
--- a/src/output.h
+++ b/src/output.h
@@ -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/post.h b/src/post.h
index a9a44a79..c9aec6b2 100644
--- a/src/post.h
+++ b/src/post.h
@@ -83,7 +83,7 @@ public:
const optional<string>& _note = none)
: item_t(_flags, _note), xact(NULL), account(_account), amount(_amount)
{
- TRACE_CTOR(post_t, "account_t *, const amount_t&, flags_t, const optional<string>&");
+ TRACE_CTOR(post_t, "account_t *, amount_t, flags_t, optional<string>");
}
post_t(const post_t& post)
: item_t(post),
diff --git a/src/print.cc b/src/print.cc
index 79d83161..a4a0bc6f 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -203,9 +203,15 @@ namespace {
(static_cast<std::string::size_type>(account_width) -
static_cast<std::string::size_type>(name.length()));
+ std::size_t amount_width =
+ (report.HANDLED(amount_width_) ?
+ lexical_cast<std::size_t>(report.HANDLER(amount_width_).str()) :
+ 12);
string amt;
if (post->amount_expr) {
- amt = post->amount_expr->text();
+ std::ostringstream amt_str;
+ justify(amt_str, post->amount_expr->text(), amount_width, true);
+ amt = amt_str.str();
}
else if (count == 2 && index == 2 &&
post_has_simple_amount(*post) &&
@@ -218,11 +224,6 @@ namespace {
// first.
}
else {
- std::size_t amount_width =
- (report.HANDLED(amount_width_) ?
- lexical_cast<std::size_t>(report.HANDLER(amount_width_).str()) :
- 12);
-
std::ostringstream amt_str;
value_t(post->amount).print(amt_str, static_cast<int>(amount_width),
-1, AMOUNT_PRINT_RIGHT_JUSTIFY |
diff --git a/src/py_xact.cc b/src/py_xact.cc
index 3d792c7b..96674207 100644
--- a/src/py_xact.cc
+++ b/src/py_xact.cc
@@ -119,8 +119,8 @@ void export_xact()
.def("__str__", py_xact_to_string)
.add_property("code",
- make_getter(&xact_t::code),
- make_setter(&xact_t::code))
+ make_getter(&xact_t::code, return_value_policy<return_by_value>()),
+ make_setter(&xact_t::code, return_value_policy<return_by_value>()))
.add_property("payee",
make_getter(&xact_t::payee),
make_setter(&xact_t::payee))
@@ -157,6 +157,8 @@ void export_xact()
make_getter(&period_xact_t::period_string),
make_setter(&period_xact_t::period_string))
;
+
+ register_optional_to_python<std::string>();
}
} // namespace ledger
diff --git a/src/report.cc b/src/report.cc
index 662386a4..80993515 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -681,6 +681,11 @@ value_t report_t::fn_floor(call_scope_t& args)
return args[0].floored();
}
+value_t report_t::fn_ceiling(call_scope_t& args)
+{
+ return args[0].ceilinged();
+}
+
value_t report_t::fn_round(call_scope_t& args)
{
return args[0].rounded();
@@ -1084,6 +1089,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(anon);
else OPT_ALT(color, ansi);
else OPT(auto_match);
+ else OPT(aux_date);
else OPT(average);
else OPT(account_width_);
else OPT(amount_width_);
@@ -1091,7 +1097,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
case 'b':
OPT(balance_format_);
else OPT(base);
- else OPT_ALT(basis, cost);
+ else OPT(basis);
else OPT_(begin_);
else OPT(bold_if_);
else OPT(budget);
@@ -1100,6 +1106,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
break;
case 'c':
OPT(csv_format_);
+ else OPT_ALT(gain, change);
else OPT(cleared);
else OPT(collapse);
else OPT(collapse_if_zero);
@@ -1117,6 +1124,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(dc);
else OPT(depth_);
else OPT(deviation);
+ else OPT_ALT(rich_data, detail);
else OPT_(display_);
else OPT(display_amount_);
else OPT(display_total_);
@@ -1141,7 +1149,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT_ALT(head_, first_);
break;
case 'g':
- OPT_ALT(gain, change);
+ OPT(gain);
else OPT(group_by_);
else OPT(group_title_format_);
else OPT(generated);
@@ -1168,7 +1176,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT_ALT(tail_, last_);
break;
case 'm':
- OPT_ALT(market, value);
+ OPT(market);
else OPT(monthly);
else OPT(meta_);
else OPT(meta_width_);
@@ -1198,6 +1206,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(price);
else OPT(prices_format_);
else OPT(pricedb_format_);
+ else OPT(primary_date);
else OPT(payee_width_);
else OPT(prepend_format_);
else OPT(prepend_width_);
@@ -1215,7 +1224,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(revalued);
else OPT(revalued_only);
else OPT(revalued_total_);
- else OPT_ALT(rich_data, detail);
+ else OPT(rich_data);
break;
case 's':
OPT(sort_);
@@ -1242,6 +1251,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 +1348,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(fn_cyan);
else if (is_eq(p, "commodity"))
return MAKE_FUNCTOR(report_t::fn_commodity);
+ else if (is_eq(p, "ceiling"))
+ return MAKE_FUNCTOR(report_t::fn_ceiling);
break;
case 'd':
@@ -1585,7 +1600,11 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return POSTS_REPORTER(new report_commodities(*this));
}
break;
-
+ case 'd':
+ if (is_eq(p, "draft")) {
+ return WRAP_FUNCTOR(xact_command);
+ }
+ break;
case 'e':
if (is_eq(p, "equity")) {
HANDLER(generated).on("#equity");
@@ -1607,7 +1626,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return POSTS_REPORTER(new format_ptree(*this,
format_ptree::FORMAT_JSON));
break;
-
+ case 'l':
+ if (is_eq(p, "lisp"))
+ return POSTS_REPORTER(new format_emacs_posts(output_stream));
+ break;
case 'o':
if (is_eq(p, "org"))
return POSTS_REPORTER(new posts_to_org_table
@@ -1649,7 +1671,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 4a02843e..b0044f60 100644
--- a/src/report.h
+++ b/src/report.h
@@ -174,6 +174,7 @@ public:
value_t fn_unrounded(call_scope_t& scope);
value_t fn_truncated(call_scope_t& scope);
value_t fn_floor(call_scope_t& scope);
+ value_t fn_ceiling(call_scope_t& scope);
value_t fn_round(call_scope_t& scope);
value_t fn_unround(call_scope_t& scope);
value_t fn_abs(call_scope_t& scope);
@@ -357,6 +358,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 +1044,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/session.cc b/src/session.cc
index b6153203..632002d4 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -98,8 +98,12 @@ 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 file %1%") % price_db_path);
+ }
+ }
if (HANDLED(explicit))
journal->force_checking = true;
@@ -143,7 +147,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 +352,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..74aeab5f 100644
--- a/src/session.h
+++ b/src/session.h
@@ -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/textual.cc b/src/textual.cc
index 0ead9232..6106914f 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -148,7 +148,7 @@ namespace {
void account_value_directive(account_t * account, string expr_str);
void account_default_directive(account_t * account);
- void default_account_directive(char * line);
+ void default_account_directive(char * args);
void alias_directive(char * line);
void payee_directive(char * line);
@@ -397,7 +397,7 @@ void instance_t::read_next_directive(bool& error_flag)
#endif // TIMELOG_SUPPORT
case 'A': // a default account for unbalanced posts
- default_account_directive(line);
+ default_account_directive(line + 1);
break;
case 'C': // a set of conversions
price_conversion_directive(line);
@@ -492,7 +492,7 @@ void instance_t::default_commodity_directive(char * line)
void instance_t::default_account_directive(char * line)
{
- context.journal->bucket = top_account()->find_account(skip_ws(line + 1));
+ context.journal->bucket = top_account()->find_account(skip_ws(line));
context.journal->bucket->add_flags(ACCOUNT_KNOWN);
}
@@ -575,7 +575,7 @@ void instance_t::automated_xact_directive(char * line)
item = ae.get();
// This is a trailing note, and possibly a metadata info tag
- item->append_note(p + 1, *context.scope, true);
+ ae->append_note(p + 1, *context.scope, true);
item->add_flags(ITEM_NOTE_ON_NEXT_LINE);
item->pos->end_pos = context.curr_pos;
item->pos->end_line++;
diff --git a/src/value.cc b/src/value.cc
index 1921d5a3..c57cff78 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1658,6 +1658,29 @@ void value_t::in_place_floor()
throw_(value_error, _f("Cannot floor %1%") % label());
}
+void value_t::in_place_ceiling()
+{
+ switch (type()) {
+ case INTEGER:
+ return;
+ case AMOUNT:
+ as_amount_lval().in_place_ceiling();
+ return;
+ case BALANCE:
+ as_balance_lval().in_place_ceiling();
+ return;
+ case SEQUENCE:
+ foreach (value_t& value, as_sequence_lval())
+ value.in_place_ceiling();
+ return;
+ default:
+ break;
+ }
+
+ add_error_context(_f("While ceiling %1%:") % *this);
+ throw_(value_error, _f("Cannot ceiling %1%") % label());
+}
+
void value_t::in_place_unround()
{
switch (type()) {
diff --git a/src/value.h b/src/value.h
index ee3d414d..249f3d7f 100644
--- a/src/value.h
+++ b/src/value.h
@@ -457,6 +457,13 @@ public:
}
void in_place_floor();
+ value_t ceilinged() const {
+ value_t temp(*this);
+ temp.in_place_ceiling();
+ return temp;
+ }
+ void in_place_ceiling();
+
value_t unrounded() const {
value_t temp(*this);
temp.in_place_unround();
diff --git a/src/xact.cc b/src/xact.cc
index a54da81a..7ac7a9e9 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -36,6 +36,7 @@
#include "account.h"
#include "journal.h"
#include "context.h"
+#include "format.h"
#include "pool.h"
namespace ledger {
@@ -644,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());
@@ -695,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);
}
}
@@ -775,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,
@@ -787,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);
+ }
}
}