Merge pull request #133 from enderw88/Bug705-862-init-file-and-pricedb
Fixes bugs 705 and 862.
This commit is contained in:
commit
a5adcaad3e
3 changed files with 43 additions and 22 deletions
|
|
@ -107,32 +107,53 @@ global_scope_t::~global_scope_t()
|
||||||
#endif
|
#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()
|
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_)) {
|
if (HANDLED(init_file_)) {
|
||||||
path init_file(HANDLER(init_file_).str());
|
init_file=HANDLER(init_file_).str();
|
||||||
if (exists(init_file)) {
|
if (exists(init_file)) {
|
||||||
TRACE_START(init, 1, "Read initialization file");
|
parse_init(init_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);
|
|
||||||
} else {
|
} else {
|
||||||
throw_(parse_error, _f("Could not find specified init file %1%") % init_file);
|
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()
|
char * global_scope_t::prompt_string()
|
||||||
{
|
{
|
||||||
static char prompt[32];
|
static char prompt[32];
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ public:
|
||||||
return _("global scope");
|
return _("global scope");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_init(path init_file);
|
||||||
void read_init();
|
void read_init();
|
||||||
void read_environment_settings(char * envp[]);
|
void read_environment_settings(char * envp[]);
|
||||||
strings_list read_command_arguments(scope_t& scope, strings_list args);
|
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())
|
if (!_init_file.empty())
|
||||||
// _init_file is filled during handle_debug_options
|
// _init_file is filled during handle_debug_options
|
||||||
on(none, _init_file);
|
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);
|
OPTION(global_scope_t, options);
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,12 @@ std::size_t session_t::read_data(const string& master_account)
|
||||||
acct = journal->find_account(master_account);
|
acct = journal->find_account(master_account);
|
||||||
|
|
||||||
optional<path> price_db_path;
|
optional<path> price_db_path;
|
||||||
if (HANDLED(price_db_))
|
if (HANDLED(price_db_)){
|
||||||
price_db_path = resolve_path(HANDLER(price_db_).str());
|
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))
|
if (HANDLED(explicit))
|
||||||
journal->force_checking = true;
|
journal->force_checking = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue