Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
cd23eff8
Commit
cd23eff8
authored
May 29, 2003
by
Steven Cole
Committed by
Linus Torvalds
May 29, 2003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PATCH] Yet more K&R to ANSI C conversions
More K&R to ANSI C conversions for lib/zlib_deflate.
parent
18e5275f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
60 deletions
+79
-60
lib/zlib_deflate/deftree.c
lib/zlib_deflate/deftree.c
+79
-60
No files found.
lib/zlib_deflate/deftree.c
View file @
cd23eff8
...
@@ -176,10 +176,11 @@ local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
...
@@ -176,10 +176,11 @@ local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
#ifdef DEBUG_ZLIB
#ifdef DEBUG_ZLIB
local
void
send_bits
OF
((
deflate_state
*
s
,
int
value
,
int
length
));
local
void
send_bits
OF
((
deflate_state
*
s
,
int
value
,
int
length
));
local
void
send_bits
(
s
,
value
,
length
)
local
void
send_bits
(
deflate_state
*
s
;
deflate_state
*
s
,
int
value
;
/* value to send */
int
value
,
/* value to send */
int
length
;
/* number of bits */
int
length
/* number of bits */
)
{
{
Tracevv
((
stderr
,
" l %2d v %4x "
,
length
,
value
));
Tracevv
((
stderr
,
" l %2d v %4x "
,
length
,
value
));
Assert
(
length
>
0
&&
length
<=
15
,
"invalid length"
);
Assert
(
length
>
0
&&
length
<=
15
,
"invalid length"
);
...
@@ -369,10 +370,11 @@ local void init_block(s)
...
@@ -369,10 +370,11 @@ local void init_block(s)
* when the heap property is re-established (each father smaller than its
* when the heap property is re-established (each father smaller than its
* two sons).
* two sons).
*/
*/
local
void
pqdownheap
(
s
,
tree
,
k
)
local
void
pqdownheap
(
deflate_state
*
s
;
deflate_state
*
s
,
ct_data
*
tree
;
/* the tree to restore */
ct_data
*
tree
,
/* the tree to restore */
int
k
;
/* node to move down */
int
k
/* node to move down */
)
{
{
int
v
=
s
->
heap
[
k
];
int
v
=
s
->
heap
[
k
];
int
j
=
k
<<
1
;
/* left son of k */
int
j
=
k
<<
1
;
/* left son of k */
...
@@ -404,9 +406,10 @@ local void pqdownheap(s, tree, k)
...
@@ -404,9 +406,10 @@ local void pqdownheap(s, tree, k)
* The length opt_len is updated; static_len is also updated if stree is
* The length opt_len is updated; static_len is also updated if stree is
* not null.
* not null.
*/
*/
local
void
gen_bitlen
(
s
,
desc
)
local
void
gen_bitlen
(
deflate_state
*
s
;
deflate_state
*
s
,
tree_desc
*
desc
;
/* the tree descriptor */
tree_desc
*
desc
/* the tree descriptor */
)
{
{
ct_data
*
tree
=
desc
->
dyn_tree
;
ct_data
*
tree
=
desc
->
dyn_tree
;
int
max_code
=
desc
->
max_code
;
int
max_code
=
desc
->
max_code
;
...
@@ -491,10 +494,11 @@ local void gen_bitlen(s, desc)
...
@@ -491,10 +494,11 @@ local void gen_bitlen(s, desc)
* OUT assertion: the field code is set for all tree elements of non
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
* zero code length.
*/
*/
local
void
gen_codes
(
tree
,
max_code
,
bl_count
)
local
void
gen_codes
(
ct_data
*
tree
;
/* the tree to decorate */
ct_data
*
tree
,
/* the tree to decorate */
int
max_code
;
/* largest code with non zero frequency */
int
max_code
,
/* largest code with non zero frequency */
ushf
*
bl_count
;
/* number of codes at each bit length */
ushf
*
bl_count
/* number of codes at each bit length */
)
{
{
ush
next_code
[
MAX_BITS
+
1
];
/* next code value for each bit length */
ush
next_code
[
MAX_BITS
+
1
];
/* next code value for each bit length */
ush
code
=
0
;
/* running code value */
ush
code
=
0
;
/* running code value */
...
@@ -533,9 +537,10 @@ local void gen_codes (tree, max_code, bl_count)
...
@@ -533,9 +537,10 @@ local void gen_codes (tree, max_code, bl_count)
* and corresponding code. The length opt_len is updated; static_len is
* and corresponding code. The length opt_len is updated; static_len is
* also updated if stree is not null. The field max_code is set.
* also updated if stree is not null. The field max_code is set.
*/
*/
local
void
build_tree
(
s
,
desc
)
local
void
build_tree
(
deflate_state
*
s
;
deflate_state
*
s
,
tree_desc
*
desc
;
/* the tree descriptor */
tree_desc
*
desc
/* the tree descriptor */
)
{
{
ct_data
*
tree
=
desc
->
dyn_tree
;
ct_data
*
tree
=
desc
->
dyn_tree
;
const
ct_data
*
stree
=
desc
->
stat_desc
->
static_tree
;
const
ct_data
*
stree
=
desc
->
stat_desc
->
static_tree
;
...
@@ -620,10 +625,11 @@ local void build_tree(s, desc)
...
@@ -620,10 +625,11 @@ local void build_tree(s, desc)
* Scan a literal or distance tree to determine the frequencies of the codes
* Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree.
* in the bit length tree.
*/
*/
local
void
scan_tree
(
s
,
tree
,
max_code
)
local
void
scan_tree
(
deflate_state
*
s
;
deflate_state
*
s
,
ct_data
*
tree
;
/* the tree to be scanned */
ct_data
*
tree
,
/* the tree to be scanned */
int
max_code
;
/* and its largest code of non zero frequency */
int
max_code
/* and its largest code of non zero frequency */
)
{
{
int
n
;
/* iterates over all tree elements */
int
n
;
/* iterates over all tree elements */
int
prevlen
=
-
1
;
/* last emitted length */
int
prevlen
=
-
1
;
/* last emitted length */
...
@@ -665,10 +671,11 @@ local void scan_tree (s, tree, max_code)
...
@@ -665,10 +671,11 @@ local void scan_tree (s, tree, max_code)
* Send a literal or distance tree in compressed form, using the codes in
* Send a literal or distance tree in compressed form, using the codes in
* bl_tree.
* bl_tree.
*/
*/
local
void
send_tree
(
s
,
tree
,
max_code
)
local
void
send_tree
(
deflate_state
*
s
;
deflate_state
*
s
,
ct_data
*
tree
;
/* the tree to be scanned */
ct_data
*
tree
,
/* the tree to be scanned */
int
max_code
;
/* and its largest code of non zero frequency */
int
max_code
/* and its largest code of non zero frequency */
)
{
{
int
n
;
/* iterates over all tree elements */
int
n
;
/* iterates over all tree elements */
int
prevlen
=
-
1
;
/* last emitted length */
int
prevlen
=
-
1
;
/* last emitted length */
...
@@ -716,8 +723,9 @@ local void send_tree (s, tree, max_code)
...
@@ -716,8 +723,9 @@ local void send_tree (s, tree, max_code)
* Construct the Huffman tree for the bit lengths and return the index in
* Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send.
* bl_order of the last bit length code to send.
*/
*/
local
int
build_bl_tree
(
s
)
local
int
build_bl_tree
(
deflate_state
*
s
;
deflate_state
*
s
)
{
{
int
max_blindex
;
/* index of last bit length code of non zero freq */
int
max_blindex
;
/* index of last bit length code of non zero freq */
...
@@ -751,9 +759,12 @@ local int build_bl_tree(s)
...
@@ -751,9 +759,12 @@ local int build_bl_tree(s)
* lengths of the bit length codes, the literal tree and the distance tree.
* lengths of the bit length codes, the literal tree and the distance tree.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/
*/
local
void
send_all_trees
(
s
,
lcodes
,
dcodes
,
blcodes
)
local
void
send_all_trees
(
deflate_state
*
s
;
deflate_state
*
s
,
int
lcodes
,
dcodes
,
blcodes
;
/* number of codes for each tree */
int
lcodes
,
/* number of codes for each tree */
int
dcodes
,
/* number of codes for each tree */
int
blcodes
/* number of codes for each tree */
)
{
{
int
rank
;
/* index in bl_order */
int
rank
;
/* index in bl_order */
...
@@ -780,11 +791,12 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
...
@@ -780,11 +791,12 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
/* ===========================================================================
/* ===========================================================================
* Send a stored block
* Send a stored block
*/
*/
void
zlib_tr_stored_block
(
s
,
buf
,
stored_len
,
eof
)
void
zlib_tr_stored_block
(
deflate_state
*
s
;
deflate_state
*
s
,
charf
*
buf
;
/* input block */
charf
*
buf
,
/* input block */
ulg
stored_len
;
/* length of input block */
ulg
stored_len
,
/* length of input block */
int
eof
;
/* true if this is the last block for a file */
int
eof
/* true if this is the last block for a file */
)
{
{
send_bits
(
s
,
(
STORED_BLOCK
<<
1
)
+
eof
,
3
);
/* send block type */
send_bits
(
s
,
(
STORED_BLOCK
<<
1
)
+
eof
,
3
);
/* send block type */
s
->
compressed_len
=
(
s
->
compressed_len
+
3
+
7
)
&
(
ulg
)
~
7L
;
s
->
compressed_len
=
(
s
->
compressed_len
+
3
+
7
)
&
(
ulg
)
~
7L
;
...
@@ -795,8 +807,9 @@ void zlib_tr_stored_block(s, buf, stored_len, eof)
...
@@ -795,8 +807,9 @@ void zlib_tr_stored_block(s, buf, stored_len, eof)
/* Send just the `stored block' type code without any length bytes or data.
/* Send just the `stored block' type code without any length bytes or data.
*/
*/
void
zlib_tr_stored_type_only
(
s
)
void
zlib_tr_stored_type_only
(
deflate_state
*
s
;
deflate_state
*
s
)
{
{
send_bits
(
s
,
(
STORED_BLOCK
<<
1
),
3
);
send_bits
(
s
,
(
STORED_BLOCK
<<
1
),
3
);
bi_windup
(
s
);
bi_windup
(
s
);
...
@@ -815,8 +828,9 @@ void zlib_tr_stored_type_only(s)
...
@@ -815,8 +828,9 @@ void zlib_tr_stored_type_only(s)
* To simplify the code, we assume the worst case of last real code encoded
* To simplify the code, we assume the worst case of last real code encoded
* on one bit only.
* on one bit only.
*/
*/
void
zlib_tr_align
(
s
)
void
zlib_tr_align
(
deflate_state
*
s
;
deflate_state
*
s
)
{
{
send_bits
(
s
,
STATIC_TREES
<<
1
,
3
);
send_bits
(
s
,
STATIC_TREES
<<
1
,
3
);
send_code
(
s
,
END_BLOCK
,
static_ltree
);
send_code
(
s
,
END_BLOCK
,
static_ltree
);
...
@@ -841,11 +855,12 @@ void zlib_tr_align(s)
...
@@ -841,11 +855,12 @@ void zlib_tr_align(s)
* trees or store, and output the encoded block to the zip file. This function
* trees or store, and output the encoded block to the zip file. This function
* returns the total compressed length for the file so far.
* returns the total compressed length for the file so far.
*/
*/
ulg
zlib_tr_flush_block
(
s
,
buf
,
stored_len
,
eof
)
ulg
zlib_tr_flush_block
(
deflate_state
*
s
;
deflate_state
*
s
,
charf
*
buf
;
/* input block, or NULL if too old */
charf
*
buf
,
/* input block, or NULL if too old */
ulg
stored_len
;
/* length of input block */
ulg
stored_len
,
/* length of input block */
int
eof
;
/* true if this is the last block for a file */
int
eof
/* true if this is the last block for a file */
)
{
{
ulg
opt_lenb
,
static_lenb
;
/* opt_len and static_len in bytes */
ulg
opt_lenb
,
static_lenb
;
/* opt_len and static_len in bytes */
int
max_blindex
=
0
;
/* index of last bit length code of non zero freq */
int
max_blindex
=
0
;
/* index of last bit length code of non zero freq */
...
@@ -953,10 +968,11 @@ ulg zlib_tr_flush_block(s, buf, stored_len, eof)
...
@@ -953,10 +968,11 @@ ulg zlib_tr_flush_block(s, buf, stored_len, eof)
* Save the match info and tally the frequency counts. Return true if
* Save the match info and tally the frequency counts. Return true if
* the current block must be flushed.
* the current block must be flushed.
*/
*/
int
zlib_tr_tally
(
s
,
dist
,
lc
)
int
zlib_tr_tally
(
deflate_state
*
s
;
deflate_state
*
s
,
unsigned
dist
;
/* distance of matched string */
unsigned
dist
,
/* distance of matched string */
unsigned
lc
;
/* match length-MIN_MATCH or unmatched char (if dist==0) */
unsigned
lc
/* match length-MIN_MATCH or unmatched char (if dist==0) */
)
{
{
s
->
d_buf
[
s
->
last_lit
]
=
(
ush
)
dist
;
s
->
d_buf
[
s
->
last_lit
]
=
(
ush
)
dist
;
s
->
l_buf
[
s
->
last_lit
++
]
=
(
uch
)
lc
;
s
->
l_buf
[
s
->
last_lit
++
]
=
(
uch
)
lc
;
...
@@ -1001,10 +1017,11 @@ int zlib_tr_tally (s, dist, lc)
...
@@ -1001,10 +1017,11 @@ int zlib_tr_tally (s, dist, lc)
/* ===========================================================================
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
* Send the block data compressed using the given Huffman trees
*/
*/
local
void
compress_block
(
s
,
ltree
,
dtree
)
local
void
compress_block
(
deflate_state
*
s
;
deflate_state
*
s
,
ct_data
*
ltree
;
/* literal tree */
ct_data
*
ltree
,
/* literal tree */
ct_data
*
dtree
;
/* distance tree */
ct_data
*
dtree
/* distance tree */
)
{
{
unsigned
dist
;
/* distance of matched string */
unsigned
dist
;
/* distance of matched string */
int
lc
;
/* match length or unmatched char (if dist == 0) */
int
lc
;
/* match length or unmatched char (if dist == 0) */
...
@@ -1054,8 +1071,9 @@ local void compress_block(s, ltree, dtree)
...
@@ -1054,8 +1071,9 @@ local void compress_block(s, ltree, dtree)
* IN assertion: the fields freq of dyn_ltree are set and the total of all
* IN assertion: the fields freq of dyn_ltree are set and the total of all
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
*/
*/
local
void
set_data_type
(
s
)
local
void
set_data_type
(
deflate_state
*
s
;
deflate_state
*
s
)
{
{
int
n
=
0
;
int
n
=
0
;
unsigned
ascii_freq
=
0
;
unsigned
ascii_freq
=
0
;
...
@@ -1070,11 +1088,12 @@ local void set_data_type(s)
...
@@ -1070,11 +1088,12 @@ local void set_data_type(s)
* Copy a stored block, storing first the length and its
* Copy a stored block, storing first the length and its
* one's complement if requested.
* one's complement if requested.
*/
*/
local
void
copy_block
(
s
,
buf
,
len
,
header
)
local
void
copy_block
(
deflate_state
*
s
;
deflate_state
*
s
,
charf
*
buf
;
/* the input data */
charf
*
buf
,
/* the input data */
unsigned
len
;
/* its length */
unsigned
len
,
/* its length */
int
header
;
/* true if block header must be written */
int
header
/* true if block header must be written */
)
{
{
bi_windup
(
s
);
/* align on byte boundary */
bi_windup
(
s
);
/* align on byte boundary */
s
->
last_eob_len
=
8
;
/* enough lookahead for inflate */
s
->
last_eob_len
=
8
;
/* enough lookahead for inflate */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment