From 23ad5197dd8c2ca2418d4e396d98f82c5d1d184c Mon Sep 17 00:00:00 2001 From: delphij Date: Mon, 28 May 2007 08:20:46 +0000 Subject: Add a '-k' flag which is similar with its bzip2(1) counterpart, meaning that the user wants the input file to be left intact. Feature request: Ighighi PR: bin/103006 MFC after: 1 month --- usr.bin/gzip/gzip.1 | 7 +++++-- usr.bin/gzip/gzip.c | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/usr.bin/gzip/gzip.1 b/usr.bin/gzip/gzip.1 index 16d715d..8aea189 100644 --- a/usr.bin/gzip/gzip.1 +++ b/usr.bin/gzip/gzip.1 @@ -27,7 +27,7 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd March 16, 2007 +.Dd May 28, 2007 .Dt GZIP 1 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd compression/decompression tool using Lempel-Ziv coding (LZ77) .Sh SYNOPSIS .Nm -.Op Fl cdfhLlNnqrtVv +.Op Fl cdfhkLlNnqrtVv .Op Fl S Ar suffix .Ar file .Oo @@ -124,6 +124,9 @@ with the option, allowing non-compressed data to pass through unchanged. .It Fl h , -help This option prints a usage summary and exits. +.It Fl k , -keep +Keep (don't delete) input files during compression +or decompression. .It Fl L , -license This option prints .Nm diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index 6f202c7..a3a2a91 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -143,7 +143,7 @@ static suffixes_t suffixes[] = { }; #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0]) -static const char gzip_version[] = "FreeBSD gzip 20070126"; +static const char gzip_version[] = "FreeBSD gzip 20070528"; #ifndef SMALL static const char gzip_copyright[] = \ @@ -181,6 +181,7 @@ static int numflag = 6; /* gzip -1..-9 value */ #ifndef SMALL static int fflag; /* force mode */ +static int kflag; /* don't delete input files */ static int nflag; /* don't save name/timestamp */ static int Nflag; /* don't restore name/timestamp */ static int qflag; /* quiet mode */ @@ -261,6 +262,7 @@ static const struct option longopts[] = { { "uncompress", no_argument, 0, 'd' }, { "force", no_argument, 0, 'f' }, { "help", no_argument, 0, 'h' }, + { "keep", no_argument, 0, 'k' }, { "list", no_argument, 0, 'l' }, { "no-name", no_argument, 0, 'n' }, { "name", no_argument, 0, 'N' }, @@ -308,7 +310,7 @@ main(int argc, char **argv) #ifdef SMALL #define OPT_LIST "123456789cdhltV" #else -#define OPT_LIST "123456789acdfhlLNnqrS:tVv" +#define OPT_LIST "123456789acdfhklLNnqrS:tVv" #endif while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) { @@ -338,6 +340,9 @@ main(int argc, char **argv) case 'f': fflag = 1; break; + case 'k': + kflag = 1; + break; case 'L': display_license(); /* NOT REACHED */ @@ -1139,6 +1144,8 @@ unlink_input(const char *file, const struct stat *sb) { struct stat nsb; + if (kflag) + return; if (stat(file, &nsb) != 0) /* Must be gone alrady */ return; @@ -1985,6 +1992,7 @@ usage(void) " --uncompress\n" " -f --force force overwriting & compress links\n" " -h --help display this help\n" + " -k --keep don't delete input files during operation\n" " -l --list list compressed file contents\n" " -N --name save or restore original file name and time stamp\n" " -n --no-name don't save original file name or time stamp\n" -- cgit v1.1