bug-gzip
[Top][All Lists]
Advanced

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

Patch to gzip-1.3.9 for adding "keep input files" feature


From: Shriramana Sharma
Subject: Patch to gzip-1.3.9 for adding "keep input files" feature
Date: Wed, 07 Feb 2007 15:41:16 +0530
User-agent: Thunderbird 1.5.0.9 (Windows/20061207)

I herewith attach the final (as far as I could see it) patch for adding the "keep input files" feature a la bzip2. It contains some differences compared to the previous "incomplete patch" I sent. Please examine it and if any corrections are needed, correct it and please implement it into the next version.

Thanks.

Shriramana Sharma.
--- gzip.c.orig
+++ gzip.c
@@ -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 */
@@ -250,7 +251,8 @@
  /* {"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" */
+    {"keep",       0, 0, 'k'}, /* keep input files */
     {"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 */
@@ -325,7 +327,8 @@
 /*  -e, --encrypt     encrypt */
  "  -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" */
+ "  -k, --keep        keep (don't delete) input files",
  "  -l, --list        list compressed file contents",
  "  -L, --license     display software license",
 #ifdef UNDOCUMENTED
@@ -421,13 +424,13 @@
        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;
     z_len = strlen(z_suffix);
 
-    while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
+    while ((optc = getopt_long (argc, argv, 
"ab:cdfhH?klLmMnNqrS:tvVZ123456789",
                                longopts, (int *)0)) != -1) {
        switch (optc) {
         case 'a':
@@ -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;
@@ -740,7 +745,7 @@
        return;
       }
 
-    if (istat.st_nlink > 1 && !to_stdout && !force) {
+    if (istat.st_nlink > 1 && !keep_input_files && !force) {
        WARN((stderr, "%s: %s has %lu other link%c -- unchanged\n",
              program_name, ifname, (unsigned long) istat.st_nlink - 1,
              istat.st_nlink > 2 ? 's' : ' '));
@@ -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]