]> git.pld-linux.org Git - packages/bzip2.git/blob - bzip2-progress-counter-1.0.2.patch
- rediffed
[packages/bzip2.git] / bzip2-progress-counter-1.0.2.patch
1 diff -uNr bzip2-1.0.2.org/bzip2.1 bzip2-1.0.2/bzip2.1
2 --- bzip2-1.0.2.org/doc/bzip2.1 Thu Jan  3 00:14:36 2002
3 +++ bzip2-1.0.2/doc/bzip2.1     Mon Jan 20 19:57:40 2003
4 @@ -235,6 +235,10 @@
5  Suppress non-essential warning messages.  Messages pertaining to
6  I/O errors and other critical events will not be suppressed.
7  .TP
8 +.B \-p --show-progress
9 +Show percentage of input-file done and while compressing show the percentage
10 +of the original file the new file is.
11 +.TP
12  .B \-v --verbose
13  Verbose mode -- show the compression ratio for each file processed.
14  Further \-v's increase the verbosity level, spewing out lots of
15 diff -uNr bzip2-1.0.2.org/bzip2.c bzip2-1.0.2/bzip2.c
16 --- bzip2-1.0.2.org/bzip2.c     Fri Jan 25 02:38:36 2002
17 +++ bzip2-1.0.2/bzip2.c Mon Jan 20 19:55:29 2003
18 @@ -145,6 +145,7 @@
19  #include <signal.h>
20  #include <math.h>
21  #include <errno.h>
22 +#include <time.h>
23  #include <ctype.h>
24  #include "bzlib.h"
25  
26 @@ -301,6 +302,7 @@
27  Char    progNameReally[FILE_NAME_LEN];
28  FILE    *outputHandleJustInCase;
29  Int32   workFactor;
30 +Char   showProgress;
31  
32  static void    panic                 ( Char* )   NORETURN;
33  static void    ioError               ( void )    NORETURN;
34 @@ -425,6 +427,12 @@
35     UInt32  nbytes_in_lo32, nbytes_in_hi32;
36     UInt32  nbytes_out_lo32, nbytes_out_hi32;
37     Int32   bzerr, bzerr_dummy, ret;
38 +   double  fileSize = 0; /* initialized to make the compiler stop crying */
39 +                         /* double because big files might otherwhise give
40 +                          * overflows. not long long since not all compilers
41 +                          * support that one
42 +                          */
43 +   time_t  startTime, currentTime;
44  
45     SET_BINARY_MODE(stream);
46     SET_BINARY_MODE(zStream);
47 @@ -432,12 +440,21 @@
48     if (ferror(stream)) goto errhandler_io;
49     if (ferror(zStream)) goto errhandler_io;
50  
51 +   if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
52 +      (void)fseek(stream, 0, SEEK_END);
53 +      fileSize = (double)ftell(stream);
54 +      rewind(stream);
55 +      if (verbosity >= 1)
56 +         fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
57 +   }
58 +
59     bzf = BZ2_bzWriteOpen ( &bzerr, zStream, 
60                             blockSize100k, verbosity, workFactor );   
61     if (bzerr != BZ_OK) goto errhandler;
62  
63     if (verbosity >= 2) fprintf ( stderr, "\n" );
64  
65 +   time(&startTime);
66     while (True) {
67  
68        if (myfeof(stream)) break;
69 @@ -446,13 +463,32 @@
70        if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
71        if (bzerr != BZ_OK) goto errhandler;
72  
73 +      if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True)
74 +      {
75 +         time(&currentTime);
76 +
77 +         if ((currentTime - startTime) > 1) { /* show progress every 2 seconds */
78 +            double curInPos = (double)ftell(stream);
79 +            double curOutPos = (double)ftell(zStream);
80 +
81 +            startTime = currentTime;
82 +
83 +            fprintf(stderr, "%.2f%% done", (curInPos * 100.0) / fileSize);
84 +            if (srcMode == SM_F2F)
85 +            {
86 +               fprintf(stderr, ", new size: %.2f%%", (curOutPos * 100.0) / curInPos);
87 +            }
88 +
89 +            fprintf(stderr, "    \r");
90 +         }
91 +      }
92     }
93  
94     BZ2_bzWriteClose64 ( &bzerr, bzf, 0, 
95                          &nbytes_in_lo32, &nbytes_in_hi32,
96                          &nbytes_out_lo32, &nbytes_out_hi32 );
97     if (bzerr != BZ_OK) goto errhandler;
98 -
99 +   
100     if (ferror(zStream)) goto errhandler_io;
101     ret = fflush ( zStream );
102     if (ret == EOF) goto errhandler_io;
103 @@ -526,6 +562,8 @@
104     UChar   unused[BZ_MAX_UNUSED];
105     Int32   nUnused;
106     UChar*  unusedTmp;
107 +   double  fileSize = 0; /* initialized to make the compiler stop crying */
108 +   time_t  startTime, currentTime;
109  
110     nUnused = 0;
111     streamNo = 0;
112 @@ -533,9 +571,19 @@
113     SET_BINARY_MODE(stream);
114     SET_BINARY_MODE(zStream);
115  
116 +   if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
117 +      long dummy = ftell(zStream);
118 +      (void)fseek(zStream, 0, SEEK_END);
119 +      fileSize = (double)ftell(zStream);
120 +      (void)fseek(zStream, dummy, SEEK_SET);
121 +      if (verbosity >= 1)
122 +         fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
123 +   }
124 +
125     if (ferror(stream)) goto errhandler_io;
126     if (ferror(zStream)) goto errhandler_io;
127  
128 +   time(&startTime);
129     while (True) {
130  
131        bzf = BZ2_bzReadOpen ( 
132 @@ -551,6 +599,17 @@
133           if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
134              fwrite ( obuf, sizeof(UChar), nread, stream );
135           if (ferror(stream)) goto errhandler_io;
136 +
137 +         if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
138 +            time(&currentTime);
139 +            if ((currentTime - startTime) >= 2)
140 +            {
141 +               double curInPos = (double)ftell(zStream);
142 +               startTime = currentTime;
143 +
144 +               fprintf(stderr, "%.2f%% done\r", (curInPos * 100.0) / fileSize);
145 +            }
146 +         }
147        }
148        if (bzerr != BZ_STREAM_END) goto errhandler;
149  
150 @@ -1872,6 +1931,7 @@
151     deleteOutputOnInterrupt = False;
152     exitValue               = 0;
153     i = j = 0; /* avoid bogus warning from egcs-1.1.X */
154 +   showProgress            = False;
155  
156     /*-- Set up signal handlers for mem access errors --*/
157     signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
158 @@ -1949,6 +2009,7 @@
159                 case 'k': keepInputFiles   = True; break;
160                 case 's': smallMode        = True; break;
161                 case 'q': noisy            = False; break;
162 +               case 'p': showProgress     = True; break;
163                 case '1': blockSize100k    = 1; break;
164                 case '2': blockSize100k    = 2; break;
165                 case '3': blockSize100k    = 3; break;
166 @@ -1985,6 +2046,7 @@
167        if (ISFLAG("--keep"))              keepInputFiles   = True;    else
168        if (ISFLAG("--small"))             smallMode        = True;    else
169        if (ISFLAG("--quiet"))             noisy            = False;   else
170 +      if (ISFLAG("--show-progress"))     showProgress     = True;    else
171        if (ISFLAG("--version"))           license();                  else
172        if (ISFLAG("--license"))           license();                  else
173        if (ISFLAG("--exponential"))       workFactor = 1;             else 
174 @@ -2014,6 +2076,10 @@
175  
176     if (srcMode == SM_F2O && numFileNames == 0)
177        srcMode = SM_I2O;
178 +
179 +   if (srcMode != SM_F2F && srcMode != SM_F2O) {
180 +      fprintf ( stderr, "progress will only be shown when compressing files.\n");
181 +   }
182  
183     if (opMode != OM_Z) blockSize100k = 0;
184  
This page took 0.097604 seconds and 3 git commands to generate.