gioser

sergio/takana

> Una distribución Linux construida con un laboratorio funcional y hermético en el > sótano, y una terminal mutable, clásica y anárquica en el piso de arriba — diseñada > desde el suelo para que una IA programadora entienda, modifique y co…

⎇ main tandas/staged-2026-06-26/bzip2-1.0.2-progress.patch 175 lines · 6.0 KB History raw

Etapa G: fuel-5 — recarga la cola del VPS (parado 14h sin producir) 08fdec3bb · sergio ·

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