From 78e6770c4c276db3647952f21a6bf3ea465edb88 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 4 Nov 2009 20:40:07 -0500 Subject: Segregated symbols into 5 separate namespaces The different namespaces are: Function Value expression functions, which receive a "context" Option Command-line options Precommand Commands which are invoked before reading the journal Command Commands which are invoked after reading the journal Directive Directives that occur at column 0 in a data file This greatly eases the ability for Python uses to add intercept hooks to change how the basic Ledger module functions. An example of what should be possible soon: import ledger def my_foo_handler(value): print "--foo received:", value ledger.add_handler(ledger.Option, "foo=", my_foo_handler) --- src/option.cc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/option.cc') diff --git a/src/option.cc b/src/option.cc index 8da66b36..6d230939 100644 --- a/src/option.cc +++ b/src/option.cc @@ -41,8 +41,7 @@ namespace { op_bool_tuple find_option(scope_t& scope, const string& name) { char buf[128]; - std::strcpy(buf, "opt_"); - char * p = &buf[4]; + char * p = buf; foreach (char ch, name) { if (ch == '-') *p++ = '_'; @@ -52,28 +51,27 @@ namespace { *p++ = '_'; *p = '\0'; - if (expr_t::ptr_op_t op = scope.lookup(buf)) + if (expr_t::ptr_op_t op = scope.lookup(symbol_t::OPTION, buf)) return op_bool_tuple(op, true); *--p = '\0'; - return op_bool_tuple(scope.lookup(buf), false); + return op_bool_tuple(scope.lookup(symbol_t::OPTION, buf), false); } op_bool_tuple find_option(scope_t& scope, const char letter) { - char buf[10]; - std::strcpy(buf, "opt_"); - buf[4] = letter; - buf[5] = '_'; - buf[6] = '\0'; + char buf[4]; + buf[0] = letter; + buf[1] = '_'; + buf[2] = '\0'; - if (expr_t::ptr_op_t op = scope.lookup(buf)) + if (expr_t::ptr_op_t op = scope.lookup(symbol_t::OPTION, buf)) return op_bool_tuple(op, true); - buf[5] = '\0'; + buf[1] = '\0'; - return op_bool_tuple(scope.lookup(buf), false); + return op_bool_tuple(scope.lookup(symbol_t::OPTION, buf), false); } void process_option(const string& whence, const function_t& opt, -- cgit v1.2.3