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

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