line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
typedef struct { |
2
|
|
|
|
|
|
|
/* Gzip, zlib or libdeflate. */ |
3
|
|
|
|
|
|
|
int type; |
4
|
|
|
|
|
|
|
/* See zopfli.h. */ |
5
|
|
|
|
|
|
|
ZopfliOptions options; |
6
|
|
|
|
|
|
|
unsigned int no_warn : 1; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
gzip_zopfli_t; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
void |
11
|
3
|
|
|
|
|
|
gzip_zopfli_init (gzip_zopfli_t * gz) |
12
|
|
|
|
|
|
|
{ |
13
|
3
|
|
|
|
|
|
gz->type = ZOPFLI_FORMAT_GZIP; |
14
|
3
|
|
|
|
|
|
ZopfliInitOptions (& gz->options); |
15
|
3
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#define CMP(x, y) strlen(#y) == x ## _len && strcmp(#y, x) == 0 |
18
|
|
|
|
|
|
|
#define TYPE(x) strlen (#x) == type_len && strcmp (#x, type) == 0 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
static void |
21
|
2
|
|
|
|
|
|
gzip_zopfli_set (gzip_zopfli_t * gz, SV * key_sv, SV * value) |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
char * key; |
24
|
|
|
|
|
|
|
STRLEN key_len; |
25
|
2
|
50
|
|
|
|
|
key = SvPV (key_sv, key_len); |
26
|
|
|
|
|
|
|
|
27
|
2
|
50
|
|
|
|
|
if (CMP(key, no_warn)) { |
|
|
0
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (SvTRUE (value)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
gz->no_warn = 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
0
|
|
|
|
|
|
gz->no_warn = 0; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
2
|
50
|
|
|
|
|
if (CMP(key, numiterations)) { |
|
|
0
|
|
|
|
|
|
38
|
|
|
|
|
|
|
int n; |
39
|
0
|
0
|
|
|
|
|
if (! SvIOK (value)) { |
40
|
0
|
|
|
|
|
|
warn ("numiterations requires a number"); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
0
|
|
|
|
|
n = SvIV (value); |
43
|
|
|
|
|
|
|
// Check values |
44
|
0
|
|
|
|
|
|
gz->options.numiterations = n; |
45
|
0
|
|
|
|
|
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
2
|
50
|
|
|
|
|
if (CMP (key, blocksplitting)) { |
|
|
0
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
gz->options.blocksplitting = SvTRUE (value); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
2
|
50
|
|
|
|
|
if (CMP (key, blocksplittingmax)) { |
|
|
0
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (! SvIOK (value)) { |
53
|
0
|
|
|
|
|
|
warn ("blocksplittingmax requires a number"); |
54
|
|
|
|
|
|
|
} |
55
|
0
|
0
|
|
|
|
|
gz->options.blocksplittingmax = SvIV (value); |
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
2
|
100
|
|
|
|
|
if (CMP (key, type)) { |
|
|
50
|
|
|
|
|
|
59
|
|
|
|
|
|
|
char * type; |
60
|
|
|
|
|
|
|
STRLEN type_len; |
61
|
1
|
50
|
|
|
|
|
type = SvPV (value, type_len); |
62
|
1
|
50
|
|
|
|
|
if (TYPE(gzip)) { |
|
|
0
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
gz->type = ZOPFLI_FORMAT_GZIP; |
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
1
|
50
|
|
|
|
|
if (TYPE(deflate)) { |
|
|
50
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
gz->type = ZOPFLI_FORMAT_DEFLATE; |
68
|
0
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
1
|
50
|
|
|
|
|
if (TYPE(zlib)) { |
|
|
0
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
gz->type = ZOPFLI_FORMAT_ZLIB; |
72
|
0
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
1
|
|
|
|
|
|
warn ("Unknown compression type '%s'", type); |
75
|
1
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
1
|
50
|
|
|
|
|
if (! gz->no_warn) { |
78
|
1
|
|
|
|
|
|
warn ("Unknown option '%s'", key); |
79
|
|
|
|
|
|
|
} |
80
|
2
|
|
|
|
|
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#undef CMP |
84
|
|
|
|
|
|
|
#undef TYPE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
SV * |
87
|
3
|
|
|
|
|
|
gzip_zopfli (gzip_zopfli_t * gz, SV * in_sv) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
SV * out_sv; |
90
|
|
|
|
|
|
|
const unsigned char * in; |
91
|
|
|
|
|
|
|
STRLEN inl; |
92
|
|
|
|
|
|
|
unsigned char * out; |
93
|
|
|
|
|
|
|
size_t out_size; |
94
|
3
|
50
|
|
|
|
|
in = (const unsigned char *) SvPV(in_sv, inl); |
95
|
3
|
|
|
|
|
|
out = 0; |
96
|
3
|
|
|
|
|
|
out_size = 0; |
97
|
3
|
|
|
|
|
|
ZopfliCompress(& gz->options, gz->type, |
98
|
|
|
|
|
|
|
in, (size_t) inl, |
99
|
|
|
|
|
|
|
& out, & out_size); |
100
|
3
|
|
|
|
|
|
out_sv = newSVpv ((const char *) out, out_size); |
101
|
3
|
|
|
|
|
|
return out_sv; |
102
|
|
|
|
|
|
|
} |