From: Max Kellermann Date: Mon, 22 Sep 2008 08:39:01 +0000 (+0200) Subject: options: added constant option_table_size X-Git-Tag: v0.12_alpha1~181 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a8c896dcc90efbad043d28d18bd4dad1403fcabd;p=ncmpc.git 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. --- 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)