nicer use of structures and use isalpha()
authorAndrew Tridgell <tridge@samba.org>
Mon, 4 Feb 2008 23:36:06 +0000 (10:36 +1100)
committerAndrew Tridgell <tridge@samba.org>
Mon, 4 Feb 2008 23:36:06 +0000 (10:36 +1100)
(This used to be ctdb commit 19b5fbcd16596a4b6c22056585dd4bd988db3db7)

ctdb/tools/ctdb.c

index e130f84571731c85ff7e01924d089a1138f3c3d4..a82d625ad8ef4f852f4772872ae8b81ac2072079 100644 (file)
@@ -23,6 +23,7 @@
 #include "system/time.h"
 #include "system/filesys.h"
 #include "system/network.h"
+#include "system/locale.h"
 #include "popt.h"
 #include "cmdline.h"
 #include "../include/ctdb.h"
@@ -973,12 +974,10 @@ static int control_listvars(struct ctdb_context *ctdb, int argc, const char **ar
        return 0;
 }
 
-struct debug_levels {
+static struct {
        int32_t level;
        const char *description;
-};
-
-static struct debug_levels debug_levels[] = {
+} debug_levels[] = {
        {DEBUG_EMERG,   "EMERG"},
        {DEBUG_ALERT,   "ALERT"},
        {DEBUG_CRIT,    "CRIT"},
@@ -986,33 +985,26 @@ static struct debug_levels debug_levels[] = {
        {DEBUG_WARNING, "WARNING"},
        {DEBUG_NOTICE,  "NOTICE"},
        {DEBUG_INFO,    "INFO"},
-       {DEBUG_DEBUG,   "DEBUG"},
-       {0, NULL}
+       {DEBUG_DEBUG,   "DEBUG"}
 };
 
 static const char *get_debug_by_level(int32_t level)
 {
        int i;
 
-       for (i=0;1;i++) {
-               if (debug_levels[i].description == NULL) {
-                       return "Unknown";
-               }
+       for (i=0;i<ARRAY_SIZE(debug_levels);i++) {
                if (debug_levels[i].level == level) {
                        return debug_levels[i].description;
                }
        }
-       return NULL;
+       return "Unknown";
 }
 
 static int32_t get_debug_by_desc(const char *desc)
 {
        int i;
 
-       for (i=0;1;i++) {
-               if (debug_levels[i].description == NULL) {
-                       return DEBUG_ERR;
-               }
+       for (i=0;i<ARRAY_SIZE(debug_levels);i++) {
                if (!strcmp(debug_levels[i].description, desc)) {
                        return debug_levels[i].level;
                }
@@ -1051,7 +1043,7 @@ static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **ar
                usage();
        }
 
-       if ( (argv[0][0]>='A') && (argv[0][0]<='Z') ) { 
+       if (isalpha(argv[0][0])) { 
                level = get_debug_by_desc(argv[0]);
        } else {
                level = strtoul(argv[0], NULL, 0);