From: Holger Schemel Date: Tue, 20 Feb 2024 01:13:48 +0000 (+0100) Subject: replaced glib function calls to g_string_*() X-Git-Tag: 4.4.0.0-test-1~330 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=e25acb01746ef65a1c5d4919b0e7c2c5d48b6807;p=rocksndiamonds.git replaced glib function calls to g_string_*() --- diff --git a/src/game_bd/bd_bdcff.c b/src/game_bd/bd_bdcff.c index 490dc1af..06e5e06b 100644 --- a/src/game_bd/bd_bdcff.c +++ b/src/game_bd/bd_bdcff.c @@ -188,12 +188,10 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_ if (prop_desc[i].type == GD_TYPE_LONGSTRING) { - GString *str = *(GString **)value; - char *compressed; + char **str = (char **)value; - compressed = getUnescapedString(param); - g_string_assign(str, compressed); - free(compressed); + checked_free(*str); + *str = getUnescapedString(param); /* remember this to skip checking the number of parameters at the end of the function */ was_string = TRUE; diff --git a/src/game_bd/bd_cave.c b/src/game_bd/bd_cave.c index 86b07a88..b0f1573e 100644 --- a/src/game_bd/bd_cave.c +++ b/src/game_bd/bd_cave.c @@ -443,7 +443,6 @@ guint gd_str_case_hash(gconstpointer v) */ GdCave *gd_cave_new(void) { - int i; GdCave *cave; cave = checked_calloc(sizeof(GdCave)); @@ -451,11 +450,6 @@ GdCave *gd_cave_new(void) /* hash table which stores unknown tags as strings. */ cave->tags = g_hash_table_new_full(gd_str_case_hash, gd_str_case_equal, free, free); - /* for strings */ - for (i = 0; gd_cave_properties[i].identifier != NULL; i++) - if (gd_cave_properties[i].type == GD_TYPE_LONGSTRING) - G_STRUCT_MEMBER(GString *, cave, gd_cave_properties[i].offset) = g_string_new(NULL); - gd_cave_set_gdash_defaults(cave); return cave; @@ -546,10 +540,10 @@ void gd_cave_free(GdCave *cave) if (cave->random) /* random generator is a GRand * */ g_rand_free(cave->random); - /* free GStrings */ + /* free strings */ for (i = 0; gd_cave_properties[i].identifier != NULL; i++) if (gd_cave_properties[i].type == GD_TYPE_LONGSTRING) - g_string_free(G_STRUCT_MEMBER(GString *, cave, gd_cave_properties[i].offset), TRUE); + checked_free(G_STRUCT_MEMBER(char *, cave, gd_cave_properties[i].offset)); /* map */ gd_cave_map_free(cave->map); @@ -597,8 +591,8 @@ void gd_cave_copy(GdCave *dest, const GdCave *src) /* for longstrings */ for (i = 0; gd_cave_properties[i].identifier != NULL; i++) if (gd_cave_properties[i].type == GD_TYPE_LONGSTRING) - G_STRUCT_MEMBER(GString *, dest, gd_cave_properties[i].offset) = - g_string_new(G_STRUCT_MEMBER(GString *, src, gd_cave_properties[i].offset)->str); + G_STRUCT_MEMBER(char *, dest, gd_cave_properties[i].offset) = + getStringCopy(G_STRUCT_MEMBER(char *, src, gd_cave_properties[i].offset)); /* no reason to copy this */ dest->objects_order = NULL; @@ -1396,8 +1390,6 @@ GdReplay *gd_replay_new(void) rep = checked_calloc(sizeof(GdReplay)); - /* create dynamic objects */ - rep->comment = g_string_new(NULL); rep->movements = g_byte_array_new(); return rep; @@ -1410,7 +1402,7 @@ GdReplay *gd_replay_new_from_replay(GdReplay *orig) rep = g_memdup(orig, sizeof(GdReplay)); /* replicate dynamic data */ - rep->comment = g_string_new(orig->comment->str); + rep->comment = getStringCopy(orig->comment); rep->movements = g_byte_array_new(); g_byte_array_append(rep->movements, orig->movements->data, orig->movements->len); @@ -1420,7 +1412,7 @@ GdReplay *gd_replay_new_from_replay(GdReplay *orig) void gd_replay_free(GdReplay *replay) { g_byte_array_free(replay->movements, TRUE); - g_string_free(replay->comment, TRUE); + checked_free(replay->comment); free(replay); } diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index aa27a5f7..bd677ead 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -322,7 +322,7 @@ typedef struct _gd_cave_replay GdString player_name; /* who played this */ GdString date; /* when played */ - GString *comment; /* some comments from the player */ + char *comment; /* some comments from the player */ int score; /* score collected */ int duration; /* number of seconds played */ @@ -366,8 +366,8 @@ typedef struct _gd_cave GdString difficulty; /* difficulty of the game, for info purposes */ GdString www; /* link to author's webpage */ GdString date; /* date of creation */ - GString *story; /* story for the cave - will be shown when the cave is played. */ - GString *remark; /* some note */ + char *story; /* story for the cave - will be shown when the cave is played. */ + char *remark; /* some note */ GdString charset; /* these are not used by gdash */ GdString fontset; diff --git a/src/game_bd/bd_caveset.c b/src/game_bd/bd_caveset.c index 26fe734b..e25fa626 100644 --- a/src/game_bd/bd_caveset.c +++ b/src/game_bd/bd_caveset.c @@ -84,16 +84,9 @@ static GdPropertyDefault caveset_defaults[] = GdCavesetData *gd_caveset_data_new(void) { GdCavesetData *data; - int i; data = checked_calloc(sizeof(GdCavesetData)); - /* create strings */ - for (i = 0; gd_caveset_properties[i].identifier != NULL; i++) - if (gd_caveset_properties[i].type == GD_TYPE_LONGSTRING) - G_STRUCT_MEMBER(GString *, data, gd_caveset_properties[i].offset) = - g_string_new(NULL); - gd_struct_set_defaults_from_array(data, gd_caveset_properties, caveset_defaults); return data; @@ -106,7 +99,7 @@ void gd_caveset_data_free(GdCavesetData *data) /* free strings */ for (i = 0; gd_caveset_properties[i].identifier != NULL; i++) if (gd_caveset_properties[i].type == GD_TYPE_LONGSTRING) - g_string_free(G_STRUCT_MEMBER(GString *, data, gd_caveset_properties[i].offset), TRUE); + checked_free(G_STRUCT_MEMBER(char *, data, gd_caveset_properties[i].offset)); free(data); } diff --git a/src/game_bd/bd_caveset.h b/src/game_bd/bd_caveset.h index 94ec4378..e5a5a7e6 100644 --- a/src/game_bd/bd_caveset.h +++ b/src/game_bd/bd_caveset.h @@ -31,11 +31,11 @@ typedef struct _gd_caveset_data GdString www; /* link to author's webpage */ GdString date; /* date of creation */ - GString *story; /* story for the caves */ - GString *remark; /* notes about the game */ + char *story; /* story for the caves */ + char *remark; /* notes about the game */ - GString *title_screen; /* base64-encoded title screen image */ - GString *title_screen_scroll; /* scrolling background for title screen image */ + char *title_screen; /* base64-encoded title screen image */ + char *title_screen_scroll; /* scrolling background for title screen image */ GdString charset; /* these are not used by gdash */ GdString fontset; diff --git a/src/game_bd/bd_gameplay.c b/src/game_bd/bd_gameplay.c index ffedad2c..ec757454 100644 --- a/src/game_bd/bd_gameplay.c +++ b/src/game_bd/bd_gameplay.c @@ -397,8 +397,8 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean /* if we have a story... */ #if 0 - if (game->show_story && game->original_cave && game->original_cave->story->len != 0) - Info("Cave Story: %s", game->original_cave->story->str); + if (game->show_story && game->original_cave && game->original_cave->story != NULL) + Info("Cave Story: %s", game->original_cave->story); #endif counter_next = GAME_INT_START_UNCOVER;