remove whitespace from end of lines
[reactos.git] / reactos / drivers / lib / bzip2 / compress.c
index cc5e31d..0391e61 100644 (file)
   1. Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
 
-  2. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
+  2. The origin of this software must not be misrepresented; you must
+     not claim that you wrote the original software.  If you use this
+     software in a product, an acknowledgment in the product
      documentation would be appreciated but is not required.
 
   3. Altered source versions must be plainly marked as such, and must
      not be misrepresented as being the original software.
 
-  4. The name of the author may not be used to endorse or promote 
-     products derived from this software without specific prior written 
+  4. The name of the author may not be used to endorse or promote
+     products derived from this software without specific prior written
      permission.
 
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
@@ -66,7 +66,7 @@
    0.9.0a/b -- no changes in this file.
 
    0.9.0c
-      * changed setting of nGroups in sendMTFValues() so as to 
+      * changed setting of nGroups in sendMTFValues() so as to
         do a bit better on small files
 --*/
 
@@ -169,11 +169,11 @@ void generateMTFValues ( EState* s )
    Int32   wr;
    Int32   EOB;
 
-   /* 
+   /*
       After sorting (eg, here),
          s->arr1 [ 0 .. s->nblock-1 ] holds sorted order,
          and
-         ((UChar*)s->arr2) [ 0 .. s->nblock-1 ] 
+         ((UChar*)s->arr2) [ 0 .. s->nblock-1 ]
          holds the original block data.
 
       The first thing to do is generate the MTF values,
@@ -188,7 +188,7 @@ void generateMTFValues ( EState* s )
          (UChar*) (&((UChar*)s->arr2)[s->nblock])
 
       These storage aliases are set up in bzCompressInit(),
-      except for the last one, which is arranged in 
+      except for the last one, which is arranged in
       compressBlock().
    */
    UInt32* ptr   = s->ptr;
@@ -211,7 +211,7 @@ void generateMTFValues ( EState* s )
       ll_i = s->unseqToSeq[block[j]];
       AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );
 
