diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-04 20:40:07 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-04 20:40:48 -0500 |
commit | 78e6770c4c276db3647952f21a6bf3ea465edb88 (patch) | |
tree | 64190d80ea0c3933dffaee3cf0e43cde5ea0e6a6 /src/option.cc | |
parent | 4a14f3224b9063202ca39a67c9aff42ae4274942 (diff) | |
download | fork-ledger-78e6770c4c276db3647952f21a6bf3ea465edb88.tar.gz fork-ledger-78e6770c4c276db3647952f21a6bf3ea465edb88.tar.bz2 fork-ledger-78e6770c4c276db3647952f21a6bf3ea465edb88.zip |
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)
Diffstat (limited to 'src/option.cc')
-rw-r--r-- | src/option.cc | 22 |
1 files changed, 10 insertions, 12 deletions
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, |