summaryrefslogtreecommitdiff
path: root/src/option.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-04 18:23:18 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-04 19:55:08 -0400
commit73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe (patch)
tree695fde78e03351750210715ea76ec686ff04fbfc /src/option.cc
parentb9603a1512acdfeb5d304e5ae910c1da553b3337 (diff)
downloadfork-ledger-73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe.tar.gz
fork-ledger-73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe.tar.bz2
fork-ledger-73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe.zip
Added structural support in main() for using a REPL.
Diffstat (limited to 'src/option.cc')
-rw-r--r--src/option.cc35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/option.cc b/src/option.cc
index a0891c4c..7f8bdeb4 100644
--- a/src/option.cc
+++ b/src/option.cc
@@ -137,17 +137,20 @@ void process_environment(const char ** envp, const string& tag,
}
}
-void process_arguments(int, char ** argv, scope_t& scope,
- std::list<string>& args)
+strings_list process_arguments(strings_list args, scope_t& scope)
{
bool anywhere = true;
- for (char ** i = argv; *i; i++) {
+ strings_list remaining;
+
+ for (strings_list::iterator i = args.begin();
+ i != args.end();
+ i++) {
DEBUG("option.args", "Examining argument '" << *i << "'");
if (! anywhere || (*i)[0] != '-') {
DEBUG("option.args", " adding to list of real args");
- args.push_back(*i);
+ remaining.push_back(*i);
continue;
}
@@ -161,20 +164,24 @@ void process_arguments(int, char ** argv, scope_t& scope,
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;
+ string opt_name;
+ const char * name = (*i).c_str() + 2;
+ const char * value = NULL;
+
+ if (const char * p = std::strchr(name, '=')) {
+ opt_name = string(name, p - name);
+ value = ++p;
DEBUG("option.args", " read option value from option: " << value);
+ } else {
+ opt_name = name;
}
- op_bool_tuple opt(find_option(scope, name));
+ op_bool_tuple opt(find_option(scope, opt_name));
if (! opt.get<0>())
throw_(option_error, "illegal option --" << name);
if (opt.get<1>() && value == NULL) {
- value = *++i;
+ value = (*++i).c_str();
DEBUG("option.args", " read option value from arg: " << value);
if (value == NULL)
throw_(option_error, "missing option argument for --" << name);
@@ -203,9 +210,9 @@ void process_arguments(int, char ** argv, scope_t& scope,
}
foreach (op_bool_char_tuple& o, option_queue) {
- char * value = NULL;
+ const char * value = NULL;
if (o.get<1>()) {
- value = *++i;
+ value = (*++i).c_str();
DEBUG("option.args", " read option value from arg: " << value);
if (value == NULL)
throw_(option_error,
@@ -216,6 +223,8 @@ void process_arguments(int, char ** argv, scope_t& scope,
}
}
}
+
+ return remaining;
}
} // namespace ledger