X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fresource.c;h=49ef35280a369daf60aeecdf6279c81fd3cf5f58;hb=refs%2Fheads%2Fmaster;hp=b3c98ecbdc1ee9724daed6849b2bee1ad1f46136;hpb=d5610e149e0384a24d00727a5815df12e85de026;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/resource.c b/libchimara/resource.c index b3c98ec..49ef352 100644 --- a/libchimara/resource.c +++ b/libchimara/resource.c @@ -1,6 +1,7 @@ #include "resource.h" +#include "stream.h" -extern GPrivate *glk_data_key; +extern GPrivate glk_data_key; /** * giblorb_set_resource_map: @@ -19,7 +20,7 @@ extern GPrivate *glk_data_key; giblorb_err_t giblorb_set_resource_map(strid_t file) { - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); giblorb_map_t *newmap; /* create map allocates memory */ giblorb_err_t error = giblorb_create_map(file, &newmap); @@ -37,6 +38,7 @@ giblorb_set_resource_map(strid_t file) glk_data->resource_map = newmap; glk_data->resource_file = file; + return giblorb_err_None; } @@ -51,11 +53,87 @@ giblorb_set_resource_map(strid_t file) giblorb_map_t* giblorb_get_resource_map() { - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); - + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); + if(glk_data->resource_map == NULL) { WARNING("Resource map not set yet.\n"); } return glk_data->resource_map; } + +/* giblorb_chunkdesc_t: Describes one chunk of the Blorb file. */ +typedef struct giblorb_chunkdesc_struct { + glui32 type; + glui32 len; + glui32 startpos; /* start of chunk header */ + glui32 datpos; /* start of data (either startpos or startpos+8) */ + + void *ptr; /* pointer to malloc'd data, if loaded */ + int auxdatnum; /* entry in the auxsound/auxpict array; -1 if none. + This only applies to chunks that represent resources; */ + +} giblorb_chunkdesc_t; + +/* giblorb_resdesc_t: Describes one resource in the Blorb file. */ +typedef struct giblorb_resdesc_struct { + glui32 usage; + glui32 resnum; + glui32 chunknum; +} giblorb_resdesc_t; + +/* giblorb_map_t: Holds the complete description of an open Blorb file. */ +struct giblorb_map_struct { + glui32 inited; /* holds giblorb_Inited_Magic if the map structure is + valid */ + strid_t file; + + int numchunks; + giblorb_chunkdesc_t *chunks; /* list of chunk descriptors */ + + int numresources; + giblorb_resdesc_t *resources; /* list of resource descriptors */ + giblorb_resdesc_t **ressorted; /* list of pointers to descriptors + in map->resources -- sorted by usage and resource number. */ +}; + +void +giblorb_print_contents(giblorb_map_t *map) +{ + int i; + for(i=0; inumresources; i++) { + giblorb_resdesc_t *resource = map->ressorted[i]; + printf("Resource #%d, chunknum: %d\n", resource->resnum, resource->chunknum); + } + + printf("\n-------\n"); + + for(i=0; inumresources; i++) { + giblorb_chunkdesc_t chunk = map->chunks[i]; + printf("Chunk #%d, type: %d\n", i, chunk.type); + } +} + +const char * +giblorb_get_error_message(giblorb_err_t err) +{ + switch(err) + { + case giblorb_err_None: + return "not BLORB's fault"; + case giblorb_err_CompileTime: + return "BLORB compile time error"; + case giblorb_err_Alloc: + return "memory allocation failed"; + case giblorb_err_Read: + return "error during reading of file"; + case giblorb_err_NotAMap: + return "invalid resource map supplied"; + case giblorb_err_Format: + return "invalid format of resource"; + case giblorb_err_NotFound: + return "resource not found"; + default: + return "Unknown error code"; + } +}