diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-22 16:27:24 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-22 16:27:24 -0400 |
commit | 0b9f22b4d24e8fa545af2d7d448ddfe9fb3736ba (patch) | |
tree | 61bb92dac4a3adc07e6b61a4b7516252fc6abbe1 /src/option.cc | |
parent | ccedf7d57f6cc42553f1d80189bf1491df6680e2 (diff) | |
download | fork-ledger-0b9f22b4d24e8fa545af2d7d448ddfe9fb3736ba.tar.gz fork-ledger-0b9f22b4d24e8fa545af2d7d448ddfe9fb3736ba.tar.bz2 fork-ledger-0b9f22b4d24e8fa545af2d7d448ddfe9fb3736ba.zip |
Redid the way command-line arguments are processed. Before, Ledger used - and
-- to mean special things after the command verb was seen. But now, what used
to be specified as this:
ledger -n reg cash -payable -- shell
Is now specified as this:
ledger reg -n cash not payable @shell
It could also be specified as:
ledger -n reg \(cash and not payable\) and @shell
Diffstat (limited to 'src/option.cc')
-rw-r--r-- | src/option.cc | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/option.cc b/src/option.cc index 2e74f3b0..fa7e659d 100644 --- a/src/option.cc +++ b/src/option.cc @@ -139,31 +139,36 @@ void process_environment(const char ** envp, const string& tag, } } -void process_arguments(int, char ** argv, const bool anywhere, - scope_t& scope, std::list<string>& args) +void process_arguments(int, char ** argv, scope_t& scope, + std::list<string>& args) { + bool anywhere = true; + for (char ** i = argv; *i; i++) { - if ((*i)[0] != '-') { - if (anywhere) { - args.push_back(*i); - continue; - } else { - for (; *i; i++) - args.push_back(*i); - break; - } + DEBUG("option.args", "Examining argument '" << *i << "'"); + + if (! anywhere || (*i)[0] != '-') { + DEBUG("option.args", " adding to list of real args"); + args.push_back(*i); + continue; } // --long-option or -s if ((*i)[1] == '-') { - if ((*i)[2] == '\0') - break; + if ((*i)[2] == '\0') { + DEBUG("option.args", " it's a --, ending options processing"); + anywhere = false; + continue; + } + + DEBUG("option.args", " it's an option string"); char * name = *i + 2; char * value = NULL; if (char * p = std::strchr(name, '=')) { *p++ = '\0'; value = p; + DEBUG("option.args", " read option value from option: " << value); } op_bool_tuple opt(find_option(scope, name)); @@ -172,6 +177,7 @@ void process_arguments(int, char ** argv, const bool anywhere, if (opt.get<1>() && value == NULL) { value = *++i; + DEBUG("option.args", " read option value from arg: " << value); if (value == NULL) throw_(option_error, "missing option argument for --" << name); } @@ -181,6 +187,8 @@ void process_arguments(int, char ** argv, const bool anywhere, throw_(option_error, "illegal option -"); } else { + DEBUG("option.args", " single-char option"); + typedef tuple<expr_t::ptr_op_t, bool, char> op_bool_char_tuple; std::list<op_bool_char_tuple> option_queue; @@ -199,6 +207,7 @@ void process_arguments(int, char ** argv, const bool anywhere, char * value = NULL; if (o.get<1>()) { value = *++i; + DEBUG("option.args", " read option value from arg: " << value); if (value == NULL) throw_(option_error, "missing option argument for -" << o.get<2>()); |