diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-01 23:40:02 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-01 23:40:02 -0600 |
commit | a125f24d29fd8275be7283a2edca9abc125703d7 (patch) | |
tree | b649aeeef3b75be85cae8197467c5fb02066d486 /src | |
parent | cfd7ffb12645c198a5b15891654f6ad6a0e4db27 (diff) | |
download | fork-ledger-a125f24d29fd8275be7283a2edca9abc125703d7.tar.gz fork-ledger-a125f24d29fd8275be7283a2edca9abc125703d7.tar.bz2 fork-ledger-a125f24d29fd8275be7283a2edca9abc125703d7.zip |
Allow --options to be added by the user in Python
Diffstat (limited to 'src')
-rw-r--r-- | src/context.h | 7 | ||||
-rw-r--r-- | src/option.cc | 1 | ||||
-rw-r--r-- | src/pyinterp.cc | 11 | ||||
-rw-r--r-- | src/session.cc | 2 | ||||
-rw-r--r-- | src/session.h | 1 | ||||
-rw-r--r-- | src/textual.cc | 5 |
6 files changed, 23 insertions, 4 deletions
diff --git a/src/context.h b/src/context.h index d7999e5a..45bb9990 100644 --- a/src/context.h +++ b/src/context.h @@ -71,6 +71,10 @@ public: std::size_t count; std::size_t sequence; + explicit parse_context_t(const path& cwd) + : current_directory(cwd), master(NULL), scope(NULL), + linenum(0), errors(0), count(0), sequence(1) {} + explicit parse_context_t(shared_ptr<std::istream> _stream, const path& cwd) : stream(_stream), current_directory(cwd), master(NULL), @@ -126,6 +130,9 @@ class parse_context_stack_t std::list<parse_context_t> parsing_context; public: + void push() { + parsing_context.push_front(parse_context_t(filesystem::current_path())); + } void push(shared_ptr<std::istream> stream, const path& cwd = filesystem::current_path()) { parsing_context.push_front(parse_context_t(stream, cwd)); diff --git a/src/option.cc b/src/option.cc index 170b94af..418980bd 100644 --- a/src/option.cc +++ b/src/option.cc @@ -89,7 +89,6 @@ namespace { catch (const std::exception&) { if (name[0] == '-') add_error_context(_("While parsing option '%1'") << name); - else add_error_context(_("While parsing environent variable '%1'") << name); throw; diff --git a/src/pyinterp.cc b/src/pyinterp.cc index 048f5a39..3157079a 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -419,10 +419,19 @@ expr_t::ptr_op_t python_interpreter_t::lookup(const symbol_t::kind_t kind, } break; - case symbol_t::OPTION: + case symbol_t::OPTION: { if (option_t<python_interpreter_t> * handler = lookup_option(name.c_str())) return MAKE_OPT_HANDLER(python_interpreter_t, handler); + + string option_name(string("option_") + name); + if (is_initialized && main_nspace.has_key(option_name.c_str())) { + DEBUG("python.interp", "Python lookup option: " << option_name); + + if (python::object obj = main_nspace.get(option_name.c_str())) + return WRAP_FUNCTOR(functor_t(obj, option_name)); + } break; + } case symbol_t::PRECOMMAND: { const char * p = name.c_str(); diff --git a/src/session.cc b/src/session.cc index db01fbf6..3e7cdb3d 100644 --- a/src/session.cc +++ b/src/session.cc @@ -68,6 +68,8 @@ session_t::session_t() HANDLER(price_db_).on(none, (path(home_var) / ".pricedb").string()); else HANDLER(price_db_).on(none, path("./.pricedb").string()); + + parsing_context.push(); } std::size_t session_t::read_data(const string& master_account) diff --git a/src/session.h b/src/session.h index 38062b78..879efeb6 100644 --- a/src/session.h +++ b/src/session.h @@ -65,6 +65,7 @@ public: explicit session_t(); virtual ~session_t() { TRACE_DTOR(session_t); + parsing_context.pop(); } virtual string description() { diff --git a/src/textual.cc b/src/textual.cc index 2ec58898..a4e03435 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -508,8 +508,9 @@ void instance_t::option_directive(char * line) *p++ = '\0'; } - if (! process_option(context.pathname.string(), line + 2, - *context.scope, p, line)) + path abs_path(filesystem::absolute(context.pathname, + context.current_directory)); + if (! process_option(abs_path.string(), line + 2, *context.scope, p, line)) throw_(option_error, _("Illegal option --%1") << line + 2); } |