rnd-20070420-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index e300b9bb50821b6c4115fb0e2a8181af2ea57de5..cfee3b2de339d5a5eb4029605b6fd8074e0e6fd1 100644 (file)
@@ -607,6 +607,23 @@ boolean strEqualN(char *s1, char *s2, int n)
          strncmp(s1, s2, n) == 0);
 }
 
+boolean strEqualPrefix(char *s, char *prefix)
+{
+  return (s == NULL && prefix == NULL ? TRUE  :
+         s == NULL && prefix != NULL ? FALSE :
+         s != NULL && prefix == NULL ? FALSE :
+         strncmp(s, prefix, strlen(prefix)) == 0);
+}
+
+boolean strEqualSuffix(char *s, char *suffix)
+{
+  return (s == NULL && suffix == NULL ? TRUE  :
+         s == NULL && suffix != NULL ? FALSE :
+         s != NULL && suffix == NULL ? FALSE :
+         strlen(s) < strlen(suffix)  ? FALSE :
+         strncmp(&s[strlen(s) - strlen(suffix)], suffix, strlen(suffix)) == 0);
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* command line option handling functions                                    */
@@ -1532,9 +1549,13 @@ int get_integer_from_string(char *s)
 
   if (result == -1)
   {
-    if (strEqual(s_lower, "false"))
+    if (strEqual(s_lower, "false") ||
+       strEqual(s_lower, "no") ||
+       strEqual(s_lower, "off"))
       result = 0;
-    else if (strEqual(s_lower, "true"))
+    else if (strEqual(s_lower, "true") ||
+            strEqual(s_lower, "yes") ||
+            strEqual(s_lower, "on"))
       result = 1;
     else
       result = atoi(s);
@@ -1853,7 +1874,11 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              string_has_parameter(value, "melt")       ? FADE_MODE_MELT :
              FADE_MODE_DEFAULT);
   }
+#if 1
+  else if (strEqualPrefix(suffix, ".font"))    /* (may also be ".font_xyz") */
+#else
   else if (strEqualN(suffix, ".font", 5))      /* (may also be ".font_xyz") */
+#endif
   {
     result = gfx.get_font_from_token_function(value);
   }
@@ -1870,35 +1895,6 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
   return result;
 }
 
-int get_token_parameter_value(char *token, char *value_raw)
-{
-  char *suffix;
-
-  if (token == NULL || value_raw == NULL)
-    return ARG_UNDEFINED_VALUE;
-
-  suffix = strrchr(token, '.');
-  if (suffix == NULL)
-    suffix = token;
-
-#if 0
-  if (strncmp(suffix, ".font", 5) == 0)
-  {
-    int i;
-
-    /* !!! OPTIMIZE THIS BY USING HASH !!! */
-    for (i = 0; i < NUM_FONTS; i++)
-      if (strEqual(value_raw, font_info[i].token_name))
-       return i;
-
-    /* if font not found, use reliable default value */
-    return FONT_INITIAL_1;
-  }
-#endif
-
-  return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
-}
-
 struct ScreenModeInfo *get_screen_mode_from_string(char *screen_mode_string)
 {
   static struct ScreenModeInfo screen_mode;