Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/pzip/funzip.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1998-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
#include <ast.h>
23
#include <error.h>
24
#include <sfdcgzip.h>
25
26
static const char usage[] =
27
"[-?\n@(#)$Id: funzip (AT&T Research) 1998-08-11 $\n]"
28
USAGE_LICENSE
29
"[+NAME?funzip - fast gunzip]"
30
"[+DESCRIPTION?\bfunzip\b decompresses \bgzip\b(1) compressed files."
31
" By default \bgzip\b crc32 cyclic redundancy checking is disabled."
32
" This may speed up decompression by 25% or more over \bgunzip\b(1)."
33
" Most data corruption errors are still caught even with crc disabled.]"
34
35
"[x:crc?Enable \agzip\a crc32 cyclic redundancy checking for decompress."
36
" On some systems this can double the execution wall time."
37
" Most data corruption errors are still caught even with \bnocrc\b.]"
38
39
"\n"
40
"\n[ file ]\n"
41
"\n"
42
43
"[+SEE ALSO?\bgzip\b(1), \bgunzip\b(1), \blibz\b(3)]"
44
;
45
46
int
47
main(int argc, char** argv)
48
{
49
Sfio_t* sp;
50
char* file;
51
int r;
52
53
int flags = SFGZ_NOCRC;
54
55
error_info.id = "funzip";
56
for (;;)
57
{
58
switch (optget(argv, usage))
59
{
60
case 'x':
61
flags &= ~SFGZ_NOCRC;
62
continue;
63
case '?':
64
error(ERROR_USAGE|4, "%s", opt_info.arg);
65
continue;
66
case ':':
67
error(2, "%s", opt_info.arg);
68
continue;
69
}
70
break;
71
}
72
argv += opt_info.index;
73
if (error_info.errors || *argv && *(argv + 1))
74
error(ERROR_USAGE|4, "%s", optusage(NiL));
75
if (!(file = *argv))
76
{
77
file = "/dev/stdin";
78
sp = sfstdin;
79
}
80
else if (!(sp = sfopen(NiL, file, "r")))
81
error(ERROR_SYSTEM|3, "%s: cannot read", file);
82
if ((r = sfdcgzip(sp, flags)) < 0)
83
error(3, "sfdcgzip discipline push error");
84
else if (!r)
85
error(3, "input not a gzip file");
86
if (sfmove(sp, sfstdout, SF_UNBOUND, -1) < 0 || sfsync(sfstdout))
87
error(ERROR_SYSTEM|3, "sfdcgzip io error");
88
return 0;
89
}
90
91