rnd-20070327-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index e0e8a0ffb30c0e915a64d1fc6ebc339d49032ef3..d28b48dff26ceb9580949eaf674b14f990e3f686 100644 (file)
@@ -106,7 +106,7 @@ char *int2str(int number, int size)
   if (size > 20)
     size = 20;
 
-  if (size)
+  if (size > 0)
   {
     sprintf(s, "                    %09d", number);
     return &s[strlen(s) - size];
@@ -156,6 +156,11 @@ int log_2(unsigned int x)
   return e;
 }
 
+boolean getTokenValueFromString(char *string, char **token, char **value)
+{
+  return getTokenValueFromSetupLine(string, token, value);
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* counter functions                                                         */
@@ -552,6 +557,21 @@ char *getStringCopy(char *s)
   return s_copy;
 }
 
+char *getStringCopyN(char *s, int n)
+{
+  char *s_copy;
+  int s_len = MAX(0, n);
+
+  if (s == NULL)
+    return NULL;
+
+  s_copy = checked_malloc(s_len + 1);
+  strncpy(s_copy, s, s_len);
+  s[s_len] = '\0';
+
+  return s_copy;
+}
+
 char *getStringToLower(char *s)
 {
   char *s_copy = checked_malloc(strlen(s) + 1);
@@ -579,6 +599,14 @@ boolean strEqual(char *s1, char *s2)
          strcmp(s1, s2) == 0);
 }
 
+boolean strEqualN(char *s1, char *s2, int n)
+{
+  return (s1 == NULL && s2 == NULL ? TRUE  :
+         s1 == NULL && s2 != NULL ? FALSE :
+         s1 != NULL && s2 == NULL ? FALSE :
+         strncmp(s1, s2, n) == 0);
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* command line option handling functions                                    */
@@ -1782,7 +1810,15 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
   {
     result = (strEqual(value, "left")   ? ALIGN_LEFT :
              strEqual(value, "right")  ? ALIGN_RIGHT :
-             strEqual(value, "center") ? ALIGN_CENTER : ALIGN_DEFAULT);
+             strEqual(value, "center") ? ALIGN_CENTER :
+             strEqual(value, "middle") ? ALIGN_CENTER : ALIGN_DEFAULT);
+  }
+  else if (strEqual(suffix, ".valign"))
+  {
+    result = (strEqual(value, "top")    ? VALIGN_TOP :
+             strEqual(value, "bottom") ? VALIGN_BOTTOM :
+             strEqual(value, "middle") ? VALIGN_MIDDLE :
+             strEqual(value, "center") ? VALIGN_MIDDLE : VALIGN_DEFAULT);
   }
   else if (strEqual(suffix, ".anim_mode"))
   {
@@ -1798,8 +1834,6 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              string_has_parameter(value, "horizontal") ? ANIM_HORIZONTAL :
              string_has_parameter(value, "vertical")   ? ANIM_VERTICAL :
              string_has_parameter(value, "centered")   ? ANIM_CENTERED :
-             string_has_parameter(value, "fade")       ? ANIM_FADE :
-             string_has_parameter(value, "crossfade")  ? ANIM_CROSSFADE :
              ANIM_DEFAULT);
 
     if (string_has_parameter(value, "reverse"))
@@ -1811,6 +1845,18 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
     if (string_has_parameter(value, "static_panel"))
       result |= ANIM_STATIC_PANEL;
   }
+  else if (strEqual(suffix, ".fade_mode"))
+  {
+    result = (string_has_parameter(value, "none")      ? FADE_MODE_NONE :
+             string_has_parameter(value, "fade")       ? FADE_MODE_FADE :
+             string_has_parameter(value, "crossfade")  ? FADE_MODE_CROSSFADE :
+             string_has_parameter(value, "melt")       ? FADE_MODE_MELT :
+             FADE_MODE_DEFAULT);
+  }
+  else if (strEqualN(suffix, ".font", 5))      /* (may also be ".font_xyz") */
+  {
+    result = gfx.get_font_from_token_function(value);
+  }
   else         /* generic parameter of type integer or boolean */
   {
     result = (strEqual(value, ARG_UNDEFINED) ? ARG_UNDEFINED_VALUE :
@@ -1824,7 +1870,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
   return result;
 }
 
-int get_auto_parameter_value(char *token, char *value_raw)
+int get_token_parameter_value(char *token, char *value_raw)
 {
   char *suffix;
 
@@ -1835,6 +1881,21 @@ int get_auto_parameter_value(char *token, char *value_raw)
   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);
 }
 
@@ -2683,7 +2744,7 @@ static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info,
                              struct FileInfo *file_list_entry)
 {
 #if 0
-  printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename);
+  printf("GOT CUSTOM ARTWORK FILE '%s'\n", file_list_entry->filename);
 #endif
 
   if (strEqual(file_list_entry->filename, UNDEFINED_FILENAME))
@@ -2806,7 +2867,7 @@ void NotifyUserAboutErrorFile()
 #if DEBUG
 
 #define DEBUG_NUM_TIMESTAMPS           3
-#define DEBUG_TIME_IN_MICROSECONDS     1
+#define DEBUG_TIME_IN_MICROSECONDS     0
 
 #if DEBUG_TIME_IN_MICROSECONDS
 static double Counter_Microseconds()