Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Finding the end of a datafile

This thread is locked; no one can reply to it. rss feed Print
Finding the end of a datafile
Tomoso
Member #3,128
January 2003
avatar

How would I go about finding out how many files are within a datafile. This is primarily for loading datafiles containing "tile gfx" within my map editor. I have a button within my map editor which allows me to load new datafiles at run time but the array of "buttons" that represent each file within the datafile needs to know how many their are, otherwise it reads to far into the datafile if I have to scroll through the objs.
Hope that makes sense :/

Thanks,

Lazy Noob - Blog

Steve Terry
Member #1,989
March 2002
avatar

I believe it's called DAT_END

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Tomoso
Member #3,128
January 2003
avatar

And what do I do with DAT_END? I want to convert it to an integer for use with loops. I was thinking about adding an obj at the end of a datafile called "END_OBJ" or something, and when the datafiles loaded using

DATAFILE *find_datafile_object(const DATAFILE *dat, const char *objectname);

If it returns null datafile is invalid, otherwise use
get_datafile_property(const DATAFILE *dat, int type);
I just don't know which "type" I'm looking for to find its ID. I need to get the number of the obj thats defined when you create a header for the datafile.
If you could elaborate on how to use DAT_END, I think that would be easier :P

Cheers

Lazy Noob - Blog

Michael Faerber
Member #4,800
July 2004
avatar

From the manual:

   for (i=0; dat<i>.type != DAT_END; i++) {
      if (stricmp(get_datafile_property(dat+i, DAT_ID('N','A','M','E')),
   "my_object") == 0) {
   /* found the object at index i */
      }
   }
   /* not found... */

Do you understand now how to use DAT_END?

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

Audric
Member #907
January 2001

(untested)

df = load_datafile("moretiles.dat");
if (! df) return -1; // error

for (i=0; df<i>.type != DAT_END ; i++)
{
   // do whatever you want with df<i>
   // You can choose to process only those where df<i>.type == DAT_BITMAP

   // df<i>.dat is a pointer to the item (ie: BITMAP *)
}

Steve Terry
Member #1,989
March 2002
avatar

Oh I don't know maybe it's called a manual?

 for (i=0; dat<i>.type != DAT_END; i++)

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Tomoso
Member #3,128
January 2003
avatar

Michael Faerber said:

Do you understand now how to use DAT_END?

Yes thankyou. :-*

Lazy Noob - Blog

Go to: