Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 Jan 2007 14:45:07 +0800
From:      LI Xin <delphij@delphij.net>
To:        FreeBSD Current <freebsd-current@freebsd.org>,  ighighi@gmail.com
Subject:   [PATCH] New feature: -k option for bsd gzip
Message-ID:  <45C03AF3.9090808@delphij.net>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigC5C7C43FF5C7677872D8E3F9
Content-Type: multipart/mixed; boundary="------------080009000100030206090108"

This is a multi-part message in MIME format.
--------------080009000100030206090108
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

As inspired by bin/103006, I have added an '-k' option for our BSD gzip,
as in attachment.  The -k option acts like bzip2(1)'s counterpart which
requests gzip(1) to keep the file (instead of the default behavior,
delete it).

Comments?

(A bsdgzip version backported to RELENG_6 can be obtained from
http://people.freebsd.org/~delphij/gzip-r6/gzip.tbz )

Cheers,
--=20
Xin LI <delphij@delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!

--------------080009000100030206090108
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
	name="patch-gzip-keep"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="patch-gzip-keep"

Index: gzip.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/gzip/gzip.1,v
retrieving revision 1.1
diff -u -p -u -r1.1 gzip.1
--- gzip.1	26 Jan 2007 10:19:07 -0000	1.1
+++ gzip.1	31 Jan 2007 06:39:38 -0000
@@ -27,7 +27,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $FreeBSD: src/usr.bin/gzip/gzip.1,v 1.1 2007/01/26 10:19:07 delphij =
Exp $
-.Dd January 26, 2007
+.Dd January 31, 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
@@ -43,7 +43,7 @@
 .Oc
 .Oc
 .Nm gunzip
-.Op Fl cfhLNqrtVv
+.Op Fl cfhkLNqrtVv
 .Op Fl S Ar suffix
 .Ar file
 .Oo
@@ -124,6 +124,8 @@ 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
Index: gzip.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/gzip/gzip.c,v
retrieving revision 1.1
diff -u -p -u -r1.1 gzip.c
--- gzip.c	26 Jan 2007 10:19:07 -0000	1.1
+++ gzip.c	31 Jan 2007 06:36:42 -0000
@@ -143,7 +143,7 @@ static suffixes_t suffixes[] =3D {
 };
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
=20
-static	const char	gzip_version[] =3D "FreeBSD gzip 20070126";
+static	const char	gzip_version[] =3D "FreeBSD gzip 20070131";
=20
 #ifndef SMALL
 static	const char	gzip_copyright[] =3D \
@@ -181,6 +181,7 @@ static	int	numflag =3D 6;		/* gzip -1..-9=20
=20
 #ifndef SMALL
 static	int	fflag;			/* force mode */
+static	int	kflag;			/* keep input file? */
 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[] =3D=20
 	{ "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
=20
 	while ((ch =3D getopt_long(argc, argv, OPT_LIST, longopts, NULL)) !=3D =
-1) {
@@ -338,6 +340,9 @@ main(int argc, char **argv)
 		case 'f':
 			fflag =3D 1;
 			break;
+		case 'k':
+			kflag =3D 1;
+			break;
 		case 'L':
 			display_license();
 			/* NOT REACHED */
@@ -1145,6 +1150,10 @@ unlink_input(const char *file, const str
 	if (nsb.st_dev !=3D sb->st_dev || nsb.st_ino !=3D sb->st_ino)
 		/* Definitely a different file */
 		return;
+#ifndef SMALL
+	if (kflag)
+		return;
+#endif
 	unlink(file);
 }
 #endif
@@ -1985,6 +1994,7 @@ usage(void)
     "    --uncompress\n"
     " -f --force           force overwriting & compress links\n"
     " -h --help            display this help\n"
+    " -k --keep            keep input files during compression or decomp=
ression\n"
     " -l --list            list compressed file contents\n"
     " -N --name            save or restore original file name and time s=
tamp\n"
     " -n --no-name         don't save original file name or time stamp\n=
"

--------------080009000100030206090108--

--------------enigC5C7C43FF5C7677872D8E3F9
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFwDrzOfuToMruuMARA1aGAJ9wXGWkYCfhgbm1fT6FvPH8V/WK+ACgh+Q0
E5RP5L8TCaddHfGTOJEzdgA=
=Enja
-----END PGP SIGNATURE-----

--------------enigC5C7C43FF5C7677872D8E3F9--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45C03AF3.9090808>