]>
git.saurik.com Git - apple/boot.git/blob - i386/rcz/rcz_decompress_file.c
ad3485c4deaf32d6769d7d94e5d8e334cacbc542
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 Library: compressor for executable files.
27 R. E. Crandall, July 1995
29 Copyright 1995 NeXT Computer, Inc.
34 #include "rcz_common.h"
37 static unsigned short que
[QLEN
];
41 // extern int read(int fd, char *buf, int len);
42 extern int b_lseek(int fdesc
, unsigned int addr
, int ptr
);
44 static unsigned char *buf
;
52 buf
= (unsigned char *)malloc(BUF_SIZE
);
59 static unsigned char *ptr
;
62 buf_count
= read(fd
, buf
, BUF_SIZE
);
84 unsigned int version
, length
;
88 version
= get_byte(in_fd
);
89 version
= (version
<<8) | (get_byte(in_fd
));
90 version
= (version
<<8) | (get_byte(in_fd
));
91 version
= (version
<<8) | (get_byte(in_fd
));
93 if(version
!= METHOD_17_JUL_95
) {
95 // fprintf(stderr, "Incompatible version.\n");
99 length
= get_byte(in_fd
);
100 length
= (length
<<8) | (get_byte(in_fd
));
101 length
= (length
<<8) | (get_byte(in_fd
));
102 length
= (length
<<8) | (get_byte(in_fd
));
112 /* Returns actual number of bytes emitted as decompressed stream 'out.'
113 Note that the 'in' stream contains this byte count already.
115 Returns -1 if the input stream was not in compressed format.
118 unsigned int c
, j
, k
, jmatch
, jabove
;
120 int even_length
, word
, token
;
121 unsigned char *outorigin
= out
;
123 length
= rcz_file_size(in_fd
);
128 b_lseek(in_fd
, 8, 0);
129 for(c
=0; c
< QLEN
; c
++) que
[c
] = c
;
130 even_length
= 2*(length
/2);
131 while((int)(out
-outorigin
) < even_length
) {
132 token
= get_byte(in_fd
);
133 token
= (token
<<8) | (get_byte(in_fd
));
134 token
= (token
<<8) | (get_byte(in_fd
));
135 token
= (token
<<8) | (get_byte(in_fd
));
137 for(k
= 0; k
<32; k
++) {
139 jmatch
= get_byte(in_fd
);
141 /* Next, dynamically process the queue for match. */
142 jabove
= (F1
*jmatch
) >> 4;
143 for(j
= jmatch
; j
> jabove
; j
--) {
148 /* Next, dynamically process the queue for unmatch. */
149 word
= get_byte(in_fd
);
150 word
= (word
<< 8) | (get_byte(in_fd
));
151 for(j
=QLEN
-1; j
> ABOVE
; j
--) {
156 *out
++ = (word
>> 8) & 0xff;
157 *out
++ = (word
) & 0xff;
158 if((int)(out
-outorigin
) >= even_length
) break;
162 if(even_length
!= length
) *out
++ = get_byte(in_fd
);