X-Git-Url: https://git.stderr.nl/gitweb?p=rodin%2Fchimara.git;a=blobdiff_plain;f=libchimara%2Fresource.c;h=9c40723057393c32f885365cff9dab2baa4dc6a1;hp=b3c98ecbdc1ee9724daed6849b2bee1ad1f46136;hb=65f88142d8843d16c203efad8830fbebba888f0f;hpb=3d647bf217282e6706887b8e0e1d0d0f884f0da0 diff --git a/libchimara/resource.c b/libchimara/resource.c index b3c98ec..9c40723 100644 --- a/libchimara/resource.c +++ b/libchimara/resource.c @@ -37,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; } @@ -59,3 +61,79 @@ giblorb_get_resource_map() 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); + } +} + +gchar* +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"; + } +}