Merge pull request #95 from enderw88/Bug695-init-file

Bug695 init file
This commit is contained in:
John Wiegley 2012-10-25 12:52:03 -07:00
commit 34ca6b3991
5 changed files with 47 additions and 5 deletions

View file

@ -44,6 +44,7 @@
namespace ledger { namespace ledger {
static bool args_only = false; static bool args_only = false;
std::string _init_file;
global_scope_t::global_scope_t(char ** envp) global_scope_t::global_scope_t(char ** envp)
{ {
@ -126,6 +127,8 @@ void global_scope_t::read_init()
} }
TRACE_FINISH(init, 1); TRACE_FINISH(init, 1);
} else {
throw_(parse_error, _f("Could not find specified init file %1%") % init_file);
} }
} }
} }
@ -473,6 +476,10 @@ void handle_debug_options(int argc, char * argv[])
_log_level = LOG_INFO; _log_level = LOG_INFO;
#endif #endif
} }
else if (i + 1 < argc && std::strcmp(argv[i], "--init-file") == 0) {
_init_file = argv[i + 1];
i++;
}
else if (i + 1 < argc && std::strcmp(argv[i], "--debug") == 0) { else if (i + 1 < argc && std::strcmp(argv[i], "--debug") == 0) {
#if DEBUG_ON #if DEBUG_ON
_log_level = LOG_DEBUG; _log_level = LOG_DEBUG;

View file

@ -46,6 +46,8 @@ namespace ledger {
class session_t; class session_t;
class report_t; class report_t;
extern std::string _init_file;
class global_scope_t : public noncopyable, public scope_t class global_scope_t : public noncopyable, public scope_t
{ {
shared_ptr<session_t> session_ptr; shared_ptr<session_t> session_ptr;
@ -151,10 +153,14 @@ See LICENSE file included with the distribution for details and disclaimer.");
OPTION__ OPTION__
(global_scope_t, init_file_, // -i (global_scope_t, init_file_, // -i
CTOR(global_scope_t, init_file_) { CTOR(global_scope_t, init_file_) {
if (const char * home_var = std::getenv("HOME")) if(!_init_file.empty())
on(none, (path(home_var) / ".ledgerrc").string()); // _init_file is filled during handle_debug_options
else on(none, _init_file);
on(none, path("./.ledgerrc").string()); 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);

View file

@ -330,6 +330,21 @@ namespace {
return NULL_VALUE; return NULL_VALUE;
} }
value_t get_filebase(item_t& item) {
if (item.pos)
return string_value(item.pos->pathname.filename().string());
else
return NULL_VALUE;
}
value_t get_filepath(item_t& item) {
if (item.pos)
return string_value(item.pos->pathname.parent_path().string());
else
return NULL_VALUE;
}
value_t get_beg_pos(item_t& item) { value_t get_beg_pos(item_t& item) {
return item.pos ? long(item.pos->beg_pos) : 0L; return item.pos ? long(item.pos->beg_pos) : 0L;
} }
@ -456,7 +471,12 @@ expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind,
case 'f': case 'f':
if (name == "filename") if (name == "filename")
return WRAP_FUNCTOR(get_wrapper<&get_pathname>); return WRAP_FUNCTOR(get_wrapper<&get_pathname>);
break; else if (name == "filebase")
return WRAP_FUNCTOR(get_wrapper<&get_filebase>);
else if (name == "filepath")
return WRAP_FUNCTOR(get_wrapper<&get_filepath>);
break;
break;
case 'h': case 'h':
if (name == "has_tag") if (name == "has_tag")

View file

@ -59,6 +59,7 @@ int main(int argc, char * argv[], char * envp[])
// --debug CATEGORY ; turns on debug logging // --debug CATEGORY ; turns on debug logging
// --trace LEVEL ; turns on trace logging // --trace LEVEL ; turns on trace logging
// --memory ; turns on memory usage tracing // --memory ; turns on memory usage tracing
// --init-file ; directs ledger to use a different init file
handle_debug_options(argc, argv); handle_debug_options(argc, argv);
#if VERIFY_ON #if VERIFY_ON
IF_VERIFY() initialize_memory_tracing(); IF_VERIFY() initialize_memory_tracing();

View file

@ -780,6 +780,14 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
// the automated xact's one. // the automated xact's one.
post_t * new_post = new post_t(account, amt); post_t * new_post = new post_t(account, amt);
new_post->copy_details(*post); new_post->copy_details(*post);
// A Cleared transaction implies all of its automatic posting are cleared
// CPR 2012/10/23
if(xact.state() == item_t::CLEARED){
DEBUG("xact.extend.cleared", "CLEARED");
new_post->set_state(item_t::CLEARED);
}
new_post->add_flags(ITEM_GENERATED); new_post->add_flags(ITEM_GENERATED);
new_post->account = new_post->account =
journal->register_account(account->fullname(), new_post, journal->register_account(account->fullname(), new_post,