home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 10 / Sonderheft_12.iso / best-of-tools / packer / xpk3.11 / xpk_source / xpkmaster / test / testmemexamine.c < prev    next >
C/C++ Source or Header  |  1996-12-06  |  2KB  |  84 lines

  1. #define NAME     "testMemExamine"
  2. #define REVISION "1"
  3. #define ENDCODE_NOCTRLC
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        testMemExamine
  8.     Author:        SDI
  9.     Distribution:    PD
  10.     Description:    tests Xpk Examine function
  11.     Compileropts:    -
  12.     Linkeropts:    -l xpkmaster
  13.  
  14.  1.1   06.12.96 : fixed for new includes, added new WriteXpkFib
  15. */
  16.  
  17. #include <pragma/exec_lib.h>
  18. #include <pragma/dos_lib.h>
  19. #include <pragma/xpkmaster_lib.h>
  20. #include <exec/memory.h>
  21. #include "WriteXpkFib.c"
  22. #include "SDI_defines.h"
  23.  
  24. struct Library        *XpkBase        = 0;
  25. ULONG            DosVersion        = 37;
  26. STRPTR            buf            = 0;
  27. BPTR            fh            = 0;
  28. struct RDArgs        *rda            = 0;
  29. struct FileInfoBlock    *fib            = 0;
  30. struct XpkFib        *xfib            = 0;
  31.  
  32. #define PARAM "FILENAME/A"
  33.  
  34. void main(void)
  35. {
  36.   UBYTE errbuf[XPKERRMSGSIZE+1];
  37.   STRPTR filename;
  38.  
  39.   if(!(rda = ReadArgs(PARAM, (LONG *) &filename, 0)) ||
  40.   !(xfib = (struct XpkFib *) AllocMem(sizeof(struct XpkFib), MEMF_ANY|MEMF_CLEAR)) ||
  41.   !(XpkBase = OpenLibrary(XPKNAME, 0)))
  42.     End(RETURN_FAIL);
  43.  
  44.   if(XpkExamineTags(xfib, XPK_InName, filename, XPK_GetError, errbuf,
  45.     TAG_DONE))
  46.   {
  47.     STRPTR a = errbuf;
  48.     VPrintf("Can't XpkExamine: %s\n", &a);
  49.     End(RETURN_FAIL);
  50.   }
  51.  
  52.   WriteXpkFib(xfib);
  53.  
  54.   if(!(fh = Open(filename, MODE_OLDFILE)) ||
  55.   !(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)) ||
  56.   !(ExamineFH(fh, fib)) ||
  57.   !(buf = (STRPTR) AllocMem(fib->fib_Size, MEMF_ANY)) ||
  58.   Read(fh, buf, fib->fib_Size) != fib->fib_Size)
  59.     End(RETURN_FAIL);
  60.  
  61.   if(XpkExamineTags(xfib, XPK_InBuf, buf, XPK_InLen, fib->fib_Size,
  62.     XPK_GetError, errbuf, TAG_DONE))
  63.   {
  64.     STRPTR a = errbuf;
  65.     VPrintf("Can't XpkExamine: %s\n", &a);
  66.     End(RETURN_FAIL);
  67.   }
  68.     
  69.   WriteXpkFib(xfib);
  70.  
  71.   End(RETURN_OK);
  72. }
  73.  
  74. void end(void)
  75. {
  76.   if(fh)    Close(fh);
  77.   if(xfib)    FreeMem(xfib, sizeof(struct XpkFib));
  78.   if(buf)    FreeMem(buf, fib->fib_Size);
  79.   if(XpkBase)    CloseLibrary(XpkBase);
  80.   if(fib)    FreeDosObject(DOS_FIB, fib);
  81.   if(rda)    FreeArgs(rda);
  82. }
  83.  
  84.