]>
git.saurik.com Git - apple/boot.git/blob - gen/rcz/rcz_decompress_file.c
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 #import "rcz_common.h"
36 static unsigned short que
[QLEN
];
40 extern int read(int fd
, char *buf
, int len
);
42 static unsigned char *buf
;
50 buf
= (unsigned char *)malloc(BUF_SIZE
);
57 static unsigned char *ptr
;
60 buf_count
= read(fd
, buf
, BUF_SIZE
);
82 unsigned int version
, length
;
86 version
= get_byte(in_fd
);
87 version
= (version
<<8) | (get_byte(in_fd
));
88 version
= (version
<<8) | (get_byte(in_fd
));
89 version
= (version
<<8) | (get_byte(in_fd
));
91 if(version
!= METHOD_17_JUL_95
) {
93 // fprintf(stderr, "Incompatible version.\n");
97 length
= get_byte(in_fd
);
98 length
= (length
<<8) | (get_byte(in_fd
));
99 length
= (length
<<8) | (get_byte(in_fd
));
100 length
= (length
<<8) | (get_byte(in_fd
));
110 /* Returns actual number of bytes emitted as decompressed stream 'out.'
111 Note that the 'in' stream contains this byte count already.
113 Returns -1 if the input stream was not in compressed format.
116 unsigned int c
, j
, k
, jmatch
, jabove
;
118 unsigned int even_length
, word
, token
, version
;
119 unsigned char *outorigin
= out
;
121 length
= rcz_file_size(in_fd
);
126 b_lseek(in_fd
, 8, 0);
127 for(c
=0; c
< QLEN
; c
++) que
[c
] = c
;
128 even_length
= 2*(length
/2);
129 while((int)(out
-outorigin
) < even_length
) {
130 token
= get_byte(in_fd
);
131 token
= (token
<<8) | (get_byte(in_fd
));
132 token
= (token
<<8) | (get_byte(in_fd
));
133 token
= (token
<<8) | (get_byte(in_fd
));
135 for(k
= 0; k
<32; k
++) {
137 jmatch
= get_byte(in_fd
);
139 /* Next, dynamically process the queue for match. */
140 jabove
= (F1
*jmatch
) >> 4;
141 for(j
= jmatch
; j
> jabove
; j
--) {
146 /* Next, dynamically process the queue for unmatch. */
147 word
= get_byte(in_fd
);
148 word
= (word
<< 8) | (get_byte(in_fd
));
149 for(j
=QLEN
-1; j
> ABOVE
; j
--) {
154 *out
++ = (word
>> 8) & 0xff;
155 *out
++ = (word
) & 0xff;
156 if((int)(out
-outorigin
) >= even_length
) break;
160 if(even_length
!= length
) *out
++ = get_byte(in_fd
);