removed library dependency to glib-2.0
[rocksndiamonds.git] / src / game_bd / bd_bdcff.c
index 663d97784bb4f1b0b3b0b6c804eb3d44f9e6e80a..53fc4c91a15718ad6f0c59bd0d0a16959798323c 100644 (file)
@@ -14,9 +14,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <glib.h>
-#include <glib/gi18n.h>
-
 #include <errno.h>
 
 #include "main_bd.h"
@@ -140,7 +137,7 @@ static boolean attrib_is_valid_for_caveset(const char *attrib)
   return FALSE;
 }
 
-static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_desc,
+static boolean struct_set_property(void *str, const GdStructDescriptor *prop_desc,
                                   const char *attrib, const char *param, int ratio)
 {
   char **params;
@@ -163,7 +160,7 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_
     if (strcasecmp(prop_desc[i].identifier, attrib) == 0)
     {
       /* found the identifier */
-      gpointer value = G_STRUCT_MEMBER_P(str, prop_desc[i].offset);
+      void *value = STRUCT_MEMBER_P(str, prop_desc[i].offset);
 
       /* these point to the same, but to avoid the awkward cast syntax */
       int *ivalue = value;
@@ -204,7 +201,7 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_
       for (j = 0; j < prop_desc[i].count && params[paramindex] != NULL; j++)
       {
        boolean success = FALSE;
-       gdouble res;
+       double res;
 
        switch (prop_desc[i].type)
        {
@@ -254,7 +251,8 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_
            break;
 
          case GD_TYPE_PROBABILITY:
-           res = g_ascii_strtod(params[paramindex], NULL);
+           errno = 0;  /* must be reset before calling strtod() to detect overflow/underflow */
+           res = strtod(params[paramindex], NULL);
            if (errno == 0 && res >= 0 && res <= 1)
            {
              /* fill all remaining items in array - may be only one */
@@ -268,7 +266,8 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_
            break;
 
          case GD_TYPE_RATIO:
-           res = g_ascii_strtod (params[paramindex], NULL);
+           errno = 0;  /* must be reset before calling strtod() to detect overflow/underflow */
+           res = strtod (params[paramindex], NULL);
            if (errno == 0 && res >= 0 && res <= 1)
            {
              for (k = j; k < prop_desc[i].count; k++)
@@ -356,7 +355,7 @@ static boolean replay_store_more_from_bdcff(GdReplay *replay, const char *param)
 }
 
 /* report all remaining tags; called after the above function. */
-static void replay_report_unknown_tags_func(const char *attrib, const char *param, gpointer data)
+static void replay_report_unknown_tags_func(const char *attrib, const char *param, void *data)
 {
   Warn("unknown replay tag '%s'", attrib);
 }
@@ -487,7 +486,7 @@ static boolean cave_process_tags_func(const char *attrib, const char *param, GdC
 }
 
 /* report all remaining tags; called after the above function. */
-static void cave_report_and_copy_unknown_tags_func(char *attrib, char *param, gpointer data)
+static void cave_report_and_copy_unknown_tags_func(char *attrib, char *param, void *data)
 {
   GdCave *cave = (GdCave *)data;
 
@@ -497,7 +496,7 @@ static void cave_report_and_copy_unknown_tags_func(char *attrib, char *param, gp
 }
 
 /* having read all strings belonging to the cave, process it. */
-static void cave_process_tags(GdCave *cave, HashTable *tags, GList *maplines)
+static void cave_process_tags(GdCave *cave, HashTable *tags, List *maplines)
 {
   char *value;
 
@@ -584,8 +583,8 @@ static void cave_process_tags(GdCave *cave, HashTable *tags, GList *maplines)
   /* some old bdcff files use smaller intermissions than the one specified. */
   if (maplines)
   {
-    int x, y, length = g_list_length(maplines);
-    GList *iter;
+    int x, y, length = list_length(maplines);
+    List *iter;
 
     /* create map and fill with initial border, in case that map strings are shorter or somewhat */
     cave->map = gd_cave_map_new(cave, GdElement);
@@ -642,7 +641,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
   char **lines;
   int lineno;
   GdCave *cave;
-  GList *iter;
+  List *iter;
   boolean reading_replay = FALSE;
   boolean reading_map = FALSE;
   boolean reading_mapcodes = FALSE;
@@ -651,7 +650,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
   boolean reading_bdcff_demo = FALSE;
   /* assume version to be 0.32, also when the file does not specify it explicitly */
   GdString version_read = "0.32";
-  GList *mapstrings = NULL;
+  List *mapstrings = NULL;
   int linenum;
   HashTable *tags, *replay_tags;
   GdObjectLevels levels = GD_OBJECT_LEVEL_ALL;
@@ -701,7 +700,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
        if (mapstrings)
        {
          Warn("incorrect file format: new [cave] section, but already read some map lines");
-         g_list_free(mapstrings);
+         list_free(mapstrings);
          mapstrings = NULL;
        }
 
@@ -710,12 +709,12 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
 
        /* ... to be able to create a copy for a new cave. */
        cave = gd_cave_new_from_cave(default_cave);
-       gd_caveset = g_list_append (gd_caveset, cave);
+       gd_caveset = list_append (gd_caveset, cave);
       }
       else if (strcasecmp(line, "[/cave]") == 0)
       {
        cave_process_tags(cave, tags, mapstrings);
-       g_list_free(mapstrings);
+       list_free(mapstrings);
        mapstrings = NULL;
 
        hashtable_foreach(tags, (hashtable_fn)cave_report_and_copy_unknown_tags_func, cave);
@@ -730,7 +729,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
        if (mapstrings != NULL)
        {
          Warn("incorrect file format: new [map] section, but already read some map lines");
-         g_list_free(mapstrings);
+         list_free(mapstrings);
          mapstrings = NULL;
        }
       }
@@ -773,7 +772,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
          replay = gd_replay_new();
          replay->saved = TRUE;
          replay->success = TRUE;   /* we think that it is a successful demo */
-         cave->replays = g_list_append(cave->replays, replay);
+         cave->replays = list_append(cave->replays, replay);
          gd_strcpy(replay->player_name, "???");    /* name not saved */
        }
        else
@@ -812,7 +811,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
 
        if (replay->movements->len != 0)
        {
-         cave->replays = g_list_append(cave->replays, replay);
+         cave->replays = list_append(cave->replays, replay);
        }
        else
        {
@@ -877,14 +876,14 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
     if (reading_map)
     {
       /* just append to the mapstrings list. we will process it later */
-      mapstrings = g_list_append(mapstrings, line);
+      mapstrings = list_append(mapstrings, line);
 
       continue;
     }
 
     /* strip leading and trailing spaces AFTER checking if we are reading a map.
        map lines might begin or end with spaces */
-    g_strstrip(line);
+    stripString(line);
 
     if (reading_highscore)
     {
@@ -912,13 +911,13 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
     if (reading_bdcff_demo)
     {
       GdReplay *replay;
-      GList *iter;
+      List *iter;
 
       /* demo must be in [cave] section. we already showed an error message for this. */
       if (cave == default_cave)
        continue;
 
-      iter = g_list_last(cave->replays);
+      iter = list_last(cave->replays);
 
       replay = (GdReplay *)iter->data;
       replay_store_more_from_bdcff(replay, line);
@@ -934,7 +933,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
       if (new_object)
       {
        new_object->levels = levels;    /* apply levels to new object */
-       cave->objects = g_list_append(cave->objects, new_object);
+       cave->objects = list_append(cave->objects, new_object);
       }
       else
       {
@@ -1060,7 +1059,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
                strcasecmp(params[0], gd_cave_properties[i].identifier) == 0)
            {
              /* found identifier */
-             gpointer value = G_STRUCT_MEMBER_P (cave, gd_cave_properties[i].offset);
+             void *value = STRUCT_MEMBER_P (cave, gd_cave_properties[i].offset);
 
              *((GdElement *) value) = gd_get_element_from_string (params[1]);
              break;
@@ -1135,7 +1134,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
   if (mapstrings)
   {
     Warn("incorrect file format: end of file, but still have some map lines read");
-    g_list_free(mapstrings);
+    list_free(mapstrings);
     mapstrings = NULL;
   }
 
@@ -1163,7 +1162,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
 
   if (strEqual(version_read, "0.32"))
   {
-    GList *iter;
+    List *iter;
 
     Warn("No BDCFF version, or 0.32. Using unspecified-intermission-size hack.");
 
@@ -1194,12 +1193,12 @@ boolean gd_caveset_load_from_bdcff(const char *contents)
        object.element = cave->initial_border;
        object.fill_element = cave->initial_border;
 
-       cave->objects = g_list_prepend(cave->objects, getMemCopy(&object, sizeof(object)));
+       cave->objects = list_prepend(cave->objects, get_memcpy(&object, sizeof(object)));
 
        object.x1 = 19;
        object.y1 = 0;    /* 19, as it is also the border */
 
-       cave->objects = g_list_prepend(cave->objects, getMemCopy(&object, sizeof(object)));    /* another */
+       cave->objects = list_prepend(cave->objects, get_memcpy(&object, sizeof(object)));    /* another */
       }
     }
   }