[PATCH] Add '-k' feature from FreeBSD plus GNU gzip compatibility fix

LI Xin delphij at delphij.net
Wed Sep 5 20:14:01 PDT 2007


Hi,

This patch adds some features/improvements from FreeBSD:

 - Add a '-k' option which does not remove input file, like bzip2(1) do.
 - Use better representation of 'S:' by expanding ':' to '.suffix'
 - Simulate GNU gzip(1) behavior where full filename is being output in
verbose mode when doing recursive[1].

If someone have commit access liked the patch, you can also find the
patched checked out version on leaf's /home/delphij/build/gzip.

Note, that I have intentionally left .Dd in gzip.1 intact, because I do
not know the exact date or wheather it would hit the tree.  When
committing the code please consider bumping the date.

Cheers,
-- 
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!
Index: gzip.1
===================================================================
RCS file: /archive/DragonFly-CVS/src/usr.bin/gzip/gzip.1,v
retrieving revision 1.1
diff -u -r1.1 gzip.1
--- gzip.1	26 Oct 2004 11:19:31 -0000	1.1
+++ gzip.1	6 Sep 2007 03:01:59 -0000
@@ -35,7 +35,7 @@
 .Nd compression/decompression tool using Lempel-Ziv coding (LZ77)
 .Sh SYNOPSIS
 .Nm
-.Op Fl cdfhlNnqrtVv
+.Op Fl cdfhklNnqrtVv
 .Op Fl S Ar suffix
 .Ar file
 .Oo
@@ -43,7 +43,7 @@
 .Oc
 .Oc
 .Nm gunzip
-.Op Fl cfhNqrtVv
+.Op Fl cfhkNqrtVv
 .Op Fl S Ar suffix
 .Ar file
 .Oo
@@ -130,6 +130,9 @@
 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 , -list
 This option displays information about the file's compressed and
 uncompressed size, ratio, uncompressed name.
Index: gzip.c
===================================================================
RCS file: /archive/DragonFly-CVS/src/usr.bin/gzip/gzip.c,v
retrieving revision 1.6
diff -u -r1.6 gzip.c
--- gzip.c	25 Oct 2006 08:27:27 -0000	1.6
+++ gzip.c	6 Sep 2007 02:59:15 -0000
@@ -148,6 +148,7 @@
 
 #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 */
@@ -224,6 +225,7 @@
 	{ "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' },
@@ -277,7 +279,7 @@
 #ifdef SMALL
 #define OPT_LIST "cdhHltV123456789"
 #else
-#define OPT_LIST "cdfhHlnNqrS:tvV123456789"
+#define OPT_LIST "cdfhHklnNqrS:tvV123456789"
 #endif
 
 	while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) {
@@ -304,6 +306,9 @@
 		case 'f':
 			fflag = 1;
 			break;
+		case 'k':
+			kflag = 1;
+			break;
 		case 'n':
 			nflag = 1;
 			Nflag = 0;
@@ -1075,6 +1080,9 @@
 {
 	struct stat nsb;
 
+	if (kflag)
+		return;
+
 	if (stat(file, &nsb) != 0)
 		/* Must be gone alrady */
 		return;
@@ -1678,7 +1686,7 @@
 
 	path_argv[0] = dir;
 	path_argv[1] = 0;
-	fts = fts_open(path_argv, FTS_PHYSICAL, NULL);
+	fts = fts_open(path_argv, FTS_PHYSICAL | FTS_NOCHDIR, NULL);
 	if (fts == NULL) {
 		warn("couldn't fts_open %s", dir);
 		return;
@@ -1696,7 +1704,7 @@
 			maybe_warn("%s", entry->fts_path);
 			continue;
 		case FTS_F:
-			handle_file(entry->fts_name, entry->fts_statp);
+			handle_file(entry->fts_path, entry->fts_statp);
 		}
 	}
 	(void)fts_close(fts);
@@ -1846,14 +1854,17 @@
 
 	fprintf(stderr, "%s\n", gzip_version);
 	fprintf(stderr,
-    "usage: %s [-" OPT_LIST "] [<file> [<file> ...]]\n"
-#ifndef SMALL
+#ifdef SMALL
+    "usage: %s [-" OPT_LIST "] [<file> [<file> ...]]\n",
+#else
+    "usage: %s [-123456789acdfhklLNnqrtVv] [-S .suffix] [<file> [<file> ...]]\n"
     " -c --stdout          write to stdout, keep original files\n"
     "    --to-stdout\n"
     " -d --decompress      uncompress files\n"
     "    --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"
     " -n --no-name         don't save original file name or time stamp\n"
     " -N --name            save or restore original file name and time stamp\n"
     " -q --quiet           output no warnings\n"
@@ -1866,8 +1877,6 @@
     " -1 --fast            fastest (worst) compression\n"
     " -2 .. -8             set compression level\n"
     " -9 --best            best (slowest) compression\n",
-#else
-    ,
 #endif
 	    getprogname());
 	exit(0);
Attachment:
signature.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00004.pgp
Type: application/octet-stream
Size: 249 bytes
Desc: "Description: OpenPGP digital signature"
URL: <http://lists.dragonflybsd.org/pipermail/bugs/attachments/20070905/038abd33/attachment-0016.obj>


More information about the Bugs mailing list