home *** CD-ROM | disk | FTP | other *** search
- #define NAME "testSeek"
- #define DISTRIBUTION "(Freeware) "
- #define REVISION "0"
-
- /* Programmheader
-
- Name: testSeek
- Author: SDI
- Distribution: Freeware
- Description: tests seeking in xpk files
- Compileropts: -
- Linkeropts: -l xpkmaster amiga
-
- 1.0 30.10.98 : first version
- */
-
- /* For correct working you need to use at least xpkmaster.library 5! */
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/xpkmaster.h>
- #include <exec/memory.h>
- #include <exec/execbase.h>
- #include "SDI_defines.h"
-
- struct Library *XpkBase = 0;
- ULONG DosVersion = 37;
-
- #define PARAM "FROM/A"
-
- struct Args {
- STRPTR from;
- };
-
- struct BufData {
- STRPTR buffer;
- ULONG start;
- ULONG filled;
- LONG err;
- struct XpkFib *xfib;
- };
-
- LONG SeekData(struct BufData *b, LONG size);
- LONG ReadData(struct BufData *b, APTR buf, ULONG size);
-
- void main(void)
- {
- struct Args args;
- struct RDArgs *rda;
-
- if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
- {
- if((XpkBase = OpenLibrary(XPKNAME, 5)))
- {
- struct BufData b;
- LONG err;
-
- if(!(err = XpkOpenTags(&b.xfib, XPK_InName, args.from, XPK_NeedSeek,
- TRUE, XPK_PassThru, TRUE, TAG_DONE)))
- {
- if((b.buffer = (STRPTR) AllocVec(b.xfib->xf_NLen, MEMF_ANY)))
- {
- b.start = 0;
- b.filled = 0;
- b.err = 0;
-
- /* this is a test, loading useless stuff saved with textChunkyPack */
- {
- ULONG buf[50];
-
- /* because of delayed error, we need not test all calls! */
- if((err = ReadData(&b, buf, 8)))
- XpkPrintFault(err, 0);
- else if(buf[0] == 0x49445854 && buf[1] == 0x43503130)
- {
- Printf("ID value IDXTCP10 is correct\n");
-
- if((err = ReadData(&b, buf, 21)))
- XpkPrintFault(err, 0);
- else
- {
- Printf("%s\n", buf); /* dosbase text */
- SeekData(&b, sizeof(struct DosLibrary));
- if((err = ReadData(&b, buf, 21)))
- XpkPrintFault(err, 0);
- else
- {
- Printf("%s\n", buf); /* sysbase text */
- SeekData(&b, sizeof(struct ExecBase));
- if((err = ReadData(&b, buf, 21)))
- XpkPrintFault(err, 0);
- else
- {
- ULONG a = *((ULONG *)(((STRPTR) 0x1000000)-20));
- Printf("%s\n", buf); /* kickstart text */
- if((err = SeekData(&b, a-20)))
- XpkPrintFault(err, 0);
- else
- {
- if((err = ReadData(&b, buf, 4)))
- XpkPrintFault(err, 0);
- else
- Printf("Kickstart size is correct: %ld\n", buf[0]);
- Printf("Now read too much and produce an error\n");
- if((err = ReadData(&b, 0, 10000)))
- XpkPrintFault(err, 0);
- Printf("Now seek too much and produce an error\n");
- if((err = SeekData(&b, 10000)))
- XpkPrintFault(err, 0);
- }
- }
- }
- }
- }
- else
- Printf("Wrong ID\n");
- }
-
- FreeVec(b.buffer);
- }
- XpkClose(b.xfib);
- }
- else
- XpkPrintFault(err, 0);
- CloseLibrary(XpkBase);
- }
- FreeArgs(rda);
- }
- }
-
- /* Call this function for seeking in stored data */
- LONG SeekData(struct BufData *b, LONG size)
- {
- LONG i;
-
- if((i = XpkSeek(b->xfib, size - b->filled + b->start, XPKSEEK_CURRENT)) < 0)
- b->err = i;
- else
- {
- b->start = i;
- if((i = XpkRead(b->xfib, b->buffer, b->xfib->xf_NLen)) < 0)
- b->err = i;
- else
- b->filled = i;
- }
-
- return b->err;
- }
-
- /* Call this function for reading stored data, calling it with buffer zero
- means skipping some data.
-
- This function uses a delayed error report, so we need not check every call.
- ReadData does nothing except returning the error again, when an error
- occured a call before. */
- LONG ReadData(struct BufData *b, APTR buf, ULONG size)
- {
- LONG i;
-
- while(size && !b->err)
- {
- if(b->filled == b->start)
- {
- if((i = XpkRead(b->xfib, b->buffer, b->xfib->xf_NLen)) < 0)
- b->err = i;
- else
- {
- if(!i) /* we reached the end */
- b->err = XPKERR_IOERRIN;
- b->filled = i;
- b->start = 0;
- }
- }
- if(!b->err)
- {
- if((i = b->filled - b->start) > size)
- i = size;
-
- if(buf)
- {
- CopyMem(b->buffer+b->start, buf, i);
- buf = ((STRPTR) buf) + i;
- }
- b->start += i;
- size -= i;
- }
- }
-
- return b->err;
- }
-
-