X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_bd%2Fbd_caveset.c;h=0e04806b66af742fa078e23c5926337de8fe3d97;hb=81dd3f141822023be2ce419c082dcf68d0ab973d;hp=d04b54c704b8ad5a070da154498a4e534c31aab3;hpb=f2cc15ab6077384c6afd14e7cc5593e210d34c4e;p=rocksndiamonds.git diff --git a/src/game_bd/bd_caveset.c b/src/game_bd/bd_caveset.c index d04b54c7..0e04806b 100644 --- a/src/game_bd/bd_caveset.c +++ b/src/game_bd/bd_caveset.c @@ -14,9 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#include +#include #include "main_bd.h" @@ -99,7 +97,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) - checked_free(G_STRUCT_MEMBER(char *, data, gd_caveset_properties[i].offset)); + checked_free(STRUCT_MEMBER(char *, data, gd_caveset_properties[i].offset)); free(data); } @@ -257,9 +255,9 @@ static GdColor brc_color_table_comp[] = 0x3526ff, }; -static GdElement brc_effect(guint8 byt) +static GdElement brc_effect(byte byt) { - if (byt >= G_N_ELEMENTS(brc_effect_table)) + if (byt >= ARRAY_SIZE(brc_effect_table)) { Warn("invalid element identifier for brc effect: %02x", byt); @@ -269,7 +267,7 @@ static GdElement brc_effect(guint8 byt) return brc_effect_table[byt]; } -static void brc_import(guint8 *data) +static void brc_import(byte *data) { int x, y; int level; @@ -337,12 +335,12 @@ static void brc_import(guint8 *data) { for (x = 0; x < cave->w; x++) { - guint8 import; + byte import; import = data[y + level * 24 + cavenum * 24 * 5 + x * 24 * 5 * 20]; // if (i == printcave) g_print("%2x", import); - if (import < G_N_ELEMENTS(brc_import_table)) + if (import < ARRAY_SIZE(brc_import_table)) cave->map[y][x] = brc_import_table[import]; else cave->map[y][x] = O_UNKNOWN; @@ -410,7 +408,7 @@ static void brc_import(guint8 *data) cave->intermission = (cavenum >= 16 || data[14 * c + datapos + 1] != 0); /* colors */ - colind = data[31 * c + datapos] % G_N_ELEMENTS(brc_color_table); + colind = data[31 * c + datapos] % ARRAY_SIZE(brc_color_table); cave->colorb = 0x000000; /* fixed rgb black */ cave->color0 = 0x000000; /* fixed rgb black */ cave->color1 = brc_color_table[colind]; @@ -476,13 +474,13 @@ static void brc_import(guint8 *data) } } -static void caveset_name_set_from_filename(const char *filename) +static void caveset_name_set_from_filename(char *filename) { char *name; char *c; /* make up a caveset name from the filename. */ - name = g_path_get_basename(filename); + name = getBaseName(filename); gd_strcpy(gd_caveset_data->name, name); free(name); @@ -504,14 +502,13 @@ static void caveset_name_set_from_filename(const char *filename) */ boolean gd_caveset_load_from_file(char *filename) { - GError *error = NULL; - gsize length; + size_t length; char *buf; - boolean read; List *new_caveset; struct stat st; + File *file; - if (g_stat(filename, &st) != 0) + if (stat(filename, &st) != 0) { Warn("cannot stat() file"); @@ -525,12 +522,22 @@ boolean gd_caveset_load_from_file(char *filename) return FALSE; } - read = g_file_get_contents (filename, &buf, &length, &error); - if (!read) + if (!(file = openFile(filename, MODE_READ))) { - Warn("%s", error->message); + Warn("cannot open file '%s'", filename); - g_error_free(error); + return FALSE; + } + + buf = checked_malloc(st.st_size + 1); + length = readFile(file, buf, 1, st.st_size); + buf[length] = '\0'; + + closeFile(file); + + if (length < st.st_size) + { + Warn("cannot read file '%s'", filename); return FALSE; } @@ -550,7 +557,7 @@ boolean gd_caveset_load_from_file(char *filename) if (strSuffix(filename, ".brc") || strSuffix(filename, "*.BRC")) { - brc_import((guint8 *) buf); + brc_import((byte *) buf); gd_caveset_edited = FALSE; /* newly loaded cave is not edited */ gd_caveset_last_selected = caveset_first_selectable_cave_index(); gd_caveset_last_selected_level = 0; @@ -561,7 +568,7 @@ boolean gd_caveset_load_from_file(char *filename) } /* BDCFF */ - if (gd_caveset_imported_get_format((guint8 *) buf) == GD_FORMAT_UNKNOWN) + if (gd_caveset_imported_get_format((byte *) buf) == GD_FORMAT_UNKNOWN) { /* try to load as bdcff */ boolean result; @@ -580,7 +587,7 @@ boolean gd_caveset_load_from_file(char *filename) } /* try to load as a binary file, as we know the format */ - new_caveset = gd_caveset_import_from_buffer ((guint8 *) buf, length); + new_caveset = gd_caveset_import_from_buffer ((byte *) buf, length); free(buf); /* if unable to load, exit here. error was reported by import_from_buffer() */ @@ -613,7 +620,7 @@ int gd_cave_check_replays(GdCave *cave, boolean report, boolean remove, boolean while (riter != NULL) { GdReplay *replay = (GdReplay *)riter->data; - guint32 checksum; + unsigned int checksum; GdCave *rendered; List *next = riter->next;