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

  1. #define NAME        "testNILPack"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "0"
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        testNILPack
  8.     Author:        SDI
  9.     Distribution:    Freeware
  10.     Description:    tests Xpk with NIL argument function
  11.     Compileropts:    -
  12.     Linkeropts:    -l xpkmaster amiga
  13.  
  14.  1.0   01.04.97 : first version
  15. */
  16.  
  17. #include <proto/dos.h>
  18. #include <proto/xpkmaster.h>
  19. #include <proto/exec.h>
  20. #include "SDI_defines.h"
  21.  
  22. #ifdef __MAXON__
  23.   #define __asm
  24.   #define __saveds
  25. #endif
  26.  
  27. struct Library *XpkBase;
  28.  
  29. LONG __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  30. {
  31.   switch(prog->xp_Type)
  32.   {
  33.   case XPKPROG_START: PutStr("Start: "); break;
  34.   case XPKPROG_MID: PutStr("\rMid  : "); break;
  35.   case XPKPROG_END: PutStr("\rEnd  : "); break;
  36.   }
  37.  
  38.   if(prog->xp_Type != XPKPROG_END)
  39.     Printf("%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s",
  40.       prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
  41.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  42.   else
  43.     Printf("%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
  44.       prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
  45.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  46.  
  47.   Flush(Output());
  48.   return (LONG) SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  49. }
  50.  
  51. struct Hook chunkhook = { {0}, (ULONG (*)()) chunkfunc};
  52.  
  53. void main(int argc, char **argv)
  54. {
  55.   STRPTR obuf = 0;
  56.   ULONG fh, err, obuflen = 0, olen = 0;
  57.  
  58.   if(argc != 2)
  59.   {
  60.     VPrintf("Filename needed\n", 0);
  61.     exit(0);
  62.   }
  63.  
  64.   if(!(XpkBase = OpenLibrary("xpkmaster.library", 4)))
  65.     exit(10);
  66.  
  67.   if(!(fh = Open("NIL:", MODE_NEWFILE)))
  68.   {
  69.     VPrintf("Could not open fh\n", 0);
  70.     CloseLibrary(XpkBase);
  71.     exit(10);
  72.   }
  73.  
  74.   VPrintf("Testing FH Pack access\n", 0);
  75.  
  76.   if((err = XpkPackTags(
  77.     XPK_InName,    argv[1],
  78.     XPK_OutFH,    fh,
  79.     XPK_ChunkHook,    &chunkhook,
  80.     XPK_PackMethod,    "NUKE",
  81.     TAG_DONE)))
  82.     XpkPrintFault(err, "FH Pack try");
  83.  
  84.   VPrintf("Testing Name Pack access\n", 0);
  85.  
  86.   if((err = XpkPackTags(
  87.     XPK_InName,    argv[1],
  88.     XPK_OutName,    "NIL:",
  89.     XPK_ChunkHook,    &chunkhook,
  90.     XPK_PackMethod,    "NUKE",
  91.     TAG_DONE)))
  92.     XpkPrintFault(err, "Name Pack try");
  93.  
  94.   VPrintf("Producing packed file\n", 0);
  95.  
  96.   if((err = XpkPackTags(
  97.     XPK_InName,        argv[1],
  98.     XPK_PackMethod,        "NUKE",
  99.     XPK_GetOutBuf,        &obuf,
  100.     XPK_GetOutBufLen,     &obuflen,
  101.     XPK_GetOutLen,         &olen,
  102.     XPK_ChunkHook,        &chunkhook,
  103.     TAG_DONE)))
  104.     XpkPrintFault(err, "Normal Pack try");
  105.  
  106.   VPrintf("Testing FH Unpack access\n", 0);
  107.  
  108.   if((err = XpkUnpackTags(
  109.     XPK_InBuf,    obuf,
  110.     XPK_InLen,    olen,
  111.     XPK_OutFH,    fh,
  112.     XPK_ChunkHook,    &chunkhook,
  113.     TAG_DONE)))
  114.     XpkPrintFault(err, "FH Unpack try");
  115.  
  116.   VPrintf("Testing direct Unpack access\n", 0);
  117.  
  118.   if((err = XpkUnpackTags(
  119.     XPK_InBuf,    obuf,
  120.     XPK_InLen,    olen,
  121.     XPK_OutName,    "NIL:",
  122.     XPK_ChunkHook,    &chunkhook,
  123.     TAG_DONE)))
  124.     XpkPrintFault(err, "Name Unpack try");
  125.  
  126.   if(obuf)
  127.     FreeMem(obuf, obuflen);
  128.  
  129.   if(!Close(fh))
  130.     VPrintf("Could not close fh\n", 0);
  131.   CloseLibrary(XpkBase);
  132. }
  133.  
  134.