home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Cruncher / XPK416SR.LHA / xpk_Source / test / testFileUnpack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-06  |  1.9 KB  |  87 lines

  1. #define NAME        "testFileUnpack"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "0"
  4. #define ENDCODE_NOCTRLC
  5.  
  6. /* Programmheader
  7.  
  8.     Name:        testFileUnpack
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    easy file to file unpacker
  12.     Compileropts:    -
  13.     Linkeropts:    -l xpkmaster amiga
  14.  
  15.  1.0   24.03.97 : first version
  16. */
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <proto/xpkmaster.h>
  21. #include "SDI_defines.h"
  22.  
  23. #ifdef __MAXON__
  24.   #define __asm
  25.   #define __saveds
  26. #endif
  27.  
  28. struct Library        *XpkBase        = 0;
  29. ULONG            DosVersion        = 37;
  30. struct RDArgs        *rda            = 0;
  31.  
  32. #define PARAM "FROM/A,TO/A"
  33.  
  34. LONG __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  35. {
  36.   switch(prog->xp_Type)
  37.   {
  38.   case XPKPROG_START: PutStr("Start: "); break;
  39.   case XPKPROG_MID: PutStr("\rMid  : "); break;
  40.   case XPKPROG_END: PutStr("\rEnd  : "); break;
  41.   }
  42.  
  43.   if(prog->xp_Type != XPKPROG_END)
  44.     Printf("%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s",
  45.       prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
  46.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  47.   else
  48.     Printf("%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
  49.       prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
  50.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  51.  
  52.   Flush(Output());
  53.   return (LONG) SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  54. }
  55.  
  56. struct Hook chunkhook = { {0}, (ULONG (*)()) chunkfunc};
  57.  
  58. void main(void)
  59. {
  60.   UBYTE errbuf[XPKERRMSGSIZE+1];
  61.   struct {
  62.     STRPTR from;
  63.     STRPTR to;
  64.   } args = {0,0};
  65.  
  66.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
  67.   !(XpkBase = OpenLibrary(XPKNAME, 3)))
  68.     End(RETURN_FAIL);
  69.  
  70.   if(XpkUnpackTags(XPK_InName, args.from, XPK_OutName, args.to,
  71.   XPK_GetError, errbuf, XPK_ChunkHook, &chunkhook, TAG_DONE))
  72.   {
  73.     STRPTR a = errbuf;
  74.     VPrintf("Can't XpkUnpack: %s\n", &a);
  75.     End(RETURN_FAIL);
  76.   }
  77.  
  78.   End(RETURN_OK);
  79. }
  80.  
  81. void end(void)
  82. {
  83.   if(XpkBase)    CloseLibrary(XpkBase);
  84.   if(rda)    FreeArgs(rda);
  85. }
  86.  
  87.