summaryrefslogtreecommitdiff
path: root/src/option.cc
diff options
context:
space:
mode:
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