]>
git.saurik.com Git - apple/boot.git/blob - i386/rcz/rcz_decompress_file.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 Library: compressor for executable files.
28 R. E. Crandall, July 1995
30 Copyright 1995 NeXT Computer, Inc.
35 #include "rcz_common.h"
38 static unsigned short que
[QLEN
];
42 // extern int read(int fd, char *buf, int len);
43 extern int b_lseek(int fdesc
, unsigned int addr
, int ptr
);
45 static unsigned char *buf
;
53 buf
= (unsigned char *)malloc(BUF_SIZE
);
60 static unsigned char *ptr
;
63 buf_count
= read(fd
, buf
, BUF_SIZE
);
85 unsigned int version
, length
;
89 version
= get_byte(in_fd
);
90 version
= (version
<<8) | (get_byte(in_fd
));
91 version
= (version
<<8) | (get_byte(in_fd
));
92 version
= (version
<<8) | (get_byte(in_fd
));
94 if(version
!= METHOD_17_JUL_95
) {
96 // fprintf(stderr, "Incompatible version.\n");
100 length
= get_byte(in_fd
);
101 length
= (length
<<8) | (get_byte(in_fd
));
102 length
= (length
<<8) | (get_byte(in_fd
));
103 length
= (length
<<8) | (get_byte(in_fd
));
113 /* Returns actual number of bytes emitted as decompressed stream 'out.'
114 Note that the 'in' stream contains this byte count already.
116 Returns -1 if the input stream was not in compressed format.
119 unsigned int c
, j
, k
, jmatch
, jabove
;
121 int even_length
, word
, token
;
122 unsigned char *outorigin
= out
;
124 length
= rcz_file_size(in_fd
);
129 b_lseek(in_fd
, 8, 0);
130 for(c
=0; c
< QLEN
; c
++) que
[c
] = c
;
131 even_length
= 2*(length
/2);
132 while((int)(out
-outorigin
) < even_length
) {
133 token
= get_byte(in_fd
);
134 token
= (token
<<8) | (get_byte(in_fd
));
135 token
= (token
<<8) | (get_byte(in_fd
));
136 token
= (token
<<8) | (get_byte(in_fd
));
138 for(k
= 0; k
<32; k
++) {
140 jmatch
= get_byte(in_fd
);
142 /* Next, dynamically process the queue for match. */
143 jabove
= (F1
*jmatch
) >> 4;
144 for(j
= jmatch
; j
> jabove
; j
--) {
149 /* Next, dynamically process the queue for unmatch. */
150 word
= get_byte(in_fd
);
151 word
= (word
<< 8) | (get_byte(in_fd
));
152 for(j
=QLEN
-1; j
> ABOVE
; j
--) {
157 *out
++ = (word
>> 8) & 0xff;
158 *out
++ = (word
) & 0xff;
159 if((int)(out
-outorigin
) >= even_length
) break;
163 if(even_length
!= length
) *out
++ = get_byte(in_fd
);