Репозитории ALT
S: | 1.0.8-alt2 |
5.1: | 1.0.6-alt1 |
4.1: | 1.0.6-alt0.M40.1 |
4.0: | 1.0.6-alt0.M40.1 |
+updates: | 1.0.5-alt2 |
3.0: | 1.0.3-alt5 |
Группа :: Архивирование/Сжатие
Пакет: bzip2
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: bzip2-1.0.6-flok-show-progress.patch
Скачать
Скачать
--- bzip2/bzip2.1
+++ bzip2/bzip2.1
@@ -235,6 +235,10 @@ less), use \-s for everything. See MEMORY MANAGEMENT below.
Suppress non-essential warning messages. Messages pertaining to
I/O errors and other critical events will not be suppressed.
.TP
+.B \-p --show-progress
+Show percentage of input-file done and while compressing show the percentage
+of the original file the new file is.
+.TP
.B \-v --verbose
Verbose mode -- show the compression ratio for each file processed.
Further \-v's increase the verbosity level, spewing out lots of
--- bzip2/bzip2.c
+++ bzip2/bzip2.c
@@ -57,6 +57,7 @@
#include <signal.h>
#include <math.h>
#include <errno.h>
+#include <time.h>
#include <ctype.h>
#include "bzlib.h"
@@ -212,6 +213,7 @@ Char tmpName[FILE_NAME_LEN];
const char *progName;
FILE *outputHandleJustInCase;
Int32 workFactor;
+Char showProgress;
static void panic ( const Char* ) NORETURN;
static void ioError ( void ) NORETURN;
@@ -340,6 +342,12 @@ void compressStream ( FILE *stream, FILE *zStream )
UInt32 nbytes_in_lo32, nbytes_in_hi32;
UInt32 nbytes_out_lo32, nbytes_out_hi32;
Int32 bzerr, bzerr_dummy, ret;
+ double fileSize = 0; /* initialized to make the compiler stop crying */
+ /* double because big files might otherwhise give
+ * overflows. not long long since not all compilers
+ * support that one
+ */
+ time_t prevTime, currentTime;
SET_BINARY_MODE(stream);
SET_BINARY_MODE(zStream);
@@ -347,12 +355,21 @@ void compressStream ( FILE *stream, FILE *zStream )
if (ferror(stream)) goto errhandler_io;
if (ferror(zStream)) goto errhandler_io;
+ if (showProgress == True && (srcMode == SM_F2F || srcMode == SM_F2O)) {
+ (void)fseek(stream, 0, SEEK_END);
+ fileSize = (double)ftell(stream);
+ rewind(stream);
+ if (verbosity >= 1)
+ fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
+ }
+
bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
blockSize100k, verbosity, workFactor );
if (bzerr != BZ_OK) goto errhandler;
if (verbosity >= 2) fprintf ( stderr, "\n" );
+ time(&prevTime);
while (True) {
if (myfeof(stream)) break;
@@ -361,6 +378,25 @@ void compressStream ( FILE *stream, FILE *zStream )
if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
if (bzerr != BZ_OK) goto errhandler;
+ if (showProgress == True && (srcMode == SM_F2F || srcMode == SM_F2O))
+ {
+ time(¤tTime);
+
+ if ((currentTime - prevTime) > 1) { /* show progress every 2 seconds */
+ double curInPos = (double)ftell(stream);
+ double curOutPos = (double)ftell(zStream);
+
+ prevTime = currentTime;
+
+ fprintf(stderr, "%.2f%% done", (curInPos * 100.0) / fileSize);
+ if (srcMode == SM_F2F)
+ {
+ fprintf(stderr, ", new size: %.2f%%", (curOutPos * 100.0) / curInPos);
+ }
+
+ fprintf(stderr, " \r");
+ }
+ }
}
BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
@@ -445,6 +481,8 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
Int32 nUnused;
void* unusedTmpV;
UChar* unusedTmp;
+ double fileSize = 0; /* initialized to make the compiler stop crying */
+ time_t prevTime, currentTime;
nUnused = 0;
streamNo = 0;
@@ -452,9 +490,19 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
SET_BINARY_MODE(stream);
SET_BINARY_MODE(zStream);
+ if (showProgress == True && (srcMode == SM_F2F || srcMode == SM_F2O)) {
+ long dummy = ftell(zStream);
+ (void)fseek(zStream, 0, SEEK_END);
+ fileSize = (double)ftell(zStream);
+ (void)fseek(zStream, dummy, SEEK_SET);
+ if (verbosity >= 1)
+ fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
+ }
+
if (ferror(stream)) goto errhandler_io;
if (ferror(zStream)) goto errhandler_io;
+ time(&prevTime);
while (True) {
bzf = BZ2_bzReadOpen (
@@ -470,6 +518,17 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
fwrite ( obuf, sizeof(UChar), nread, stream );
if (ferror(stream)) goto errhandler_io;
+
+ if (showProgress == True && (srcMode == SM_F2F || srcMode == SM_F2O)) {
+ time(¤tTime);
+ if ((currentTime - prevTime) >= 2)
+ {
+ double curInPos = (double)ftell(zStream);
+ prevTime = currentTime;
+
+ fprintf(stderr, "%.2f%% done\r", (curInPos * 100.0) / fileSize);
+ }
+ }
}
if (bzerr != BZ_STREAM_END) goto errhandler;
@@ -1894,6 +1953,7 @@ IntNative main ( IntNative argc, Char *argv[] )
case 'k': keepInputFiles = True; break;
case 's': smallMode = True; break;
case 'q': noisy = False; break;
+ case 'p': showProgress = True; break;
case '1': blockSize100k = 1; break;
case '2': blockSize100k = 2; break;
case '3': blockSize100k = 3; break;
@@ -1928,6 +1988,7 @@ IntNative main ( IntNative argc, Char *argv[] )
if (ISFLAG("--keep")) keepInputFiles = True; else
if (ISFLAG("--small")) smallMode = True; else
if (ISFLAG("--quiet")) noisy = False; else
+ if (ISFLAG("--show-progress")) showProgress = True; else
if (ISFLAG("--version")) license(); else
if (ISFLAG("--license")) license(); else
if (ISFLAG("--exponential")) workFactor = 1; else