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