diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2003-09-05 04:46:36 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2003-09-05 04:46:36 +0000 |
commit | 2378d32bb8f4b89cafeaf11ef4edbc1ef3bf583f (patch) | |
tree | fcbb898be584fc113114361b11096739976805f6 /usr.bin | |
parent | d4d927905b23d313d6c74fe7fd875f18739146f6 (diff) |
add a null compressor from canacar@ that lets gzcat work with uncompressed
files.
also introduce SMALLness that removes null and Z compressors to save floppy
space.
ok deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/compress/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/compress/compress.1 | 11 | ||||
-rw-r--r-- | usr.bin/compress/compress.h | 11 | ||||
-rw-r--r-- | usr.bin/compress/main.c | 41 |
4 files changed, 56 insertions, 11 deletions
diff --git a/usr.bin/compress/Makefile b/usr.bin/compress/Makefile index d64671934c7..f318902e7c1 100644 --- a/usr.bin/compress/Makefile +++ b/usr.bin/compress/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.18 2003/08/03 01:28:38 deraadt Exp $ +# $OpenBSD: Makefile,v 1.19 2003/09/05 04:46:35 tedu Exp $ PROG= compress -SRCS= main.c zopen.c gzopen.c +SRCS= main.c zopen.c gzopen.c nullopen.c MAN= compress.1 zmore.1 zdiff.1 zforce.1 gzexe.1 znew.1 LINKS= ${BINDIR}/compress ${BINDIR}/uncompress \ ${BINDIR}/compress ${BINDIR}/zcat \ diff --git a/usr.bin/compress/compress.1 b/usr.bin/compress/compress.1 index f97eff0fd8c..c8a651c1f26 100644 --- a/usr.bin/compress/compress.1 +++ b/usr.bin/compress/compress.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: compress.1,v 1.26 2003/08/16 23:43:06 millert Exp $ +.\" $OpenBSD: compress.1,v 1.27 2003/09/05 04:46:35 tedu Exp $ .\" $NetBSD: compress.1,v 1.5 1995/03/26 09:44:34 glass Exp $ .\" .\" Copyright (c) 1986, 1990, 1993 @@ -178,6 +178,15 @@ Force compression of .Ar file , even if it is not actually reduced in size. Additionally, files are overwritten without prompting for confirmation. +If the input data is not in a format recognized by +.Nm +and if the option +.Fl c +is also given, copy the input data without change +to the standard ouput: let +.Nm zcat +behave as +.Nm cat . .It Fl g Use deflate scheme which reportedly provides better compression rates (force .Nm gzip diff --git a/usr.bin/compress/compress.h b/usr.bin/compress/compress.h index 22671b6b436..8fc4065df23 100644 --- a/usr.bin/compress/compress.h +++ b/usr.bin/compress/compress.h @@ -1,4 +1,4 @@ -/* $OpenBSD: compress.h,v 1.6 2003/07/17 20:06:01 millert Exp $ */ +/* $OpenBSD: compress.h,v 1.7 2003/09/05 04:46:35 tedu Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -49,7 +49,8 @@ struct z_info { #define WARNING 2 extern const char main_rcsid[], z_rcsid[], gz_rcsid[], pkzip_rcsid[], - pack_rcsid[], lzh_rcsid[]; + pack_rcsid[], lzh_rcsid[], null_rcsid[]; +extern char null_magic[]; extern void *z_open(int, const char *, char *, int, u_int32_t, int); extern FILE *zopen(const char *, const char *,int); @@ -69,3 +70,9 @@ extern int lzh_read(void *, char *, int); extern int lzh_write(void *, const char *, int); extern int lzh_close(void *, struct z_info *); extern int lzh_flush(void *, int); + +extern void *null_open(int, const char *, char *, int, u_int32_t, int); +extern int null_read(void *, char *, int); +extern int null_write(void *, const char *, int); +extern int null_close(void *, struct z_info *); +extern int null_flush(void *, int); diff --git a/usr.bin/compress/main.c b/usr.bin/compress/main.c index 34970dcf22b..2303928b674 100644 --- a/usr.bin/compress/main.c +++ b/usr.bin/compress/main.c @@ -1,10 +1,11 @@ -/* $OpenBSD: main.c,v 1.44 2003/08/05 18:22:17 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.45 2003/09/05 04:46:35 tedu Exp $ */ static const char copyright[] = "@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n" "Copyright (c) 1997-2002 Michael Shalayeff\n"; +#ifndef SMALL static const char license[] = "\n" " Redistribution and use in source and binary forms, with or without\n" @@ -30,12 +31,13 @@ static const char license[] = " STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n" " IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\n" " THE POSSIBILITY OF SUCH DAMAGE.\n"; +#endif /* SMALL */ #ifndef lint #if 0 static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94"; #else -static const char main_rcsid[] = "$OpenBSD: main.c,v 1.44 2003/08/05 18:22:17 deraadt Exp $"; +static const char main_rcsid[] = "$OpenBSD: main.c,v 1.45 2003/09/05 04:46:35 tedu Exp $"; #endif #endif /* not lint */ @@ -72,10 +74,12 @@ const struct compressor { int (*write)(void *, const char *, int); int (*close)(void *, struct z_info *); } c_table[] = { -#define M_COMPRESS (&c_table[0]) - { "compress", ".Z", "\037\235", z_open, zread, zwrite, z_close }, -#define M_DEFLATE (&c_table[1]) +#define M_DEFLATE (&c_table[0]) { "deflate", ".gz", "\037\213", gz_open, gz_read, gz_write, gz_close }, +#define M_COMPRESS (&c_table[1]) +#ifndef SMALL + { "compress", ".Z", "\037\235", z_open, zread, zwrite, z_close }, +#endif /* SMALL */ #if 0 #define M_LZH (&c_table[2]) { "lzh", ".lzh", "\037\240", lzh_open, lzh_read, lzh_write, lzh_close }, @@ -87,6 +91,11 @@ const struct compressor { { NULL } }; +#ifndef SMALL +const struct compressor null_method = +{ "null", ".nul", "XX", null_open, null_read, null_write, null_close }; +#endif /* SMALL */ + int permission(const char *); void setfile(const char *, struct stat *); __dead void usage(int); @@ -102,6 +111,7 @@ void verbose_info(const char *, off_t, off_t, u_int32_t); #define OPTSTRING "123456789ab:cdfghlLnNOo:qrS:tvV" const struct option longopts[] = { +#ifndef SMALL { "ascii", no_argument, 0, 'a' }, { "stdout", no_argument, 0, 'c' }, { "to-stdout", no_argument, 0, 'c' }, @@ -121,6 +131,7 @@ const struct option longopts[] = { { "version", no_argument, 0, 'V' }, { "fast", no_argument, 0, '1' }, { "best", no_argument, 0, '9' }, +#endif /* SMALL */ { NULL } }; @@ -145,7 +156,11 @@ main(int argc, char *argv[]) bits = 6; p++; } else +#ifdef SMALL + method = M_DEFLATE; +#else method = M_COMPRESS; +#endif /* SMALL */ decomp = 0; if (!strcmp(p, "zcat")) { @@ -235,10 +250,12 @@ main(int argc, char *argv[]) case 'N': nosave = 0; break; +#ifndef SMALL case 'O': method = M_COMPRESS; strlcpy(suffix, method->suffix, sizeof(suffix)); break; +#endif /* SMALL */ case 'o': if (strlcpy(outfile, optarg, sizeof(outfile)) >= sizeof(outfile)) @@ -261,14 +278,19 @@ main(int argc, char *argv[]) break; case 'V': printf("%s\n%s\n%s\n", main_rcsid, - z_rcsid, gz_rcsid); +#ifndef SMALL + z_rcsid, +#endif + gz_rcsid); exit (0); case 'v': verbose++; break; case 'L': fputs(copyright, stderr); +#ifndef SMALL fputs(license, stderr); +#endif exit (0); case 'r': recurse++; @@ -528,6 +550,13 @@ check_method(int fd) magic[1] == method->magic[1]) return (method); } +#ifndef SMALL + if (force && cat) { + null_magic[0] = magic[0]; + null_magic[1] = magic[1]; + return (&null_method); + } +#endif /* SMALL */ return (NULL); } |