| 1 | \ Load a file into an allocated memory image.\r |
| 2 | \\r |
| 3 | \ Author: Phil Burk\r |
| 4 | \ Copyright 3DO 1995\r |
| 5 | \r |
| 6 | anew task-load_file.fth\r |
| 7 | \r |
| 8 | : $LOAD.FILE { $filename | fid numbytes numread err data -- data-addr 0 | 0 err }\r |
| 9 | 0 -> data\r |
| 10 | \ open file\r |
| 11 | $filename count r/o open-file -> err -> fid\r |
| 12 | err\r |
| 13 | IF\r |
| 14 | ." $LOAD.FILE - Could not open input file!" cr\r |
| 15 | ELSE\r |
| 16 | \ determine size of file\r |
| 17 | fid file-size -> err -> numbytes\r |
| 18 | err\r |
| 19 | IF\r |
| 20 | ." $LOAD.FILE - File size failed!" cr\r |
| 21 | ELSE\r |
| 22 | ." File size = " numbytes . cr\r |
| 23 | \ allocate memory for sample, when done free memory using FREE\r |
| 24 | numbytes allocate -> err -> data\r |
| 25 | err\r |
| 26 | IF\r |
| 27 | ." $LOAD.FILE - Memory allocation failed!" cr\r |
| 28 | ELSE\r |
| 29 | \ read data\r |
| 30 | data numbytes fid read-file -> err\r |
| 31 | ." Read " . ." bytes from file " $filename count type cr\r |
| 32 | THEN\r |
| 33 | THEN\r |
| 34 | fid close-file drop\r |
| 35 | THEN\r |
| 36 | data err\r |
| 37 | ;\r |
| 38 | \r |
| 39 | \ Example: c" myfile" $load.file abort" Oops!" free .\r |