]>
Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
12 | * this file. | |
13 | * | |
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 | |
20 | * under the License. | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | Library: compressor for executable files. | |
26 | ||
27 | R. E. Crandall, July 1995 | |
28 | ||
29 | Copyright 1995 NeXT Computer, Inc. | |
30 | All rights reserved. | |
31 | ||
32 | */ | |
33 | ||
34 | #import "rcz_common.h" | |
35 | ||
36 | static unsigned short que[QLEN]; | |
37 | ||
38 | unsigned int | |
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. | |
42 | ||
43 | Returns -1 if the input stream was not in compressed format. | |
44 | */ | |
45 | { | |
46 | unsigned int c, j, k, jmatch, jabove; | |
47 | unsigned int length, even_length, word, token, version; | |
48 | unsigned char *outorigin = out; | |
49 | int *a, *b; | |
50 | ||
51 | version = *in++; | |
52 | version = (version<<8) | (*in++); | |
53 | version = (version<<8) | (*in++); | |
54 | version = (version<<8) | (*in++); | |
55 | ||
56 | if(version != METHOD_17_JUL_95) { | |
57 | return (-1); | |
58 | // fprintf(stderr, "Incompatible version.\n"); | |
59 | // return(0); | |
60 | } | |
61 | ||
62 | length = *in++; | |
63 | length = (length<<8) | (*in++); | |
64 | length = (length<<8) | (*in++); | |
65 | length = (length<<8) | (*in++); | |
66 | ||
67 | for(c=0; c < QLEN; c++) que[c] = c; | |
68 | even_length = 2*(length/2); | |
69 | while((int)(out-outorigin) < even_length) { | |
70 | token = *in++; | |
71 | token = (token<<8) | (*in++); | |
72 | token = (token<<8) | (*in++); | |
73 | token = (token<<8) | (*in++); | |
74 | c = 1<<31; | |
75 | for(k = 0; k<32; k++) { | |
76 | if(c & token) { | |
77 | jmatch = *in++; | |
78 | word = que[jmatch]; | |
79 | /* Next, dynamically process the queue for match. */ | |
80 | jabove = (F1*jmatch) >> 4; | |
81 | for(j = jmatch; j > jabove; j--) { | |
82 | que[j] = que[j-1]; | |
83 | } | |
84 | que[jabove] = word; | |
85 | } else { | |
86 | /* Next, dynamically process the queue for unmatch. */ | |
87 | word = *in++; | |
88 | word = (word << 8) | (*in++); | |
89 | for(j=QLEN-1; j > ABOVE; j--) { | |
90 | que[j] = que[j-1]; | |
91 | } | |
92 | que[ABOVE] = word; | |
93 | } | |
94 | *out++ = (word >> 8) & 0xff; | |
95 | *out++ = (word) & 0xff; | |
96 | if((int)(out-outorigin) >= even_length) break; | |
97 | c >>= 1; | |
98 | } | |
99 | } | |
100 | if(even_length != length) *out++ = *in++; | |
101 | return(length); | |
102 | } |