From a8c896dcc90efbad043d28d18bd4dad1403fcabd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 22 Sep 2008 10:39:01 +0200 Subject: [PATCH] options: added constant option_table_size Instead of checking for the sentinel at the end of the option table, check the option_table_size constant. --- src/options.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/options.c b/src/options.c index 2c81827..dc0475c 100644 --- a/src/options.c +++ b/src/options.c @@ -66,21 +66,20 @@ static const arg_opt_t option_table[] = { { 'K', "dump-keys", NULL, "Dump key bindings to stdout" }, { 'D', "debug", NULL, "Enable debug output on stderr" }, #endif - { 0, NULL, NULL, NULL }, }; +static const unsigned option_table_size = sizeof(option_table) / sizeof(option_table[0]); + static const arg_opt_t * lookup_option(int s, char *l) { - int i; + unsigned i; - i=0; - while (option_table[i].descrition) { + for (i = 0; i < option_table_size; ++i) { if (l && strcmp(l, option_table[i].longopt) == 0) return &option_table[i];; if (s && s == option_table[i].shortopt) return &option_table[i];; - i++; } return NULL; @@ -113,10 +112,11 @@ option_error(int error, const char *option, const char *arg) static void display_help(void) { - int i = 0; + unsigned i; printf("Usage: %s [OPTION]...\n", PACKAGE); - while (option_table[i].descrition) { + + for (i = 0; i < option_table_size; ++i) { char tmp[MAX_LONGOPT_LENGTH]; if (option_table[i].argument) -- 2.30.2