~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to packages/base/paszlib/zbase.pas

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Unit Zbase;
 
1
unit zbase;
2
2
 
3
3
 
4
4
{ Original:
41
41
 
42
42
{$I zconf.inc}
43
43
 
44
 
uses
45
 
  zutil;
46
 
 
47
44
{ zconf.h -- configuration of the zlib compression library }
48
45
{ zutil.c -- target dependent utility functions for the compression library }
49
46
 
69
66
 
70
67
 
71
68
{ Compile with -DMAXSEG_64K if the alloc function cannot allocate more
72
 
  than 64k bytes at a time (needed on systems with 16-bit int). }
 
69
  than 64k bytes at a time (needed on systems with 16-bit integer). }
73
70
 
74
71
{ Maximum value for memLevel in deflateInit2 }
75
72
{$ifdef MAXSEG_64K}
76
 
const
77
 
  MAX_MEM_LEVEL = 8;
78
 
  DEF_MEM_LEVEL = MAX_MEM_LEVEL;  { default memLevel }
 
73
  {$IFDEF VER70}
 
74
  const
 
75
    MAX_MEM_LEVEL = 7;
 
76
    DEF_MEM_LEVEL = MAX_MEM_LEVEL;  { default memLevel }
 
77
  {$ELSE}
 
78
  const
 
79
    MAX_MEM_LEVEL = 8;
 
80
    DEF_MEM_LEVEL = MAX_MEM_LEVEL;  { default memLevel }
 
81
  {$ENDIF}
79
82
{$else}
80
83
const
81
84
  MAX_MEM_LEVEL = 9;
84
87
 
85
88
{ Maximum value for windowBits in deflateInit2 and inflateInit2 }
86
89
const
 
90
{$IFDEF VER70}
 
91
  MAX_WBITS = 14; { 32K LZ77 window }
 
92
{$ELSE}
87
93
  MAX_WBITS = 15; { 32K LZ77 window }
 
94
{$ENDIF}
 
95
 
88
96
{ default windowBits for decompression. MAX_WBITS is for compression only }
89
97
const
90
98
  DEF_WBITS = MAX_WBITS;
91
99
 
 
100
 
 
101
type  Pbytearray=^Tbytearray;
 
102
      Pwordarray=^Twordarray;
 
103
      Pcardinalarray=^Tcardinalarray;
 
104
 
 
105
      Tbytearray = array [0..maxint div sizeof(byte)-1] of byte;
 
106
      Twordarray = array [0..maxint div sizeof(word)-1] of word;
 
107
      Tintegerarray = array [0..maxint div sizeof(integer)-1] of integer;
 
108
      Tcardinalarray = array [0..maxint div sizeof(cardinal)-1] of cardinal;
 
109
 
 
110
 
