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

  1. #define NAME     "testMemunpack"
  2. #define REVISION "1"
  3. #define ENDCODE_NOCTRLC
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        testMemUnpack
  8.     Author:        SDI
  9.     Distribution:    PD
  10.     Description:    tests Xpk Pack function
  11.     Compileropts:    -
  12.     Linkeropts:    -l xpkmaster amiga
  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. #ifdef __MAXON__
  25.   #define __asm
  26.   #define __saveds
  27. #endif
  28.  
  29. struct Library        *XpkBase        = 0;
  30. ULONG            DosVersion        = 37;
  31. STRPTR            ibuf            = 0,
  32.             obuf            = 0;
  33. ULONG            ibuflen            = 0,
  34.             obuflen            = 0;
  35. BPTR            fh            = 0;
  36. struct RDArgs        *rda            = 0;
  37. struct FileInfoBlock    *fib            = 0;
  38. struct XpkFib        *xfib            = 0;
  39.  
  40. #define PARAM "FROM/A,TO"
  41.  
  42. LONG __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  43. {
  44.   switch(prog->xp_Type)
  45.   {
  46.   case XPKPROG_START: PutStr("Start: "); break;
  47.   case XPKPROG_MID: PutStr("\rMid  : "); break;
  48.   case XPKPROG_END: PutStr("\rEnd  : "); break;
  49.   }
  50.  
  51.   if(prog->xp_Type != XPKPROG_END)
  52.     Printf("%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s",
  53.       prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
  54.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  55.   else
  56.     Printf("%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
  57.       prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
  58.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  59.  
  60.   Flush(Output());
  61.   return (LONG) SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  62. }
  63.  
  64. struct Hook chunkhook = { {0}, (ULONG (*)()) chunkfunc};
  65.  
  66. void main(void)
  67. {
  68.   UBYTE errbuf[XPKERRMSGSIZE+1];
  69.   ULONG olen;
  70.   struct {
  71.     STRPTR from;
  72.     STRPTR to;
  73.   } args = {0,0};
  74.  
  75.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
  76.   !(xfib = (struct XpkFib *) AllocMem(sizeof(struct XpkFib), MEMF_ANY|MEMF_CLEAR)) ||
  77.   !(XpkBase = OpenLibrary(XPKNAME, 0)) ||
  78.   !(fh = Open(args.from, MODE_OLDFILE)) ||
  79.   !(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)) ||
  80.   !(ExamineFH(fh, fib)) ||
  81.   !(ibuf = (STRPTR) AllocMem(fib->fib_Size, MEMF_ANY)) ||
  82.   Read(fh, ibuf, fib->fib_Size) != fib->fib_Size)
  83.     End(RETURN_FAIL);
  84.  
  85.   ibuflen = fib->fib_Size;
  86.   Close(fh); fh = 0;
  87.  
  88.   if(XpkExamineTags(xfib, XPK_InBuf, ibuf, XPK_InLen, ibuflen,
  89.     XPK_GetError, errbuf, TAG_DONE))
  90.   {
  91.     STRPTR a = errbuf;
  92.     VPrintf("Can't XpkExamine: %s\n", &a);
  93.     End(RETURN_FAIL);
  94.   }
  95.  
  96.   if(XpkUnpackTags(XPK_InBuf, ibuf, XPK_InLen, ibuflen,
  97.     XPK_GetOutBuf, &obuf, XPK_GetOutBufLen, &obuflen,
  98.     XPK_GetOutLen, &olen, XPK_GetError, errbuf,
  99.     XPK_PassThru, 1, XPK_ChunkHook, &chunkhook, TAG_DONE))
  100.   {
  101.     STRPTR a = errbuf;
  102.     VPrintf("Can't XpkUnpack: %s\n", &a);
  103.     End(RETURN_FAIL);
  104.   }
  105.  
  106.   if(args.to)
  107.     if(!(fh = Open(args.to, MODE_NEWFILE)) ||
  108.     Write(fh, obuf, olen) != olen)
  109.       End(RETURN_FAIL);
  110.  
  111.   End(RETURN_OK);
  112. }
  113.  
  114. void end(void)
  115. {
  116.   if(fh)    Close(fh);
  117.   if(xfib)    FreeMem(xfib, sizeof(struct XpkFib));
  118.   if(XpkBase)    CloseLibrary(XpkBase);
  119.   if(fib)    FreeDosObject(DOS_FIB, fib);
  120.   if(rda)    FreeArgs(rda);
  121.   if(ibuf)    FreeMem(ibuf, ibuflen);
  122.   if(obuf)    FreeMem(obuf, obuflen);
  123. }
  124.  
  125.