Blame patches/bzip2/bzip2-1.0.2-progress.patch

Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
Ripped from Mandrake.
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
http://bugs.gentoo.org/show_bug.cgi?id=82192
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
--- bzip2-1.0.2.org/bzip2.1
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+++ bzip2-1.0.2/bzip2.1
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -235,6 +235,10 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 Suppress non-essential warning messages.  Messages pertaining to
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 I/O errors and other critical events will not be suppressed.
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 .TP
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+.B \-p --show-progress
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+Show percentage of input-file done and while compressing show the percentage
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+of the original file the new file is.
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+.TP
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 .B \-v --verbose
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 Verbose mode -- show the compression ratio for each file processed.
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 Further \-v's increase the verbosity level, spewing out lots of
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
--- bzip2-1.0.2.org/bzip2.c
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+++ bzip2-1.0.2/bzip2.c
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -145,6 +145,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 #include <signal.h>
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 #include <math.h>
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 #include <errno.h>
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+#include <time.h>
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 #include <ctype.h>
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 #include "bzlib.h"
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -301,6 +302,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 Char    progNameReally[FILE_NAME_LEN];
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 FILE    *outputHandleJustInCase;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 Int32   workFactor;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+Char	showProgress;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 static void    panic                 ( Char* )   NORETURN;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 static void    ioError               ( void )    NORETURN;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -425,6 +427,12 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    UInt32  nbytes_in_lo32, nbytes_in_hi32;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    UInt32  nbytes_out_lo32, nbytes_out_hi32;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    Int32   bzerr, bzerr_dummy, ret;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   double  fileSize = 0; /* initialized to make the compiler stop crying */
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+                         /* double because big files might otherwhise give
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+                          * overflows. not long long since not all compilers
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+                          * support that one
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+                          */
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   time_t  startTime, currentTime;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    SET_BINARY_MODE(stream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    SET_BINARY_MODE(zStream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -432,12 +440,21 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (ferror(stream)) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (ferror(zStream)) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      (void)fseek(stream, 0, SEEK_END);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      fileSize = (double)ftell(stream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      rewind(stream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      if (verbosity >= 1)
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    bzf = BZ2_bzWriteOpen ( &bzerr, zStream, 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                            blockSize100k, verbosity, workFactor );   
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (bzerr != BZ_OK) goto errhandler;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (verbosity >= 2) fprintf ( stderr, "\n" );
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   time(&startTime);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    while (True) {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (myfeof(stream)) break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -446,13 +463,32 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (bzerr != BZ_OK) goto errhandler;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True)
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         time(&currentTime);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         if ((currentTime - startTime) > 1) { /* show progress every 2 seconds */
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            double curInPos = (double)ftell(stream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            double curOutPos = (double)ftell(zStream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            startTime = currentTime;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            fprintf(stderr, "%.2f%% done", (curInPos * 100.0) / fileSize);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            if (srcMode == SM_F2F)
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+               fprintf(stderr, ", new size: %.2f%%", (curOutPos * 100.0) / curInPos);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            fprintf(stderr, "    \r");
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    BZ2_bzWriteClose64 ( &bzerr, bzf, 0, 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                         &nbytes_in_lo32, &nbytes_in_hi32,
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                         &nbytes_out_lo32, &nbytes_out_hi32 );
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (bzerr != BZ_OK) goto errhandler;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
-
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (ferror(zStream)) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    ret = fflush ( zStream );
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (ret == EOF) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -526,6 +562,8 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    UChar   unused[BZ_MAX_UNUSED];
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    Int32   nUnused;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    UChar*  unusedTmp;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   double  fileSize = 0; /* initialized to make the compiler stop crying */
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   time_t  startTime, currentTime;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    nUnused = 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    streamNo = 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -533,9 +571,19 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    SET_BINARY_MODE(stream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    SET_BINARY_MODE(zStream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      long dummy = ftell(zStream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      (void)fseek(zStream, 0, SEEK_END);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      fileSize = (double)ftell(zStream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      (void)fseek(zStream, dummy, SEEK_SET);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      if (verbosity >= 1)
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (ferror(stream)) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    if (ferror(zStream)) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   time(&startTime);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    while (True) {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       bzf = BZ2_bzReadOpen ( 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -551,6 +599,17 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
          if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
             fwrite ( obuf, sizeof(UChar), nread, stream );
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
          if (ferror(stream)) goto errhandler_io;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            time(&currentTime);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            if ((currentTime - startTime) >= 2)
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            {
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+               double curInPos = (double)ftell(zStream);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+               startTime = currentTime;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+               fprintf(stderr, "%.2f%% done\r", (curInPos * 100.0) / fileSize);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+            }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+         }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       }
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (bzerr != BZ_STREAM_END) goto errhandler;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -1872,6 +1931,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    deleteOutputOnInterrupt = False;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    exitValue               = 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    i = j = 0; /* avoid bogus warning from egcs-1.1.X */
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+   showProgress            = False;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
 
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    /*-- Set up signal handlers for mem access errors --*/
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
    signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -1949,6 +2009,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                case 'k': keepInputFiles   = True; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                case 's': smallMode        = True; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                case 'q': noisy            = False; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+               case 'p': showProgress     = True; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                case '1': blockSize100k    = 1; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                case '2': blockSize100k    = 2; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
                case '3': blockSize100k    = 3; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
@@ -1985,6 +2046,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (ISFLAG("--keep"))              keepInputFiles   = True;    else
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (ISFLAG("--small"))             smallMode        = True;    else
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (ISFLAG("--quiet"))             noisy            = False;   else
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
+      if (ISFLAG("--show-progress"))     showProgress     = True;    else
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (ISFLAG("--version"))           license();                  else
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (ISFLAG("--license"))           license();                  else
Lucio Andrés Illanes Albornoz (arab, vxp) 854ef8
       if (ISFLAG("--exponential"))       workFactor = 1;             else