show-progress.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. Ripped from Mandrake
  2. http://bugs.gentoo.org/82192
  3. --- bzip2-1.0.6/bzip2.1
  4. +++ bzip2-1.0.6/bzip2.1
  5. @@ -235,6 +235,10 @@
  6. Suppress non-essential warning messages. Messages pertaining to
  7. I/O errors and other critical events will not be suppressed.
  8. .TP
  9. +.B \-p \-\-show\-progress
  10. +Show percentage of input\-file done and while compressing show the percentage
  11. +of the original file the new file is.
  12. +.TP
  13. .B \-v --verbose
  14. Verbose mode -- show the compression ratio for each file processed.
  15. Further \-v's increase the verbosity level, spewing out lots of
  16. --- bzip2-1.0.6/bzip2.c
  17. +++ bzip2-1.0.6/bzip2.c
  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. @@ -301,4 +302,5 @@
  26. Char progNameReally[FILE_NAME_LEN];
  27. FILE *outputHandleJustInCase;
  28. Int32 workFactor;
  29. +Char showProgress;
  30. @@ -425,6 +427,12 @@
  31. UInt32 nbytes_in_lo32, nbytes_in_hi32;
  32. UInt32 nbytes_out_lo32, nbytes_out_hi32;
  33. Int32 bzerr, bzerr_dummy, ret;
  34. + double fileSize = 0; /* initialized to make the compiler stop crying */
  35. + /* double because big files might otherwhise give
  36. + * overflows. not long long since not all compilers
  37. + * support that one
  38. + */
  39. + time_t startTime, currentTime;
  40. SET_BINARY_MODE(stream);
  41. SET_BINARY_MODE(zStream);
  42. @@ -432,12 +440,21 @@
  43. if (ferror(stream)) goto errhandler_io;
  44. if (ferror(zStream)) goto errhandler_io;
  45. + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
  46. + (void)fseek(stream, 0, SEEK_END);
  47. + fileSize = ftello(stream);
  48. + rewind(stream);
  49. + if (verbosity >= 1)
  50. + fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
  51. + }
  52. +
  53. bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
  54. blockSize100k, verbosity, workFactor );
  55. if (bzerr != BZ_OK) goto errhandler;
  56. if (verbosity >= 2) fprintf ( stderr, "\n" );
  57. + time(&startTime);
  58. while (True) {
  59. if (myfeof(stream)) break;
  60. @@ -446,6 +463,22 @@
  61. if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
  62. if (bzerr != BZ_OK) goto errhandler;
  63. + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
  64. + time(&currentTime);
  65. +
  66. + if ((currentTime - startTime) > 1) { /* show progress every 2 seconds */
  67. + double curInPos = ftello(stream);
  68. + double curOutPos = ftello(zStream);
  69. +
  70. + startTime = currentTime;
  71. +
  72. + fprintf(stderr, "%.2f%% done", (curInPos * 100.0) / fileSize);
  73. + if (srcMode == SM_F2F)
  74. + fprintf(stderr, ", new size: %.2f%%", (curOutPos * 100.0) / curInPos);
  75. +
  76. + fprintf(stderr, " \r");
  77. + }
  78. + }
  79. }
  80. BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
  81. @@ -520,12 +553,14 @@
  82. Bool uncompressStream ( FILE *zStream, FILE *stream )
  83. {
  84. BZFILE* bzf = NULL;
  85. Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
  86. UChar obuf[5000];
  87. UChar unused[BZ_MAX_UNUSED];
  88. Int32 nUnused;
  89. void* unusedTmpV;
  90. UChar* unusedTmp;
  91. + double fileSize = 0; /* initialized to make the compiler stop crying */
  92. + time_t startTime, currentTime;
  93. nUnused = 0;
  94. streamNo = 0;
  95. @@ -533,9 +568,19 @@
  96. SET_BINARY_MODE(stream);
  97. SET_BINARY_MODE(zStream);
  98. + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
  99. + off_t dummy = ftello(zStream);
  100. + (void)fseeko(zStream, 0, SEEK_END);
  101. + fileSize = ftello(zStream);
  102. + (void)fseeko(zStream, dummy, SEEK_SET);
  103. + if (verbosity >= 1)
  104. + fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
  105. + }
  106. +
  107. if (ferror(stream)) goto errhandler_io;
  108. if (ferror(zStream)) goto errhandler_io;
  109. + time(&startTime);
  110. while (True) {
  111. bzf = BZ2_bzReadOpen (
  112. @@ -551,6 +596,16 @@
  113. if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
  114. fwrite ( obuf, sizeof(UChar), nread, stream );
  115. if (ferror(stream)) goto errhandler_io;
  116. +
  117. + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
  118. + time(&currentTime);
  119. + if ((currentTime - startTime) >= 2) {
  120. + double curInPos = ftello(zStream);
  121. + startTime = currentTime;
  122. +
  123. + fprintf(stderr, "%.2f%% done\r", (curInPos * 100.0) / fileSize);
  124. + }
  125. + }
  126. }
  127. if (bzerr != BZ_STREAM_END) goto errhandler;
  128. @@ -1872,6 +1927,7 @@
  129. deleteOutputOnInterrupt = False;
  130. exitValue = 0;
  131. i = j = 0; /* avoid bogus warning from egcs-1.1.X */
  132. + showProgress = False;
  133. /*-- Set up signal handlers for mem access errors --*/
  134. signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
  135. @@ -1949,6 +2005,7 @@
  136. case 'k': keepInputFiles = True; break;
  137. case 's': smallMode = True; break;
  138. case 'q': noisy = False; break;
  139. + case 'p': showProgress = True; break;
  140. case '1': blockSize100k = 1; break;
  141. case '2': blockSize100k = 2; break;
  142. case '3': blockSize100k = 3; break;
  143. @@ -1985,6 +2042,7 @@
  144. if (ISFLAG("--keep")) keepInputFiles = True; else
  145. if (ISFLAG("--small")) smallMode = True; else
  146. if (ISFLAG("--quiet")) noisy = False; else
  147. + if (ISFLAG("--show-progress")) showProgress = True; else
  148. if (ISFLAG("--version")) license(); else
  149. if (ISFLAG("--license")) license(); else
  150. if (ISFLAG("--exponential")) workFactor = 1; else