On Wed, Apr 06 2022, prx <p...@si3t.ch> wrote: > Since gzip has -k flag to keep original file, the output when used with -v > flag is wrong. > > Find below a stupid diff almost shorter than this message. > > Regards > > Index: main.c > =================================================================== > RCS file: /cvs/src/usr.bin/compress/main.c,v > retrieving revision 1.99 > diff -u -r1.99 main.c > --- main.c 14 Mar 2022 21:52:08 -0000 1.99 > +++ main.c 6 Apr 2022 12:49:51 -0000 > @@ -932,7 +932,7 @@ > return; > } > if (!pipin) { > - fprintf(stderr, "\t%4.1f%% -- replaced with %s\n", > + fprintf(stderr, "\t%4.1f%% -- compressed to %s\n", > (uncompressed - compressed) * 100.0 / uncompressed, file); > } > compressed += hlen; >
The diff below keeps the same output by default and outputs the same as GNU gzip(1) is -k is given. ok? Index: main.c =================================================================== RCS file: /home/cvs/src/usr.bin/compress/main.c,v retrieving revision 1.99 diff -u -p -p -u -r1.99 main.c --- main.c 14 Mar 2022 21:52:08 -0000 1.99 +++ main.c 10 Apr 2022 11:10:43 -0000 @@ -53,6 +53,7 @@ enum program_mode pmode; int cat, decomp, pipin, force, verbose, testmode, list, recurse, storename; +int kflag; extern char *__progname; const struct compressor { @@ -167,12 +168,12 @@ main(int argc, char *argv[]) const char *optstr, *s; char *p, *infile; char outfile[PATH_MAX], _infile[PATH_MAX], suffix[16]; - int bits, ch, error, rc, cflag, kflag, oflag; + int bits, ch, error, rc, cflag, oflag; if (pledge("stdio rpath wpath cpath fattr chown", NULL) == -1) err(1, "pledge"); - bits = cflag = kflag = oflag = 0; + bits = cflag = oflag = 0; storename = -1; p = __progname; if (p[0] == 'g') { @@ -932,8 +933,9 @@ verbose_info(const char *file, off_t com return; } if (!pipin) { - fprintf(stderr, "\t%4.1f%% -- replaced with %s\n", - (uncompressed - compressed) * 100.0 / uncompressed, file); + fprintf(stderr, "\t%4.1f%% -- %s %s\n", + (uncompressed - compressed) * 100.0 / uncompressed, + kflag ? "created" : "replaced with", file); } compressed += hlen; fprintf(stderr, "%lld bytes in, %lld bytes out\n", -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE