1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/*
Copyright 1990-2008 Light Infocon Tecnologia S/A
Este arquivo é parte do programa LightBase - Banco de Dados Textual Documental
O LightBase é um software livre; você pode redistribui-lo e/ou modifica-lo dentro
dos termos da Licença Pública Geral GNU como publicada pela Fundação do Software
Livre (FSF); na versão 2 da Licença.
Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO
EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral GNU versao 2, sob o
título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do
Software Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//
// void * ALGreenleafEngine::operator new( size_t size )
//
// ARGUMENTS:
//
// size : The number of bytes needed to create a new object.
//
// RETURNS
//
// A pointer to the newly allocated storage area, or 0 if no storage
// was available.
//
// DESCRIPTION
//
// When using a DLL, it is easy to get into a dangerous situation when
// creating objects whose ctor and dtor are both in the DLL. The problem
// arises because when you create an object using new, the memory for
// the object will be allocated from the EXE. However, when you destroy
// the object using delete, the memory is freed inside the DLL. Since
// the DLL doesn't really own that memory, bad things can happen.
//
// But, you say, won't the space just go back to the Windows heap regardless
// of who tries to free it? Maybe, but maybe not. If the DLL is using
// a subsegment allocation scheme, it might do some sort of local free
// before returning the space to the windows heap. That is the point where
// you could conceivably cook your heap.
//
// By providing our own version of operator new inside this class, we
// ensure that all memory allocation for the class will be done from
// inside the DLL, not the EXE calling the DLL.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
void AL_DLL_FAR * AL_PROTO ALGreenleafEngine::operator new
//
// ALGreenleafEngine::
// ALGreenleafEngine( short int compression_level = AL_GREENLEAF_LEVEL_2,
// short int fail_uncompressible = 0 )
//
// ARGUMENTS:
//
// compression_level : This is one of the enumerated types found in ALDEFS.H,
// namely AL_GREENLEAF_LEVEL_0 through
// AL_GREENLEAF_LEVEL_4. Level 4 gives the most
// compression, but takes up the most memory as well.
//
// fail_uncompressible : This flag is used to indicate the disposition
// of an uncompressible file. If this flag is set,
// the compression of an incompressible file will
// be interrupted, and the file will be recompressed
// using a straight copy. Note that this requires
// a Seek() operation!
//
// RETURNS
//
// Nothing, a constructor.
//
// DESCRIPTION
//
// The constructor for the Greenleaf engine has a pretty simple life. All
// it has to do is call the base class constructor, then define a couple of
// data members. This is a lightweight object until the compression
// or expansion routines are invoked, at which time the memory requirements
// go through the roof.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
AL_PROTO :
//
// ALGreenleafEngine::~ALGreenleafEngine()
//
// ARGUMENTS:
//
// None.
//
// RETURNS
//
// Nothing.
//
// DESCRIPTION
//
// The destructor for objects of this class doesn't have to do
// anything. In debug mode, we at least check for the validity
// of the object.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
AL_PROTO ALGreenleafEngine::~
//
// int ALGreenleafEngine::Compress( ALStorage &input,
// ALStorage &output )
//
// ARGUMENTS:
//
// input : A reference to the storage object that will be compressed.
//
// output : A reference to the storage object that will receive the
// compressed data.
//
// RETURNS
//
//
// AL_SUCCESS in the event of a success, an error code < AL_SUCCESS
// if a failure occurred.
//
// DESCRIPTION
//
// This is the virtual function that is called to compress data. The
// This section of code is really just a front end to the real engine,
// which is found in _RC.CPP. The first thing we do here
// is create an RCompress object, which allocates all of the
// storage we need to perform the compression. In a tight memory
// situation, that may well fail, so we check its status before moving
// on. If it succeeded, we can call the low level compression function
// to do the real work.
//
// After the compress function returns, we have to check for errors on
// any of the other objects involved in the compression, and return the
// cumulative result.
//
// If the miFailUncompressible option is set, there is always a possiblity
// that the compressor will return an indication that the file could
// not be compressed. If this is the case, we change the compression
// level in this to AL_GREENLEAF_COPY, then perform a binary copy of
// the data.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
// August 10, 1994 1.0B : Added proper support for the incompressible
// option.
int AL_PROTO
//
// int ALGreenleafEngine::Decompress( ALStorage &input,
// ALStorage &output,
// long compressed_length )
//
// ARGUMENTS:
//
// input : A reference to the storage object that will be
// expanded.
//
// output : A reference to the storage object that will receive
// the expanded data.
//
// compressed_length : A long value indicating how long the compressed
// object is. This helps to tell the decompressor
// when to quit.
// RETURNS
//
//
// AL_SUCCESS in the event of a success, an error code < AL_SUCCESS
// if a failure occurred.
//
// DESCRIPTION
//
// This is the virtual function that is called to expand a compressed
// object. This section of code is really just a front end to the real
// engine, which is found in _RE.CPP. The first thing we do here
// is create an RExpand object, which allocates all of the
// storage we need to perform the decompression. In a tight memory
// situation, that may well fail, so we check its status before moving
// on. If it succeeded, we can call the low level expansion function
// to do the real work.
//
// After the expand function returns, we have to check for errors on
// any of the other objects involved in the expansion, and return the
// cumulative result.
//
// This function now properly supports the incompressible option. When
// the type of compression is selectec, via a compression level of
// AL_GREENLEAF_COPY, we just do a straight binary copy here, instead
// of calling the actual compressor.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
int AL_PROTO
//
// int ALGreenleafEngine::WriteEngineData( ALStorage * archive )
//
// ARGUMENTS:
//
// A pointer to the storage area where the data is to be written.
//
// RETURNS
//
// AL_SUCCESS if the data was written properly, else an error code
// less than AL_SUCCESS.
//
// DESCRIPTION
//
// Every compression engine used in ArchiveLib gets the opportunity
// to store data it needs to save in order to characterize its compression
// process. The Greenleaf compression engine only needs to save a single
// integer, which contains the compression level used. This is the
// function that does so.
//
// Data like this is stored in string format, which consists of a single
// short integer describing the number of bytes in the string, followed
// by the string. We store in this portable format so that even a program
// that doesn't know about compression engines would be able to read in
// archive directory data.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
int AL_PROTO
//
// int ALGreenleafEngine::ReadEngineData( ALStorage * archive )
//
// ARGUMENTS:
//
// A pointer to the storage area where the data is to be read.
//
// RETURNS
//
// AL_SUCCESS if the data was read properly, else an error code
// less than AL_SUCCESS.
//
// DESCRIPTION
//
// Every compression engine used in ArchiveLib gets the opportunity
// to store data it needs to save in order to characterize its compression
// process. The Greenleaf compression engine only needs to save a single
// integer, which contains the compression level used.
//
// During the creation of the compression engine, this function gets called
// in order to load the engine's private data. All we do is read in
// the compression level, along with a little error checking.
//
// Data like this is stored in string format, which consists of a single
// short integer describing the number of bytes in the string, followed
// by the string. We store in this portable format so that even a program
// that doesn't know about compression engines would be able to read in
// archive directory data.
//
// REVISION HISTORY
//
// May 26, 1994 1.0A : First release
//
int AL_PROTO