Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Jun 2002 07:40:03 -0700 (PDT)
From:      Jonathan Towne <jontow@twcny.rr.com>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/13043: minigzip -c option support.
Message-ID:  <200206091440.g59Ee3n51009@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

The following reply was made to PR bin/13043; it has been noted by GNATS.

From: Jonathan Towne <jontow@twcny.rr.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc: toshi@jp.freebsd.org
Subject: Re: bin/13043: minigzip -c option support.
Date: Sun, 9 Jun 2002 10:37:39 -0400

 --1LKvkjL3sHcu1TtY
 Content-Type: text/plain; charset=us-ascii
 
 Having stumbled across this, I thought it was a great idea.. and
 upon noticing that it was a rather old PR, decided to make it a
 little less stale.  The patch that follows applies to -CURRENT
 from anoncvs.freebsd.org as of Sunday, June 9, ~10:30 EDT.
 
 cd /usr/src/usr.bin/minigzip 
 patch < path/to/minigzip.stdout.fbsd5.patch
 
 
 - Jonathan Towne
 
 --1LKvkjL3sHcu1TtY
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="minigzip.stdout.fbsd5.patch"
 
 *** ../../lib/libz/minigzip.c.orig	Sun Jun  9 10:00:14 2002
 --- ../../lib/libz/minigzip.c	Sun Jun  9 10:18:00 2002
 ***************
 *** 123,129 ****
           if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
       }
       fclose(in);
 -     if (gzclose(out) != Z_OK) error("failed gzclose");
   }
   
   #ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
 --- 123,128 ----
 ***************
 *** 158,164 ****
   
       munmap(buf, buf_len);
       fclose(in);
 -     if (gzclose(out) != Z_OK) error("failed gzclose");
       return Z_OK;
   }
   #endif /* USE_MMAP */
 --- 157,162 ----
 ***************
 *** 183,189 ****
   	    error("failed fwrite");
   	}
       }
 -     if (fclose(out)) error("failed fclose");
   
       if (gzclose(in) != Z_OK) error("failed gzclose");
   }
 --- 181,186 ----
 ***************
 *** 221,226 ****
 --- 218,224 ----
       }
       gz_compress(in, out);
   
 +     if (gzclose(out) != Z_OK) error("failed gzclose");
       unlink(file);
   }
   
 ***************
 *** 266,277 ****
   
       gz_uncompress(in, out);
   
       unlink(infile);
   }
   
   
   /* ===========================================================================
 !  * Usage:  minigzip [-d] [-f] [-h] [-1 to -9] [files...]
    *   -d : decompress
    *   -f : compress with Z_FILTERED
    *   -h : compress with Z_HUFFMAN_ONLY
 --- 264,277 ----
   
       gz_uncompress(in, out);
   
 +     if (fclose(out)) error("failed fclose");
       unlink(infile);
   }
   
   
   /* ===========================================================================
 !  * Usage:  minigzip [-c ] [-d] [-f] [-h] [-1 to -9] [files...]
 !  *   -c : decompress to standard output
    *   -d : decompress
    *   -f : compress with Z_FILTERED
    *   -h : compress with Z_HUFFMAN_ONLY
 ***************
 *** 282,287 ****
 --- 282,288 ----
       int argc;
       char *argv[];
   {
 +     int copyout = 0;
       int uncompr = 0;
       gzFile file;
       char *bname, outmode[20];
 ***************
 *** 296,307 ****
         bname = argv[0];
       argc--, argv++;
   
 !     if (!strcmp(bname, "gunzip") || !strcmp(bname, "zcat"))
         uncompr = 1;
   
       while (argc > 0) {
         if (strcmp(*argv, "-c") == 0)
 ! 	; /* Just for compatibility with gzip */
         else if (strcmp(*argv, "-d") == 0)
   	uncompr = 1;
         else if (strcmp(*argv, "-f") == 0)
 --- 297,310 ----
         bname = argv[0];
       argc--, argv++;
   
 !     if (!strcmp(bname, "gunzip"))
         uncompr = 1;
 +     else if (!strcmp(bname, "zcat"))
 +       copyout = uncompr = 1;
   
       while (argc > 0) {
         if (strcmp(*argv, "-c") == 0)
 ! 	copyout = 1; /* Just for compatibility with gzip */
         else if (strcmp(*argv, "-d") == 0)
   	uncompr = 1;
         else if (strcmp(*argv, "-f") == 0)
 ***************
 *** 326,341 ****
               file = gzdopen(fileno(stdout), outmode);
               if (file == NULL) error("can't gzdopen stdout");
               gz_compress(stdin, file);
           }
       } else {
           do {
               if (uncompr) {
 !                 file_uncompress(*argv);
               } else {
 !                 file_compress(*argv, outmode);
               }
           } while (argv++, --argc);
       }
       exit(0);
       return 0; /* to avoid warning */
   }
 --- 329,371 ----
               file = gzdopen(fileno(stdout), outmode);
               if (file == NULL) error("can't gzdopen stdout");
               gz_compress(stdin, file);
 + 	    if (gzclose(file) != Z_OK) error("failed gzclose");
           }
       } else {
 + 	if (copyout) {
 + 	    SET_BINARY_MODE(stdout);
 + 	    if (!uncompr) {
 + 		file = gzdopen(fileno(stdout), outmode);
 + 		if (file == NULL) error("can't gzdopen stdout");
 + 	    }
 + 	}
           do {
               if (uncompr) {
 ! 	    	if (copyout) {
 ! 		    file = gzopen(*argv, "rb");
 ! 		    if (file == NULL)
 ! 			fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
 ! 		    else
 ! 			gz_uncompress(file, stdout);
 ! 		} else
 ! 		    file_uncompress(*argv);
               } else {
 ! 		if (copyout) {
 ! 		    FILE * in = fopen(*argv, "rb");
 ! 		    if (in == NULL)
 ! 			perror(*argv);
 ! 		    else
 ! 			gz_compress(in, file);
 ! 		} else
 ! 		    file_compress(*argv, outmode);
               }
           } while (argv++, --argc);
 + 
 +         if (copyout && !uncompr)
 + 	    if (gzclose(file) != Z_OK) error("failed gzclose");
       }
 + 
 + 
       exit(0);
       return 0; /* to avoid warning */
   }
 *** ../../usr.bin/minigzip/minigzip.1.orig	Sat Apr 20 08:15:48 2002
 --- ../../usr.bin/minigzip/minigzip.1	Sun Jun  9 10:27:05 2002
 ***************
 *** 32,37 ****
 --- 32,38 ----
   .Nd minimal implementation of the 'gzip' compression tool
   .Sh SYNOPSIS
   .Nm
 + .Op Fl c
   .Op Fl d
   .Op Ar
   .Sh DESCRIPTION
 ***************
 *** 64,69 ****
 --- 65,74 ----
   .Nm
   reads from standard input and writes the results of the operation
   to standard output.
 + .Pp
 + If the
 + .Fl c
 + option is specified, write results to standard output.
   .Sh SEE ALSO
   .Xr gzip 1
   .Sh AUTHORS
 
 --1LKvkjL3sHcu1TtY--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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