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

  1.  
  2. /* xType - Unpack file to stdout */
  3. #include <proto/exec.h>
  4. #include <proto/dos.h>
  5. #include <proto/xpk.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. static char ver[]= "$VER: xType 1.0 (" __DATE__ ")\r\n";
  10.  
  11. struct Library *XpkBase;
  12. UBYTE errbuf[XPKERRMSGSIZE + 1], *outbuf;
  13. long outbuflen;
  14.  
  15. void 
  16. end (char *text)
  17. {
  18.   if (text)
  19.     Write (Output (), text, strlen (text));
  20.   if (XpkBase)
  21.     CloseLibrary (XpkBase);
  22.   exit (text ? 10 : 0);
  23. }
  24.  
  25. void 
  26. main (int argc, char *argv[])
  27. {
  28.   XFH *xfh;
  29.   UBYTE *ptr, *last, *eol;
  30.   int i, len;
  31.  
  32.   if (!(XpkBase = OpenLibrary (XPKNAME, 0)))
  33.     end ("Cannot open " XPKNAME "\n");
  34.  
  35.   if (argc < 2 || !strcmp (argv[1], "?"))
  36.     end ("Usage: xType filename\n");
  37.  
  38.   for (i = 1; i < argc; i++) {
  39.  
  40.     if (XpkOpenTags (&xfh, XPK_InName, argv[i], XPK_PassThru, TRUE, TAG_DONE))
  41.       end (strcat (errbuf, "\n"));
  42.  
  43.     if (!(outbuf = (UBYTE *) AllocMem (outbuflen = xfh->NLen + XPK_MARGIN, 0)))
  44.       end ("Out of memory\n");
  45.  
  46.     while ((len = XpkRead (xfh, outbuf, XPKLEN_ONECHUNK)) > 0) {
  47.  
  48.       ptr = (UBYTE *) outbuf;
  49.       last = ptr + len;
  50.       *last = '\n';
  51.  
  52.       do {
  53.     if (SetSignal (0L, 0L) & SIGBREAKF_CTRL_C) {
  54.       XpkClose (xfh);
  55.       end ("***Break\n");
  56.     }
  57.  
  58.     if (!(eol = strchr (ptr, '\n')))
  59.       eol = last - 1;
  60.     Write (Output (), ptr, 1 + eol - ptr);
  61.     ptr = eol + 1;
  62.       } while (ptr < last);
  63.     }
  64.  
  65.     if (XpkClose (xfh) || len)
  66.       end (strcat (errbuf, "\n"));
  67.  
  68.     FreeMem (outbuf, outbuflen);
  69.     outbuf = NULL;
  70.   }
  71.  
  72.   end (NULL);
  73. }
  74.