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

  1. #ifndef XPKMASTER_FIB_C
  2. #define XPKMASTER_FIB_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        fib.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: fib.c 1.0 (05.10.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    FIB related routines
  12.  
  13.  1.0   05.10.96 : first real version
  14. */
  15.  
  16. #include <pragma/exec_lib.h>
  17. #include <pragma/dos_lib.h>
  18. #include <exec/types.h>
  19. #include "xpkmaster.h"
  20.  
  21. void updatefib(struct XpkBuffer *xbuf)
  22. {
  23.   struct XpkStreamHeader *globhdr = &xbuf->xb_Headers.h_Glob;
  24.   XpkChunkHeader *lochdr = &xbuf->xb_Headers.h_Loc;
  25.   struct XpkFib *fib = &xbuf->xb_Fib;
  26.   LONG ulen, clen;
  27.  
  28. #ifdef DEBUG
  29.   DebugRunTime("updatefib:start, %ld, %ld, %ld, %ld, %ld, %ld",
  30.   fib->xf_CLen, fib->xf_ULen, fib->xf_NLen, fib->xf_CCur, fib->xf_UCur);
  31. #endif
  32.  
  33.   if(xbuf->xb_Headers.h_Glob.xsh_Flags & XPKSTREAMF_LONGHEADERS)
  34.   {
  35.     ulen = lochdr->xch_Long.xchl_ULen;
  36.     clen = lochdr->xch_Long.xchl_CLen;
  37.   }
  38.   else
  39.   {
  40.     ulen = lochdr->xch_Word.xchw_ULen;
  41.     clen = lochdr->xch_Word.xchw_CLen;
  42.   }
  43.  
  44.   fib->xf_Type = XPKTYPE_PACKED;
  45.   fib->xf_CLen = globhdr->xsh_CLen + 8;
  46.   fib->xf_ULen = globhdr->xsh_ULen;
  47.   fib->xf_NLen = ulen + XPK_MARGIN;
  48.   fib->xf_CCur += ROUNDLONG (clen) + xbuf->xb_Headers.h_LocSize;
  49.   fib->xf_UCur += ulen;
  50.   fib->xf_ID = globhdr->xsh_Type;
  51.   fib->xf_SubVersion = globhdr->xsh_SubVrs;
  52.   fib->xf_MasVersion = globhdr->xsh_MasVrs;
  53.   CopyMem(globhdr->xsh_Initial, fib->xf_Head, 16);
  54.  
  55. #ifdef DEBUG
  56.   DebugRunTime("updatefib:end, %ld, %ld, %ld, %ld, %ld, %ld",
  57.   fib->xf_CLen, fib->xf_ULen, fib->xf_NLen, fib->xf_CCur, fib->xf_UCur);
  58. #endif
  59.  
  60.   percentages(fib);
  61. }
  62. /*
  63. void storefib (struct XpkBuffer *xbuf)
  64. {
  65.   struct Headers globloc;
  66.   UBYTE comment[80];
  67.   STRPTR in = (STRPTR) &globloc, out = comment;
  68.  
  69.   if (!xbuf->xb_OutName || !(xbuf->xb_Flags & XMF_USECOMMENT))
  70.     return;
  71.  
  72.   CopyMem(&xbuf->xb_Headers, &globloc, sizeof(struct Headers));
  73.   globloc.h_LocSize = 0;
  74.  
  75.   *(out++) = 'X'; *(out++) = 'P'; *(out++) = 'K'; *(out++) = 'F';
  76.  
  77.   for(; in < (STRPTR) &globloc + sizeof(struct Headers) - 4; in += 3)
  78.   {
  79.     *out++ = 64 | (in[0] & 3) << 4 | (in[1] & 3) << 2 | in[0] & 3;
  80.     *out++ = 64 | in[0] >> 2;
  81.     *out++ = 64 | in[1] >> 2;
  82.     *out++ = 64 | in[2] >> 2;
  83.   }
  84.   *out = 0;
  85.  
  86.   SetComment(xbuf->xb_OutName, comment);
  87. }
  88. */
  89. void percentages (struct XpkFib *fib)
  90. {
  91.   fib->xf_Ratio = 0;
  92.   if(fib->xf_ULen)
  93.     fib->xf_Ratio = 100 - 100 * fib->xf_CLen / fib->xf_ULen;
  94.   if(fib->xf_Ratio < 0)
  95.     fib->xf_Ratio = 0;
  96.   *(LONG *) fib->xf_Packer = fib->xf_ID;
  97.   fib->xf_Packer[4] = 0;
  98. }
  99.  
  100. #endif /* XPKMASTER_FIB_C */
  101.