Home » Archimedes archive » Acorn User » AU 1997-01 B.adf » Features » Arcade/!Popcorn/c/LoadResF
Arcade/!Popcorn/c/LoadResF
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-01 B.adf » Features |
Filename: | Arcade/!Popcorn/c/LoadResF |
Read OK: | ✔ |
File size: | 051A bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "DeskLib:h.Core" #include "DeskLib:h.File" #include "DeskLib:h.Str" #include "Popcorn:h.Popcorn" os_error ERROR_OPEN = {0, "Couldn't open resource file"}; os_error _err_returned; os_error *_err(char *msg, int line, FILE *handle) { sprintf(_err_returned.errmess, "LoadResourceFile: %s (line %d).", msg, line); if (handle != NULL) fclose(handle); return(&_err_returned); } os_error *Popcorn_LoadResourceFile(char *filename) { FILE *handle; char temp_name[256]; int line = 0; handle = fopen(filename, "rb"); if (handle == NULL) return(&ERROR_OPEN); while (!feof(handle)) { resource[resource_free] = malloc(sizeof(struct resource)); fscanf(handle, "%s %s\n", &(resource[resource_free]->group), temp_name); line++; resource[resource_free]->file = malloc(strlen(temp_name)+1); strcpycr(resource[resource_free]->file, temp_name); resource[resource_free]->addr = NULL; if (!File_Exists(temp_name)) return(_err("Couldn't find resource", line, handle)); resource[resource_free]->size = File_Size(temp_name); /* printf("%08X %s\n", resource[resource_free]->group, resource[resource_free]->file); */ resource_free++; } fclose(handle); return(NULL); }
00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include <stdio.| 00000010 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 |h>.#include <std| 00000020 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 |lib.h>.#include | 00000030 3c 73 74 72 69 6e 67 2e 68 3e 0a 0a 23 69 6e 63 |<string.h>..#inc| 00000040 6c 75 64 65 20 22 44 65 73 6b 4c 69 62 3a 68 2e |lude "DeskLib:h.| 00000050 43 6f 72 65 22 0a 23 69 6e 63 6c 75 64 65 20 22 |Core".#include "| 00000060 44 65 73 6b 4c 69 62 3a 68 2e 46 69 6c 65 22 0a |DeskLib:h.File".| 00000070 23 69 6e 63 6c 75 64 65 20 22 44 65 73 6b 4c 69 |#include "DeskLi| 00000080 62 3a 68 2e 53 74 72 22 0a 0a 23 69 6e 63 6c 75 |b:h.Str"..#inclu| 00000090 64 65 20 22 50 6f 70 63 6f 72 6e 3a 68 2e 50 6f |de "Popcorn:h.Po| 000000a0 70 63 6f 72 6e 22 0a 0a 6f 73 5f 65 72 72 6f 72 |pcorn"..os_error| 000000b0 20 45 52 52 4f 52 5f 4f 50 45 4e 20 3d 20 7b 30 | ERROR_OPEN = {0| 000000c0 2c 20 22 43 6f 75 6c 64 6e 27 74 20 6f 70 65 6e |, "Couldn't open| 000000d0 20 72 65 73 6f 75 72 63 65 20 66 69 6c 65 22 7d | resource file"}| 000000e0 3b 0a 0a 6f 73 5f 65 72 72 6f 72 20 5f 65 72 72 |;..os_error _err| 000000f0 5f 72 65 74 75 72 6e 65 64 3b 0a 0a 6f 73 5f 65 |_returned;..os_e| 00000100 72 72 6f 72 20 2a 5f 65 72 72 28 63 68 61 72 20 |rror *_err(char | 00000110 2a 6d 73 67 2c 20 69 6e 74 20 6c 69 6e 65 2c 20 |*msg, int line, | 00000120 46 49 4c 45 20 2a 68 61 6e 64 6c 65 29 0a 7b 0a |FILE *handle).{.| 00000130 20 20 73 70 72 69 6e 74 66 28 5f 65 72 72 5f 72 | sprintf(_err_r| 00000140 65 74 75 72 6e 65 64 2e 65 72 72 6d 65 73 73 2c |eturned.errmess,| 00000150 20 22 4c 6f 61 64 52 65 73 6f 75 72 63 65 46 69 | "LoadResourceFi| 00000160 6c 65 3a 20 25 73 20 28 6c 69 6e 65 20 25 64 29 |le: %s (line %d)| 00000170 2e 22 2c 20 6d 73 67 2c 20 6c 69 6e 65 29 3b 0a |.", msg, line);.| 00000180 20 20 69 66 20 28 68 61 6e 64 6c 65 20 21 3d 20 | if (handle != | 00000190 4e 55 4c 4c 29 20 66 63 6c 6f 73 65 28 68 61 6e |NULL) fclose(han| 000001a0 64 6c 65 29 3b 0a 20 20 72 65 74 75 72 6e 28 26 |dle);. return(&| 000001b0 5f 65 72 72 5f 72 65 74 75 72 6e 65 64 29 3b 0a |_err_returned);.| 000001c0 7d 0a 0a 0a 6f 73 5f 65 72 72 6f 72 20 2a 50 6f |}...os_error *Po| 000001d0 70 63 6f 72 6e 5f 4c 6f 61 64 52 65 73 6f 75 72 |pcorn_LoadResour| 000001e0 63 65 46 69 6c 65 28 63 68 61 72 20 2a 66 69 6c |ceFile(char *fil| 000001f0 65 6e 61 6d 65 29 0a 7b 0a 20 20 46 49 4c 45 20 |ename).{. FILE | 00000200 20 20 20 20 20 20 20 20 20 2a 68 61 6e 64 6c 65 | *handle| 00000210 3b 0a 20 20 63 68 61 72 09 09 74 65 6d 70 5f 6e |;. char..temp_n| 00000220 61 6d 65 5b 32 35 36 5d 3b 0a 20 20 69 6e 74 09 |ame[256];. int.| 00000230 09 6c 69 6e 65 20 3d 20 30 3b 0a 0a 20 20 68 61 |.line = 0;.. ha| 00000240 6e 64 6c 65 20 3d 20 66 6f 70 65 6e 28 66 69 6c |ndle = fopen(fil| 00000250 65 6e 61 6d 65 2c 20 22 72 62 22 29 3b 0a 20 20 |ename, "rb");. | 00000260 69 66 20 28 68 61 6e 64 6c 65 20 3d 3d 20 4e 55 |if (handle == NU| 00000270 4c 4c 29 0a 20 20 20 20 72 65 74 75 72 6e 28 26 |LL). return(&| 00000280 45 52 52 4f 52 5f 4f 50 45 4e 29 3b 0a 0a 20 20 |ERROR_OPEN);.. | 00000290 77 68 69 6c 65 20 28 21 66 65 6f 66 28 68 61 6e |while (!feof(han| 000002a0 64 6c 65 29 29 0a 20 20 7b 0a 20 20 20 20 72 65 |dle)). {. re| 000002b0 73 6f 75 72 63 65 5b 72 65 73 6f 75 72 63 65 5f |source[resource_| 000002c0 66 72 65 65 5d 20 3d 20 6d 61 6c 6c 6f 63 28 73 |free] = malloc(s| 000002d0 69 7a 65 6f 66 28 73 74 72 75 63 74 20 72 65 73 |izeof(struct res| 000002e0 6f 75 72 63 65 29 29 3b 0a 0a 20 20 20 20 66 73 |ource));.. fs| 000002f0 63 61 6e 66 28 68 61 6e 64 6c 65 2c 20 22 25 73 |canf(handle, "%s| 00000300 20 25 73 5c 6e 22 2c 20 26 28 72 65 73 6f 75 72 | %s\n", &(resour| 00000310 63 65 5b 72 65 73 6f 75 72 63 65 5f 66 72 65 65 |ce[resource_free| 00000320 5d 2d 3e 67 72 6f 75 70 29 2c 20 74 65 6d 70 5f |]->group), temp_| 00000330 6e 61 6d 65 29 3b 0a 20 20 20 20 6c 69 6e 65 2b |name);. line+| 00000340 2b 3b 0a 20 20 20 20 72 65 73 6f 75 72 63 65 5b |+;. resource[| 00000350 72 65 73 6f 75 72 63 65 5f 66 72 65 65 5d 2d 3e |resource_free]->| 00000360 66 69 6c 65 20 3d 20 6d 61 6c 6c 6f 63 28 73 74 |file = malloc(st| 00000370 72 6c 65 6e 28 74 65 6d 70 5f 6e 61 6d 65 29 2b |rlen(temp_name)+| 00000380 31 29 3b 0a 20 20 20 20 73 74 72 63 70 79 63 72 |1);. strcpycr| 00000390 28 72 65 73 6f 75 72 63 65 5b 72 65 73 6f 75 72 |(resource[resour| 000003a0 63 65 5f 66 72 65 65 5d 2d 3e 66 69 6c 65 2c 20 |ce_free]->file, | 000003b0 74 65 6d 70 5f 6e 61 6d 65 29 3b 0a 20 20 20 20 |temp_name);. | 000003c0 72 65 73 6f 75 72 63 65 5b 72 65 73 6f 75 72 63 |resource[resourc| 000003d0 65 5f 66 72 65 65 5d 2d 3e 61 64 64 72 20 3d 20 |e_free]->addr = | 000003e0 4e 55 4c 4c 3b 0a 20 20 20 20 69 66 20 28 21 46 |NULL;. if (!F| 000003f0 69 6c 65 5f 45 78 69 73 74 73 28 74 65 6d 70 5f |ile_Exists(temp_| 00000400 6e 61 6d 65 29 29 0a 20 20 20 20 20 20 72 65 74 |name)). ret| 00000410 75 72 6e 28 5f 65 72 72 28 22 43 6f 75 6c 64 6e |urn(_err("Couldn| 00000420 27 74 20 66 69 6e 64 20 72 65 73 6f 75 72 63 65 |'t find resource| 00000430 22 2c 20 6c 69 6e 65 2c 20 68 61 6e 64 6c 65 29 |", line, handle)| 00000440 29 3b 0a 20 20 20 20 72 65 73 6f 75 72 63 65 5b |);. resource[| 00000450 72 65 73 6f 75 72 63 65 5f 66 72 65 65 5d 2d 3e |resource_free]->| 00000460 73 69 7a 65 20 3d 20 46 69 6c 65 5f 53 69 7a 65 |size = File_Size| 00000470 28 74 65 6d 70 5f 6e 61 6d 65 29 3b 0a 0a 2f 2a |(temp_name);../*| 00000480 20 20 20 20 20 70 72 69 6e 74 66 28 22 25 30 38 | printf("%08| 00000490 58 20 25 73 5c 6e 22 2c 20 72 65 73 6f 75 72 63 |X %s\n", resourc| 000004a0 65 5b 72 65 73 6f 75 72 63 65 5f 66 72 65 65 5d |e[resource_free]| 000004b0 2d 3e 67 72 6f 75 70 2c 20 72 65 73 6f 75 72 63 |->group, resourc| 000004c0 65 5b 72 65 73 6f 75 72 63 65 5f 66 72 65 65 5d |e[resource_free]| 000004d0 2d 3e 66 69 6c 65 29 3b 20 2a 2f 0a 0a 20 20 20 |->file); */.. | 000004e0 20 72 65 73 6f 75 72 63 65 5f 66 72 65 65 2b 2b | resource_free++| 000004f0 3b 0a 20 20 7d 0a 20 20 66 63 6c 6f 73 65 28 68 |;. }. fclose(h| 00000500 61 6e 64 6c 65 29 3b 0a 20 20 72 65 74 75 72 6e |andle);. return| 00000510 28 4e 55 4c 4c 29 3b 0a 7d 0a |(NULL);.}.| 0000051a