]>
Commit | Line | Data |
---|---|---|
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 | ||
50 | version = *in++; | |
51 | version = (version<<8) | (*in++); | |
52 | version = (version<<8) | (*in++); | |
53 | version = (version<<8) | (*in++); | |
54 | ||
55 | if(version != METHOD_17_JUL_95) { | |
56 | return (-1); | |
57 | // fprintf(stderr, "Incompatible version.\n"); | |
58 | // return(0); | |
59 | } | |
60 | ||
61 | length = *in++; | |
62 | length = (length<<8) | (*in++); | |
63 | length = (length<<8) | (*in++); | |
64 | length = (length<<8) | (*in++); | |
65 | ||
66 | for(c=0; c < QLEN; c++) que[c] = c; | |
67 | even_length = 2*(length/2); | |
68 | while((int)(out-outorigin) < even_length) { | |
69 | token = *in++; | |
70 | token = (token<<8) | (*in++); | |
71 | token = (token<<8) | (*in++); | |
72 | token = (token<<8) | (*in++); | |
73 | c = 1<<31; | |
74 | for(k = 0; k<32; k++) { | |
75 | if(c & token) { | |
76 | jmatch = *in++; | |
77 | word = que[jmatch]; | |
78 | /* Next, dynamically process the queue for match. */ | |
79 | jabove = (F1*jmatch) >> 4; | |
80 | for(j = jmatch; j > jabove; j--) { | |
81 | que[j] = que[j-1]; | |
82 | } | |
83 | que[jabove] = word; | |
84 | } else { | |
85 | /* Next, dynamically process the queue for unmatch. */ | |
86 | word = *in++; | |
87 | word = (word << 8) | (*in++); | |
88 | for(j=QLEN-1; j > ABOVE; j--) { | |
89 | que[j] = que[j-1]; | |
90 | } | |
91 | que[ABOVE] = word; | |
92 | } | |
93 | *out++ = (word >> 8) & 0xff; | |
94 | *out++ = (word) & 0xff; | |
95 | if((int)(out-outorigin) >= even_length) break; | |
96 | c >>= 1; | |
97 | } | |
98 | } | |
99 | if(even_length != length) *out++ = *in++; | |
100 | return(length); | |
101 | } |