added definition for string constant
[rocksndiamonds.git] / src / libgame / misc.c
index 48d67a792dd5b7ea435f5217c0ad1a83b6e1f257..239a7d8ce8b637ab26764b9dcc2fb9ff7db3585f 100644 (file)
@@ -557,7 +557,12 @@ boolean getTokenValueFromString(char *string, char **token, char **value)
 #define UUID_CHARS             (UUID_BYTES * 2)
 #define UUID_LENGTH            (UUID_CHARS + 4)
 
-char *getUUID(void)
+static unsigned int uuid_random_function(int max)
+{
+  return GetBetterRandom(max);
+}
+
+char *getUUIDExt(unsigned int (*random_function)(int max))
 {
   static char uuid[UUID_LENGTH + 1];
   int data[UUID_BYTES];
@@ -565,7 +570,7 @@ char *getUUID(void)
   int i;
 
   for (i = 0; i < UUID_BYTES; i++)
-    data[i] = GetSimpleRandom(256);
+    data[i] = random_function(256);
 
   data[6] = 0x40 | (data[6] & 0x0f);
   data[8] = 0x80 | (data[8] & 0x3f);
@@ -582,6 +587,11 @@ char *getUUID(void)
   return uuid;
 }
 
+char *getUUID(void)
+{
+  return getUUIDExt(uuid_random_function);
+}
+
 
 // ----------------------------------------------------------------------------
 // counter functions
@@ -2417,47 +2427,23 @@ char getValidConfigValueChar(char c)
 
 int get_integer_from_string(char *s)
 {
-  static char *number_text[][3] =
-  {
-    { "0",     "zero",         "null",         },
-    { "1",     "one",          "first"         },
-    { "2",     "two",          "second"        },
-    { "3",     "three",        "third"         },
-    { "4",     "four",         "fourth"        },
-    { "5",     "five",         "fifth"         },
-    { "6",     "six",          "sixth"         },
-    { "7",     "seven",        "seventh"       },
-    { "8",     "eight",        "eighth"        },
-    { "9",     "nine",         "ninth"         },
-    { "10",    "ten",          "tenth"         },
-    { "11",    "eleven",       "eleventh"      },
-    { "12",    "twelve",       "twelfth"       },
-
-    { NULL,    NULL,           NULL            },
-  };
+  // check for the most common case first
+  if (s[0] >= '0' && s[0] <= '9')
+    return atoi(s);
 
-  int i, j;
   char *s_lower = getStringToLower(s);
   int result = -1;
 
-  for (i = 0; number_text[i][0] != NULL; i++)
-    for (j = 0; j < 3; j++)
-      if (strEqual(s_lower, number_text[i][j]))
-       result = i;
-
-  if (result == -1)
-  {
-    if (strEqual(s_lower, "false") ||
-       strEqual(s_lower, "no") ||
-       strEqual(s_lower, "off"))
-      result = 0;
-    else if (strEqual(s_lower, "true") ||
-            strEqual(s_lower, "yes") ||
-            strEqual(s_lower, "on"))
-      result = 1;
-    else
-      result = atoi(s);
-  }
+  if (strEqual(s_lower, "false") ||
+      strEqual(s_lower, "no") ||
+      strEqual(s_lower, "off"))
+    result = 0;
+  else if (strEqual(s_lower, "true") ||
+          strEqual(s_lower, "yes") ||
+          strEqual(s_lower, "on"))
+    result = 1;
+  else
+    result = atoi(s);
 
   free(s_lower);