-      if (yy[0] == ll_i) { 
+      if (yy[0] == ll_i) {
          zPend++;
       } else {
 
@@ -219,11 +219,11 @@ void generateMTFValues ( EState* s )
             zPend--;
             while (True) {
                if (zPend & 1) {
-                  mtfv[wr] = BZ_RUNB; wr++; 
-                  s->mtfFreq[BZ_RUNB]++; 
+                  mtfv[wr] = BZ_RUNB; wr++;
+                  s->mtfFreq[BZ_RUNB]++;
                } else {
-                  mtfv[wr] = BZ_RUNA; wr++; 
-                  s->mtfFreq[BZ_RUNA]++; 
+                  mtfv[wr] = BZ_RUNA; wr++;
+                  s->mtfFreq[BZ_RUNA]++;
                }
                if (zPend < 2) break;
                zPend = (zPend - 2) / 2;
@@ -257,11 +257,11 @@ void generateMTFValues ( EState* s )
       zPend--;
       while (True) {
          if (zPend & 1) {
-            mtfv[wr] = BZ_RUNB; wr++; 
-            s->mtfFreq[BZ_RUNB]++; 
+            mtfv[wr] = BZ_RUNB; wr++;
+            s->mtfFreq[BZ_RUNB]++;
          } else {
-            mtfv[wr] = BZ_RUNA; wr++; 
-            s->mtfFreq[BZ_RUNA]++; 
+            mtfv[wr] = BZ_RUNA; wr++;
+            s->mtfFreq[BZ_RUNA]++;
          }
          if (zPend < 2) break;
          zPend = (zPend - 2) / 2;
@@ -304,7 +304,7 @@ void sendMTFValues ( EState* s )
 
    if (s->verbosity >= 3)
       VPrintf3( "      %d in block, %d after MTF & 1-2 coding, "
-                "%d+2 syms in use\n", 
+                "%d+2 syms in use\n",
                 s->nblock, s->nMTF, s->nInUse );
 
    alphaSize = s->nInUse+2;
@@ -321,7 +321,7 @@ void sendMTFValues ( EState* s )
                        nGroups = 6;
 
    /*--- Generate an initial set of coding tables ---*/
-   { 
+   {
       Int32 nPart, remF, tFreq, aFreq;
 
       nPart = nGroups;
@@ -336,8 +336,8 @@ void sendMTFValues ( EState* s )
             aFreq += s->mtfFreq[ge];
          }
 
-         if (ge > gs 
-             && nPart != nGroups && nPart != 1 
+         if (ge > gs
+             && nPart != nGroups && nPart != 1
              && ((nGroups-nPart) % 2 == 1)) {
             aFreq -= s->mtfFreq[ge];
             ge--;
@@ -346,21 +346,21 @@ void sendMTFValues ( EState* s )
          if (s->verbosity >= 3)
             VPrintf5( "      initial group %d, [%d .. %d], "
                       "has %d syms (%4.1f%%)\n",
-                      nPart, gs, ge, aFreq, 
+                      nPart, gs, ge, aFreq,
                       (100.0 * (float)aFreq) / (float)(s->nMTF) );
+
          for (v = 0; v < alphaSize; v++)
-            if (v >= gs && v <= ge) 
+            if (v >= gs && v <= ge)
                s->len[nPart-1][v] = BZ_LESSER_ICOST; else
                s->len[nPart-1][v] = BZ_GREATER_ICOST;
+
          nPart--;
          gs = ge+1;
          remF -= aFreq;
       }
    }
 
-   /*--- 
+   /*---
       Iterate up to BZ_N_ITERS times to improve the tables.
    ---*/
    for (iter = 0; iter < BZ_N_ITERS; iter++) {
@@ -373,7 +373,7 @@ void sendMTFValues ( EState* s )
 
       /*---
         Set up an auxiliary length table which is used to fast-track
-       the common case (nGroups == 6). 
+       the common case (nGroups == 6).
       ---*/
       if (nGroups == 6) {
          for (v = 0; v < alphaSize; v++) {
@@ -390,10 +390,10 @@ void sendMTFValues ( EState* s )
 
          /*--- Set group start & end marks. --*/
          if (gs >= s->nMTF) break;
-         ge = gs + BZ_G_SIZE - 1; 
+         ge = gs + BZ_G_SIZE - 1;
          if (ge >= s->nMTF) ge = s->nMTF-1;
 
-         /*-- 
+         /*--
             Calculate the cost of this group as coded
             by each of the coding tables.
          --*/
@@ -430,13 +430,13 @@ void sendMTFValues ( EState* s )
 
          } else {
            /*--- slow version which correctly handles all situations ---*/
-            for (i = gs; i <= ge; i++) { 
+            for (i = gs; i <= ge; i++) {
                UInt16 icv = mtfv[i];
                for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
             }
          }
-         /*-- 
+
+         /*--
             Find the coding table which is best for this group,
             and record its identity in the selector table.
          --*/
@@ -448,7 +448,7 @@ void sendMTFValues ( EState* s )
          s->selector[nSelectors] = bt;
          nSelectors++;
 
-         /*-- 
+         /*--
             Increment the symbol frequencies for the selected table.
           --*/
          if (nGroups == 6 && 50 == ge-gs+1) {
@@ -478,7 +478,7 @@ void sendMTFValues ( EState* s )
          gs = ge+1;
       }
       if (s->verbosity >= 3) {
-         VPrintf2 ( "      pass %d: size is %d, grp uses are ", 
+         VPrintf2 ( "      pass %d: size is %d, grp uses are ",
                    iter+1, totc/8 );
          for (t = 0; t < nGroups; t++)
             VPrintf1 ( "%d ", fave[t] );
@@ -489,7 +489,7 @@ void sendMTFValues ( EState* s )
         Recompute the tables based on the accumulated frequencies.
       --*/
       for (t = 0; t < nGroups; t++)
-         BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]), 
+         BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
                                  alphaSize, 20 );
    }
 
@@ -529,19 +529,19 @@ void sendMTFValues ( EState* s )
       }
       AssertH ( !(maxLen > 20), 3004 );
       AssertH ( !(minLen < 1),  3005 );
-      BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]), 
+      BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
                           minLen, maxLen, alphaSize );
    }
 
    /*--- Transmit the mapping table. ---*/
-   { 
+   {
       Bool inUse16[16];
       for (i = 0; i < 16; i++) {
           inUse16[i] = False;
           for (j = 0; j < 16; j++)
              if (s->inUse[i * 16 + j]) inUse16[i] = True;
       }
-     
+
       nBytes = s->numZ;
       for (i = 0; i < 16; i++)
          if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
@@ -552,7 +552,7 @@ void sendMTFValues ( EState* s )
                if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
             }
 
-      if (s->verbosity >= 3) 
+      if (s->verbosity >= 3)
          VPrintf1( "      bytes: mapping %d, ", s->numZ-nBytes );
    }
 
@@ -560,7 +560,7 @@ void sendMTFValues ( EState* s )
    nBytes = s->numZ;
    bsW ( s, 3, nGroups );
    bsW ( s, 15, nSelectors );
-   for (i = 0; i < nSelectors; i++) { 
+   for (i = 0; i < nSelectors; i++) {
       for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
       bsW(s,1,0);
    }
@@ -589,14 +589,14 @@ void sendMTFValues ( EState* s )
    gs = 0;
    while (True) {
       if (gs >= s->nMTF) break;
-      ge = gs + BZ_G_SIZE - 1; 
+      ge = gs + BZ_G_SIZE - 1;
       if (ge >= s->nMTF) ge = s->nMTF-1;
       AssertH ( s->selector[selCtr] < nGroups, 3006 );
 
       if (nGroups == 6 && 50 == ge-gs+1) {
             /*--- fast track the common case ---*/
             UInt16 mtfv_i;
-            UChar* s_len_sel_selCtr 
+            UChar* s_len_sel_selCtr
                = &(s->len[s->selector[selCtr]][0]);
             Int32* s_code_sel_selCtr
                = &(s->code[s->selector[selCtr]][0]);
@@ -623,7 +623,7 @@ void sendMTFValues ( EState* s )
       } else {
         /*--- slow version which correctly handles all situations ---*/
          for (i = gs; i <= ge; i++) {
-            bsW ( s, 
+            bsW ( s,
                   s->len  [s->selector[selCtr]] [mtfv[i]],
                   s->code [s->selector[selCtr]] [mtfv[i]] );
          }
@@ -678,8 +678,8 @@ void BZ2_compressBlock ( EState* s, Bool is_last_block )
       /*-- Now the block's CRC, so it is in a known place. --*/
       bsPutUInt32 ( s, s->blockCRC );
 
-      /*-- 
-         Now a single bit indicating (non-)randomisation. 
+      /*--
+         Now a single bit indicating (non-)randomisation.
          As of version 0.9.5, we use a better sorting algorithm
          which makes randomisation unnecessary.  So always set
          the randomised bit to 'no'.  Of course, the decoder