[Gllug] Pointer arithmetic with void *
Jonathan Harker
jon at jonathanharker.co.uk
Thu Aug 15 16:01:44 UTC 2002
On Wednesday 14 Aug 2002 6:22 pm, you wrote:
> A umod file is basically just an archive of uncompressed files
> concatenated together, with a contents table, and a "header"
> tacked on the end. Each entry in the contents table has an int
> describing the length of the filename, followed by the NUL terminated
> filename itself (and then it's offset withing the file, it's length
> and some magic flags). The problem is that the int for the filename
> length is stored as a variable length numebr itself (from 1 to 5
> bytes). Thus it can't be cast to a suitable structure, because the
> structure size varies...
I know this is a Linux list and not alt.lang.cpp or similar, but have you
considered using C++ and iostreams? Perfect for this sort of thing.
eg.
// turn it into a giant string and create an input stream
string s = static_cast<char*>(mmap(blah)); // depending on how big it is?!
istringstream ss(s);
// then you can grab whitespaced tokens like this:
string token;
ss >> token;
// or get individual chars like this:
char c;
ss.get(c)
// or indeed whole chunks:
char chunk[size];
ss.get(chunk, size);
etc.
HTH
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list