diff options
author | Kalle Wallin <kaw@linux.se> | 2004-07-12 09:22:16 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-07-12 09:22:16 +0000 |
commit | 38f981dd428f68ac70d710a3593e7e6bdd90e126 (patch) | |
tree | 25c4980eacc9855a43c848e3a2f585338bb37882 /src | |
parent | 6543bbf99ea822c453f44054bffca90f5dd9d53a (diff) | |
download | mpd-38f981dd428f68ac70d710a3593e7e6bdd90e126.tar.gz mpd-38f981dd428f68ac70d710a3593e7e6bdd90e126.tar.xz mpd-38f981dd428f68ac70d710a3593e7e6bdd90e126.zip |
Fixed short option handling for multiple short options at once (-abcde)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1846 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/options.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/options.c b/src/options.c index 314a0e98c..94da5b836 100644 --- a/src/options.c +++ b/src/options.c @@ -100,7 +100,7 @@ option_error(int error, char *option, char *arg) fprintf(stderr, PACKAGE ": invalid option %s=%s\n", option, arg); break; case ERROR_MISSING_ARGUMENT: - fprintf(stderr, PACKAGE ": missing value for %s\n", option); + fprintf(stderr, PACKAGE ": missing value for %s option\n", option); break; default: fprintf(stderr, PACKAGE ": internal error %d\n", error); @@ -242,22 +242,28 @@ options_parse(int argc, const char *argv[]) opt = NULL; } } - /* check for a short option */ - else if( len==2 && g_str_has_prefix(arg, "-") ) + /* check for short options */ + else if( len>=2 && g_str_has_prefix(arg, "-") ) { - /* make shure we got an argument for the previous option */ - if( opt && opt->argument ) - option_error(ERROR_MISSING_ARGUMENT, opt->longopt, opt->argument); + int j; - /* check if the option exists */ - if( (opt=lookup_option(arg[1], NULL))==NULL ) - option_error(ERROR_UNKNOWN_OPTION, arg, NULL); - - /* if no option argument is needed execute callback */ - if( opt->argument==NULL ) + for(j=1; j<len; j++) { - option_cb (opt->shortopt, NULL); - opt = NULL; + /* make shure we got an argument for the previous option */ + if( opt && opt->argument ) + option_error(ERROR_MISSING_ARGUMENT, + opt->longopt, opt->argument); + + /* check if the option exists */ + if( (opt=lookup_option(arg[j], NULL))==NULL ) + option_error(ERROR_UNKNOWN_OPTION, arg, NULL); + + /* if no option argument is needed execute callback */ + if( opt->argument==NULL ) + { + option_cb (opt->shortopt, NULL); + opt = NULL; + } } } else |