diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-02 00:24:26 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-02 00:24:26 -0400 |
commit | 9540406af15d522d15c94cc3d63c77b7da7e1423 (patch) | |
tree | 6dd912aac2adb018c16a8b506bc0e18eb8444caa /src/option.cc | |
parent | ef3943c60498ab0fd4de1f1735109b0d103c167a (diff) | |
download | fork-ledger-9540406af15d522d15c94cc3d63c77b7da7e1423.tar.gz fork-ledger-9540406af15d522d15c94cc3d63c77b7da7e1423.tar.bz2 fork-ledger-9540406af15d522d15c94cc3d63c77b7da7e1423.zip |
Simplified error context handling.
Diffstat (limited to 'src/option.cc')
-rw-r--r-- | src/option.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/option.cc b/src/option.cc index 3cafa06a..a0891c4c 100644 --- a/src/option.cc +++ b/src/option.cc @@ -75,7 +75,7 @@ namespace { } void process_option(const function_t& opt, scope_t& scope, - const char * arg) + const char * arg, const string& name) { try { call_scope_t args(scope); @@ -85,23 +85,23 @@ namespace { opt(args); } catch (const std::exception& err) { -#if 0 - add_error_context("While parsing option '--" << opt->long_opt - << "'" << (opt->short_opt != '\0' ? - (string(" (-") + opt->short_opt + "):") : - ": ")); -#endif + if (name[0] == '-') + add_error_context("While parsing option '" << name << "':"); + + else + add_error_context("While parsing environent variable '" + << name << "':"); throw; } } } void process_option(const string& name, scope_t& scope, - const char * arg) + const char * arg, const string& varname) { op_bool_tuple opt(find_option(scope, name)); if (opt.get<0>()) - process_option(opt.get<0>()->as_function(), scope, arg); + process_option(opt.get<0>()->as_function(), scope, arg, varname); } void process_environment(const char ** envp, const string& tag, @@ -126,7 +126,7 @@ void process_environment(const char ** envp, const string& tag, if (*q == '=') { try { - process_option(string(buf), scope, q + 1); + process_option(string(buf), scope, q + 1, string(*p, q - *p)); } catch (const std::exception& err) { add_error_context("While parsing environment variable option '" @@ -179,7 +179,8 @@ void process_arguments(int, char ** argv, scope_t& scope, if (value == NULL) throw_(option_error, "missing option argument for --" << name); } - process_option(opt.get<0>()->as_function(), scope, value); + process_option(opt.get<0>()->as_function(), scope, value, + string("--") + name); } else if ((*i)[1] == '\0') { throw_(option_error, "illegal option -"); @@ -210,7 +211,8 @@ void process_arguments(int, char ** argv, scope_t& scope, throw_(option_error, "missing option argument for -" << o.get<2>()); } - process_option(o.get<0>()->as_function(), scope, value); + process_option(o.get<0>()->as_function(), scope, value, + string("-") + o.get<2>()); } } } |