4 extern GPrivate glk_data_key;
7 * giblorb_set_resource_map:
8 * @file: The file stream to read the resource map from
10 * This function tells the library that the file is indeed the Blorby source
11 * of all resource goodness. Whenever your program calls an image or sound
12 * function, such as glk_image_draw(), the library will search this file for
13 * the resource you request.
15 * Do <emphasis>not</emphasis> close the stream after calling this function.
16 * The library is responsible for closing the stream at shutdown time.
18 * Returns: a Blorb error code.
21 giblorb_set_resource_map(strid_t file)
23 ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);
24 giblorb_map_t *newmap; /* create map allocates memory */
25 giblorb_err_t error = giblorb_create_map(file, &newmap);
27 if(error != giblorb_err_None) {
32 /* Check if there was already an existing resource map */
33 if(glk_data->resource_map != NULL) {
34 WARNING("Overwriting existing resource map.\n");
35 giblorb_destroy_map(glk_data->resource_map);
36 glk_stream_close(glk_data->resource_file, NULL);
39 glk_data->resource_map = newmap;
40 glk_data->resource_file = file;
42 return giblorb_err_None;
46 * giblorb_get_resource_map:
48 * This function returns the current resource map being used. Returns %NULL
49 * if giblorb_set_resource_map() has not been called yet.
51 * Returns: a resource map, or %NULL.
54 giblorb_get_resource_map()
56 ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);
58 if(glk_data->resource_map == NULL) {
59 WARNING("Resource map not set yet.\n");
62 return glk_data->resource_map;
65 /* giblorb_chunkdesc_t: Describes one chunk of the Blorb file. */
66 typedef struct giblorb_chunkdesc_struct {
69 glui32 startpos; /* start of chunk header */
70 glui32 datpos; /* start of data (either startpos or startpos+8) */
72 void *ptr; /* pointer to malloc'd data, if loaded */
73 int auxdatnum; /* entry in the auxsound/auxpict array; -1 if none.
74 This only applies to chunks that represent resources; */
76 } giblorb_chunkdesc_t;
78 /* giblorb_resdesc_t: Describes one resource in the Blorb file. */
79 typedef struct giblorb_resdesc_struct {
85 /* giblorb_map_t: Holds the complete description of an open Blorb file. */
86 struct giblorb_map_struct {
87 glui32 inited; /* holds giblorb_Inited_Magic if the map structure is
92 giblorb_chunkdesc_t *chunks; /* list of chunk descriptors */
95 giblorb_resdesc_t *resources; /* list of resource descriptors */
96 giblorb_resdesc_t **ressorted; /* list of pointers to descriptors
97 in map->resources -- sorted by usage and resource number. */
101 giblorb_print_contents(giblorb_map_t *map)
104 for(i=0; i<map->numresources; i++) {
105 giblorb_resdesc_t *resource = map->ressorted[i];
106 printf("Resource #%d, chunknum: %d\n", resource->resnum, resource->chunknum);
109 printf("\n-------\n");
111 for(i=0; i<map->numresources; i++) {
112 giblorb_chunkdesc_t chunk = map->chunks[i];
113 printf("Chunk #%d, type: %d\n", i, chunk.type);
118 giblorb_get_error_message(giblorb_err_t err)
122 case giblorb_err_None:
123 return "not BLORB's fault";
124 case giblorb_err_CompileTime:
125 return "BLORB compile time error";
126 case giblorb_err_Alloc:
127 return "memory allocation failed";
128 case giblorb_err_Read:
129 return "error during reading of file";
130 case giblorb_err_NotAMap:
131 return "invalid resource map supplied";
132 case giblorb_err_Format:
133 return "invalid format of resource";
134 case giblorb_err_NotFound:
135 return "resource not found";
137 return "Unknown error code";