summaryrefslogtreecommitdiff
path: root/option.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-08-22 00:52:08 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:33 -0400
commit04dfda2282bfb3686336600cfafd1d9653369445 (patch)
tree9ee02db5c2d33290dfa6060475973f7c378ce643 /option.cc
parentdb0ef2e25731a824aa728315f2f7f6e8a41a5ddf (diff)
downloadfork-ledger-04dfda2282bfb3686336600cfafd1d9653369445.tar.gz
fork-ledger-04dfda2282bfb3686336600cfafd1d9653369445.tar.bz2
fork-ledger-04dfda2282bfb3686336600cfafd1d9653369445.zip
Made separate modules for the csv command, since the prior method was
not fully correct.
Diffstat (limited to 'option.cc')
-rw-r--r--option.cc54
1 files changed, 29 insertions, 25 deletions
diff --git a/option.cc b/option.cc
index 266e6b08..a9ef802d 100644
--- a/option.cc
+++ b/option.cc
@@ -86,47 +86,56 @@ void process_arguments(option_t * options, int argc, char ** argv,
// --long-option or -s
again:
- option_t * opt = NULL;
- char * value = NULL;
-
if ((*i)[1] == '-') {
if ((*i)[2] == '\0')
break;
- char * name = *i + 2;
+ char * name = *i + 2;
+ char * value = NULL;
if (char * p = std::strchr(name, '=')) {
*p++ = '\0';
value = p;
}
- opt = search_options(options, name);
+ option_t * opt = search_options(options, name);
if (! opt)
throw new option_error(std::string("illegal option --") + name);
- if (opt->wants_arg && ! value) {
+ if (opt->wants_arg && value == NULL) {
value = *++i;
- if (! value)
+ if (value == NULL)
throw new option_error(std::string("missing option argument for --") +
name);
}
process_option(opt, value);
- } else {
- char c = (*i)[1];
- opt = search_options(options, c);
- if (! opt)
- throw new option_error(std::string("illegal option -") + c);
+ }
+ else if ((*i)[1] == '\0') {
+ throw new option_error(std::string("illegal option -"));
+ }
+ else {
+ std::list<option_t *> opt_queue;
+
+ int x = 1;
+ for (char c = (*i)[x]; c != '\0'; x++, c = (*i)[x]) {
+ option_t * opt = search_options(options, c);
+ if (! opt)
+ throw new option_error(std::string("illegal option -") + c);
+ opt_queue.push_back(opt);
+ }
- if (opt->wants_arg) {
- value = *++i;
- if (! value)
- throw new option_error(std::string("missing option argument for -") + c);
+ for (std::list<option_t *>::iterator o = opt_queue.begin();
+ o != opt_queue.end(); o++) {
+ char * value = NULL;
+ if ((*o)->wants_arg) {
+ value = *++i;
+ if (value == NULL)
+ throw new option_error(std::string("missing option argument for -") +
+ (*o)->short_opt);
+ }
+ process_option(*o, value);
}
}
- assert(opt);
- assert(! value || opt->wants_arg);
- process_option(opt, value);
-
next:
;
}
@@ -562,10 +571,6 @@ OPT_BEGIN(wide_register_format, ":") {
config->wide_register_format = optarg;
} OPT_END(wide_register_format);
-OPT_BEGIN(csv_register_format, ":") {
- config->csv_register_format = optarg;
-} OPT_END(csv_register_format);
-
OPT_BEGIN(plot_amount_format, ":") {
config->plot_amount_format = optarg;
} OPT_END(plot_amount_format);
@@ -977,7 +982,6 @@ option_t config_options[CONFIG_OPTIONS_SIZE] = {
{ "collapse", 'n', false, opt_collapse, false },
{ "comm-as-payee", 'x', false, opt_comm_as_payee, false },
{ "cost", '\0', false, opt_basis, false },
- { "csv-register-format", '\0', true, opt_csv_register_format, false },
{ "current", 'c', false, opt_current, false },
{ "daily", '\0', false, opt_daily, false },
{ "date-format", 'y', true, opt_date_format, false },