home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 10 / Sonderheft_12.iso / best-of-tools / packer / xpk3.11 / xpk_source / examples / xpkdice.c < prev    next >
C/C++ Source or Header  |  1996-11-26  |  2KB  |  78 lines

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