92
111
{ The memory requirements for deflate are (in bytes):
93
112
            1 shl (windowBits+2)   +  1 shl (memLevel+9)
94
113
 that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
110
129
  inflate_huft = Record
111
130
    Exop,             { number of extra bits or operation }
112
131
    bits : Byte;      { number of bits in this code or subcode }
113
 
    {pad : uInt;}       { pad structure to a power of 2 (4 bytes for }
114
 
                      {  16-bit, 8 bytes for 32-bit int's) }
115
 
    base : uInt;      { literal, length base, or distance base }
 
132
    {pad : cardinal;}       { pad structure to a power of 2 (4 bytes for }
 
133
                      {  16-bit, 8 bytes for 32-bit integer's) }
 
134
    base : cardinal;      { literal, length base, or distance base }
116
135
                      { or table offset }
117
136
  End;
118
137
 
119
138
type
120
 
  huft_field = Array[0..(MaxInt div SizeOf(inflate_huft))-1] of inflate_huft;
 
139
  huft_field = Array[0..(maxint div SizeOf(inflate_huft))-1] of inflate_huft;
121
140
  huft_ptr = ^huft_field;
122
141
type
123
142
  ppInflate_huft = ^pInflate_huft;
143
162
    mode : inflate_codes_mode;        { current inflate_codes mode }
144
163
 
145
164
    { mode dependent information }
146
 
    len : uInt;
 
165
    len : cardinal;
147
166
    sub : record                      { submode }
148
167
      Case Byte of
149
168
      0:(code : record                { if LEN or DIST, where in tree }
150
169
          tree : pInflate_huft;       { pointer into tree }
151
 
          need : uInt;                { bits needed }
 
170
          need : cardinal;                { bits needed }
152
171
         end);
153
 
      1:(lit : uInt);                 { if LIT, literal }
 
172
      1:(lit : cardinal);                 { if LIT, literal }
154
173
      2:(copy: record                 { if EXT or COPY, where and how much }
155
 
           get : uInt;                { bits to get for extra }
156
 
           dist : uInt;               { distance back to copy from }
 
174
           get : cardinal;                { bits to get for extra }
 
175
           dist : cardinal;               { distance back to copy from }
157
176
         end);
158
177
    end;
159
178
 
165
184
  end;
166
185
 
167
186
type
168
 
  check_func = function(check : uLong;
169
 
                        buf : pBytef;
 
187
  check_func = function(check : cardinal;
 
188
                        buf : Pbyte;
170
189
                        {const buf : array of byte;}
171
 
                        len : uInt) : uLong;
 
190
                        len : cardinal) : cardinal;
172
191
type
173
192
  inflate_block_mode =
174
193
     (ZTYPE,    { get type bits (3, including end bit) }
193
212
    { mode dependent information }
194
213
    sub : record                  { submode }
195
214
    case Byte of
196
 
    0:(left : uInt);              { if STORED, bytes left to copy }
 
215
    0:(left : cardinal);              { if STORED, bytes left to copy }
197
216
    1:(trees : record             { if DTREE, decoding info for trees }
198
 
        table : uInt;               { table lengths (14 bits) }
199
 
        index : uInt;               { index into blens (or border) }
200
 
        blens : PuIntArray;         { bit lengths of codes }
201
 
        bb : uInt;                  { bit length tree depth }
 
217
        table : cardinal;               { table lengths (14 bits) }
 
218
        index : cardinal;               { index into blens (or border) }
 
219
        blens : Pcardinalarray;         { bit lengths of codes }
 
220
        bb : cardinal;                  { bit length tree depth }
202
221
        tb : pInflate_huft;         { bit length decoding tree }
203
222
      end);
204
223
    2:(decode : record            { if CODES, current state }
210
229
    last : boolean;               { true if this block is the last block }
211
230
 
212
231
    { mode independent information }
213
 
    bitk : uInt;            { bits in bit buffer }
214
 
    bitb : uLong;           { bit buffer }
 
232
    bitk : cardinal;            { bits in bit buffer }
 
233
    bitb : cardinal;           { bit buffer }
215
234
    hufts : huft_ptr; {pInflate_huft;}  { single malloc for tree space }
216
 
    window : pBytef;        { sliding window }
217
 
    zend : pBytef;          { one byte after sliding window }
218
 
    read : pBytef;          { window read pointer }
219
 
    write : pBytef;         { window write pointer }
 
235
    window : Pbyte;        { sliding window }
 
236
    zend : Pbyte;          { one byte after sliding window }
 
237
    read : Pbyte;          { window read pointer }
 
238
    write : Pbyte;         { window write pointer }
220
239
    checkfn : check_func;   { check function }
221
 
    check : uLong;          { check on output }
 
240
    check : cardinal;          { check on output }
222
241
  end;
223
242
 
224
243
type
248
267
     { mode dependent information }
249
268
     sub : record          { submode }
250
269
       case byte of
251
 
       0:(method : uInt);  { if FLAGS, method byte }
 
270
       0:(method : cardinal);  { if FLAGS, method byte }
252
271
       1:(check : record   { if CHECK, check values to compare }
253
 
           was : uLong;        { computed check value }
254
 
           need : uLong;       { stream check value }
 
272
           was : cardinal;        { computed check value }
 
273
           need : cardinal;       { stream check value }
255
274
          end);
256
 
       2:(marker : uInt);  { if BAD, inflateSync's marker bytes count }
 
275
       2:(marker : cardinal);  { if BAD, inflateSync's marker bytes count }
257
276
     end;
258
277
 
259
278
     { mode independent information }
260
279
     nowrap : boolean;      { flag for no wrapper }
261
 
     wbits : uInt;          { log2(window size)  (8..15, defaults to 15) }
 
280
     wbits : cardinal;          { log2(window size)  (8..15, defaults to 15) }
262
281
     blocks : pInflate_blocks_state;    { current inflate_blocks state }
263
282
   end;
264
283
 
265
284
type
266
 
  alloc_func = function(opaque : voidpf; items : uInt; size : uInt) : voidpf;
267
 
  free_func = procedure(opaque : voidpf; address : voidpf);
 
285
  alloc_func = function(opaque : pointer; items : cardinal; size : cardinal) : pointer;
 
286
  free_func = procedure(opaque : pointer; address : pointer);
268
287
 
269
288
type
270
289
  z_streamp = ^z_stream;
271
290
  z_stream = record
272
 
    next_in : pBytef;     { next input byte }
273
 
    avail_in : uInt;      { number of bytes available at next_in }
274
 
    total_in : uLong;     { total nb of input bytes read so far }
275
 
 
276
 
    next_out : pBytef;    { next output byte should be put there }
277
 
    avail_out : uInt;     { remaining free space at next_out }
278
 
    total_out : uLong;    { total nb of bytes output so far }
279
 
 
280
 
    msg : string;         { last error message, '' if no error }
 
291
    next_in : Pbyte;     { next input byte }
 
292
    avail_in : cardinal;      { number of bytes available at next_in }
 
293
    total_in : cardinal;     { total nb of input bytes read so far }
 
294
 
 
295
    next_out : Pbyte;    { next output byte should be put there }
 
296
    avail_out : cardinal;     { remaining free space at next_out }
 
297
    total_out : cardinal;    { total nb of bytes output so far }
 
298
 
 
299
    msg : string[255];         { last error message, '' if no error }
281
300
    state : pInternal_state; { not visible by applications }
282
301
 
283
 
    zalloc : alloc_func;  { used to allocate the internal state }
284
 
    zfree : free_func;    { used to free the internal state }
285
 
    opaque : voidpf;      { private data object passed to zalloc and zfree }
286
 
 
287
 
    data_type : int;      { best guess about the data type: ascii or binary }
288
 
    adler : uLong;        { adler32 value of the uncompressed data }
289
 
    reserved : uLong;     { reserved for future use }
 
302
    data_type : integer;      { best guess about the data type: ascii or binary }
 
303
    adler : cardinal;        { adler32 value of the uncompressed data }
 
304
    reserved : cardinal;     { reserved for future use }
290
305
  end;
291
 
{$ifdef fpc}
292
 
  TZStream = z_stream;
293
 
  PZStream = ^TZStream;
294
 
{$endif}
 
306
 
295
307
 
296
308
{  The application must update next_in and avail_in when avail_in has
297
309
   dropped to zero. It must update next_out and avail_out when avail_out
363
375
 
364
376
  {$IFDEF GZIO}
365
377
var
366
 
  errno : int;
 
378
  errno : integer;
367
379
  {$ENDIF}
368
380
 
369
381
        { common constants }
387
399
  PRESET_DICT = $20; { preset dictionary flag in zlib header }
388
400
 
389
401
 
390
 
  {$IFDEF DEBUG}
 
402
  {$IFDEF ZLIB_DEBUG}
391
403
  procedure Assert(cond : boolean; msg : string);
392
404
  {$ENDIF}
393
405
 
404
416
  not compatible with the zlib.h header file used by the application.
405
417
  This check is automatically made by deflateInit and inflateInit. }
406
418
 
407
 
function zError(err : int) : string;
408
 
 
409
 
function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;
410
 
 
411
 
procedure ZFREE (var strm : z_stream; ptr : voidpf);
412
 
 
413
 
procedure TRY_FREE (var strm : z_stream; ptr : voidpf);
 
419
function zError(err : integer) : string;
 
420
 
 
421
function ZALLOC (var strm : z_stream; items : cardinal; size : cardinal) : pointer;
 
422
 
 
423
procedure ZFREE (var strm : z_stream; ptr : pointer);
 
424
 
 
425
procedure TRY_FREE (var strm : z_stream; ptr : pointer);
414
426
 
415
427
const
416
428
  ZLIB_VERSION : string[10] = '1.1.2';
429
441
            'incompatible version',{ Z_VERSION_ERROR (-6) }
430
442
            '');
431
443
const
432
 
  z_verbose : int = 1;
 
444
  z_verbose : integer = 1;
433
445
 
434
 
{$IFDEF DEBUG}
 
446
{$IFDEF ZLIB_DEBUG}
435
447
procedure z_error (m : string);
436
448
{$ENDIF}
437
449
 
438
450
implementation
439
451
 
440
 
function zError(err : int) : string;
 
452
function zError(err : integer) : string;
441
453
begin
442
454
  zError := z_errmsg[Z_NEED_DICT-err];
443
455
end;
496
508
    WriteLn(x);
497
509
end;
498
510
 
499
 
function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;
500
 
begin
501
 
  ZALLOC := strm.zalloc(strm.opaque, items, size);
502
 
end;
503
 
 
504
 
procedure ZFREE (var strm : z_stream; ptr : voidpf);
505
 
begin
506
 
  strm.zfree(strm.opaque, ptr);
507
 
end;
508
 
 
509
 
procedure TRY_FREE (var strm : z_stream; ptr : voidpf);
510
 
begin
511
 
  {if @strm <> Z_NULL then}
512
 
    strm.zfree(strm.opaque, ptr);
513
 
end;
514
 
 
515
 
end.
 
511
function ZALLOC (var strm : z_stream; items : cardinal; size : cardinal) : pointer;
 
512
begin
 
513
  getmem(ZALLOC,items*size);
 
514
end;
 
515
 
 
516
procedure ZFREE (var strm : z_stream; ptr : pointer);
 
517
begin
 
518
  freemem(ptr);
 
519
end;
 
520
 
 
521
procedure TRY_FREE (var strm : z_stream; ptr : pointer);
 
522
begin
 
523
  freemem(ptr);
 
524
end;
 
525
 
 
526
end.
 
 
b'\\ No newline at end of file'