home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / examples / xpkdice.c < prev    next >
C/C++ Source or Header  |  1996-10-19  |  2KB  |  73 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 <libraries/dos.h>
  9. #include <xpk/xpk.h>
  10.  
  11. extern hookstub();
  12.  
  13. struct Library *XpkBase, *OpenLibrary( UBYTE *libName, ULONG version );
  14. char errbuf[XPKERRMSGSIZE + 1];      /* +1 to make room for '\n'        */
  15.  
  16. __stkargs long chunkfunc(struct Hook *myhook, struct XpkProgress *prog)
  17. {
  18.     printf("\r%4s: %-9s %-12s (%6d bytes, %3d%% done, %2d%% CF, %6d cps) ",
  19.         prog->PackerName,  prog->Activity,  prog->FileName,
  20.         prog->ULen,        prog->Done,      prog->CF,       prog->Speed);
  21.     fflush(stdout);
  22.     if( prog->Type==XPKPROG_END ) printf("\n");
  23.  
  24.     return (long)SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  25. }
  26. struct Hook chunkhook = {{0},(void*)hookstub,(void*)chunkfunc};
  27.  
  28.  
  29. struct TagItem tags[] = {
  30.     XPK_InName,    (long)NULL ,
  31.     XPK_OutName,   (long)NULL ,
  32.     XPK_GetError,  (long)NULL,
  33.     XPK_ChunkHook, (long)NULL,
  34.     XPK_Ignore,    (long)0    ,
  35.     XPK_NoClobber, (long)TRUE ,
  36.     TAG_DONE};
  37.  
  38.  
  39. void end( char *text )
  40. {
  41.     if( text ) Write(Output(), text, strlen(text));
  42.     if( XpkBase ) CloseLibrary( XpkBase );
  43.     exit(text ? 10 : 0);
  44. }
  45.  
  46. void main(int argc, char *argv[])
  47. {
  48.     int res;
  49.  
  50.     if(!(XpkBase=OpenLibrary( XPKNAME,0)))
  51.         end("Cannot open "XPKNAME"\n");
  52.     
  53.     if((argc < 3) || (argc > 4))
  54.         end("Usage: XPK [<method>] <infile> <outfile>\n");
  55.     
  56.     tags[0].ti_Data = (long)argv[argc-2]; /* First try to decompress... */
  57.     tags[1].ti_Data = (long)argv[argc-1];
  58.     tags[2].ti_Data = (long)errbuf;
  59.     tags[3].ti_Data = (long)&chunkhook;
  60.  
  61.     if( argc==3 )
  62.         res=XpkUnpack( tags );
  63.     else {
  64.         tags[4].ti_Tag = XPK_FindMethod;
  65.         tags[4].ti_Data= (long)argv[1];
  66.         res=XpkPack(tags);
  67.     }
  68.     if( res )
  69.         end(strcat(errbuf,"\n"));
  70.     
  71.     end(NULL);
  72. }
  73.