Author : Filipe Medeiros
Page : << Previous 16
in the dat utility). The function to do this is `load_datafile_object' and it is used like this:
data_object = load_datafile_object ("DATAFILE.DAT", "object_name");
`data_object' should be a `DATAFILE *', just as if you were loading a whole datafile. To access the object you just dereference this pointer, e.g.:
music_object = load_datafile_object ("DATAFILE.DAT", "MUSIC");
play_midi (music_object->dat); /* or music_object[0].dat */
Since this loads only one object, it returns a pointer to a single DATAFILE struct, not an array of them. So you don't use the object's index from the header file, and also there is no `DAT_END' object after the returned object.
To unload an object loaded in this way use `unload_datafile_object':
unload_datafile_object (data_object);
10.3.3 Reading a datafile component as a normal packfile
A handy feature of Allegro's packfile routines is the ability to read a datafile object as if it were a file on disk. To do this you simply use the encoded filename format `datafile_filename#object_name', for example:
fp = pack_fopen ("DATAFILE.DAT#MUSIC", F_READ);
Then if `fp' is not NULL you can read from it as you would read from a normal packfile. You can't write to the file. To close it you use `fclose' as normal.
Page : << Previous 16