summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc23
-rw-r--r--src/commodity.cc1
-rw-r--r--src/commodity.h2
-rw-r--r--src/global.cc53
-rw-r--r--src/global.h6
-rw-r--r--src/output.cc28
-rw-r--r--src/output.h27
-rw-r--r--src/report.cc20
-rw-r--r--src/report.h2
-rw-r--r--src/session.cc10
-rw-r--r--src/session.h5
11 files changed, 142 insertions, 35 deletions
diff --git a/src/amount.cc b/src/amount.cc
index cba9a282..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
@@ -737,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;
}
@@ -1090,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/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 37b02e74..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);
diff --git a/src/global.cc b/src/global.cc
index bc172075..5fc10f02 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -107,32 +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];
diff --git a/src/global.h b/src/global.h
index dc6abd78..11459529 100644
--- a/src/global.h
+++ b/src/global.h
@@ -67,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);
@@ -156,11 +157,6 @@ See LICENSE file included with the distribution for details and disclaimer.");
if (!_init_file.empty())
// _init_file is filled during handle_debug_options
on(none, _init_file);
- else
- if (const char * home_var = std::getenv("HOME"))
- on(none, (path(home_var) / ".ledgerrc").string());
- else
- on(none, path("./.ledgerrc").string());
});
OPTION(global_scope_t, options);
diff --git a/src/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 5ce9dc58..44eca2d2 100644
--- a/src/output.h
+++ b/src/output.h
@@ -189,6 +189,33 @@ 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:
diff --git a/src/report.cc b/src/report.cc
index d4beaf2a..f7b71b94 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -1089,7 +1089,6 @@ 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_);
@@ -1097,7 +1096,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
case 'b':
OPT(balance_format_);
else OPT(base);
- else OPT(basis);
+ else OPT_ALT(basis, cost);
else OPT_(begin_);
else OPT(bold_if_);
else OPT(budget);
@@ -1106,7 +1105,6 @@ 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);
@@ -1124,7 +1122,6 @@ 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_);
@@ -1149,7 +1146,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT_ALT(head_, first_);
break;
case 'g':
- OPT(gain);
+ OPT_ALT(gain, change);
else OPT(group_by_);
else OPT(group_title_format_);
else OPT(generated);
@@ -1176,7 +1173,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT_ALT(tail_, last_);
break;
case 'm':
- OPT(market);
+ OPT_ALT(market, value);
else OPT(monthly);
else OPT(meta_);
else OPT(meta_width_);
@@ -1206,7 +1203,6 @@ 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_);
@@ -1224,7 +1220,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(rich_data);
+ else OPT_ALT(rich_data, detail);
break;
case 's':
OPT(sort_);
@@ -1252,7 +1248,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(unround);
break;
case 'v':
- OPT_ALT(market, value);
+ OPT(values);
break;
case 'w':
OPT(weekly);
@@ -1670,7 +1666,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 2eac61fe..b0044f60 100644
--- a/src/report.h
+++ b/src/report.h
@@ -358,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);
@@ -1043,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 f047a540..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;
@@ -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"; });