aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>2009-06-11 16:20:39 +0100
committerAlan Jenkins <alan-jenkins@tuffmail.co.uk>2009-06-11 16:28:44 +0100
commit22604fda4de92559b108cde7df298a5d0627fa0e (patch)
tree6af008509700c73f0bbe0415a293d45735442b3a
parent53c1b0acd9d0517e8b0f046852b0e5a70cd0cd34 (diff)
downloadmodule-init-tools-22604fda4de92559b108cde7df298a5d0627fa0e.tar.gz
modindex: simplify option handling
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
-rw-r--r--modindex.c18
-rw-r--r--tests/test-modindex/05order.sh4
2 files changed, 9 insertions, 13 deletions
diff --git a/modindex.c b/modindex.c
index 24dec20..da397d0 100644
--- a/modindex.c
+++ b/modindex.c
@@ -98,8 +98,8 @@ static void print_usage(const char *progname)
"Usage: %s [MODE] [FILE] ...\n"
" -o, --output <outfile>\n"
" -d, --dump <infile>\n"
- " -s, --search <infile> <key>\n"
- " -w, --searchwild <infile> <key>\n"
+ " -s, --search <key> <infile>\n"
+ " -w, --searchwild <key> <infile>\n"
,progname);
exit(1);
}
@@ -107,8 +107,8 @@ static void print_usage(const char *progname)
static struct option options[] = {
{ "output", 0, NULL, 'o' },
{ "dump", 0, NULL, 'd' },
- { "search", 0, NULL, 's' },
- { "searchwild", 0, NULL, 'w' },
+ { "search", 1, NULL, 's' },
+ { "searchwild", 1, NULL, 'w' },
};
int main(int argc, char *argv[])
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
char *filename = NULL;
char *key = NULL;
- while ((opt = getopt_long(argc, argv, "odsw", options, NULL))
+ while ((opt = getopt_long(argc, argv, "ods:w:", options, NULL))
!= -1) {
switch (opt) {
case 'o':
@@ -129,9 +129,11 @@ int main(int argc, char *argv[])
break;
case 's':
mode = 's';
+ key = optarg;
break;
case 'w':
mode = 'w';
+ key = optarg;
break;
default:
print_usage(argv[0]);
@@ -144,12 +146,6 @@ int main(int argc, char *argv[])
print_usage(argv[0]);
filename = argv[optind];
- if (mode == 's' || mode == 'w') {
- if (optind+1 >= argc)
- print_usage(argv[0]);
- key = argv[optind+1];
- }
-
switch(mode) {
case 'o':
write_index(filename);
diff --git a/tests/test-modindex/05order.sh b/tests/test-modindex/05order.sh
index f9c560c..24676d5 100644
--- a/tests/test-modindex/05order.sh
+++ b/tests/test-modindex/05order.sh
@@ -30,7 +30,7 @@ b* 2
* 3
EOF
-[ "`modindex -w tests/tmp/index ba`" = "Found value(s):
+[ "`modindex -w ba tests/tmp/index`" = "Found value(s):
1
2
3" ]
@@ -41,7 +41,7 @@ b* 2
*a 3
EOF
-[ "`modindex -w tests/tmp/index ba`" = "Found value(s):
+[ "`modindex -w ba tests/tmp/index`" = "Found value(s):
1
2
3" ]