[AD] Custom packfiles #2

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Here's my new attempt.  The vtable now looks like:

struct PACKFILE_VTABLE
{
  AL_METHOD(int, pf_fclose, (void *userdata));
  AL_METHOD(int, pf_getc, (void *userdata));
  AL_METHOD(int, pf_ungetc, (int c, void *userdata));
  AL_METHOD(long, pf_fread, (void *p, long n, void *userdata));
  AL_METHOD(int, pf_putc, (int c, void *userdata));
  AL_METHOD(long, pf_fwrite, (AL_CONST void *p, long n, void *userdata));
  AL_METHOD(int, pf_fseek, (void *userdata, int offset));
  AL_METHOD(int, pf_feof, (void *userdata));
  AL_METHOD(int, pf_ferror, (void *userdata));
};

I had to add pf_ungetc in there for pack_fgets, so I also exposed the previously internal function:

   AL_FUNC(int, pack_ungetc, (int c, PACKFILE *f));

Most of the default packfile implementation is put into a vtable as well. However, it is still considered a special case.

The LZSS compression code is now exposed to the user via these functions:

   AL_FUNC(LZSS_PACK_DATA *, create_lzss_pack_data, (void));
   AL_FUNC(void, free_lzss_pack_data, (LZSS_PACK_DATA *dat));
AL_FUNC(int, lzss_write, (PACKFILE *file, LZSS_PACK_DATA *dat, int size, unsigned char *buf, int last));

   AL_FUNC(LZSS_UNPACK_DATA *, create_lzss_unpack_data, (void));
   AL_FUNC(void, free_lzss_unpack_data, (LZSS_UNPACK_DATA *dat));
AL_FUNC(int, lzss_read, (PACKFILE *file, LZSS_UNPACK_DATA *dat, int s, unsigned char *buf));

The older encryption method has been ripped out.[1] There's a big (and ugly) chunk of _pack_fdopen() which I ripped out as it looked to me like it was only to support the older encryption method. I'm not totally sure.

I should also mention that packfile_password() has no effect on "files" opened with packfile_fopen_vtable().

Chris and Elias, have at it.

Peter


[1] The newer encryption method is exactly the same as the older method except that it worked at higher level. If the call stack for pack_getc() looks like this:

   pack_getc(f)
   f->vtable->pf_getc(f)
   normal_getc(f)
   normal_refill_buffer(f)
   lzss_read(f, unpack_data, ...)

then the older encryption method worked in lzss_read(), whereas the newer method works in normal_refill_buffer(). It would be possible to keep compatibility with the older method by copying the password into `unpack_data' structure instead of letting it read from `f' (which is supposed to be opaque to lzss_read() now). This would complicate _pack_fdopen() -- see the aforementioned big and ugly chunk that I ripped out.

Attachment: packfile-vtable2.diff.gz
Description: GNU Zip compressed data

Attachment: expackf.c.gz
Description: GNU Zip compressed data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/