Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/dss-compress.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2002-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
/*
23
* compress query
24
*/
25
26
static const char compress_usage[] =
27
"[-1ls5P?\n@(#)$Id: dss compress query (AT&T Research) 2003-05-05 $\n]"
28
USAGE_LICENSE
29
"[+PLUGIN?\findex\f]"
30
"[+DESCRIPTION?The \bdss\b \bcompress\b query compresses the parent output"
31
" stream according to \amethod\a. If \amethod\a is omitted then"
32
" the method preferred compression, if specified, is used, otherwise"
33
" \bgzip\b is assumed. The methods are:]{"
34
" [+bzip?\bbzip\b(1) (a.k.a. bzip2) compression using the"
35
" \bsfdcbzip\b(3) discipline for \b-lbz\b.]"
36
" [+gzip?\bgzip\b(1) compression using the \bsfdcgzip\b(3)"
37
" discipline for \b-lz\b.]"
38
" [+lzw?\bcompress\b(1) LZW compression using the \bsfdclzw\b(3)"
39
" discipline.]"
40
" [+pzip?\bpzip\b(1) compression using the \bsfdcpzip\b(3)"
41
" discipline for \b-lpz\b. \aoperand\a must specify"
42
" the \bpzip\b(1) partition file.]"
43
"}"
44
"\n"
45
"\n[ method [ operand ] ]\n"
46
"\n"
47
;
48
49
static int
50
compress_beg(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
51
{
52
char** argv = (char**)data;
53
int errors = error_info.errors;
54
char* meth;
55
56
for (;;)
57
{
58
switch (optget(argv, compress_usage))
59
{
60
case '?':
61
if (disc->errorf)
62
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", opt_info.arg);
63
continue;
64
case ':':
65
if (disc->errorf)
66
(*disc->errorf)(NiL, disc, 2, "%s", opt_info.arg);
67
continue;
68
}
69
break;
70
}
71
if (error_info.errors > errors)
72
return -1;
73
argv += opt_info.index;
74
if (expr->pass || expr->fail || expr->parent->pass != expr)
75
{
76
if (disc->errorf)
77
(*disc->errorf)(NiL, disc, 2, "can only compress parent output stream");
78
return -1;
79
}
80
expr->parent->pass = 0;
81
if (expr->parent->op != expr->op)
82
{
83
if (expr->parent->op != sfstdout)
84
sfclose(expr->parent->op);
85
expr->parent->op = expr->op;
86
}
87
if (!(meth = *argv))
88
sfdisc(expr->op, &dssstate(disc)->compress_preferred);
89
else
90
{
91
if (*++argv)
92
{
93
sfprintf(cx->buf, "%s", meth);
94
while (meth = *argv++)
95
sfprintf(cx->buf, " %s", meth);
96
if (!(meth = sfstruse(cx->buf)))
97
return -1;
98
}
99
if (sfdczip(expr->op, expr->file, meth, disc->errorf) < 0)
100
return -1;
101
}
102
return 0;
103
}
104
105
#define QUERY_compress \
106
{ \
107
"compress", \
108
"compress parent output stream", \
109
CXH, \
110
compress_beg, \
111
0, \
112
0, \
113
0 \
114
}
115
116