home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / examples / xpkmanx.c < prev    next >
C/C++ Source or Header  |  1996-10-19  |  2KB  |  89 lines

  1. /* XPK - General XPK file-to-file packer/unpacker */
  2. /* This is the version to be compiled with Manx C */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <libraries/dos.h>
  8. #include <xpk/xpk.h>
  9.  
  10. long chunkfunc (struct XpkProgress *prog);
  11. #pragma regcall(chunkfunc(a1))
  12.  
  13. struct Library *XpkBase, *OpenLibrary (UBYTE * libName, ULONG version);
  14.  
  15. char errbuf[XPKERRMSGSIZE + 1];    /* +1 to make room for '\n'        */
  16.  
  17. long 
  18. chunkfunc (struct XpkProgress *prog)
  19. {
  20.   long abort = (long) SetSignal (0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  21.  
  22.   printf ("\r%4s: %-9s %-12s (%6d bytes, %3d%% done, %2d%% CF, %6d cps) ",
  23.       prog->PackerName, prog->Activity, prog->FileName,
  24.       prog->ULen, prog->Done, prog->CF, prog->Speed);
  25.   fflush (stdout);
  26.   if (prog->Type == XPKPROG_END)
  27.     printf ("\n");
  28.  
  29.   return abort;
  30. }
  31. struct Hook chunkhook =
  32. {
  33.   {0}, (void *) chunkfunc};
  34.  
  35.  
  36. struct TagItem tags[]=
  37. {
  38.   XPK_InName, (long) NULL,
  39.   XPK_OutName, (long) NULL,
  40.   XPK_GetError, (long) NULL,
  41.   XPK_ChunkHook, (long) NULL,
  42.   XPK_Ignore, (long) 0,
  43.   XPK_NoClobber, (long) TRUE,
  44.   TAG_DONE};
  45.  
  46.  
  47. void 
  48. end (char *text)
  49. {
  50.   if (text)
  51.     Write (Output (), text, strlen (text));
  52.   if (XpkBase)
  53.     CloseLibrary (XpkBase);
  54.   exit (text ? 10 : 0);
  55. }
  56.  
  57. extern int Enable_Abort;
  58.  
  59. void 
  60. main (int argc, char *argv[])
  61. {
  62.   int res;
  63.  
  64.   Enable_Abort = 0;
  65.  
  66.   if (!(XpkBase = OpenLibrary ((STRPTR) XPKNAME, 0)))
  67.     end ("Cannot open " XPKNAME "\n");
  68.  
  69.   if ((argc < 3) || (argc > 4))
  70.     end ("Usage: XPK [<method>] <infile> <outfile>\n");
  71.  
  72.   tags[0].ti_Data = (long) argv[argc - 2];    /* First try to decompress... */
  73.   tags[1].ti_Data = (long) argv[argc - 1];
  74.   tags[2].ti_Data = (long) errbuf;
  75.   tags[3].ti_Data = (long) &chunkhook;
  76.  
  77.   if (argc == 3)
  78.     res = XpkUnpack (tags);
  79.   else {
  80.     tags[4].ti_Tag = XPK_FindMethod;
  81.     tags[4].ti_Data = (long) argv[1];
  82.     res = XpkPack (tags);
  83.   }
  84.   if (res)
  85.     end (strcat (errbuf, "\n"));
  86.  
  87.   end (NULL);
  88. }
  89.