summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account.cc8
-rw-r--r--src/account.h2
-rw-r--r--src/item.cc6
-rw-r--r--src/item.h2
-rw-r--r--src/main.cc31
-rw-r--r--src/report.cc2
-rw-r--r--src/report.h5
-rw-r--r--src/session.h4
-rw-r--r--src/work.cc4
-rw-r--r--src/work.h2
10 files changed, 34 insertions, 32 deletions
diff --git a/src/account.cc b/src/account.cc
index 614d7119..9d7bf1e5 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -197,7 +197,7 @@ expr_t::ptr_op_t account_t::lookup(const string& name)
break;
}
- return session_t::current->report->lookup(name);
+ return session_t::current->global_scope->lookup(name);
}
bool account_t::valid() const
@@ -222,12 +222,12 @@ bool account_t::valid() const
return true;
}
-void account_t::calculate_sums()
+void account_t::calculate_sums(expr_t& amount_expr)
{
xdata_t& xd(xdata());
foreach (accounts_map::value_type& pair, accounts) {
- (*pair.second).calculate_sums();
+ (*pair.second).calculate_sums(amount_expr);
xdata_t& child_xd((*pair.second).xdata());
if (! child_xd.total.is_null()) {
@@ -240,7 +240,7 @@ void account_t::calculate_sums()
}
call_scope_t args(*this);
- value_t amount(session_t::current->report->get_amount_expr(args));
+ value_t amount(amount_expr.calc(args));
if (! amount.is_null()) {
add_or_set_value(xd.total, amount);
xd.total_count += xd.count;
diff --git a/src/account.h b/src/account.h
index fa077bbc..ad59a5b8 100644
--- a/src/account.h
+++ b/src/account.h
@@ -177,7 +177,7 @@ class account_t : public scope_t
return *xdata_;
}
- void calculate_sums();
+ void calculate_sums(expr_t& amount_expr);
};
std::ostream& operator<<(std::ostream& out, const account_t& account);
diff --git a/src/item.cc b/src/item.cc
index 2fe7601c..175797ff 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -35,6 +35,8 @@
namespace ledger {
+bool item_t::use_effective_date = false;
+
bool item_t::has_tag(const string& tag) const
{
if (! metadata)
@@ -224,7 +226,7 @@ value_t get_comment(item_t& item)
optional<date_t> item_t::date() const
{
- if (session_t::current->report->use_effective_date && _date_eff)
+ if (use_effective_date && _date_eff)
return effective_date();
else
return actual_date();
@@ -293,7 +295,7 @@ expr_t::ptr_op_t item_t::lookup(const string& name)
break;
}
- return session_t::current->report->lookup(name);
+ return session_t::current->global_scope->lookup(name);
}
bool item_t::valid() const
diff --git a/src/item.h b/src/item.h
index 78052e81..2fd9d0a3 100644
--- a/src/item.h
+++ b/src/item.h
@@ -93,6 +93,8 @@ public:
std::size_t full_end_line;
#endif
+ static bool use_effective_date;
+
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
: supports_flags<>(_flags),
_state(UNCLEARED), note(_note), journal(NULL), src_idx(0),
diff --git a/src/main.cc b/src/main.cc
index f454313a..b5b65da9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -39,6 +39,7 @@ int main(int argc, char * argv[], char * envp[])
using namespace ledger;
session_t * session = NULL;
+ report_t * report = NULL;
int status = 1;
try {
// The very first thing we do is handle some very special command-line
@@ -67,8 +68,8 @@ int main(int argc, char * argv[], char * envp[])
// between session and report doesn't really matter, but if a GUI were
// calling into Ledger it would have one session object per open document,
// with a separate report_t object for each report it generated.
- session->report.reset(new report_t(*session));
- report_t& report(*session->report.get());
+ report = new report_t(*session);
+ session->global_scope = report;
// Read the user's options, in the following order:
//
@@ -79,10 +80,10 @@ int main(int argc, char * argv[], char * envp[])
// Before processing command-line options, we must notify the session
// object that such options are beginning, since options like -f cause a
// complete override of files found anywhere else.
- read_environment_settings(report, envp);
- session->read_init(); // accesses report object via session.report
+ read_environment_settings(*report, envp);
+ session->read_init();
session->now_at_command_line(true);
- strings_list args = read_command_line_arguments(report, argc, argv);
+ strings_list args = read_command_line_arguments(*report, argc, argv);
// Look for a precommand first, which is defined as any defined function
// whose name starts with "ledger_precmd_". The difference between a
@@ -100,21 +101,21 @@ int main(int argc, char * argv[], char * envp[])
string_iterator arg = args.begin();
string verb = *arg++;
- if (function_t command = look_for_precommand(report, verb)) {
+ if (function_t command = look_for_precommand(*report, verb)) {
// Create the output stream (it might be a file, the console or a PAGER
// subprocess) and invoke the report command.
- create_output_stream(report);
- invoke_command_verb(report, command, arg, args.end());
+ create_output_stream(*report);
+ invoke_command_verb(*report, command, arg, args.end());
}
- else if (function_t command = look_for_command(report, verb)) {
+ else if (function_t command = look_for_command(*report, verb)) {
// This is regular command verb, so parse the user's data.
- if (journal_t * journal = read_journal_files(*session)) {
- normalize_report_options(report, verb); // jww (2009-02-02): a hack
+ if (journal_t * journal = read_journal_files(*session, report->account)) {
+ normalize_report_options(*report, verb); // jww (2009-02-02): a hack
// Create the output stream (it might be a file, the console or a
// PAGER subprocess) and invoke the report command.
- create_output_stream(report);
- invoke_command_verb(report, command, arg, args.end());
+ create_output_stream(*report);
+ invoke_command_verb(*report, command, arg, args.end());
// Write out a binary cache of the journal data, if needful and
// appropriate to do so.
@@ -146,7 +147,7 @@ int main(int argc, char * argv[], char * envp[])
}
// Close the output stream, waiting on the pager process to exit if need be
- session->report->output_stream.close();
+ report->output_stream.close();
// If memory verification is being performed (which can be very slow), clean
// up everything by closing the session and deleting the session object, and
@@ -156,6 +157,8 @@ int main(int argc, char * argv[], char * envp[])
set_session_context(NULL);
if (session != NULL)
checked_delete(session);
+ if (report != NULL)
+ checked_delete(report);
INFO("Ledger ended (Boost/libstdc++ may still hold memory)");
shutdown_memory_tracing();
diff --git a/src/report.cc b/src/report.cc
index efcb9c1b..f72798ec 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -62,7 +62,7 @@ void report_t::sum_all_accounts()
pass_down_xacts
(chain_xact_handlers(*this, xact_handler_ptr(new set_account_value), false),
walker);
- session.master->calculate_sums();
+ session.master->calculate_sums(amount_expr);
}
void report_t::accounts_report(acct_handler_ptr handler)
diff --git a/src/report.h b/src/report.h
index 2654d7c6..d8796741 100644
--- a/src/report.h
+++ b/src/report.h
@@ -149,8 +149,6 @@ public:
bool entry_sort;
bool sort_all;
bool anonymize;
- bool use_effective_date;
-
string account;
optional<path> pager_path;
@@ -186,7 +184,6 @@ public:
entry_sort(false),
sort_all(false),
anonymize(false),
- use_effective_date(false),
raw_mode(false),
@@ -277,7 +274,7 @@ public:
// Report filtering
value_t option_effective(call_scope_t& args) {
- use_effective_date = true;
+ item_t::use_effective_date = true;
}
#endif
diff --git a/src/session.h b/src/session.h
index d7023045..ea5538c4 100644
--- a/src/session.h
+++ b/src/session.h
@@ -53,8 +53,6 @@
namespace ledger {
-class report_t;
-
/**
* @brief Brief
*
@@ -71,7 +69,7 @@ class session_t : public noncopyable, public scope_t
public:
static session_t * current;
- scoped_ptr<report_t> report;
+ scope_t * global_scope;
std::list<path> data_files;
bool next_data_file_from_command_line;
diff --git a/src/work.cc b/src/work.cc
index e991bc96..a54b1352 100644
--- a/src/work.cc
+++ b/src/work.cc
@@ -148,13 +148,13 @@ function_t look_for_precommand(report_t& report, const string& verb)
return function_t();
}
-journal_t * read_journal_files(session_t& session)
+journal_t * read_journal_files(session_t& session, const string& account)
{
INFO_START(journal, "Read journal file");
journal_t * journal(session.create_journal());
- std::size_t count = session.read_data(*journal, session.report->account);
+ std::size_t count = session.read_data(*journal, account);
if (count == 0)
throw_(parse_error, "Failed to locate any journal entries; "
"did you specify a valid file with -f?");
diff --git a/src/work.h b/src/work.h
index acba3725..607e46eb 100644
--- a/src/work.h
+++ b/src/work.h
@@ -49,7 +49,7 @@ strings_list read_command_line_arguments(report_t& report,
int argc, char * argv[]);
void normalize_session_options(session_t& session);
function_t look_for_precommand(report_t& report, const string& verb);
-journal_t * read_journal_files(session_t& session);
+journal_t * read_journal_files(session_t& session, const string& account);
function_t look_for_command(report_t& report, const string& verb);
void normalize_report_options(report_t& report, const string& verb);
void create_output_stream(report_t& report);