* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <glib/gstdio.h>
+#include <sys/stat.h>
#include "main_bd.h"
/* 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);
}
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);
return brc_effect_table[byt];
}
-static void brc_import(guint8 *data)
+static void brc_import(byte *data)
{
int x, y;
int level;
imported[level * 20 + cavenum] = cave;
if (cavenum < 16)
- g_snprintf(cave->name, sizeof(GdString), "Cave %c/%d", 'A' + cavenum,
- level + 1);
+ snprintf(cave->name, sizeof(GdString), "Cave %c/%d", 'A' + cavenum,
+ level + 1);
else
- g_snprintf(cave->name, sizeof(GdString), "Intermission %d/%d",
- cavenum - 15, level + 1);
+ snprintf(cave->name, sizeof(GdString), "Intermission %d/%d",
+ cavenum - 15, level + 1);
/* fixed intermission caves; are smaller. */
if (cavenum >= 16)
{
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;
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];
}
}
-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);
*/
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");
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;
}
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;
}
/* 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;
}
/* 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() */
while (riter != NULL)
{
GdReplay *replay = (GdReplay *)riter->data;
- guint32 checksum;
+ unsigned int checksum;
GdCave *rendered;
List *next = riter->next;