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

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