]>
git.saurik.com Git - apple/boot.git/blob - gen/rcz/rcz_decompress_mem.c
e223f492b6a3634214ae28871357b5917dc1c4aa
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
];
39 rcz_decompress_memory(unsigned char *in
, unsigned char *out
)
40 /* Returns actual number of bytes emitted as decompressed stream 'out.'
41 Note that the 'in' stream contains this byte count already.
43 Returns -1 if the input stream was not in compressed format.
46 unsigned int c
, j
, k
, jmatch
, jabove
;
47 unsigned int length
, even_length
, word
, token
, version
;
48 unsigned char *outorigin
= out
;
51 version
= (version
<<8) | (*in
++);
52 version
= (version
<<8) | (*in
++);
53 version
= (version
<<8) | (*in
++);
55 if(version
!= METHOD_17_JUL_95
) {
57 // fprintf(stderr, "Incompatible version.\n");
62 length
= (length
<<8) | (*in
++);
63 length
= (length
<<8) | (*in
++);
64 length
= (length
<<8) | (*in
++);
66 for(c
=0; c
< QLEN
; c
++) que
[c
] = c
;
67 even_length
= 2*(length
/2);
68 while((int)(out
-outorigin
) < even_length
) {
70 token
= (token
<<8) | (*in
++);
71 token
= (token
<<8) | (*in
++);
72 token
= (token
<<8) | (*in
++);
74 for(k
= 0; k
<32; k
++) {
78 /* Next, dynamically process the queue for match. */
79 jabove
= (F1
*jmatch
) >> 4;
80 for(j
= jmatch
; j
> jabove
; j
--) {
85 /* Next, dynamically process the queue for unmatch. */
87 word
= (word
<< 8) | (*in
++);
88 for(j
=QLEN
-1; j
> ABOVE
; j
--) {
93 *out
++ = (word
>> 8) & 0xff;
94 *out
++ = (word
) & 0xff;
95 if((int)(out
-outorigin
) >= even_length
) break;
99 if(even_length
!= length
) *out
++ = *in
++;