]>
git.saurik.com Git - apple/boot.git/blob - gen/rcz/rcz_decompress_mem.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 #import "rcz_common.h"
37 static unsigned short que
[QLEN
];
40 rcz_decompress_memory(unsigned char *in
, unsigned char *out
)
41 /* Returns actual number of bytes emitted as decompressed stream 'out.'
42 Note that the 'in' stream contains this byte count already.
44 Returns -1 if the input stream was not in compressed format.
47 unsigned int c
, j
, k
, jmatch
, jabove
;
48 unsigned int length
, even_length
, word
, token
, version
;
49 unsigned char *outorigin
= out
;
52 version
= (version
<<8) | (*in
++);
53 version
= (version
<<8) | (*in
++);
54 version
= (version
<<8) | (*in
++);
56 if(version
!= METHOD_17_JUL_95
) {
58 // fprintf(stderr, "Incompatible version.\n");
63 length
= (length
<<8) | (*in
++);
64 length
= (length
<<8) | (*in
++);
65 length
= (length
<<8) | (*in
++);
67 for(c
=0; c
< QLEN
; c
++) que
[c
] = c
;
68 even_length
= 2*(length
/2);
69 while((int)(out
-outorigin
) < even_length
) {
71 token
= (token
<<8) | (*in
++);
72 token
= (token
<<8) | (*in
++);
73 token
= (token
<<8) | (*in
++);
75 for(k
= 0; k
<32; k
++) {
79 /* Next, dynamically process the queue for match. */
80 jabove
= (F1
*jmatch
) >> 4;
81 for(j
= jmatch
; j
> jabove
; j
--) {
86 /* Next, dynamically process the queue for unmatch. */
88 word
= (word
<< 8) | (*in
++);
89 for(j
=QLEN
-1; j
> ABOVE
; j
--) {
94 *out
++ = (word
>> 8) & 0xff;
95 *out
++ = (word
) & 0xff;
96 if((int)(out
-outorigin
) >= even_length
) break;
100 if(even_length
!= length
) *out
++ = *in
++;