From 22604fda4de92559b108cde7df298a5d0627fa0e Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Thu, 11 Jun 2009 16:20:39 +0100 Subject: [PATCH] modindex: simplify option handling Signed-off-by: Alan Jenkins --- modindex.c | 18 +++++++----------- tests/test-modindex/05order.sh | 4 ++-- 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 \n" " -d, --dump \n" - " -s, --search \n" - " -w, --searchwild \n" + " -s, --search \n" + " -w, --searchwild \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" ] -- 2.11.4.GIT