1 " |
1 " |
2 COPYRIGHT (c) 2002 by eXept Software AG |
2 COPYRIGHT (c) 2002 by eXept Software AG |
3 All Rights Reserved |
3 All Rights Reserved |
4 |
4 |
5 This software is furnished under a license and may be used |
5 This software is furnished under a license and may be used |
6 only in accordance with the terms of that license and with the |
6 only in accordance with the terms of that license and with the |
7 inclusion of the above copyright notice. This software may not |
7 inclusion of the above copyright notice. This software may not |
8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
29 |
29 |
30 #include <stdio.h> |
30 #include <stdio.h> |
31 |
31 |
32 #ifdef WIN32 |
32 #ifdef WIN32 |
33 // sigh - bzlib.h includes windows.h, which does not like ST/X definitions |
33 // sigh - bzlib.h includes windows.h, which does not like ST/X definitions |
34 #undef Process |
34 # undef Process |
35 #undef Processor |
35 # undef Processor |
36 #undef Context |
36 # undef Context |
37 #undef Array |
37 # undef Array |
38 #undef Date |
38 # undef Date |
39 #undef Method |
39 # undef Method |
40 #undef Delay |
40 # undef Delay |
41 #undef Character |
41 # undef Character |
42 #undef String |
42 # undef String |
43 #undef Time |
43 # undef Time |
44 #undef Signal |
44 # undef Signal |
45 #undef Set |
45 # undef Set |
46 #undef Message |
46 # undef Message |
47 #undef Rectangle |
47 # undef Rectangle |
48 #undef Block |
48 # undef Block |
49 #undef Object |
49 # undef Object |
50 #undef Point |
50 # undef Point |
|
51 # undef INT |
|
52 # undef UINT |
|
53 # define NO_STDIO |
|
54 # if defined(__i386__) || defined(__x86__) |
|
55 # define _X86_ |
|
56 # endif |
51 #endif |
57 #endif |
52 |
58 |
53 #include "bzlib.h" |
59 #include "bzlib.h" |
54 |
60 |
55 #ifdef WIN32 |
61 #ifdef WIN32 |
56 #ifdef STX_Process |
62 # define INT STX_INT |
57 # define Process STX_Process |
63 # define UINT STX_UINT |
58 #endif |
64 # ifdef STX_Process |
59 #ifdef STX_Processor |
65 # define Process STX_Process |
60 # define Processor STX_Processor |
66 # endif |
61 #endif |
67 # ifdef STX_Processor |
62 #ifdef STX_Context |
68 # define Processor STX_Processor |
63 # define Context STX_Context |
69 # endif |
64 #endif |
70 # ifdef STX_Context |
65 #ifdef STX_Array |
71 # define Context STX_Context |
66 # define Array STX_Array |
72 # endif |
67 #endif |
73 # ifdef STX_Array |
68 #ifdef STX_Date |
74 # define Array STX_Array |
69 # define Date STX_Date |
75 # endif |
70 #endif |
76 # ifdef STX_Date |
71 #ifdef STX_Method |
77 # define Date STX_Date |
72 # define Method STX_Method |
78 # endif |
73 #endif |
79 # ifdef STX_Method |
74 #ifdef STX_Delay |
80 # define Method STX_Method |
75 # define Delay STX_Delay |
81 # endif |
76 #endif |
82 # ifdef STX_Delay |
77 #ifdef STX_Character |
83 # define Delay STX_Delay |
78 # define Character STX_Character |
84 # endif |
79 #endif |
85 # ifdef STX_Character |
80 #ifdef STX_String |
86 # define Character STX_Character |
81 # define String STX_String |
87 # endif |
82 #endif |
88 # ifdef STX_String |
83 #ifdef STX_Time |
89 # define String STX_String |
84 # define Time STX_Time |
90 # endif |
85 #endif |
91 # ifdef STX_Time |
86 #ifdef STX_Signal |
92 # define Time STX_Time |
87 # define Signal STX_Signal |
93 # endif |
88 #endif |
94 # ifdef STX_Signal |
89 #ifdef STX_Set |
95 # define Signal STX_Signal |
90 # define Set STX_Set |
96 # endif |
91 #endif |
97 # ifdef STX_Set |
92 #ifdef STX_Message |
98 # define Set STX_Set |
93 # define Message STX_Message |
99 # endif |
94 #endif |
100 # ifdef STX_Message |
95 #ifdef STX_Rectangle |
101 # define Message STX_Message |
96 # define Rectangle STX_Rectangle |
102 # endif |
97 #endif |
103 # ifdef STX_Rectangle |
98 #ifdef STX_Block |
104 # define Rectangle STX_Rectangle |
99 # define Block STX_Block |
105 # endif |
100 #endif |
106 # ifdef STX_Block |
101 #ifdef STX_Object |
107 # define Block STX_Block |
102 # define Object STX_Object |
108 # endif |
103 #endif |
109 # ifdef STX_Object |
104 #ifdef STX_Point |
110 # define Object STX_Object |
105 # define Point STXPoint |
111 # endif |
106 #endif |
112 # ifdef STX_Point |
|
113 # define Point STXPoint |
|
114 # endif |
107 #endif |
115 #endif |
108 |
116 |
109 typedef enum { |
117 typedef enum { |
110 e_opmode_unspecified /* processing done */ |
118 e_opmode_unspecified /* processing done */ |
111 , e_opmode_deflate /* running deflate */ |
119 , e_opmode_deflate /* running deflate */ |
127 !BZip2Stream class methodsFor:'documentation'! |
135 !BZip2Stream class methodsFor:'documentation'! |
128 |
136 |
129 copyright |
137 copyright |
130 " |
138 " |
131 COPYRIGHT (c) 2002 by eXept Software AG |
139 COPYRIGHT (c) 2002 by eXept Software AG |
132 All Rights Reserved |
140 All Rights Reserved |
133 |
141 |
134 This software is furnished under a license and may be used |
142 This software is furnished under a license and may be used |
135 only in accordance with the terms of that license and with the |
143 only in accordance with the terms of that license and with the |
136 inclusion of the above copyright notice. This software may not |
144 inclusion of the above copyright notice. This software may not |
137 be provided or otherwise made available to, or used by, any |
145 be provided or otherwise made available to, or used by, any |
174 %{ |
182 %{ |
175 OBJ _zstreamObj = __INST( zstream ); |
183 OBJ _zstreamObj = __INST( zstream ); |
176 |
184 |
177 if( _zstreamObj != nil ) |
185 if( _zstreamObj != nil ) |
178 { |
186 { |
179 int _errorNo, _action; |
187 int _errorNo, _action; |
180 unsigned int _bfsize; |
188 unsigned int _bfsize; |
181 zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
189 zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
182 |
190 |
183 if( _zstream->op_mode != e_opmode_deflate ) |
191 if( _zstream->op_mode != e_opmode_deflate ) |
184 RETURN( nil ); |
192 RETURN( nil ); |
185 |
193 |
186 _bfsize = _zstream->out_total; |
194 _bfsize = _zstream->out_total; |
187 |
195 |
188 if( _zstream->stream.state == NULL ) |
196 if( _zstream->stream.state == NULL ) |
189 { |
197 { |
190 _zstream->op_mode = e_opmode_unspecified; |
198 _zstream->op_mode = e_opmode_unspecified; |
191 RETURN( nil ); |
199 RETURN( nil ); |
192 } |
200 } |
193 _action = (__INST(hitEOF) == true) ? BZ_FINISH : BZ_RUN; |
201 _action = (__INST(hitEOF) == true) ? BZ_FINISH : BZ_RUN; |
194 |
202 |
195 _zstream->stream.avail_out = _bfsize; |
203 _zstream->stream.avail_out = _bfsize; |
196 _zstream->stream.next_out = _zstream->out_ref; |
204 _zstream->stream.next_out = _zstream->out_ref; |
197 |
205 |
198 _errorNo = BZ2_bzCompress( & _zstream->stream, _action ); |
206 _errorNo = BZ2_bzCompress( & _zstream->stream, _action ); |
199 |
207 |
200 if( _errorNo == BZ_STREAM_END ) |
208 if( _errorNo == BZ_STREAM_END ) |
201 { |
209 { |
202 _zstream->stream.avail_in = 0; |
210 _zstream->stream.avail_in = 0; |
203 _zstream->stream.next_in = NULL; |
211 _zstream->stream.next_in = NULL; |
204 _errorNo = BZ2_bzCompressEnd( & _zstream->stream ); |
212 _errorNo = BZ2_bzCompressEnd( & _zstream->stream ); |
205 } |
213 } |
206 |
214 |
207 if( (_errorNo == BZ_OK) |
215 if( (_errorNo == BZ_OK) |
208 || (_errorNo == BZ_RUN_OK) |
216 || (_errorNo == BZ_RUN_OK) |
209 || (_errorNo == BZ_FINISH_OK) |
217 || (_errorNo == BZ_FINISH_OK) |
210 ) |
218 ) |
211 { |
219 { |
212 if( (_zstream->stream.avail_out != _bfsize) |
220 if( (_zstream->stream.avail_out != _bfsize) |
213 || (_zstream->stream.avail_in != 0) |
221 || (_zstream->stream.avail_in != 0) |
214 ) |
222 ) |
215 RETURN( true ); |
223 RETURN( true ); |
216 |
224 |
217 RETURN( false ); |
225 RETURN( false ); |
218 } |
226 } |
219 errorNo = __MKSMALLINT( _errorNo ); |
227 errorNo = __MKSMALLINT( _errorNo ); |
220 } |
228 } |
221 %}. |
229 %}. |
222 errorNo ifNil:[ |
230 errorNo ifNil:[ |
223 zstream ifNil:[self errorNotOpen]. |
231 zstream ifNil:[self errorNotOpen]. |
224 self invalidArgument. |
232 self invalidArgument. |
225 ]. |
233 ]. |
226 self zerror:errorNo. |
234 self zerror:errorNo. |
227 ! |
235 ! |
228 |
236 |
229 zdeflateInit |
237 zdeflateInit |
237 %{ |
245 %{ |
238 OBJ _zstreamObj = __INST( zstream ); |
246 OBJ _zstreamObj = __INST( zstream ); |
239 |
247 |
240 if( (_zstreamObj != nil) && __bothSmallInteger(blockSize100k, workFactor) ) |
248 if( (_zstreamObj != nil) && __bothSmallInteger(blockSize100k, workFactor) ) |
241 { |
249 { |
242 int _errorNo; |
250 int _errorNo; |
243 zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
251 zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
244 |
252 |
245 _zstream->op_mode = e_opmode_deflate; |
253 _zstream->op_mode = e_opmode_deflate; |
246 |
254 |
247 _errorNo = BZ2_bzCompressInit( & _zstream->stream |
255 _errorNo = BZ2_bzCompressInit( & _zstream->stream |
248 , __intVal( blockSize100k ), 0, __intVal( workFactor ) ); |
256 , __intVal( blockSize100k ), 0, __intVal( workFactor ) ); |
249 |
257 |
250 if( _errorNo == BZ_OK ) |
258 if( _errorNo == BZ_OK ) |
251 RETURN( self ); |
259 RETURN( self ); |
252 |
260 |
253 errorNo = __MKSMALLINT( _errorNo ); |
261 errorNo = __MKSMALLINT( _errorNo ); |
254 } |
262 } |
255 %}. |
263 %}. |
256 errorNo ifNil:[ |
264 errorNo ifNil:[ |
257 zstream ifNil:[ self errorNotOpen ]. |
265 zstream ifNil:[ self errorNotOpen ]. |
258 self invalidArgument. |
266 self invalidArgument. |
259 ]. |
267 ]. |
260 self zerror:errorNo. |
268 self zerror:errorNo. |
261 ! |
269 ! |
262 |
270 |
263 zget_avail_out |
271 zget_avail_out |
404 %{ |
412 %{ |
405 OBJ _zstreamObj = __INST( zstream ); |
413 OBJ _zstreamObj = __INST( zstream ); |
406 |
414 |
407 if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
415 if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
408 { |
416 { |
409 int _count; |
417 int _count; |
410 zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
418 zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
411 |
419 |
412 if( (_count = __intVal( count )) > 0 ) |
420 if( (_count = __intVal( count )) > 0 ) |
413 { |
421 { |
414 char * _in_ref = _zstream->in_ref; |
422 char * _in_ref = _zstream->in_ref; |
415 |
423 |
416 _zstream->stream.avail_in = _count; |
424 _zstream->stream.avail_in = _count; |
417 _zstream->stream.next_in = _in_ref; |
425 _zstream->stream.next_in = _in_ref; |
418 } else { |
426 } else { |
419 _zstream->stream.avail_in = 0; |
427 _zstream->stream.avail_in = 0; |
420 _zstream->stream.next_in = NULL; |
428 _zstream->stream.next_in = NULL; |
421 } |
429 } |
422 RETURN( self ); |
430 RETURN( self ); |
423 } |
431 } |
424 %}. |
432 %}. |
425 zstream ifNil:[ self errorNotOpen ]. |
433 zstream ifNil:[ self errorNotOpen ]. |
426 self invalidArgument. |
434 self invalidArgument. |
427 ! ! |
435 ! ! |