X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fresource.c;h=abf0fc389c971ca8f19aa27c6c3ac53362c19741;hb=77fe88af15dc59b5595822f70d75082f1ccd34a4;hp=ad5dbf115d1c4a7fc6a3ecb436ba9b61e7c697c5;hpb=bae31a7df18ecafe05ec1a11b0961708bc3badd6;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/resource.c b/libchimara/resource.c index ad5dbf1..abf0fc3 100644 --- a/libchimara/resource.c +++ b/libchimara/resource.c @@ -1,6 +1,6 @@ #include "resource.h" -extern ChimaraGlkPrivate *glk_data; +extern GPrivate *glk_data_key; /** * giblorb_set_resource_map: @@ -19,6 +19,7 @@ extern ChimaraGlkPrivate *glk_data; giblorb_err_t giblorb_set_resource_map(strid_t file) { + 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); @@ -36,6 +37,8 @@ giblorb_set_resource_map(strid_t file) glk_data->resource_map = newmap; glk_data->resource_file = file; + + //giblorb_print_contents(newmap); return giblorb_err_None; } @@ -50,9 +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); + 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"; + } +}