bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gzip and gunzip should have -k (--keep) option like bzip2 and bunzip


From: Shriramana Sharma
Subject: Re: gzip and gunzip should have -k (--keep) option like bzip2 and bunzip2
Date: Sun, 07 Jan 2007 16:15:15 +0530
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

All right so I tried implementing my wish myself, but it was complicated
by the fact that the program previously used to_stdout both:

1. to set the output file to stdout and

2. to stop unlinking the input files.

Now I had to separate the two functionalities and also remember to set
keep_input_files when stdout is used, so that the input files are not
unlinked just because -k was not used. I have tried a little bit,
working on the code of gzip 1.3.9, but I am not sure that I have:

1. replaced all relevant occurrences of to_stdout with keep_input_files
(there were one or two places where the value of to_stdout was tested
for something that did not seem to be to be related to unlinking - so I
left them out in the replacement)

2. set keep_input_files to on whenever to_stdout is set to on (well I
did this fully wherever to_stdout = 1 was there explicitly, but I am not
sure that there is no implicit switching-on of to_stdout so to be
careful I mentioned this also)

So please examine the patch - I'm not great with programming related to
file internals, so I can't be sure I haven't messed up anything, but if
I did help, then I'd be happy. If there are any minor changes needed to
my patch to fully implement the desired functionality without affecting
existing unrelated behaviour, please tell me those changes and with
them, please implement this feature.

Thank you.

Shriramana Sharma.

--- gzip.c~     2006-12-12 05:33:17.000000000 +0530
+++ gzip.c      2007-01-07 12:44:30.000000000 +0530
@@ -196,6 +196,7 @@
 int recursive = 0;    /* recurse through directories (-r) */
 int list = 0;         /* list the file contents (-l) */
 int verbose = 0;      /* be verbose (-v) */
+int keep_input_files = 0; /* do not delete input files */
 int quiet = 0;        /* be very quiet (-q) */
 int do_lzw = 0;       /* generate output compatible with old compress (-Z) */
 int test = 0;         /* test .gz file integrity */
@@ -247,10 +248,11 @@
     {"stdout",     0, 0, 'c'}, /* write output on standard output */
     {"decompress", 0, 0, 'd'}, /* decompress */
     {"uncompress", 0, 0, 'd'}, /* decompress */
+    {"keep",       0, 0, 'k'}, /* keep input files */
  /* {"encrypt",    0, 0, 'e'},    encrypt */
     {"force",      0, 0, 'f'}, /* force overwrite of output file */
     {"help",       0, 0, 'h'}, /* give help */
- /* {"pkzip",      0, 0, 'k'},    force output in pkzip format */
+ /* {"pkzip",      0, 0, 'k'},    force output in pkzip format */ /* IF THIS 
IS ENABLED IT WILL CONFLICT WITH "KEEP" */
     {"list",       0, 0, 'l'}, /* list .gz file contents */
     {"license",    0, 0, 'L'}, /* display software license */
     {"no-name",    0, 0, 'n'}, /* don't save or restore original name & time */
@@ -323,9 +325,10 @@
  "  -c, --stdout      write on standard output, keep original files unchanged",
  "  -d, --decompress  decompress",
 /*  -e, --encrypt     encrypt */
+ "  -k, --keep        keep (don't delete) input files",
  "  -f, --force       force overwrite of output file and compress links",
  "  -h, --help        give this help",
-/*  -k, --pkzip       force output in pkzip format */
+/*  -k, --pkzip       force output in pkzip format */ /* IF THIS IS ENABLED IT 
WILL CONFLICT WITH "KEEP" */
  "  -l, --list        list compressed file contents",
  "  -L, --license     display software license",
 #ifdef UNDOCUMENTED
@@ -421,7 +424,7 @@
        decompress = 1;
     else if (strequ (program_name + 1, "cat")     /* zcat, pcat, gcat */
             || strequ (program_name, "gzcat"))   /* gzcat */
-       decompress = to_stdout = 1;
+       decompress = to_stdout = keep_input_files = 1;
 #endif
 
     z_suffix = Z_SUFFIX;
@@ -443,15 +446,17 @@
                }
            break;
        case 'c':
-           to_stdout = 1; break;
+           to_stdout = keep_input_files = 1; break;
        case 'd':
            decompress = 1; break;
+       case 'k':
+           keep_input_files = 1; break;
        case 'f':
            force++; break;
        case 'h': case 'H':
            help(); do_exit(OK); break;
        case 'l':
-           list = decompress = to_stdout = 1; break;
+           list = decompress = to_stdout = keep_input_files = 1; break;
        case 'L':
            license(); do_exit(OK); break;
        case 'm': /* undocumented, may change later */
@@ -481,7 +486,7 @@
            z_suffix = optarg;
             break;
        case 't':
-           test = decompress = to_stdout = 1;
+           test = decompress = to_stdout = keep_input_files = 1;
            break;
        case 'v':
            verbose++; quiet = 0; break;
@@ -634,7 +639,7 @@
     ifile_size = -1L; /* convention for unknown size */
 
     clear_bufs(); /* clear input and output buffers */
-    to_stdout = 1;
+    to_stdout = keep_input_files = 1;
     part_nb = 0;
 
     if (decompress) {
@@ -823,7 +828,7 @@
     if (close (ifd) != 0)
       read_error ();
 
-    if (!to_stdout)
+    if (!keep_input_files)
       {
        sigset_t oldset;
        int unlink_errno;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]