summaryrefslogtreecommitdiff
path: root/src/global.cc
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-01-29 10:30:18 -0700
committerCraig Earls <enderw88@gmail.com>2013-01-29 10:30:18 -0700
commitaba5c1aa465c6ad92839fc9259a6a21d2292192e (patch)
treeb9211a7302874076128850897430e0bc6b8f5509 /src/global.cc
parent5d1971ee51a18f927185d20fb0a4426d8f08aa86 (diff)
downloadfork-ledger-aba5c1aa465c6ad92839fc9259a6a21d2292192e.tar.gz
fork-ledger-aba5c1aa465c6ad92839fc9259a6a21d2292192e.tar.bz2
fork-ledger-aba5c1aa465c6ad92839fc9259a6a21d2292192e.zip
Fixes bugs 705 and 862. Ledger now fails if init or pricedb files are specified on the command line but not found.
Diffstat (limited to 'src/global.cc')
-rw-r--r--src/global.cc53
1 files changed, 37 insertions, 16 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];