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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
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
*/
/*
* class ALStorage
*
* DESCRIPTION
*
* ALStorage is a base class that defines the different types
* of storage objects used by Archive Library. The two most
* commonly used storage object types are file objects and memory
* objects, defined by the derived classes ALFile and
* ALMemory.
*
* ALStorage objects are used to store and retrieve objects from archives.
* They are also used to store and retrieve the archives themselves,
* allowing archives to be stored in files or directly in memory.
*
* The ALStorage adds buffering to the storage object, allowing for
* fast access to data presently cached in memory. This is very similar to
* the buffering provided for FILE types in stdio.h. Note that this
* buffering is generally only efficient/useful if lots of sequential
* reads or writes are being done, as opposed to random accessess.
*
* ALStorage objects give up a lot of flexibility in order to provide
* quick and efficient access to data. The primary way this affects
* use of the class is that the I/O buffer can only be used for reading
* or writing, but not both simultaneously. The class doesn't check
* for this at run time, so programmers need to enforce it themselves.
*
* When a read is initiated for the first time, the buffer is loaded up,
* and subsequent reads are performed out of the I/O buffer. To switch
* to writing mode, a call to FlushBuffer needs to be performed, which
* will reset the input and output indices. Likewise, when, done writing,
* a call to FlushBuffer() can be performed to clear the indices. A
* read can be done subsequently.
*
* DATA MEMBERS
*
* mpcBuffer : This is the I/O buffer. I read big blocks of
* data into this buffer, then I can perform
* character reads from an inline functin that
* doesn't have to access any virtual fns. Speeds
* things up tremendously. Likewise, I write
* to this buffer using inline functions until it
* it is full. Only then do I call a virtual
* to flush it to disk, memory, or whatever.
*
* muBufferValidData : This keeps track of the end of valid data,
* both when reading and writing. When re
* read in a block of data, this index is set
* to the end of the data. When writing, this
* index is continually updated to reflect the
* end of the user written data.
*
* muWriteIndex : The index in the I/O buffer where the next byte
* is going to be written.
*
* muReadIndex : The index in the I/O buffer where the next read
* will come from.
*
* mlFilePointer : The current location of the read/write pointer
* in the underlying object, e.g. a file. This
* is the location where the data will be written
* out of the I/O buffer when a FlushBuffer() call
* is made. Or, if reading, it is where the next
* LoadBuffer() will read data from.
*
* mlSize : The size of the file/object. This will ordinarily
* be set to -1 when we create an object, because
* we don't know the size yet. When you call Open()
* for an existing object, the value will usually
* be loaded using some sort of system call. We
* also can figure out what the size is when we do
* a ReadDirectory call on an archive.
*
* mlCrc32 : The CRC-32 for the object. This value normally
* won't be known until an object has been placed
* in an archive, or when the information has
* been read out using in ReadDirectory().
*
* miUpdateCrcFlag : This flag is set to indicate that we are in the
* process of calculating the CRC while the file
* is being compressed.
*
* miCreated : This flag will be set if the file was opened
* using Create(), clear if it was opened using
* Open(). When miCreated is set, we will try
* to set the file time, date and attributes when
* we close the file. This is so we can set these
* attributes when we are recreating a file that
* was stored in an archive.
*
* miStorageObjectType : An integer that is assigned when the object was
* constructed. Usually one of the enumerated
* constants found in ALDEFS.H. This is the number
* that gets stored in the Archive directory with
* the object, so we can figure out what type of
* object to create when extracting.
*
* muBufferSize : The size of the I/O buffer.
*
* mpMonitor : A pointer to the monitor attached to this object.
* During the archiving process, this pointer gets
* set by the archive routine for each storage object
* as it is being processes. A value of 0 just
* means no monitor is watching this object at the
* moment.
*
* mTimeDate : The time and date stamp for the file, this usually
* gets set when the object is opened using Open(),
* it is also set when we read in a storage object's
* information using ReadDirectory().
*
* mAttributes : The attributes associated with the file. R/H/S/A.
*
* mName : The name of the storage object.
*
* mStatus : The current status of the object.
*
* MEMBER FUNCTIONS
*
* ALStorage() : The constructor, creates the object, but doesn't
* necessarily create the file/whatever.
* operator=() : Assignment operator.
* operator new() : The memory allocation operator. This is only
* used if the library is in a DLL.
* ~ALStorage() : Virtual destructor.
* UpdateCrc() : Protected function used internally when the
* crc is being calculated
* ReadString() : Read a string in ArchiveLib's proprietary format.
* WriteStorageObjectData() : Protected function to write custom data needed
* for a particular derived classe.
* ReadStorageObjectData() : Protected function read that data back in.
* ReadChar() : Superfast inline function to read a bytee
* WriteChar() : Fast inline function to write a byte.
* ReadBuffer() : Function to read blocks of data.
* WriteBuffer() : Function to write blocks of data.
* Open() : Open() used to prepare an existing object for I/O.
* Create() : Create a new underlying object for I/O.
* Close() : Called when I/O is complete.
* LoadBuffer() : Called to reload the I/O buffer, used internally
* when ReadChar() runs out of stuff to read.
* FlushBuffer() : Called to flush the I/O buffer to the underlying
* object. Called when WriteChar() has gone too far.
* Seek() : Called to reposition the I/O pointer of the
* underlying object.
* YieldTime() : Called whenever a FlushBuffer() or LoadBuffer()
* takes place. Used to update the Monitor attached
* to the file, and to yield time to the O/S.
* Compare() : Compare two storage objects.
* InitCrc32() : Called to start calculating the CRC for an object.
* WritePortableShort() : Write 16 bit integer in little endian format.
* WritePortableLong() : Write 32 bit integer in little endian format.
* ReadPortableShort() : Read 16 bit integer in little endian format.
* ReadPortableLong() : Read 32 bit integer in little endian format.
* WriteString() : Write string in ArchiveLib format.
* Rename() : Rename the underlying object.
* UnRename() : Undo a rename operation.
* RenameToBackup() : Rename to a special backup name.
* Delete() : Delete an underlying storage object.
* GetCrc32() : Return value of the CRC member.
* GetSize() : Reeturn value of the size member.
* IsOpen() : Indicate if the file is open.
* Tell() : Indicate where the next read or write will
* take place.
* ReadCopyright() : A function to get at the Greenleaf Copyright.
*
* REVISION HISTORY
*
* May 26, 1994 1.0A : First release
*
*/
/*
* Forward declaration
*/
class AL_CLASS_TYPE ALMonitor;
class AL_CLASS_TYPE ALStorage ;
/*
* It is really important to keep these guys inline.
*/
/*
* inline int ALStorage::ReadChar()
*
* ARGUMENTS:
*
* None.
*
* RETURNS
*
* Either the next character available from the I/O buffer, or
* AL_END_OF_FILE.
*
* DESCRIPTION
*
* This is an inline function that is able to quickly do buffered I/O.
* By utilizing an I/O buffer we can make this routine very fast, since
* it doesn't have to call a virtual function. The virtual function
* only has to be called when LoadBuffer() gets called.
*
* Different compilers have different abilities to make this code inline,
* so sometimes it needs to be tinkered with. If you see anything in here
* that looks funny, that probably explains why.
*
* REVISION HISTORY
*
* May 26, 1994 1.0A : First release
*
*/
inline int AL_PROTO ALStorage::
/*
* inline int ALStorage::WriteChar( int c )
*
* ARGUMENTS:
*
* c : The character that is going to be written.
*
* RETURNS
*
* Either the character that we just wrote out, or an error < AL_SUCCESS.
*
* DESCRIPTION
*
* This is an inline function that is able to quickly do buffered I/O.
* By utilizing an I/O buffer we can make this routine very fast, since
* it doesn't have to call a virtual function. The virtual function
* only has to be called when FlushBuffer() gets called.
*
* Different compilers have different abilities to make this code inline,
* so sometimes it needs to be tinkered with. If you see anything in here
* that looks funny, that probably explains why.
*
* REVISION HISTORY
*
* May 26, 1994 1.0A : First release
*
*/
inline int AL_PROTO ALStorage::
/* #if defined( __cplusplus ) */
/* #ifndef _STOR_H */