summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/global.cc53
-rw-r--r--src/global.h6
-rw-r--r--src/session.cc6
3 files changed, 43 insertions, 22 deletions
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/session.cc b/src/session.cc
index f047a540..f9815c3f 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;