From 04dfda2282bfb3686336600cfafd1d9653369445 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 22 Aug 2006 00:52:08 +0000 Subject: Made separate modules for the csv command, since the prior method was not fully correct. --- option.cc | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'option.cc') 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 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::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 }, -- cgit v1.2.3