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

  1. #include <proto/exec.h>
  2. #include <exec/memory.h>
  3. #include <proto/dos.h>
  4. #include <proto/xpk.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "printXpkFib.c"
  9.  
  10. struct Library *XpkBase = NULL;
  11.  
  12. char errbuf[XPKERRMSGSIZE + 1], *buf = NULL;
  13. long bufsize;
  14. BPTR fh = 0;
  15.  
  16. void 
  17. end (char *text)
  18. {
  19.   if (fh)
  20.     Close (fh);
  21.   if (buf)
  22.     FreeMem (buf, bufsize);
  23.   if (text)
  24.     printf ("%s %s\n", text, errbuf);
  25.   if (XpkBase)
  26.     CloseLibrary (XpkBase);
  27.   exit (text ? 10 : 0);
  28. }
  29.  
  30. void 
  31. main (int argc, char *argv[])
  32. {
  33.   struct XpkFib xfib;
  34.   struct FileInfoBlock fib;
  35.   ULONG ulen;
  36.  
  37.   errbuf[0] = 0;
  38.  
  39.   if (!(XpkBase = OpenLibrary (XPKNAME, 0)))
  40.     end ("Cannot open " XPKNAME "\n");
  41.  
  42.   if (argc != 2)
  43.     end ("Usage: testMemExamine filename\n");
  44.  
  45.   if (XpkExamineTags( &xfib,
  46.               XPK_InName, argv[1],
  47.                       XPK_GetError, errbuf,
  48.               TAG_DONE
  49.             ))
  50.     end ("Can't XpkExamine;");
  51.  
  52.   printXpkFib(&xfib);
  53.  
  54.   errbuf[0] = 0;
  55.  
  56.   if (!(fh = Open (argv[1], MODE_OLDFILE)))
  57.     end ("Cannot open input file");
  58.  
  59.   if (!(ExamineFH (fh, &fib)))
  60.     end ("Failed to ExamineFH input file");
  61.  
  62.   bufsize = fib.fib_Size;
  63.  
  64.   if (!(buf = AllocMem (bufsize, MEMF_ANY)))
  65.     end ("Out of memory!");
  66.  
  67.   ulen = Read (fh, buf, bufsize);
  68.  
  69.   if (ulen != bufsize)
  70.     end ("Could not read whole file with one Read()");
  71.  
  72.   Close (fh);
  73.   fh = 0;
  74.  
  75.   if (XpkExamineTags( &xfib,
  76.               XPK_InBuf, buf,
  77.               XPK_InLen, bufsize,
  78.                       XPK_GetError, errbuf,
  79.               TAG_DONE
  80.             ))
  81.     end ("Can't XpkExamine:");
  82.     
  83.   printXpkFib(&xfib);
  84.  
  85.   end (NULL);
  86. }
  87.