diff options
Diffstat (limited to 'minigzip.c')
-rw-r--r-- | minigzip.c | 46 |
1 files changed, 31 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* minigzip.c -- simulate gzip using the zlib compression library | 1 | /* minigzip.c -- simulate gzip using the zlib compression library |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995-1998 Jean-loup Gailly. |
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -13,7 +13,7 @@ | |||
13 | * or in pipe mode. | 13 | * or in pipe mode. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | /* $Id: minigzip.c,v 1.10 1996/07/24 13:41:04 me Exp $ */ | 16 | /* @(#) $Id$ */ |
17 | 17 | ||
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include "zlib.h" | 19 | #include "zlib.h" |
@@ -47,18 +47,19 @@ | |||
47 | #ifndef GZ_SUFFIX | 47 | #ifndef GZ_SUFFIX |
48 | # define GZ_SUFFIX ".gz" | 48 | # define GZ_SUFFIX ".gz" |
49 | #endif | 49 | #endif |
50 | #define SUFFIX_LEN sizeof(GZ_SUFFIX) | 50 | #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) |
51 | 51 | ||
52 | extern int unlink OF((const char *)); | 52 | extern int unlink OF((const char *)); |
53 | 53 | ||
54 | #define BUFLEN 4096 | 54 | #define BUFLEN 4096 |
55 | #define MAX_NAME_LEN 1024 | 55 | #define MAX_NAME_LEN 1024 |
56 | 56 | ||
57 | #define local static | 57 | #ifdef MAXSEG_64K |
58 | /* For MSDOS and other systems with limitation on stack size. For Unix, | 58 | # define local static |
59 | #define local | 59 | /* Needed for systems with limitation on stack size. */ |
60 | works also. | 60 | #else |
61 | */ | 61 | # define local |
62 | #endif | ||
62 | 63 | ||
63 | char *prog; | 64 | char *prog; |
64 | 65 | ||
@@ -201,7 +202,11 @@ void file_uncompress(file) | |||
201 | 202 | ||
202 | 203 | ||
203 | /* =========================================================================== | 204 | /* =========================================================================== |
204 | * Usage: minigzip [-d] [files...] | 205 | * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...] |
206 | * -d : decompress | ||
207 | * -f : compress with Z_FILTERED | ||
208 | * -h : compress with Z_HUFFMAN_ONLY | ||
209 | * -1 to -9 : compression level | ||
205 | */ | 210 | */ |
206 | 211 | ||
207 | int main(argc, argv) | 212 | int main(argc, argv) |
@@ -210,15 +215,26 @@ int main(argc, argv) | |||
210 | { | 215 | { |
211 | int uncompr = 0; | 216 | int uncompr = 0; |
212 | gzFile file; | 217 | gzFile file; |
218 | char outmode[20]; | ||
219 | |||
220 | strcpy(outmode, "wb6 "); | ||
213 | 221 | ||
214 | prog = argv[0]; | 222 | prog = argv[0]; |
215 | argc--, argv++; | 223 | argc--, argv++; |
216 | 224 | ||
217 | if (argc > 0) { | 225 | while (argc > 0) { |
218 | uncompr = (strcmp(*argv, "-d") == 0); | 226 | if (strcmp(*argv, "-d") == 0) |
219 | if (uncompr) { | 227 | uncompr = 1; |
220 | argc--, argv++; | 228 | else if (strcmp(*argv, "-f") == 0) |
221 | } | 229 | outmode[3] = 'f'; |
230 | else if (strcmp(*argv, "-h") == 0) | ||
231 | outmode[3] = 'h'; | ||
232 | else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && | ||
233 | (*argv)[2] == 0) | ||
234 | outmode[2] = (*argv)[1]; | ||
235 | else | ||
236 | break; | ||
237 | argc--, argv++; | ||
222 | } | 238 | } |
223 | if (argc == 0) { | 239 | if (argc == 0) { |
224 | SET_BINARY_MODE(stdin); | 240 | SET_BINARY_MODE(stdin); |
@@ -228,7 +244,7 @@ int main(argc, argv) | |||
228 | if (file == NULL) error("can't gzdopen stdin"); | 244 | if (file == NULL) error("can't gzdopen stdin"); |
229 | gz_uncompress(file, stdout); | 245 | gz_uncompress(file, stdout); |
230 | } else { | 246 | } else { |
231 | file = gzdopen(fileno(stdout), "wb"); /* "wb9" for max compr. */ | 247 | file = gzdopen(fileno(stdout), outmode); |
232 | if (file == NULL) error("can't gzdopen stdout"); | 248 | if (file == NULL) error("can't gzdopen stdout"); |
233 | gz_compress(stdin, file); | 249 | gz_compress(stdin, file); |
234 | } | 250 | } |