Ver código fonte

* Replace C types with native Pascal types
* Avoid sysutils overhead

git-svn-id: trunk@1843 -

daniel 19 anos atrás
pai
commit
4e4099e835

+ 9 - 9
packages/base/paszlib/adler.pas

@@ -1,4 +1,4 @@
-Unit Adler;
+unit adler;
 
 {
   adler32.c -- compute the Adler-32 checksum of a data stream
@@ -16,7 +16,7 @@ interface
 uses
   zutil;
 
-function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong;
+function adler32(adler : cardinal; buf : Pbyte; len : cardinal) : cardinal;
 
 {    Update a running Adler-32 checksum with the bytes buf[0..len-1] and
    return the updated checksum. If buf is NIL, this function returns
@@ -25,9 +25,9 @@ function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong;
    much faster. Usage example:
 
    var
-     adler : uLong;
+     adler : cardinal;
    begin
-     adler := adler32(0, Z_NULL, 0);
+     adler := adler32(0, nil, 0);
 
      while (read_buffer(buffer, length) <> EOF) do
        adler := adler32(adler, buffer, length);
@@ -40,7 +40,7 @@ function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong;
 implementation
 
 const
-  BASE = uLong(65521); { largest prime smaller than 65536 }
+  BASE = cardinal(65521); { largest prime smaller than 65536 }
   {NMAX = 5552; original code with unsigned 32 bit integer }
   { NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 }
   NMAX = 3854;        { code with signed 32 bit integer }
@@ -50,17 +50,17 @@ const
 
 { ========================================================================= }
 
-function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong;
+function adler32(adler : cardinal; buf : Pbyte; len : cardinal) : cardinal;
 var
-  s1, s2 : uLong;
-  k : int;
+  s1, s2 : cardinal;
+  k : integer;
 begin
   s1 := adler and $ffff;
   s2 := (adler shr 16) and $ffff;
 
   if not Assigned(buf) then
   begin
-    adler32 := uLong(1);
+    adler32 := cardinal(1);
     exit;
   end;
 

+ 30 - 30
packages/base/paszlib/crc.pas

@@ -1,4 +1,4 @@
-Unit Crc;
+unit crc;
 
 {
   crc32.c -- compute the CRC-32 of a data stream
@@ -17,7 +17,7 @@ uses
   zutil, zbase;
 
 
-function crc32(crc : uLong; buf : pBytef; len : uInt) : uLong;
+function crc32(crc : cardinal; buf : Pbyte; len : cardinal) : cardinal;
 
 {  Update a running crc with the bytes buf[0..len-1] and return the updated
    crc. If buf is NULL, this function returns the required initial value
@@ -26,9 +26,9 @@ function crc32(crc : uLong; buf : pBytef; len : uInt) : uLong;
    Usage example:
 
     var
-      crc : uLong;
+      crc : cardinal;
     begin
-      crc := crc32(0, Z_NULL, 0);
+      crc := crc32(0, nil, 0);
 
       while (read_buffer(buffer, length) <> EOF) do
         crc := crc32(crc, buffer, length);
@@ -38,7 +38,7 @@ function crc32(crc : uLong; buf : pBytef; len : uInt) : uLong;
 
 }
 
-function get_crc_table : puLong;  { can be used by asm versions of crc32() }
+function get_crc_table : Pcardinal;  { can be used by asm versions of crc32() }
 
 
 implementation
@@ -80,9 +80,9 @@ var
 {local}
 procedure make_crc_table;
 var
- c    : uLong;
- n,k  : int;
- poly : uLong; { polynomial exclusive-or pattern }
+ c    : cardinal;
+ n,k  : integer;
+ poly : cardinal; { polynomial exclusive-or pattern }
 
 const
  { terms of polynomial defining this crc (except x^32): }
@@ -90,13 +90,13 @@ const
 
 begin
   { make exclusive-or pattern from polynomial ($EDB88320) }
-  poly := Long(0);
+  poly := longint(0);
   for n := 0 to (sizeof(p) div sizeof(Byte))-1 do
-    poly := poly or (Long(1) shl (31 - p[n]));
+    poly := poly or (longint(1) shl (31 - p[n]));
 
   for n := 0 to 255 do
   begin
-    c := uLong(n);
+    c := cardinal(n);
     for k := 0 to 7 do
     begin
       if (c and 1) <> 0 then
@@ -116,7 +116,7 @@ end;
 
 {local}
 const
-  crc_table : array[0..256-1] of uLongf = (
+  crc_table : array[0..256-1] of cardinal = (
   $00000000, $77073096, $ee0e612c, $990951ba, $076dc419,
   $706af48f, $e963a535, $9e6495a3, $0edb8832, $79dcb8a4,
   $e0d5e91e, $97d2d988, $09b64c2b, $7eb17cbd, $e7b82d07,
@@ -175,21 +175,21 @@ const
 { =========================================================================
   This function can be used by asm versions of crc32() }
 
-function get_crc_table : {const} puLong;
+function get_crc_table : {const} Pcardinal;
 begin
 {$ifdef DYNAMIC_CRC_TABLE}
   if (crc_table_empty) then
     make_crc_table;
 {$endif}
-  get_crc_table :=  {const} puLong(@crc_table);
+  get_crc_table :=  {const} Pcardinal(@crc_table);
 end;
 
 { ========================================================================= }
 
-function crc32 (crc : uLong; buf : pBytef; len : uInt): uLong;
+function crc32 (crc : cardinal; buf : Pbyte; len : cardinal): cardinal;
 begin
-  if (buf = Z_NULL) then
-    crc32 := Long(0)
+  if (buf = nil) then
+    crc32 := 0
   else
   begin
 
@@ -198,38 +198,38 @@ begin
       make_crc_table;
 {$ENDIF}
 
-    crc := crc xor uLong($ffffffff);
+    crc := crc xor cardinal($ffffffff);
     while (len >= 8) do
     begin
       {DO8(buf)}
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
 
-      Dec(len, 8);
+      dec(len, 8);
     end;
     if (len <> 0) then
     repeat
       {DO1(buf)}
-      crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8);
+      crc := crc_table[(integer(crc) xor buf^) and $ff] xor (crc shr 8);
       inc(buf);
 
-      Dec(len);
+      dec(len);
     until (len = 0);
-    crc32 := crc xor uLong($ffffffff);
+    crc32 := crc xor cardinal($ffffffff);
   end;
 end;
 

+ 82 - 90
packages/base/paszlib/example.pas

@@ -17,24 +17,16 @@ program example;
 {$DEFINE TEST_FLUSH}
 
 uses
-{$ifdef ver80}
- WinCrt,
-{$endif}
-{$ifdef you may have to define this in Delphi < 5}
   strings,
-{$endif}
-{$ifndef MSDOS}
-  SysUtils,
-{$endif}
   zutil,
   zbase,
-  gzIo,
-  zInflate,
-  zDeflate,
-  zCompres,
-  zUnCompr
-{$ifdef MemCheck}
-  , MemCheck in '..\..\monotekt\pas\memcheck\memcheck.pas'
+  gzio,
+  zinflate,
+  zdeflate,
+  zcompres,
+  zuncompr
+{$ifdef memcheck}
+  , memcheck in '..\..\monotekt\pas\memcheck\memcheck.pas'
 {$endif}
 ;
 
@@ -45,7 +37,7 @@ begin
   Halt(1);
 end;
 
-procedure CHECK_ERR(err : int; msg : string);
+procedure CHECK_ERR(err : integer; msg : string);
 begin
   if (err <> Z_OK) then
   begin
@@ -63,21 +55,21 @@ const
 const
   dictionary : PChar = 'hello';
 var
-  dictId : uLong; { Adler32 value of the dictionary }
+  dictId : cardinal; { Adler32 value of the dictionary }
 {$ENDIF}
 
 { ===========================================================================
   Test compress() and uncompress() }
 
 {$IFDEF TEST_COMPRESS}
-procedure test_compress(compr : pBytef; var comprLen : uLong;
-                        uncompr : pBytef; uncomprLen : uLong);
+procedure test_compress(compr : Pbyte; var comprLen : cardinal;
+                        uncompr : Pbyte; uncomprLen : cardinal);
 var
-  err : int;
-  len : uLong;
+  err : integer;
+  len : cardinal;
 begin
   len := strlen(hello)+1;
-  err := compress(compr, comprLen, pBytef(hello)^, len);
+  err := compress(compr, comprLen, Pbyte(hello)^, len);
   CHECK_ERR(err, 'compress');
 
   strcopy(PChar(uncompr), 'garbage');
@@ -101,11 +93,11 @@ end;
 {$IFDEF TEST_GZIO}
 procedure test_gzio(const outf : string; { output file }
                     const inf : string;  { input file }
-                    uncompr : pBytef;
-                    uncomprLen : int);
+                    uncompr : Pbyte;
+                    uncomprLen : integer);
 var
-  err : int;
-  len : int;
+  err : integer;
+  len : integer;
 var
   zfile : gzFile;
   pos : z_off_t;
@@ -137,7 +129,7 @@ begin
     Stop;
   end;
   {$ENDIF}
-  gzseek(zfile, Long(1), SEEK_CUR); { add one zero byte }
+  gzseek(zfile, longint(1), SEEK_CUR); { add one zero byte }
   gzclose(zfile);
 
   zfile := gzopen(inf, 'r');
@@ -146,7 +138,7 @@ begin
 
   strcopy(pchar(uncompr), 'garbage');
 
-  uncomprLen := gzread(zfile, uncompr, uInt(uncomprLen));
+  uncomprLen := gzread(zfile, uncompr, cardinal(uncomprLen));
   if (uncomprLen <> len) then
   begin
     WriteLn('gzread err: ', gzerror(zfile, err));
@@ -160,7 +152,7 @@ begin
   else
     WriteLn('gzread(): ', pchar(uncompr));
 
-  pos := gzseek(zfile, Long(-8), SEEK_CUR);
+  pos := gzseek(zfile, longint(-8), SEEK_CUR);
   if (pos <> 6) or (gztell(zfile) <> pos) then
   begin
     WriteLn('gzseek error, pos=',pos,', gztell=',gztell(zfile));
@@ -196,11 +188,11 @@ end;
   Test deflate() with small buffers }
 
 {$IFDEF TEST_DEFLATE}
-procedure test_deflate(compr : pBytef; comprLen : uLong);
+procedure test_deflate(compr : Pbyte; comprLen : cardinal);
 var
   c_stream : z_stream; { compression stream }
-  err : int;
-  len : int;
+  err : integer;
+  len : integer;
 begin
   len := strlen(hello)+1;
   c_stream.zalloc := NIL; {alloc_func(0);}
@@ -210,10 +202,10 @@ begin
   err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION);
   CHECK_ERR(err, 'deflateInit');
 
-  c_stream.next_in  := pBytef(hello);
+  c_stream.next_in  := Pbyte(hello);
   c_stream.next_out := compr;
 
-  while (c_stream.total_in <> uLong(len)) and (c_stream.total_out < comprLen) do
+  while (c_stream.total_in <> cardinal(len)) and (c_stream.total_out < comprLen) do
   begin
     c_stream.avail_out := 1; { force small buffers }
     c_stream.avail_in := 1;
@@ -241,10 +233,10 @@ end;
 }
 
 {$IFDEF TEST_INFLATE}
-procedure test_inflate(compr : pBytef; comprLen : uLong;
-                       uncompr : pBytef;  uncomprLen : uLong);
+procedure test_inflate(compr : Pbyte; comprLen : cardinal;
+                       uncompr : Pbyte;  uncomprLen : cardinal);
 var
-  err : int;
+  err : integer;
   d_stream : z_stream; { decompression stream }
 begin
   strcopy(PChar(uncompr), 'garbage');
@@ -291,11 +283,11 @@ end;
  }
 
 {$IFDEF TEST_DEFLATE}
-procedure test_large_deflate(compr : pBytef; comprLen : uLong;
-                             uncompr : pBytef;  uncomprLen : uLong);
+procedure test_large_deflate(compr : Pbyte; comprLen : cardinal;
+                             uncompr : Pbyte;  uncomprLen : cardinal);
 var
   c_stream : z_stream; { compression stream }
-  err : int;
+  err : integer;
 begin
   c_stream.zalloc := NIL; {alloc_func(0);}
   c_stream.zfree := NIL;  {free_func(0);}
@@ -305,13 +297,13 @@ begin
   CHECK_ERR(err, 'deflateInit');
 
   c_stream.next_out := compr;
-  c_stream.avail_out := uInt(comprLen);
+  c_stream.avail_out := cardinal(comprLen);
 
   { At this point, uncompr is still mostly zeroes, so it should compress
     very well: }
 
   c_stream.next_in := uncompr;
-  c_stream.avail_in := uInt(uncomprLen);
+  c_stream.avail_in := cardinal(uncomprLen);
   err := deflate(c_stream, Z_NO_FLUSH);
   CHECK_ERR(err, 'deflate');
   if (c_stream.avail_in <> 0) then
@@ -323,14 +315,14 @@ begin
   { Feed in already compressed data and switch to no compression: }
   deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
   c_stream.next_in := compr;
-  c_stream.avail_in := uInt(comprLen div 2);
+  c_stream.avail_in := cardinal(comprLen div 2);
   err := deflate(c_stream, Z_NO_FLUSH);
   CHECK_ERR(err, 'deflate');
 
   { Switch back to compressing mode: }
   deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
   c_stream.next_in := uncompr;
-  c_stream.avail_in := uInt(uncomprLen);
+  c_stream.avail_in := cardinal(uncomprLen);
   err := deflate(c_stream, Z_NO_FLUSH);
   CHECK_ERR(err, 'deflate');
 
@@ -349,10 +341,10 @@ end;
   Test inflate() with large buffers }
 
 {$IFDEF TEST_INFLATE}
-procedure test_large_inflate(compr : pBytef; comprLen : uLong;
-                             uncompr : pBytef;  uncomprLen : uLong);
+procedure test_large_inflate(compr : Pbyte; comprLen : cardinal;
+                             uncompr : Pbyte;  uncomprLen : cardinal);
 var
-  err : int;
+  err : integer;
   d_stream : z_stream; { decompression stream }
 begin
   strcopy(PChar(uncompr), 'garbage');
@@ -362,7 +354,7 @@ begin
   d_stream.opaque := NIL; {voidpf(0);}
 
   d_stream.next_in  := compr;
-  d_stream.avail_in := uInt(comprLen);
+  d_stream.avail_in := cardinal(comprLen);
 
   err := inflateInit(d_stream);
   CHECK_ERR(err, 'inflateInit');
@@ -370,7 +362,7 @@ begin
   while TRUE do
   begin
     d_stream.next_out := uncompr;            { discard the output }
-    d_stream.avail_out := uInt(uncomprLen);
+    d_stream.avail_out := cardinal(uncomprLen);
     err := inflate(d_stream, Z_NO_FLUSH);
     if (err = Z_STREAM_END) then
       break;
@@ -394,11 +386,11 @@ end;
   Test deflate() with full flush
  }
 {$IFDEF TEST_FLUSH}
-procedure test_flush(compr : pBytef; var comprLen : uLong);
+procedure test_flush(compr : Pbyte; var comprLen : cardinal);
 var
   c_stream : z_stream; { compression stream }
-  err : int;
-  len : int;
+  err : integer;
+  len : integer;
 
 begin
   len := strlen(hello)+1;
@@ -409,10 +401,10 @@ begin
   err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION);
   CHECK_ERR(err, 'deflateInit');
 
-  c_stream.next_in := pBytef(hello);
+  c_stream.next_in := Pbyte(hello);
   c_stream.next_out := compr;
   c_stream.avail_in := 3;
-  c_stream.avail_out := uInt(comprLen);
+  c_stream.avail_out := cardinal(comprLen);
 
   err := deflate(c_stream, Z_FULL_FLUSH);
   CHECK_ERR(err, 'deflate');
@@ -435,10 +427,10 @@ end;
   Test inflateSync()
  }
 {$IFDEF TEST_SYNC}
-procedure test_sync(compr : pBytef; comprLen : uLong;
-                    uncompr : pBytef; uncomprLen : uLong);
+procedure test_sync(compr : Pbyte; comprLen : cardinal;
+                    uncompr : Pbyte; uncomprLen : cardinal);
 var
-  err : int;
+  err : integer;
   d_stream : z_stream; { decompression stream }
 begin
   strcopy(PChar(uncompr), 'garbage');
@@ -454,12 +446,12 @@ begin
   CHECK_ERR(err, 'inflateInit');
 
   d_stream.next_out := uncompr;
-  d_stream.avail_out := uInt(uncomprLen);
+  d_stream.avail_out := cardinal(uncomprLen);
 
   inflate(d_stream, Z_NO_FLUSH);
   CHECK_ERR(err, 'inflate');
 
-  d_stream.avail_in := uInt(comprLen-2);   { read all compressed data }
+  d_stream.avail_in := cardinal(comprLen-2);   { read all compressed data }
   err := inflateSync(d_stream);           { but skip the damaged part }
   CHECK_ERR(err, 'inflateSync');
 
@@ -481,10 +473,10 @@ end;
   Test deflate() with preset dictionary
  }
 {$IFDEF TEST_DICT}
-procedure test_dict_deflate(compr : pBytef; comprLen : uLong);
+procedure test_dict_deflate(compr : Pbyte; comprLen : cardinal);
 var
   c_stream : z_stream; { compression stream }
-  err : int;
+  err : integer;
 begin
   c_stream.zalloc := NIL; {(alloc_func)0;}
   c_stream.zfree := NIL; {(free_func)0;}
@@ -494,15 +486,15 @@ begin
   CHECK_ERR(err, 'deflateInit');
 
   err := deflateSetDictionary(c_stream,
-                              pBytef(dictionary), StrLen(dictionary));
+                              Pbyte(dictionary), StrLen(dictionary));
   CHECK_ERR(err, 'deflateSetDictionary');
 
   dictId := c_stream.adler;
   c_stream.next_out := compr;
-  c_stream.avail_out := uInt(comprLen);
+  c_stream.avail_out := cardinal(comprLen);
 
-  c_stream.next_in := pBytef(hello);
-  c_stream.avail_in := uInt(strlen(hello)+1);
+  c_stream.next_in := Pbyte(hello);
+  c_stream.avail_in := cardinal(strlen(hello)+1);
 
   err := deflate(c_stream, Z_FINISH);
   if (err <> Z_STREAM_END) then
@@ -517,10 +509,10 @@ end;
 { ===========================================================================
   Test inflate() with a preset dictionary }
 
-procedure test_dict_inflate(compr : pBytef; comprLen : uLong;
-                            uncompr : pBytef; uncomprLen : uLong);
+procedure test_dict_inflate(compr : Pbyte; comprLen : cardinal;
+                            uncompr : Pbyte; uncomprLen : cardinal);
 var
-  err : int;
+  err : integer;
   d_stream : z_stream; { decompression stream }
 begin
   strcopy(PChar(uncompr), 'garbage');
@@ -530,13 +522,13 @@ begin
   d_stream.opaque := NIL;              { voidpf(0); }
 
   d_stream.next_in  := compr;
-  d_stream.avail_in := uInt(comprLen);
+  d_stream.avail_in := cardinal(comprLen);
 
   err := inflateInit(d_stream);
   CHECK_ERR(err, 'inflateInit');
 
   d_stream.next_out := uncompr;
-  d_stream.avail_out := uInt(uncomprLen);
+  d_stream.avail_out := cardinal(uncomprLen);
 
   while TRUE do
   begin
@@ -550,7 +542,7 @@ begin
         WriteLn('unexpected dictionary');
 	Stop;
       end;
-      err := inflateSetDictionary(d_stream, pBytef(dictionary),
+      err := inflateSetDictionary(d_stream, Pbyte(dictionary),
 				     StrLen(dictionary));
     end;
     CHECK_ERR(err, 'inflate with dict');
@@ -571,13 +563,13 @@ begin
 end;
 {$ENDIF}
 
-function GetFromFile(buf : pBytef; FName : string;
-                     var MaxLen : uInt) : boolean;
+function GetFromFile(buf : Pbyte; FName : string;
+                     var MaxLen : cardinal) : boolean;
 const
   zOfs = 0;
 var
   f : file;
-  Len : uLong;
+  Len : cardinal;
 begin
   assign(f, FName);
   GetFromFile := false;
@@ -604,17 +596,17 @@ end;
 }
 
 var
-  compr, uncompr : pBytef;
+  compr, uncompr : Pbyte;
 const
   msdoslen = 25000;
-  comprLenL : uLong = msdoslen div sizeof(uInt); { don't overflow on MSDOS }
-  uncomprLenL : uLong = msdoslen div sizeof(uInt);
+  comprLenL : cardinal = msdoslen div sizeof(cardinal); { don't overflow on MSDOS }
+  uncomprLenL : cardinal = msdoslen div sizeof(cardinal);
 var
   zVersion,
   myVersion : string;
 var
-  comprLen : uInt;
-  uncomprLen : uInt;
+  comprLen : cardinal;
+  uncomprLen : cardinal;
 begin
   {$ifdef MemCheck}
   MemChk;
@@ -635,20 +627,20 @@ begin
       WriteLn('warning: different zlib version');
     end;
 
-  GetMem(compr, comprLen*sizeof(uInt));
-  GetMem(uncompr, uncomprLen*sizeof(uInt));
+  GetMem(compr, comprLen*sizeof(cardinal));
+  GetMem(uncompr, uncomprLen*sizeof(cardinal));
   { compr and uncompr are cleared to avoid reading uninitialized
     data and to ensure that uncompr compresses well. }
 
-  if (compr = Z_NULL) or (uncompr = Z_NULL) then
+  if (compr = nil) or (uncompr = nil) then
   begin
     WriteLn('out of memory');
     Stop;
   end;
-  FillChar(compr^, comprLen*sizeof(uInt), 0);
-  FillChar(uncompr^, uncomprLen*sizeof(uInt), 0);
+  FillChar(compr^, comprLen*sizeof(cardinal), 0);
+  FillChar(uncompr^, uncomprLen*sizeof(cardinal), 0);
 
-  if (compr = Z_NULL) or (uncompr = Z_NULL) then
+  if (compr = nil) or (uncompr = nil) then
   begin
     WriteLn('out of memory');
     Stop;
@@ -659,10 +651,10 @@ begin
 
   {$IFDEF TEST_GZIO}
   Case ParamCount of
-    0:  test_gzio('foo.gz', 'foo.gz', uncompr, int(uncomprLen));
-    1:  test_gzio(ParamStr(1), 'foo.gz', uncompr, int(uncomprLen));
+    0:  test_gzio('foo.gz', 'foo.gz', uncompr, integer(uncomprLen));
+    1:  test_gzio(ParamStr(1), 'foo.gz', uncompr, integer(uncomprLen));
   else
-    test_gzio(ParamStr(1), ParamStr(2), uncompr, int(uncomprLen));
+    test_gzio(ParamStr(1), ParamStr(2), uncompr, integer(uncomprLen));
   end;
   {$ENDIF}
 
@@ -699,6 +691,6 @@ begin
   test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
   {$ENDIF}
   readln;
-  FreeMem(compr, comprLen*sizeof(uInt));
-  FreeMem(uncompr, uncomprLen*sizeof(uInt));
+  FreeMem(compr, comprLen*sizeof(cardinal));
+  FreeMem(uncompr, uncomprLen*sizeof(cardinal));
 end.

+ 141 - 132
packages/base/paszlib/gzio.pas

@@ -16,39 +16,46 @@ interface
 {$I zconf.inc}
 
 uses
+  {$ifdef UNIX}
+  baseunix,
+  {$else}
+  dos,
+  {$endif}
+(*
   {$ifdef MSDOS}
   dos, strings,
   {$else}
   sysutils,
   {$endif}
+*)
   zutil, zbase, crc, zdeflate, zinflate;
 
-type gzFile = voidp;
-type z_off_t = long;
+type gzFile = pointer;
+type z_off_t = longint;
 
 function gzopen  (path:string; mode:string) : gzFile;
-function gzread  (f:gzFile; buf:voidp; len:uInt) : int;
-function gzgetc  (f:gzfile) : int;
-function gzgets  (f:gzfile; buf:PChar; len:int) : PChar;
+function gzread  (f:gzFile; buf:pointer; len:cardinal) : integer;
+function gzgetc  (f:gzfile) : integer;
+function gzgets  (f:gzfile; buf:Pchar; len:integer) : Pchar;
 
 {$ifndef NO_DEFLATE}
-function gzwrite (f:gzFile; buf:voidp; len:uInt) : int;
-function gzputc  (f:gzfile; c:char) : int;
-function gzputs  (f:gzfile; s:PChar) : int;
-function gzflush (f:gzFile; flush:int)           : int;
+function gzwrite (f:gzFile; buf:pointer; len:cardinal) : integer;
+function gzputc  (f:gzfile; c:char) : integer;
+function gzputs  (f:gzfile; s:Pchar) : integer;
+function gzflush (f:gzFile; flush:integer)           : integer;
   {$ifdef GZ_FORMAT_STRING}
   function gzprintf (zfile : gzFile;
                      const format : string;
-                     a : array of int);    { doesn't compile }
+                     a : array of integer);    { doesn't compile }
   {$endif}
 {$endif}
 
-function gzseek  (f:gzfile; offset:z_off_t; whence:int) : z_off_t;
+function gzseek  (f:gzfile; offset:z_off_t; whence:integer) : z_off_t;
 function gztell  (f:gzfile) : z_off_t;
-function gzclose (f:gzFile)                      : int;
-function gzerror (f:gzFile; var errnum:Int)      : string;
-function gzsetparams (f:gzfile; level:int; strategy:int) : int;
-function gzrewind (f:gzFile) : int;
+function gzclose (f:gzFile)                      : integer;
+function gzerror (f:gzFile; var errnum:integer)      : string;
+function gzsetparams (f:gzfile; level:integer; strategy:integer) : integer;
+function gzrewind (f:gzFile) : integer;
 function gzeof (f:gzfile) : boolean;
 
 const
@@ -77,22 +84,22 @@ const
 
 type gz_stream = record
   stream      : z_stream;
-  z_err       : int;      { error code for last stream operation }
+  z_err       : integer;      { error code for last stream operation }
   z_eof       : boolean;  { set if end of input file }
   gzfile      : file;     { .gz file }
-  inbuf       : pBytef;   { input buffer }
-  outbuf      : pBytef;   { output buffer }
-  crc         : uLong;    { crc32 of uncompressed data }
+  inbuf       : Pbyte;   { input buffer }
+  outbuf      : Pbyte;   { output buffer }
+  crc         : cardinal;    { crc32 of uncompressed data }
   msg,                    { error message - limit 79 chars }
   path        : string[79];   { path name for debugging only - limit 79 chars }
   transparent : boolean;  { true if input file is not a .gz file }
   mode        : char;     { 'w' or 'r' }
-  startpos    : long;     { start of compressed data in file (header skipped) }
+  startpos    : longint;     { start of compressed data in file (header skipped) }
 end;
 
 type gz_streamp = ^gz_stream;
 
-function destroy (var s:gz_streamp) : int; forward;
+function destroy (var s:gz_streamp) : integer; forward;
 procedure check_header(s:gz_streamp); forward;
 
 
@@ -109,7 +116,7 @@ procedure check_header(s:gz_streamp); forward;
   gzopen can be used to open a file which is not in gzip format; in this
   case, gzread will directly read from the file without decompression.
 
-  gzopen returns NIL if the file could not be opened (non-zero IOResult)
+  gzopen returns nil if the file could not be opened (non-zero IOResult)
   or if there was insufficient memory to allocate the (de)compression state
   (zlib error is Z_MEM_ERROR).
 
@@ -119,14 +126,16 @@ function gzopen (path:string; mode:string) : gzFile;
 
 var
 
-  i        : uInt;
-  err      : int;
-  level    : int;        { compression level }
-  strategy : int;        { compression strategy }
+  i        : cardinal;
+  err      : integer;
+  level    : integer;        { compression level }
+  strategy : integer;        { compression strategy }
   s        : gz_streamp;
-{$IFDEF MSDOS}
-  attr     : word;       { file attributes }
-{$ENDIF}  
+{$ifdef UNIX}
+  info:      stat;
+{$else}
+  attr:      word;
+{$endif}
 
 {$IFNDEF NO_DEFLATE}
   gzheader : array [0..9] of byte;
@@ -135,31 +144,31 @@ var
 begin
 
   if (path='') or (mode='') then begin
-    gzopen := Z_NULL;
+    gzopen := nil;
     exit;
   end;
 
   GetMem (s,sizeof(gz_stream));
   if not Assigned (s) then begin
-    gzopen := Z_NULL;
+    gzopen := nil;
     exit;
   end;
 
   level := Z_DEFAULT_COMPRESSION;
   strategy := Z_DEFAULT_STRATEGY;
 
-  s^.stream.zalloc := NIL;     { (alloc_func)0 }
-  s^.stream.zfree := NIL;      { (free_func)0 }
-  s^.stream.opaque := NIL;     { (voidpf)0 }
-  s^.stream.next_in := Z_NULL;
-  s^.stream.next_out := Z_NULL;
+  s^.stream.zalloc := nil;     { (alloc_func)0 }
+  s^.stream.zfree := nil;      { (free_func)0 }
+  s^.stream.opaque := nil;     { (voidpf)0 }
+  s^.stream.next_in := nil;
+  s^.stream.next_out := nil;
   s^.stream.avail_in := 0;
   s^.stream.avail_out := 0;
   s^.z_err := Z_OK;
   s^.z_eof := false;
-  s^.inbuf := Z_NULL;
-  s^.outbuf := Z_NULL;
-  s^.crc := crc32(0, Z_NULL, 0);
+  s^.inbuf := nil;
+  s^.outbuf := nil;
+  s^.crc := crc32(0, nil, 0);
   s^.msg := '';
   s^.transparent := false;
 
@@ -177,7 +186,7 @@ begin
   end;
   if (s^.mode=chr(0)) then begin
     destroy(s);
-    gzopen := gzFile(Z_NULL);
+    gzopen := gzFile(nil);
     exit;
   end;
 
@@ -192,9 +201,9 @@ begin
     GetMem (s^.outbuf, Z_BUFSIZE);
     s^.stream.next_out := s^.outbuf;
 {$ENDIF}
-    if (err <> Z_OK) or (s^.outbuf = Z_NULL) then begin
+    if (err <> Z_OK) or (s^.outbuf = nil) then begin
       destroy(s);
-      gzopen := gzFile(Z_NULL);
+      gzopen := gzFile(nil);
       exit;
     end;
   end
@@ -206,9 +215,9 @@ begin
     err := inflateInit2_ (s^.stream, -MAX_WBITS, ZLIB_VERSION, sizeof(z_stream));
         { windowBits is passed < 0 to tell that there is no zlib header }
 
-    if (err <> Z_OK) or (s^.inbuf = Z_NULL) then begin
+    if (err <> Z_OK) or (s^.inbuf = nil) then begin
       destroy(s);
-      gzopen := gzFile(Z_NULL);
+      gzopen := gzFile(nil);
       exit;
     end;
   end;
@@ -217,22 +226,22 @@ begin
 
   {$IFOPT I+} {$I-} {$define IOcheck} {$ENDIF}
   Assign (s^.gzfile, s^.path);
-  {$ifdef MSDOS}
-  GetFAttr(s^.gzfile, Attr);
-  if (DosError <> 0) and (s^.mode='w') then
-    ReWrite (s^.gzfile,1)
+  {$ifdef unix}
+  if (fpstat(s^.path,info)<0) and (s^.mode='w') then
+    ReWrite (s^.gzfile,1)  
   else
     Reset (s^.gzfile,1);
   {$else}
-  if (not FileExists(s^.path)) and (s^.mode='w') then
-    ReWrite (s^.gzfile,1)  
+  GetFAttr(s^.gzfile, Attr);
+  if (DosError <> 0) and (s^.mode='w') then
+    ReWrite (s^.gzfile,1)
   else
     Reset (s^.gzfile,1);
   {$endif}
   {$IFDEF IOCheck} {$I+} {$ENDIF}
   if (IOResult <> 0) then begin
     destroy(s);
-    gzopen := gzFile(Z_NULL);
+    gzopen := gzFile(nil);
     exit;
   end;
 
@@ -249,7 +258,7 @@ begin
     gzheader [8] := 0;            { xflags }
     gzheader [9] := 0;            { OS code = MS-DOS }
     blockwrite (s^.gzfile, gzheader, 10);
-    s^.startpos := LONG(10);
+    s^.startpos := longint(10);
 {$ENDIF}
   end
   else begin
@@ -267,7 +276,7 @@ end;
 
 ============================================================================}
 
-function gzsetparams (f:gzfile; level:int; strategy:int) : int;
+function gzsetparams (f:gzfile; level:integer; strategy:integer) : integer;
 
 var
 
@@ -278,7 +287,7 @@ begin
 
   s := gz_streamp(f);
 
-  if (s = NIL) or (s^.mode <> 'w') then begin
+  if (s = nil) or (s^.mode <> 'w') then begin
     gzsetparams := Z_STREAM_ERROR;
     exit;
   end;
@@ -303,7 +312,7 @@ end;
 
 ============================================================================}
 
-function get_byte (s:gz_streamp) : int;
+function get_byte (s:gz_streamp) : integer;
 
 begin
 
@@ -338,11 +347,11 @@ end;
 
 ============================================================================}
 {
-function getLong (s:gz_streamp) : uLong;
+function getLong (s:gz_streamp) : cardinal;
 var
   x  : array [0..3] of byte;
   i  : byte;
-  c  : int;
+  c  : integer;
   n1 : longint;
   n2 : longint;
 begin
@@ -357,12 +366,12 @@ begin
   getlong := (n1 shl 16) or n2;
 end;
 }
-function getLong(s : gz_streamp) : uLong;
+function getLong(s : gz_streamp) : cardinal;
 var
   x : packed array [0..3] of byte;
-  c : int;
+  c : integer;
 begin
-  { x := uLong(get_byte(s));  - you can't do this with TP, no unsigned long }
+  { x := cardinal(get_byte(s));  - you can't do this with TP, no unsigned longint }
   { the following assumes a little endian machine and TP }
   x[0] := Byte(get_byte(s));
   x[1] := Byte(get_byte(s));
@@ -371,7 +380,7 @@ begin
   x[3] := Byte(c);
   if (c = Z_EOF) then
     s^.z_err := Z_DATA_ERROR;
-  GetLong := uLong(longint(x));
+  GetLong := cardinal(longint(x));
 end;
 
 
@@ -392,10 +401,10 @@ procedure check_header (s:gz_streamp);
 
 var
 
-  method : int;  { method byte }
-  flags  : int;  { flags byte }
-  len    : uInt;
-  c      : int;
+  method : integer;  { method byte }
+  flags  : integer;  { flags byte }
+  len    : cardinal;
+  c      : integer;
 
 begin
 
@@ -428,8 +437,8 @@ begin
   for len := 0 to 5 do get_byte(s); { Discard time, xflags and OS code }
 
   if ((flags and EXTRA_FIELD) <> 0) then begin { skip the extra field }
-    len := uInt(get_byte(s));
-    len := len + (uInt(get_byte(s)) shr 8);
+    len := cardinal(get_byte(s));
+    len := len + (cardinal(get_byte(s)) shr 8);
     { len is garbage if EOF but the loop below will quit anyway }
     while (len <> 0) and (get_byte(s) <> Z_EOF) do Dec(len);
   end;
@@ -466,7 +475,7 @@ end;
 
 ============================================================================}
 
-function destroy (var s:gz_streamp) : int;
+function destroy (var s:gz_streamp) : integer;
 
 begin
 
@@ -477,7 +486,7 @@ begin
     exit;
   end;
 
-  if (s^.stream.state <> NIL) then begin
+  if (s^.stream.state <> nil) then begin
     if (s^.mode = 'w') then begin
 {$IFDEF NO_DEFLATE}
       destroy := Z_STREAM_ERROR;
@@ -519,27 +528,27 @@ end;
 
 ============================================================================}
 
-function gzread (f:gzFile; buf:voidp; len:uInt) : int;
+function gzread (f:gzFile; buf:pointer; len:cardinal) : integer;
 
 var
 
   s         : gz_streamp;
-  start     : pBytef;
-  next_out  : pBytef;
-  n         : uInt;
-  crclen    : uInt;  { Buffer length to update CRC32 }
-  filecrc   : uLong; { CRC32 stored in GZIP'ed file }
-  filelen   : uLong; { Total lenght of uncompressed file }
+  start     : Pbyte;
+  next_out  : Pbyte;
+  n         : cardinal;
+  crclen    : cardinal;  { Buffer length to update CRC32 }
+  filecrc   : cardinal; { CRC32 stored in GZIP'ed file }
+  filelen   : cardinal; { Total lenght of uncompressed file }
   bytes     : integer;  { bytes actually read in I/O blockread }
-  total_in  : uLong;
-  total_out : uLong;
+  total_in  : cardinal;
+  total_out : cardinal;
 
 begin
 
   s := gz_streamp(f);
-  start := pBytef(buf); { starting point for crc computation }
+  start := Pbyte(buf); { starting point for crc computation }
 
-  if (s = NIL) or (s^.mode <> 'r') then begin
+  if (s = nil) or (s^.mode <> 'r') then begin
     gzread := Z_STREAM_ERROR;
     exit;
   end;
@@ -554,7 +563,7 @@ begin
     exit;
   end;
 
-  s^.stream.next_out := pBytef(buf);
+  s^.stream.next_out := Pbyte(buf);
   s^.stream.avail_out := len;
 
   while (s^.stream.avail_out <> 0) do begin
@@ -572,12 +581,12 @@ begin
       end;
       if (s^.stream.avail_out > 0) then begin
         blockread (s^.gzfile, s^.stream.next_out^, s^.stream.avail_out, bytes);
-        dec (s^.stream.avail_out, uInt(bytes));
+        dec (s^.stream.avail_out, cardinal(bytes));
       end;
       dec (len, s^.stream.avail_out);
-      inc (s^.stream.total_in, uLong(len));
-      inc (s^.stream.total_out, uLong(len));
-      gzread := int(len);
+      inc (s^.stream.total_in, cardinal(len));
+      inc (s^.stream.total_out, cardinal(len));
+      gzread := integer(len);
       exit;
     end; { IF transparent }
 
@@ -623,7 +632,7 @@ begin
 	    inflateReset (s^.stream);
 	    s^.stream.total_in := total_in;
 	    s^.stream.total_out := total_out;
-	    s^.crc := crc32 (0, Z_NULL, 0);
+	    s^.crc := crc32 (0, nil, 0);
 	  end;
       end; {IF-THEN-ELSE}
     end;
@@ -640,7 +649,7 @@ begin
   end;
   s^.crc := crc32 (s^.crc, start, crclen);
 
-  gzread := int(len - s^.stream.avail_out);
+  gzread := integer(len - s^.stream.avail_out);
 
 end;
 
@@ -652,7 +661,7 @@ end;
 
 ============================================================================}
 
-function gzgetc (f:gzfile) : int;
+function gzgetc (f:gzfile) : integer;
 
 var c:byte;
 
@@ -669,23 +678,23 @@ end;
   or a newline character is read and transferred to buf, or an end-of-file
   condition is encountered. The string is then Null-terminated.
 
-  gzgets returns buf, or Z_NULL in case of error.
+  gzgets returns buf, or nil in case of error.
   The current implementation is not optimized at all.
 
 ============================================================================}
 
-function gzgets (f:gzfile; buf:PChar; len:int) : PChar;
+function gzgets (f:gzfile; buf:Pchar; len:integer) : Pchar;
 
 var
 
-  b      : PChar; { start of buffer }
-  bytes  : Int;   { number of bytes read by gzread }
+  b      : Pchar; { start of buffer }
+  bytes  : integer;   { number of bytes read by gzread }
   gzchar : char;  { char read by gzread }
 
 begin
 
-    if (buf = Z_NULL) or (len <= 0) then begin
-      gzgets := Z_NULL;
+    if (buf = nil) or (len <= 0) then begin
+      gzgets := nil;
       exit;
     end;
 
@@ -698,7 +707,7 @@ begin
     until (len = 0) or (bytes <> 1) or (gzchar = Chr(13));
 
     buf^ := Chr(0);
-    if (b = buf) and (len > 0) then gzgets := Z_NULL else gzgets := b;
+    if (b = buf) and (len > 0) then gzgets := nil else gzgets := b;
 
 end;
 
@@ -713,7 +722,7 @@ end;
 
 ============================================================================}
 
-function gzwrite (f:gzfile; buf:voidp; len:uInt) : int;
+function gzwrite (f:gzfile; buf:pointer; len:cardinal) : integer;
 
 var
 
@@ -724,12 +733,12 @@ begin
 
     s := gz_streamp(f);
 
-    if (s = NIL) or (s^.mode <> 'w') then begin
+    if (s = nil) or (s^.mode <> 'w') then begin
       gzwrite := Z_STREAM_ERROR;
       exit;
     end;
 
-    s^.stream.next_in := pBytef(buf);
+    s^.stream.next_in := Pbyte(buf);
     s^.stream.avail_in := len;
 
     while (s^.stream.avail_in <> 0) do begin
@@ -750,7 +759,7 @@ begin
     end; {WHILE}
 
     s^.crc := crc32(s^.crc, buf, len);
-    gzwrite := int(len - s^.stream.avail_in);
+    gzwrite := integer(len - s^.stream.avail_in);
 
 end;
 
@@ -764,10 +773,10 @@ end;
 {$IFDEF GZ_FORMAT_STRING}
 function gzprintf (zfile : gzFile;
                    const format : string;
-                   a : array of int) : int;
+                   a : array of integer) : integer;
 var
   buf : array[0..Z_PRINTF_BUFSIZE-1] of char;
-  len : int;
+  len : integer;
 begin
 {$ifdef HAS_snprintf}
     snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
@@ -791,13 +800,13 @@ end;
 
 ============================================================================}
 
-function gzputc (f:gzfile; c:char) : int;
+function gzputc (f:gzfile; c:char) : integer;
 begin
   if (gzwrite (f,@c,1) = 1) then
   {$IFDEF FPC}
-    gzputc := int(ord(c))
+    gzputc := integer(ord(c))
   {$ELSE}
-    gzputc := int(c)
+    gzputc := integer(c)
   {$ENDIF}
   else
     gzputc := -1;
@@ -812,9 +821,9 @@ end;
 
 ============================================================================}
 
-function gzputs (f:gzfile; s:PChar) : int;
+function gzputs (f:gzfile; s:Pchar) : integer;
 begin
-  gzputs := gzwrite (f, voidp(s), strlen(s));
+  gzputs := gzwrite (f, pointer(s), strlen(s));
 end;
 
 
@@ -825,9 +834,9 @@ end;
 
 ============================================================================}
 
-function do_flush (f:gzfile; flush:int) : int;
+function do_flush (f:gzfile; flush:integer) : integer;
 var
-  len     : uInt;
+  len     : cardinal;
   done    : boolean;
   s       : gz_streamp;
   written : integer;
@@ -835,7 +844,7 @@ begin
   done := false;
   s := gz_streamp(f);
 
-  if (s = NIL) or (s^.mode <> 'w') then begin
+  if (s = nil) or (s^.mode <> 'w') then begin
     do_flush := Z_STREAM_ERROR;
     exit;
   end;
@@ -890,9 +899,9 @@ end;
 
 ============================================================================}
 
-function gzflush (f:gzfile; flush:int) : int;
+function gzflush (f:gzfile; flush:integer) : integer;
 var
-  err : int;
+  err : integer;
   s   : gz_streamp;
 begin
   s := gz_streamp(f);
@@ -915,13 +924,13 @@ end;
 
 ============================================================================}
 
-function gzrewind (f:gzFile) : int;
+function gzrewind (f:gzFile) : integer;
 var
   s:gz_streamp;
 begin
   s := gz_streamp(f);
 
-  if (s = NIL) or (s^.mode <> 'r') then begin
+  if (s = nil) or (s^.mode <> 'r') then begin
     gzrewind := -1;
     exit;
   end;
@@ -943,7 +952,7 @@ begin
   {$I-}
   seek (s^.gzfile, s^.startpos);
   {$I+}
-  gzrewind := int(IOResult);
+  gzrewind := integer(IOResult);
   exit;
 end;
 
@@ -960,14 +969,14 @@ end;
 
 ============================================================================}
 
-function gzseek (f:gzfile; offset:z_off_t; whence:int) : z_off_t;
+function gzseek (f:gzfile; offset:z_off_t; whence:integer) : z_off_t;
 var
   s : gz_streamp;
-  size : uInt;
+  size : cardinal;
 begin
   s := gz_streamp(f);
 
-  if (s = NIL) or (whence = SEEK_END) or (s^.z_err = Z_ERRNO)
+  if (s = nil) or (whence = SEEK_END) or (s^.z_err = Z_ERRNO)
   or (s^.z_err = Z_DATA_ERROR) then begin
     gzseek := z_off_t(-1);
     exit;
@@ -985,14 +994,14 @@ begin
     end;
 
     { At this point, offset is the number of zero bytes to write. }
-    if (s^.inbuf = Z_NULL) then begin
+    if (s^.inbuf = nil) then begin
       GetMem (s^.inbuf, Z_BUFSIZE);
       zmemzero(s^.inbuf, Z_BUFSIZE);
     end;
 
     while (offset > 0) do begin
       size := Z_BUFSIZE;
-      if (offset < Z_BUFSIZE) then size := uInt(offset);
+      if (offset < Z_BUFSIZE) then size := cardinal(offset);
 
       size := gzwrite(f, s^.inbuf, size);
       if (size = 0) then begin
@@ -1027,14 +1036,14 @@ begin
       exit;
     end;
 
-    s^.stream.total_in := uLong(offset);
-    s^.stream.total_out := uLong(offset);
+    s^.stream.total_in := cardinal(offset);
+    s^.stream.total_out := cardinal(offset);
     gzseek := z_off_t(offset);
     exit;
   end;
 
   { For a negative seek, rewind and use positive seek }
-  if (uLong(offset) >= s^.stream.total_out)
+  if (cardinal(offset) >= s^.stream.total_out)
     then dec (offset, s^.stream.total_out)
     else if (gzrewind(f) <> 0) then begin
       gzseek := z_off_t(-1);
@@ -1042,12 +1051,12 @@ begin
   end;
   { offset is now the number of bytes to skip. }
 
-  if (offset <> 0) and (s^.outbuf = Z_NULL)
+  if (offset <> 0) and (s^.outbuf = nil)
   then GetMem (s^.outbuf, Z_BUFSIZE);
 
   while (offset > 0) do begin
     size := Z_BUFSIZE;
-    if (offset < Z_BUFSIZE) then size := int(offset);
+    if (offset < Z_BUFSIZE) then size := integer(offset);
 
     size := gzread (f, s^.outbuf, size);
     if (size <= 0) then begin
@@ -1088,7 +1097,7 @@ var
 begin
   s := gz_streamp(f);
 
-  if (s=NIL) or (s^.mode<>'r') then
+  if (s=nil) or (s^.mode<>'r') then
     gzeof := false
   else
     gzeof := s^.z_eof;
@@ -1101,9 +1110,9 @@ end;
 
 ============================================================================}
 
-procedure putLong (var f:file; x:uLong);
+procedure putLong (var f:file; x:cardinal);
 var
-  n : int;
+  n : integer;
   c : byte;
 begin
   for n:=0 to 3 do begin
@@ -1123,13 +1132,13 @@ end;
 
 ============================================================================}
 
-function gzclose (f:gzFile) : int;
+function gzclose (f:gzFile) : integer;
 var
-  err : int;
+  err : integer;
   s   : gz_streamp;
 begin
   s := gz_streamp(f);
-  if (s = NIL) then begin
+  if (s = nil) then begin
     gzclose := Z_STREAM_ERROR;
     exit;
   end;
@@ -1164,13 +1173,13 @@ end;
 
 ============================================================================}
 
-function gzerror (f:gzfile; var errnum:int) : string;
+function gzerror (f:gzfile; var errnum:integer) : string;
 var
  m : string;
  s : gz_streamp;
 begin
   s := gz_streamp(f);
-  if (s = NIL) then begin
+  if (s = nil) then begin
     errnum := Z_STREAM_ERROR;
     gzerror := zError(Z_STREAM_ERROR);
     end;

+ 125 - 128
packages/base/paszlib/infblock.pas

@@ -14,34 +14,31 @@ interface
 {$I zconf.inc}
 
 uses
-  {$IFDEF DEBUG}
-  strutils,
-  {$ENDIF}
   zutil, zbase;
 
 function inflate_blocks_new(var z : z_stream;
                             c : check_func;  { check function }
-                            w : uInt     { window size }
+                            w : cardinal     { window size }
                             ) : pInflate_blocks_state;
 
 function inflate_blocks (var s : inflate_blocks_state;
                          var z : z_stream;
-                         r : int             { initial return code }
-                         ) : int;
+                         r : integer             { initial return code }
+                         ) : integer;
 
 procedure inflate_blocks_reset (var s : inflate_blocks_state;
                                 var z : z_stream;
-                                c : puLong); { check value on output }
+                                c : Pcardinal); { check value on output }
 
 
 function inflate_blocks_free(s : pInflate_blocks_state;
-                             var z : z_stream) : int;
+                             var z : z_stream) : integer;
 
 procedure inflate_set_dictionary(var s : inflate_blocks_state;
                                  const d : array of byte;  { dictionary }
-                                 n : uInt);         { dictionary length }
+                                 n : cardinal);         { dictionary length }
 
-function inflate_blocks_sync_point(var s : inflate_blocks_state) : int;
+function inflate_blocks_sync_point(var s : inflate_blocks_state) : integer;
 
 implementation
 
@@ -50,7 +47,7 @@ uses
 
 { Tables for deflate from PKZIP's appnote.txt. }
 Const
-  border : Array [0..18] Of Word  { Order of the bit length code lengths }
+  border : array [0..18] of word  { Order of the bit length code lengths }
     = (16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
 
 { Notes beyond the 1.93a appnote.txt:
@@ -99,9 +96,9 @@ Const
 
 procedure inflate_blocks_reset (var s : inflate_blocks_state;
                                 var z : z_stream;
-                                c : puLong); { check value on output }
+                                c : Pcardinal); { check value on output }
 begin
-  if (c <> Z_NULL) then
+  if (c <> nil) then
     c^ := s.check;
   if (s.mode = BTREE) or (s.mode = DTREE) then
     ZFREE(z, s.sub.trees.blens);
@@ -116,7 +113,7 @@ begin
   s.read := s.window;
   if Assigned(s.checkfn) then
   begin
-    s.check := s.checkfn(uLong(0), pBytef(NIL), 0);
+    s.check := s.checkfn(cardinal(0), Pbyte(NIL), 0);
     z.adler := s.check;
   end;
   {$IFDEF DEBUG}
@@ -127,32 +124,32 @@ end;
 
 function inflate_blocks_new(var z : z_stream;
                             c : check_func;  { check function }
-                            w : uInt         { window size }
+                            w : cardinal         { window size }
                             ) : pInflate_blocks_state;
 var
   s : pInflate_blocks_state;
 begin
   s := pInflate_blocks_state( ZALLOC(z,1, sizeof(inflate_blocks_state)) );
-  if (s = Z_NULL) then
+  if (s = nil) then
   begin
     inflate_blocks_new := s;
     exit;
   end;
   s^.hufts := huft_ptr( ZALLOC(z, sizeof(inflate_huft), MANY) );
 
-  if (s^.hufts = Z_NULL) then
+  if (s^.hufts = nil) then
   begin
     ZFREE(z, s);
-    inflate_blocks_new := Z_NULL;
+    inflate_blocks_new := nil;
     exit;
   end;
 
-  s^.window := pBytef( ZALLOC(z, 1, w) );
-  if (s^.window = Z_NULL) then
+  s^.window := Pbyte( ZALLOC(z, 1, w) );
+  if (s^.window = nil) then
   begin
     ZFREE(z, s^.hufts);
     ZFREE(z, s);
-    inflate_blocks_new := Z_NULL;
+    inflate_blocks_new := nil;
     exit;
   end;
   s^.zend := s^.window;
@@ -162,34 +159,34 @@ begin
   {$IFDEF DEBUG}  
   Tracev('inflate:   blocks allocated');
   {$ENDIF}
-  inflate_blocks_reset(s^, z, Z_NULL);
+  inflate_blocks_reset(s^, z, nil);
   inflate_blocks_new := s;
 end;
 
 
 function inflate_blocks (var s : inflate_blocks_state;
                          var z : z_stream;
-                         r : int) : int;           { initial return code }
+                         r : integer) : integer;           { initial return code }
 label
   start_btree, start_dtree,
   start_blkdone, start_dry,
   start_codes;
 
 var
-  t : uInt;               { temporary storage }
-  b : uLong;              { bit buffer }
-  k : uInt;               { bits in bit buffer }
-  p : pBytef;             { input data pointer }
-  n : uInt;               { bytes available there }
-  q : pBytef;             { output window write pointer }
-  m : uInt;               { bytes to end of window or read pointer }
+  t : cardinal;               { temporary storage }
+  b : cardinal;              { bit buffer }
+  k : cardinal;               { bits in bit buffer }
+  p : Pbyte;             { input data pointer }
+  n : cardinal;               { bytes available there }
+  q : Pbyte;             { output window write pointer }
+  m : cardinal;               { bytes to end of window or read pointer }
 { fixed code blocks }
 var
-  bl, bd : uInt;
+  bl, bd : cardinal;
   tl, td : pInflate_huft;
 var
   h : pInflate_huft;
-  i, j, c : uInt;
+  i, j, c : cardinal;
 var
   cs : pInflate_codes_state;
 begin
@@ -199,10 +196,10 @@ begin
   b := s.bitb;
   k := s.bitk;
   q := s.write;
-  if ptr2int(q) < ptr2int(s.read) then
-    m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+  if ptrint(q) < ptrint(s.read) then
+    m := cardinal(ptrint(s.read)-ptrint(q)-1)
   else
-    m := uInt(ptr2int(s.zend)-ptr2int(q));
+    m := cardinal(ptrint(s.zend)-ptrint(q));
 
 { decompress an inflated block }
 
@@ -224,19 +221,19 @@ begin
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             exit;
           end;
-          Dec(n);
-          b := b or (uLong(p^) shl k);
+          dec(n);
+          b := b or (cardinal(p^) shl k);
           Inc(p);
           Inc(k, 8);
         end;
 
-        t := uInt(b) and 7;
+        t := cardinal(b) and 7;
         s.last := boolean(t and 1);
         case (t shr 1) of
           0:                         { stored }
@@ -249,12 +246,12 @@ begin
               {$ENDIF}
               {DUMPBITS(3);}
               b := b shr 3;
-              Dec(k, 3);
+              dec(k, 3);
 
               t := k and 7;                  { go to byte boundary }
               {DUMPBITS(t);}
               b := b shr t;
-              Dec(k, t);
+              dec(k, t);
 
               s.mode := LENS;                { get length of stored block }
             end;
@@ -269,14 +266,14 @@ begin
                 {$ENDIF}
                 inflate_trees_fixed(bl, bd, tl, td, z);
                 s.sub.decode.codes := inflate_codes_new(bl, bd, tl, td, z);
-                if (s.sub.decode.codes = Z_NULL) then
+                if (s.sub.decode.codes = nil) then
                 begin
                   r := Z_MEM_ERROR;
                   { update pointers and return }
                   s.bitb := b;
                   s.bitk := k;
                   z.avail_in := n;
-                  Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+                  Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
                   z.next_in := p;
                   s.write := q;
                   inflate_blocks := inflate_flush(s,z,r);
@@ -285,7 +282,7 @@ begin
               end;
               {DUMPBITS(3);}
               b := b shr 3;
-              Dec(k, 3);
+              dec(k, 3);
 
               s.mode := CODES;
             end;
@@ -299,7 +296,7 @@ begin
               {$ENDIF}                
               {DUMPBITS(3);}
               b := b shr 3;
-              Dec(k, 3);
+              dec(k, 3);
 
               s.mode := TABLE;
             end;
@@ -307,7 +304,7 @@ begin
             begin                   { illegal }
               {DUMPBITS(3);}
               b := b shr 3;
-              Dec(k, 3);
+              dec(k, 3);
 
               s.mode := BLKBAD;
               z.msg := 'invalid block type';
@@ -316,7 +313,7 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+              Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
               z.next_in := p;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
@@ -338,14 +335,14 @@ begin
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             exit;
           end;
-          Dec(n);
-          b := b or (uLong(p^) shl k);
+          dec(n);
+          b := b or (cardinal(p^) shl k);
           Inc(p);
           Inc(k, 8);
         end;
@@ -359,13 +356,13 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           exit;
         end;
-        s.sub.left := uInt(b) and $ffff;
+        s.sub.left := cardinal(b) and $ffff;
         k := 0;
         b := 0;                      { dump bits }
         {$IFDEF DEBUG}
@@ -387,7 +384,7 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
@@ -400,10 +397,10 @@ begin
           if (q = s.zend) and (s.read <> s.window) then
           begin
             q := s.window;
-            if ptr2int(q) < ptr2int(s.read) then
-              m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+            if ptrint(q) < ptrint(s.read) then
+              m := cardinal(ptrint(s.read)-ptrint(q)-1)
             else
-              m := uInt(ptr2int(s.zend)-ptr2int(q));
+              m := cardinal(ptrint(s.zend)-ptrint(q));
           end;
 
           if (m = 0) then
@@ -412,19 +409,19 @@ begin
             s.write := q;
             r := inflate_flush(s,z,r);
             q := s.write;
-            if ptr2int(q) < ptr2int(s.read) then
-              m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+            if ptrint(q) < ptrint(s.read) then
+              m := cardinal(ptrint(s.read)-ptrint(q)-1)
             else
-              m := uInt(ptr2int(s.zend)-ptr2int(q));
+              m := cardinal(ptrint(s.zend)-ptrint(q));
 
             {WRAP}
             if (q = s.zend) and (s.read <> s.window) then
             begin
               q := s.window;
-              if ptr2int(q) < ptr2int(s.read) then
-                m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+              if ptrint(q) < ptrint(s.read) then
+                m := cardinal(ptrint(s.read)-ptrint(q)-1)
               else
-                m := uInt(ptr2int(s.zend)-ptr2int(q));
+                m := cardinal(ptrint(s.zend)-ptrint(q));
             end;
 
             if (m = 0) then
@@ -433,7 +430,7 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
               z.next_in := p;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
@@ -449,19 +446,19 @@ begin
         if (t > m) then
           t := m;
         zmemcpy(q, p, t);
-        Inc(p, t);  Dec(n, t);
-        Inc(q, t);  Dec(m, t);
-        Dec(s.sub.left, t);
+        Inc(p, t);  dec(n, t);
+        Inc(q, t);  dec(m, t);
+        dec(s.sub.left, t);
         if (s.sub.left = 0) then
         begin
           {$IFDEF DEBUG}
-          if (ptr2int(q) >= ptr2int(s.read)) then
+          if (ptrint(q) >= ptrint(s.read)) then
             Tracev('inflate:       stored end '+
-                IntToStr(z.total_out + ptr2int(q) - ptr2int(s.read)) + ' total out')
+                IntToStr(z.total_out + ptrint(q) - ptrint(s.read)) + ' total out')
           else
             Tracev('inflate:       stored end '+
-                    IntToStr(z.total_out + ptr2int(s.zend) - ptr2int(s.read) +
-                    ptr2int(q) - ptr2int(s.window)) +  ' total out');
+                    IntToStr(z.total_out + ptrint(s.zend) - ptrint(s.read) +
+                    ptrint(q) - ptrint(s.window)) +  ' total out');
           {$ENDIF}
           if s.last then
             s.mode := DRY
@@ -483,19 +480,19 @@ begin
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             exit;
           end;
-          Dec(n);
-          b := b or (uLong(p^) shl k);
+          dec(n);
+          b := b or (cardinal(p^) shl k);
           Inc(p);
           Inc(k, 8);
         end;
 
-        t := uInt(b) and $3fff;
+        t := cardinal(b) and $3fff;
         s.sub.trees.table := t;
   {$ifndef PKZIP_BUG_WORKAROUND}
         if ((t and $1f) > 29) or (((t shr 5) and $1f) > 29) then
@@ -507,7 +504,7 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
@@ -515,15 +512,15 @@ begin
         end;
   {$endif}
         t := 258 + (t and $1f) + ((t shr 5) and $1f);
-        s.sub.trees.blens := puIntArray( ZALLOC(z, t, sizeof(uInt)) );
-        if (s.sub.trees.blens = Z_NULL) then
+        s.sub.trees.blens := puIntArray( ZALLOC(z, t, sizeof(cardinal)) );
+        if (s.sub.trees.blens = nil) then
         begin
           r := Z_MEM_ERROR;
           { update pointers and return }
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
@@ -531,7 +528,7 @@ begin
         end;
         {DUMPBITS(14);}
         b := b shr 14;
-        Dec(k, 14);
+        dec(k, 14);
 
         s.sub.trees.index := 0;
         {$IFDEF DEBUG}
@@ -559,23 +556,23 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
               z.next_in := p;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               exit;
             end;
-            Dec(n);
-            b := b or (uLong(p^) shl k);
+            dec(n);
+            b := b or (cardinal(p^) shl k);
             Inc(p);
             Inc(k, 8);
           end;
 
-          s.sub.trees.blens^[border[s.sub.trees.index]] := uInt(b) and 7;
+          s.sub.trees.blens^[border[s.sub.trees.index]] := cardinal(b) and 7;
           Inc(s.sub.trees.index);
           {DUMPBITS(3);}
           b := b shr 3;
-          Dec(k, 3);
+          dec(k, 3);
         end;
         while (s.sub.trees.index < 19) do
         begin
@@ -595,7 +592,7 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
@@ -631,20 +628,20 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
               z.next_in := p;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               exit;
             end;
-            Dec(n);
-            b := b or (uLong(p^) shl k);
+            dec(n);
+            b := b or (cardinal(p^) shl k);
             Inc(p);
             Inc(k, 8);
           end;
 
           h := s.sub.trees.tb;
-          Inc(h, uInt(b) and inflate_mask[t]);
+          Inc(h, cardinal(b) and inflate_mask[t]);
           t := h^.Bits;
           c := h^.Base;
 
@@ -652,7 +649,7 @@ begin
           begin
             {DUMPBITS(t);}
             b := b shr t;
-            Dec(k, t);
+            dec(k, t);
 
             s.sub.trees.blens^[s.sub.trees.index] := c;
             Inc(s.sub.trees.index);
@@ -681,26 +678,26 @@ begin
                 s.bitb := b;
                 s.bitk := k;
                 z.avail_in := n;
-                Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+                Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
                 z.next_in := p;
                 s.write := q;
                 inflate_blocks := inflate_flush(s,z,r);
                 exit;
               end;
-              Dec(n);
-              b := b or (uLong(p^) shl k);
+              dec(n);
+              b := b or (cardinal(p^) shl k);
               Inc(p);
               Inc(k, 8);
             end;
 
             {DUMPBITS(t);}
             b := b shr t;
-            Dec(k, t);
+            dec(k, t);
 
-            Inc(j, uInt(b) and inflate_mask[i]);
+            Inc(j, cardinal(b) and inflate_mask[i]);
             {DUMPBITS(i);}
             b := b shr i;
-            Dec(k, i);
+            dec(k, i);
 
             i := s.sub.trees.index;
             t := s.sub.trees.table;
@@ -715,7 +712,7 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+              Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
               z.next_in := p;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
@@ -728,12 +725,12 @@ begin
             repeat
               s.sub.trees.blens^[i] := c;
               Inc(i);
-              Dec(j);
+              dec(j);
             until (j=0);
             s.sub.trees.index := i;
           end;
         end; { while }
-        s.sub.trees.tb := Z_NULL;
+        s.sub.trees.tb := nil;
         begin
           bl := 9;         { must be <= 9 for lookahead assumptions }
           bd := 6;         { must be <= 9 for lookahead assumptions }
@@ -744,14 +741,14 @@ begin
           ZFREE(z, s.sub.trees.blens);
           if (t <> Z_OK) then
           begin
-            if (t = uInt(Z_DATA_ERROR)) then
+            if (t = cardinal(Z_DATA_ERROR)) then
               s.mode := BLKBAD;
             r := t;
             { update pointers and return }
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+            Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
@@ -762,14 +759,14 @@ begin
           {$ENDIF}          
           { c renamed to cs }
           cs := inflate_codes_new(bl, bd, tl, td, z);
-          if (cs = Z_NULL) then
+          if (cs = nil) then
           begin
             r := Z_MEM_ERROR;
             { update pointers and return }
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+            Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
@@ -788,7 +785,7 @@ begin
         s.bitb := b;
         s.bitk := k;
         z.avail_in := n;
-        Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+        Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
         z.next_in := p;
         s.write := q;
 
@@ -806,18 +803,18 @@ begin
         b := s.bitb;
         k := s.bitk;
         q := s.write;
-        if ptr2int(q) < ptr2int(s.read) then
-          m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+        if ptrint(q) < ptrint(s.read) then
+          m := cardinal(ptrint(s.read)-ptrint(q)-1)
         else
-          m := uInt(ptr2int(s.zend)-ptr2int(q));
+          m := cardinal(ptrint(s.zend)-ptrint(q));
         {$IFDEF DEBUG}
-        if (ptr2int(q) >= ptr2int(s.read)) then
+        if (ptrint(q) >= ptrint(s.read)) then
           Tracev('inflate:       codes end '+
-              IntToStr(z.total_out + ptr2int(q) - ptr2int(s.read)) + ' total out')
+              IntToStr(z.total_out + ptrint(q) - ptrint(s.read)) + ' total out')
         else
           Tracev('inflate:       codes end '+
-                  IntToStr(z.total_out + ptr2int(s.zend) - ptr2int(s.read) +
-                  ptr2int(q) - ptr2int(s.window)) +  ' total out');
+                  IntToStr(z.total_out + ptrint(s.zend) - ptrint(s.read) +
+                  ptrint(q) - ptrint(s.window)) +  ' total out');
         {$ENDIF}
         if (not s.last) then
         begin
@@ -830,9 +827,9 @@ begin
           {$IFDEF DEBUG}
           Assert(k < 16, 'inflate_codes grabbed too many bytes');
           {$ENDIF}
-          Dec(k, 8);
-          Inc(n);
-          Dec(p);                    { can always return one }
+          dec(k, 8);
+          inc(n);
+          dec(p);                    { can always return one }
         end;
         {$endif}
         s.mode := DRY;
@@ -848,10 +845,10 @@ begin
         q := s.write;
 
         { not needed anymore, we are done:
-        if ptr2int(q) < ptr2int(s.read) then
-          m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+        if ptrint(q) < ptrint(s.read) then
+          m := cardinal(ptrint(s.read)-ptrint(q)-1)
         else
-          m := uInt(ptr2int(s.zend)-ptr2int(q));
+          m := cardinal(ptrint(s.zend)-ptrint(q));
         }
 
         if (s.read <> s.write) then
@@ -860,7 +857,7 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
@@ -877,7 +874,7 @@ begin
         s.bitb := b;
         s.bitk := k;
         z.avail_in := n;
-        Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+        Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
         z.next_in := p;
         s.write := q;
         inflate_blocks := inflate_flush(s,z,r);
@@ -890,7 +887,7 @@ begin
         s.bitb := b;
         s.bitk := k;
         z.avail_in := n;
-        Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+        Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
         z.next_in := p;
         s.write := q;
         inflate_blocks := inflate_flush(s,z,r);
@@ -903,7 +900,7 @@ begin
       s.bitb := b;
       s.bitk := k;
       z.avail_in := n;
-      Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+      Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
       z.next_in := p;
       s.write := q;
       inflate_blocks := inflate_flush(s,z,r);
@@ -915,9 +912,9 @@ end;
 
 
 function inflate_blocks_free(s : pInflate_blocks_state;
-                             var z : z_stream) : int;
+                             var z : z_stream) : integer;
 begin
-  inflate_blocks_reset(s^, z, Z_NULL);
+  inflate_blocks_reset(s^, z, nil);
   ZFREE(z, s^.window);
   ZFREE(z, s^.hufts);
   ZFREE(z, s);
@@ -930,9 +927,9 @@ end;
 
 procedure inflate_set_dictionary(var s : inflate_blocks_state;
                                  const d : array of byte; { dictionary }
-                                 n : uInt);         { dictionary length }
+                                 n : cardinal);         { dictionary length }
 begin
-  zmemcpy(s.window, pBytef(@d), n);
+  zmemcpy(s.window, Pbyte(@d), n);
   s.write := s.window;
   Inc(s.write, n);
   s.read := s.write;
@@ -941,11 +938,11 @@ end;
 
 { Returns true if inflate is currently at the end of a block generated
   by Z_SYNC_FLUSH or Z_FULL_FLUSH.
-  IN assertion: s <> Z_NULL }
+  IN assertion: s <> nil }
 
-function inflate_blocks_sync_point(var s : inflate_blocks_state) : int;
+function inflate_blocks_sync_point(var s : inflate_blocks_state) : integer;
 begin
-  inflate_blocks_sync_point := int(s.mode = LENS);
+  inflate_blocks_sync_point := integer(s.mode = LENS);
 end;
 
 end.

+ 82 - 85
packages/base/paszlib/infcodes.pas

@@ -1,4 +1,4 @@
-Unit InfCodes;
+unit infcodes;
 
 { infcodes.c -- process literals and length/distance pairs
   Copyright (C) 1995-1998 Mark Adler
@@ -13,20 +13,17 @@ interface
 {$I zconf.inc}
 
 uses
-  {$IFDEF DEBUG}
-  strutils,
-  {$ENDIF}
   zutil, zbase;
 
-function inflate_codes_new (bl : uInt;
-                            bd : uInt;
+function inflate_codes_new (bl : cardinal;
+                            bd : cardinal;
                             tl : pInflate_huft;
                             td : pInflate_huft;
                             var z : z_stream): pInflate_codes_state;
 
 function inflate_codes(var s : inflate_blocks_state;
                        var z : z_stream;
-                       r : int) : int;
+                       r : integer) : integer;
 
 procedure inflate_codes_free(c : pInflate_codes_state;
                              var z : z_stream);
@@ -37,8 +34,8 @@ uses
   infutil, inffast;
 
 
-function inflate_codes_new (bl : uInt;
-                            bd : uInt;
+function inflate_codes_new (bl : cardinal;
+                            bd : cardinal;
                             tl : pInflate_huft;
                             td : pInflate_huft;
                             var z : z_stream): pInflate_codes_state;
@@ -63,18 +60,18 @@ end;
 
 function inflate_codes(var s : inflate_blocks_state;
                        var z : z_stream;
-                       r : int) : int;
+                       r : integer) : integer;
 var
-  j : uInt;               { temporary storage }
+  j : cardinal;               { temporary storage }
   t : pInflate_huft;      { temporary pointer }
-  e : uInt;               { extra bits or operation }
-  b : uLong;              { bit buffer }
-  k : uInt;               { bits in bit buffer }
-  p : pBytef;             { input data pointer }
-  n : uInt;               { bytes available there }
-  q : pBytef;             { output window write pointer }
-  m : uInt;               { bytes to end of window or read pointer }
-  f : pBytef;             { pointer to copy strings from }
+  e : cardinal;               { extra bits or operation }
+  b : cardinal;              { bit buffer }
+  k : cardinal;               { bits in bit buffer }
+  p : Pbyte;             { input data pointer }
+  n : cardinal;               { bytes available there }
+  q : Pbyte;             { output window write pointer }
+  m : cardinal;               { bytes to end of window or read pointer }
+  f : Pbyte;             { pointer to copy strings from }
 var
   c : pInflate_codes_state;
 begin
@@ -86,10 +83,10 @@ begin
   b := s.bitb;
   k := s.bitk;
   q := s.write;
-  if ptr2int(q) < ptr2int(s.read) then
-    m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+  if ptrint(q) < ptrint(s.read) then
+    m := cardinal(ptrint(s.read)-ptrint(q)-1)
   else
-    m := uInt(ptr2int(s.zend)-ptr2int(q));
+    m := cardinal(ptrint(s.zend)-ptrint(q));
 
   { process input and output based on current state }
   while True do
@@ -104,7 +101,7 @@ begin
         s.bitb := b;
         s.bitk := k;
         z.avail_in := n;
-        Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+        Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
         z.next_in := p;
         s.write := q;
 
@@ -115,10 +112,10 @@ begin
         b := s.bitb;
         k := s.bitk;
         q := s.write;
-        if ptr2int(q) < ptr2int(s.read) then
-          m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+        if ptrint(q) < ptrint(s.read) then
+          m := cardinal(ptrint(s.read)-ptrint(q)-1)
         else
-          m := uInt(ptr2int(s.zend)-ptr2int(q));
+          m := cardinal(ptrint(s.zend)-ptrint(q));
 
         if (r <> Z_OK) then
         begin
@@ -149,24 +146,24 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_codes := inflate_flush(s,z,r);
           exit;
         end;
-        Dec(n);
-        b := b or (uLong(p^) shl k);
+        dec(n);
+        b := b or (cardinal(p^) shl k);
         Inc(p);
         Inc(k, 8);
       end;
       t := c^.sub.code.tree;
-      Inc(t, uInt(b) and inflate_mask[j]);
+      Inc(t, cardinal(b) and inflate_mask[j]);
       {DUMPBITS(t^.bits);}
       b := b shr t^.bits;
-      Dec(k, t^.bits);
+      dec(k, t^.bits);
 
-      e := uInt(t^.exop);
+      e := cardinal(t^.exop);
       if (e = 0) then            { literal }
       begin
         c^.sub.lit := t^.base;
@@ -207,7 +204,7 @@ begin
       s.bitb := b;
       s.bitk := k;
       z.avail_in := n;
-      Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+      Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
       z.next_in := p;
       s.write := q;
       inflate_codes := inflate_flush(s,z,r);
@@ -228,21 +225,21 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_codes := inflate_flush(s,z,r);
           exit;
         end;
-        Dec(n);
-        b := b or (uLong(p^) shl k);
+        dec(n);
+        b := b or (cardinal(p^) shl k);
         Inc(p);
         Inc(k, 8);
       end;
-      Inc(c^.len, uInt(b and inflate_mask[j]));
+      Inc(c^.len, cardinal(b and inflate_mask[j]));
       {DUMPBITS(j);}
       b := b shr j;
-      Dec(k, j);
+      dec(k, j);
 
       c^.sub.code.need := c^.dbits;
       c^.sub.code.tree := c^.dtree;
@@ -267,23 +264,23 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_codes := inflate_flush(s,z,r);
           exit;
         end;
-        Dec(n);
-        b := b or (uLong(p^) shl k);
+        dec(n);
+        b := b or (cardinal(p^) shl k);
         Inc(p);
         Inc(k, 8);
       end;
-      t := @huft_ptr(c^.sub.code.tree)^[uInt(b) and inflate_mask[j]];
+      t := @huft_ptr(c^.sub.code.tree)^[cardinal(b) and inflate_mask[j]];
       {DUMPBITS(t^.bits);}
       b := b shr t^.bits;
-      Dec(k, t^.bits);
+      dec(k, t^.bits);
 
-      e := uInt(t^.exop);
+      e := cardinal(t^.exop);
       if (e and 16 <> 0) then            { distance }
       begin
         c^.sub.copy.get := e and 15;
@@ -304,7 +301,7 @@ begin
       s.bitb := b;
       s.bitk := k;
       z.avail_in := n;
-      Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+      Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
       z.next_in := p;
       s.write := q;
       inflate_codes := inflate_flush(s,z,r);
@@ -325,21 +322,21 @@ begin
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+          Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_codes := inflate_flush(s,z,r);
           exit;
         end;
-        Dec(n);
-        b := b or (uLong(p^) shl k);
+        dec(n);
+        b := b or (cardinal(p^) shl k);
         Inc(p);
         Inc(k, 8);
       end;
-      Inc(c^.sub.copy.dist, uInt(b) and inflate_mask[j]);
+      Inc(c^.sub.copy.dist, cardinal(b) and inflate_mask[j]);
       {DUMPBITS(j);}
       b := b shr j;
-      Dec(k, j);
+      dec(k, j);
       {$IFDEF DEBUG}
       Tracevv('inflate:         distance '+ IntToStr(c^.sub.copy.dist));
       {$ENDIF}
@@ -349,11 +346,11 @@ begin
   COPY:          { o: copying bytes in window, waiting for space }
     begin
       f := q;
-      Dec(f, c^.sub.copy.dist);
-      if (uInt(ptr2int(q) - ptr2int(s.window)) < c^.sub.copy.dist) then
+      dec(f, c^.sub.copy.dist);
+      if (cardinal(ptrint(q) - ptrint(s.window)) < c^.sub.copy.dist) then
       begin
         f := s.zend;
-        Dec(f, c^.sub.copy.dist - uInt(ptr2int(q) - ptr2int(s.window)));
+        dec(f, c^.sub.copy.dist - cardinal(ptrint(q) - ptrint(s.window)));
       end;
 
       while (c^.len <> 0) do
@@ -365,10 +362,10 @@ begin
           if (q = s.zend) and (s.read <> s.window) then
           begin
             q := s.window;
-            if ptr2int(q) < ptr2int(s.read) then
-              m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+            if ptrint(q) < ptrint(s.read) then
+              m := cardinal(ptrint(s.read)-ptrint(q)-1)
             else
-              m := uInt(ptr2int(s.zend)-ptr2int(q));
+              m := cardinal(ptrint(s.zend)-ptrint(q));
           end;
 
           if (m = 0) then
@@ -377,19 +374,19 @@ begin
             s.write := q;
             r := inflate_flush(s,z,r);
             q := s.write;
-            if ptr2int(q) < ptr2int(s.read) then
-              m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+            if ptrint(q) < ptrint(s.read) then
+              m := cardinal(ptrint(s.read)-ptrint(q)-1)
             else
-              m := uInt(ptr2int(s.zend)-ptr2int(q));
+              m := cardinal(ptrint(s.zend)-ptrint(q));
 
             {WRAP}
             if (q = s.zend) and (s.read <> s.window) then
             begin
               q := s.window;
-              if ptr2int(q) < ptr2int(s.read) then
-                m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+              if ptrint(q) < ptrint(s.read) then
+                m := cardinal(ptrint(s.read)-ptrint(q)-1)
               else
-                m := uInt(ptr2int(s.zend)-ptr2int(q));
+                m := cardinal(ptrint(s.zend)-ptrint(q));
             end;
 
             if (m = 0) then
@@ -398,7 +395,7 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
               z.next_in := p;
               s.write := q;
               inflate_codes := inflate_flush(s,z,r);
@@ -412,11 +409,11 @@ begin
         q^ := f^;
         Inc(q);
         Inc(f);
-        Dec(m);
+        dec(m);
 
         if (f = s.zend) then
           f := s.window;
-        Dec(c^.len);
+        dec(c^.len);
       end;
       c^.mode := START;
       { C-switch break; not needed }
@@ -430,10 +427,10 @@ begin
         if (q = s.zend) and (s.read <> s.window) then
         begin
           q := s.window;
-          if ptr2int(q) < ptr2int(s.read) then
-            m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+          if ptrint(q) < ptrint(s.read) then
+            m := cardinal(ptrint(s.read)-ptrint(q)-1)
           else
-            m := uInt(ptr2int(s.zend)-ptr2int(q));
+            m := cardinal(ptrint(s.zend)-ptrint(q));
         end;
 
         if (m = 0) then
@@ -442,19 +439,19 @@ begin
           s.write := q;
           r := inflate_flush(s,z,r);
           q := s.write;
-          if ptr2int(q) < ptr2int(s.read) then
-            m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+          if ptrint(q) < ptrint(s.read) then
+            m := cardinal(ptrint(s.read)-ptrint(q)-1)
           else
-            m := uInt(ptr2int(s.zend)-ptr2int(q));
+            m := cardinal(ptrint(s.zend)-ptrint(q));
 
           {WRAP}
           if (q = s.zend) and (s.read <> s.window) then
           begin
             q := s.window;
-            if ptr2int(q) < ptr2int(s.read) then
-              m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+            if ptrint(q) < ptrint(s.read) then
+              m := cardinal(ptrint(s.read)-ptrint(q)-1)
             else
-              m := uInt(ptr2int(s.zend)-ptr2int(q));
+              m := cardinal(ptrint(s.zend)-ptrint(q));
           end;
 
           if (m = 0) then
@@ -463,7 +460,7 @@ begin
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
             inflate_codes := inflate_flush(s,z,r);
@@ -476,7 +473,7 @@ begin
       {OUTBYTE(c^.sub.lit);}
       q^ := c^.sub.lit;
       Inc(q);
-      Dec(m);
+      dec(m);
 
       c^.mode := START;
       {break;}
@@ -489,19 +486,19 @@ begin
         {$IFDEF DEBUG}
         Assert(k < 16, 'inflate_codes grabbed too many bytes');
         {$ENDIF}
-        Dec(k, 8);
+        dec(k, 8);
         Inc(n);
-        Dec(p);                    { can always return one }
+        dec(p);                    { can always return one }
       end;
       {$endif}
       {FLUSH}
       s.write := q;
       r := inflate_flush(s,z,r);
       q := s.write;
-      if ptr2int(q) < ptr2int(s.read) then
-        m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+      if ptrint(q) < ptrint(s.read) then
+        m := cardinal(ptrint(s.read)-ptrint(q)-1)
       else
-        m := uInt(ptr2int(s.zend)-ptr2int(q));
+        m := cardinal(ptrint(s.zend)-ptrint(q));
 
       if (s.read <> s.write) then
       begin
@@ -509,7 +506,7 @@ begin
         s.bitb := b;
         s.bitk := k;
         z.avail_in := n;
-        Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+        Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
         z.next_in := p;
         s.write := q;
         inflate_codes := inflate_flush(s,z,r);
@@ -526,7 +523,7 @@ begin
       s.bitb := b;
       s.bitk := k;
       z.avail_in := n;
-      Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+      Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
       z.next_in := p;
       s.write := q;
       inflate_codes := inflate_flush(s,z,r);
@@ -539,7 +536,7 @@ begin
       s.bitb := b;
       s.bitk := k;
       z.avail_in := n;
-      Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+      Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
       z.next_in := p;
       s.write := q;
       inflate_codes := inflate_flush(s,z,r);
@@ -552,7 +549,7 @@ begin
       s.bitb := b;
       s.bitk := k;
       z.avail_in := n;
-      Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+      Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
       z.next_in := p;
       s.write := q;
       inflate_codes := inflate_flush(s,z,r);

+ 80 - 83
packages/base/paszlib/inffast.pas

@@ -16,17 +16,14 @@ interface
 {$I zconf.inc}
 
 uses
-  {$ifdef DEBUG}
-  strutils,
-  {$ENDIF}
   zutil, zbase;
 
-function inflate_fast( bl : uInt;
-                       bd : uInt;
+function inflate_fast( bl : cardinal;
+                       bd : cardinal;
                        tl : pInflate_huft;
                        td : pInflate_huft;
                       var s : inflate_blocks_state;
-                      var z : z_stream) : int;
+                      var z : z_stream) : integer;
 
 
 implementation
@@ -40,27 +37,27 @@ uses
   at least ten.  The ten bytes are six bytes for the longest length/
   distance pair plus four bytes for overloading the bit buffer. }
 
-function inflate_fast( bl : uInt;
-                       bd : uInt;
+function inflate_fast( bl : cardinal;
+                       bd : cardinal;
                        tl : pInflate_huft;
                        td : pInflate_huft;
                       var s : inflate_blocks_state;
-                      var z : z_stream) : int;
+                      var z : z_stream) : integer;
 
 var
   t : pInflate_huft;      { temporary pointer }
-  e : uInt;               { extra bits or operation }
-  b : uLong;              { bit buffer }
-  k : uInt;               { bits in bit buffer }
-  p : pBytef;             { input data pointer }
-  n : uInt;               { bytes available there }
-  q : pBytef;             { output window write pointer }
-  m : uInt;               { bytes to end of window or read pointer }
-  ml : uInt;              { mask for literal/length tree }
-  md : uInt;              { mask for distance tree }
-  c : uInt;               { bytes to copy }
-  d : uInt;               { distance back to copy from }
-  r : pBytef;             { copy source pointer }
+  e : cardinal;               { extra bits or operation }
+  b : longint;              { bit buffer }
+  k : cardinal;               { bits in bit buffer }
+  p : Pbyte;             { input data pointer }
+  n : cardinal;               { bytes available there }
+  q : Pbyte;             { output window write pointer }
+  m : cardinal;               { bytes to end of window or read pointer }
+  ml : cardinal;              { mask for literal/length tree }
+  md : cardinal;              { mask for distance tree }
+  c : cardinal;               { bytes to copy }
+  d : cardinal;               { distance back to copy from }
+  r : Pbyte;             { copy source pointer }
 begin
   { load input, output, bit values (macro LOAD) }
   p := z.next_in;
@@ -68,10 +65,10 @@ begin
   b := s.bitb;
   k := s.bitk;
   q := s.write;
-  if ptr2int(q) < ptr2int(s.read) then
-    m := uInt(ptr2int(s.read)-ptr2int(q)-1)
+  if ptrint(q) < ptrint(s.read) then
+    m := cardinal(ptrint(s.read)-ptrint(q)-1)
   else
-    m := uInt(ptr2int(s.zend)-ptr2int(q));
+    m := cardinal(ptrint(s.zend)-ptrint(q));
 
   { initialize masks }
   ml := inflate_mask[bl];
@@ -83,20 +80,20 @@ begin
     {GRABBITS(20);}             { max bits for literal/length code }
     while (k < 20) do
     begin
-      Dec(n);
-      b := b or (uLong(p^) shl k);
-      Inc(p);
-      Inc(k, 8);
+      dec(n);
+      b := b or (longint(p^) shl k);
+      inc(p);
+      inc(k, 8);
     end;
 
-    t := @(huft_ptr(tl)^[uInt(b) and ml]);
+    t := @(huft_ptr(tl)^[cardinal(b) and ml]);
 
     e := t^.exop;
     if (e = 0) then
     begin
       {DUMPBITS(t^.bits);}
       b := b shr t^.bits;
-      Dec(k, t^.bits);
+      dec(k, t^.bits);
      {$IFDEF DEBUG}
       if (t^.base >= $20) and (t^.base < $7f) then
         Tracevv('inflate:         * literal '+char(t^.base))
@@ -104,23 +101,23 @@ begin
         Tracevv('inflate:         * literal '+ IntToStr(t^.base));
       {$ENDIF}
       q^ := Byte(t^.base);
-      Inc(q);
-      Dec(m);
+      inc(q);
+      dec(m);
       continue;
     end;
     repeat
       {DUMPBITS(t^.bits);}
       b := b shr t^.bits;
-      Dec(k, t^.bits);
+      dec(k, t^.bits);
 
       if (e and 16 <> 0) then
       begin
         { get extra bits for length }
         e := e and 15;
-        c := t^.base + (uInt(b) and inflate_mask[e]);
+        c := t^.base + (cardinal(b) and inflate_mask[e]);
         {DUMPBITS(e);}
         b := b shr e;
-        Dec(k, e);
+        dec(k, e);
         {$IFDEF DEBUG}
         Tracevv('inflate:         * length ' + IntToStr(c));
         {$ENDIF}
@@ -128,18 +125,18 @@ begin
         {GRABBITS(15);}           { max bits for distance code }
         while (k < 15) do
         begin
-          Dec(n);
-          b := b or (uLong(p^) shl k);
-          Inc(p);
-          Inc(k, 8);
+          dec(n);
+          b := b or (longint(p^) shl k);
+          inc(p);
+          inc(k, 8);
         end;
 
-        t := @huft_ptr(td)^[uInt(b) and md];
+        t := @huft_ptr(td)^[cardinal(b) and md];
         e := t^.exop;
         repeat
           {DUMPBITS(t^.bits);}
           b := b shr t^.bits;
-          Dec(k, t^.bits);
+          dec(k, t^.bits);
 
           if (e and 16 <> 0) then
           begin
@@ -148,58 +145,58 @@ begin
             {GRABBITS(e);}         { get extra bits (up to 13) }
             while (k < e) do
             begin
-              Dec(n);
-              b := b or (uLong(p^) shl k);
-              Inc(p);
-              Inc(k, 8);
+              dec(n);
+              b := b or (longint(p^) shl k);
+              inc(p);
+              inc(k, 8);
             end;
 
-            d := t^.base + (uInt(b) and inflate_mask[e]);
+            d := t^.base + (cardinal(b) and inflate_mask[e]);
             {DUMPBITS(e);}
             b := b shr e;
-            Dec(k, e);
+            dec(k, e);
 
             {$IFDEF DEBUG}
             Tracevv('inflate:         * distance '+IntToStr(d));
             {$ENDIF}
             { do the copy }
-            Dec(m, c);
-            if (uInt(ptr2int(q) - ptr2int(s.window)) >= d) then     { offset before dest }
+            dec(m, c);
+            if (cardinal(ptrint(q) - ptrint(s.window)) >= d) then     { offset before dest }
             begin                                  {  just copy }
               r := q;
-              Dec(r, d);
-              q^ := r^;  Inc(q); Inc(r); Dec(c); { minimum count is three, }
-              q^ := r^;  Inc(q); Inc(r); Dec(c); { so unroll loop a little }
+              dec(r, d);
+              q^ := r^;  inc(q); inc(r); dec(c); { minimum count is three, }
+              q^ := r^;  inc(q); inc(r); dec(c); { so unroll loop a little }
             end
             else                        { else offset after destination }
             begin
-              e := d - uInt(ptr2int(q) - ptr2int(s.window)); { bytes from offset to end }
+              e := d - cardinal(ptrint(q) - ptrint(s.window)); { bytes from offset to end }
               r := s.zend;
-              Dec(r, e);                  { pointer to offset }
+              dec(r, e);                  { pointer to offset }
               if (c > e) then             { if source crosses, }
               begin
-                Dec(c, e);                { copy to end of window }
+                dec(c, e);                { copy to end of window }
                 repeat
                   q^ := r^;
-                  Inc(q);
-                  Inc(r);
-                  Dec(e);
+                  inc(q);
+                  inc(r);
+                  dec(e);
                 until (e=0);
                 r := s.window;           { copy rest from start of window }
               end;
             end;
             repeat                       { copy all or what's left }
               q^ := r^;
-              Inc(q);
-              Inc(r);
-              Dec(c);
+              inc(q);
+              inc(r);
+              dec(c);
             until (c = 0);
             break;
           end
           else
             if (e and 64 = 0) then
             begin
-              Inc(t, t^.base + (uInt(b) and inflate_mask[e]));
+              inc(t, t^.base + (cardinal(b) and inflate_mask[e]));
               e := t^.exop;
             end
           else
@@ -209,14 +206,14 @@ begin
             c := z.avail_in-n;
             if (k shr 3) < c then
               c := k shr 3;
-            Inc(n, c);
-            Dec(p, c);
-            Dec(k, c shl 3);
+            inc(n, c);
+            dec(p, c);
+            dec(k, c shl 3);
             {UPDATE}
             s.bitb := b;
             s.bitk := k;
             z.avail_in := n;
-            Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+            inc(z.total_in, ptrint(p)-ptrint(z.next_in));
             z.next_in := p;
             s.write := q;
 
@@ -229,15 +226,15 @@ begin
       if (e and 64 = 0) then
       begin
          {t += t->base;
-          e = (t += ((uInt)b & inflate_mask[e]))->exop;}
+          e = (t += ((cardinal)b & inflate_mask[e]))->exop;}
 
-        Inc(t, t^.base + (uInt(b) and inflate_mask[e]));
+        inc(t, t^.base + (cardinal(b) and inflate_mask[e]));
         e := t^.exop;
         if (e = 0) then
         begin
           {DUMPBITS(t^.bits);}
           b := b shr t^.bits;
-          Dec(k, t^.bits);
+          dec(k, t^.bits);
 
          {$IFDEF DEBUG}
           if (t^.base >= $20) and (t^.base < $7f) then
@@ -246,8 +243,8 @@ begin
             Tracevv('inflate:         * literal '+IntToStr(t^.base));
           {$ENDIF}            
           q^ := Byte(t^.base);
-          Inc(q);
-          Dec(m);
+          inc(q);
+          dec(m);
           break;
         end;
       end
@@ -261,14 +258,14 @@ begin
           c := z.avail_in-n;
           if (k shr 3) < c then
             c := k shr 3;
-          Inc(n, c);
-          Dec(p, c);
-          Dec(k, c shl 3);
+          inc(n, c);
+          dec(p, c);
+          dec(k, c shl 3);
           {UPDATE}
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+          inc(z.total_in, ptrint(p)-ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_fast := Z_STREAM_END;
@@ -281,14 +278,14 @@ begin
           c := z.avail_in-n;
           if (k shr 3) < c then
             c := k shr 3;
-          Inc(n, c);
-          Dec(p, c);
-          Dec(k, c shl 3);
+          inc(n, c);
+          dec(p, c);
+          dec(k, c shl 3);
           {UPDATE}
           s.bitb := b;
           s.bitk := k;
           z.avail_in := n;
-          Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+          inc(z.total_in, ptrint(p)-ptrint(z.next_in));
           z.next_in := p;
           s.write := q;
           inflate_fast := Z_DATA_ERROR;
@@ -302,14 +299,14 @@ begin
   c := z.avail_in-n;
   if (k shr 3) < c then
     c := k shr 3;
-  Inc(n, c);
-  Dec(p, c);
-  Dec(k, c shl 3);
+  inc(n, c);
+  dec(p, c);
+  dec(k, c shl 3);
   {UPDATE}
   s.bitb := b;
   s.bitk := k;
   z.avail_in := n;
-  Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in));
+  inc(z.total_in, ptrint(p)-ptrint(z.next_in));
   z.next_in := p;
   s.write := q;
   inflate_fast := Z_OK;

+ 91 - 91
packages/base/paszlib/inftrees.pas

@@ -1,4 +1,4 @@
-Unit InfTrees;
+unit inftrees;
 
 { inftrees.h -- header to use inftrees.c
   inftrees.c -- generate Huffman trees for efficient decoding
@@ -13,7 +13,7 @@ Unit InfTrees;
   For conditions of distribution and use, see copyright notice in readme.txt
 }
 
-Interface
+interface
 
 {$I zconf.inc}
 
@@ -32,36 +32,36 @@ const
 
 {$ifdef DEBUG}
 var
-  inflate_hufts : uInt;
+  inflate_hufts : cardinal;
 {$endif}
 
 function inflate_trees_bits(
-  var c : array of uIntf;  { 19 code lengths }
-  var bb : uIntf;          { bits tree desired/actual depth }
+  var c : array of cardinal;  { 19 code lengths }
+  var bb : cardinal;          { bits tree desired/actual depth }
   var tb : pinflate_huft;  { bits tree result }
   var hp : array of Inflate_huft;      { space for trees }
   var z : z_stream         { for messages }
-    ) : int;
+    ) : integer;
 
 function inflate_trees_dynamic(
-    nl : uInt;                    { number of literal/length codes }
-    nd : uInt;                    { number of distance codes }
-    var c : Array of uIntf;           { that many (total) code lengths }
-    var bl : uIntf;               { literal desired/actual bit depth }
-    var bd : uIntf;               { distance desired/actual bit depth }
+    nl : cardinal;                    { number of literal/length codes }
+    nd : cardinal;                    { number of distance codes }
+    var c : Array of cardinal;           { that many (total) code lengths }
+    var bl : cardinal;               { literal desired/actual bit depth }
+    var bd : cardinal;               { distance desired/actual bit depth }
 var tl : pInflate_huft;           { literal/length tree result }
 var td : pInflate_huft;           { distance tree result }
 var hp : array of Inflate_huft;   { space for trees }
 var z : z_stream                  { for messages }
-     ) : int;
+     ) : integer;
 
 function inflate_trees_fixed (
-    var bl : uInt;                { literal desired/actual bit depth }
-    var bd : uInt;                { distance desired/actual bit depth }
+    var bl : cardinal;                { literal desired/actual bit depth }
+    var bd : cardinal;                { distance desired/actual bit depth }
     var tl : pInflate_huft;       { literal/length tree result }
     var td : pInflate_huft;       { distance tree result }
     var z : z_stream              { for memory allocation }
-     ) : int;
+     ) : integer;
 
 
 implementation
@@ -79,23 +79,23 @@ const
 
 const
 { Tables for deflate from PKZIP's appnote.txt. }
-  cplens : Array [0..30] Of uInt  { Copy lengths for literal codes 257..285 }
+  cplens : Array [0..30] Of cardinal  { Copy lengths for literal codes 257..285 }
      = (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);
         { actually lengths - 2; also see note #13 above about 258 }
 
   invalid_code = 112;
 
-  cplext : Array [0..30] Of uInt  { Extra bits for literal codes 257..285 }
+  cplext : Array [0..30] Of cardinal  { Extra bits for literal codes 257..285 }
      = (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
         3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, invalid_code, invalid_code);
 
-  cpdist : Array [0..29] Of uInt { Copy offsets for distance codes 0..29 }
+  cpdist : Array [0..29] Of cardinal { Copy offsets for distance codes 0..29 }
      = (1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
         8193, 12289, 16385, 24577);
 
-  cpdext : Array [0..29] Of uInt { Extra bits for distance codes }
+  cpdext : Array [0..29] Of cardinal { Extra bits for distance codes }
      = (0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
         7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
         12, 12, 13, 13);
@@ -138,48 +138,48 @@ const
 {$DEFINE USE_PTR}
 
 function huft_build(
-var b : array of uIntf;    { code lengths in bits (all assumed <= BMAX) }
-    n : uInt;              { number of codes (assumed <= N_MAX) }
-    s : uInt;              { number of simple-valued codes (0..s-1) }
-const d : array of uIntf;  { list of base values for non-simple codes }
+var b : array of cardinal;    { code lengths in bits (all assumed <= BMAX) }
+    n : cardinal;              { number of codes (assumed <= N_MAX) }
+    s : cardinal;              { number of simple-valued codes (0..s-1) }
+const d : array of cardinal;  { list of base values for non-simple codes }
 { array of word }
-const e : array of uIntf;  { list of extra bits for non-simple codes }
+const e : array of cardinal;  { list of extra bits for non-simple codes }
 { array of byte }
   t : ppInflate_huft;     { result: starting table }
-var m : uIntf;             { maximum lookup bits, returns actual }
+var m : cardinal;             { maximum lookup bits, returns actual }
 var hp : array of inflate_huft;  { space for trees }
-var hn : uInt;             { hufts used in space }
-var v : array of uIntf     { working area: values in order of bit length }
-   ) : int;
+var hn : cardinal;             { hufts used in space }
+var v : array of cardinal     { working area: values in order of bit length }
+   ) : integer;
 { Given a list of code lengths and a maximum table size, make a set of
   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
   if the given code set is incomplete (the tables are still built in this
   case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
   lengths), or Z_MEM_ERROR if not enough memory. }
 Var
-  a : uInt;                     { counter for codes of length k }
-  c : Array [0..BMAX] Of uInt;  { bit length count table }
-  f : uInt;                     { i repeats in table every f entries }
-  g : int;                      { maximum code length }
-  h : int;                      { table level }
-  i : uInt;  {register}         { counter, current code }
-  j : uInt;  {register}         { counter }
-  k : Int;   {register}         { number of bits in current code }
-  l : int;			{ bits per table (returned in m) }
-  mask : uInt;                  { (1 shl w) - 1, to avoid cc -O bug on HP }
-  p : ^uIntf; {register}        { pointer into c[], b[], or v[] }
+  a : cardinal;                     { counter for codes of length k }
+  c : Array [0..BMAX] Of cardinal;  { bit length count table }
+  f : cardinal;                     { i repeats in table every f entries }
+  g : integer;                      { maximum code length }
+  h : integer;                      { table level }
+  i : cardinal;  {register}         { counter, current code }
+  j : cardinal;  {register}         { counter }
+  k : integer;   {register}         { number of bits in current code }
+  l : integer;			{ bits per table (returned in m) }
+  mask : cardinal;                  { (1 shl w) - 1, to avoid cc -O bug on HP }
+  p : ^cardinal; {register}        { pointer into c[], b[], or v[] }
   q : pInflate_huft;            { points to current table }
   r : inflate_huft;             { table entry for structure assignment }
   u : Array [0..BMAX-1] Of pInflate_huft; { table stack }
-  w : int;   {register}         { bits before this table = (l*h) }
-  x : Array [0..BMAX] Of uInt;  { bit offsets, then code stack }
+  w : integer;   {register}         { bits before this table = (l*h) }
+  x : Array [0..BMAX] Of cardinal;  { bit offsets, then code stack }
   {$IFDEF USE_PTR}
-  xp : puIntf;                  { pointer into x }
+  xp : Pcardinal;                  { pointer into x }
   {$ELSE}
-  xp : uInt;
+  xp : cardinal;
   {$ENDIF}
-  y : int;                      { number of dummy codes added }
-  z : uInt;                     { number of entries in current table }
+  y : integer;                      { number of dummy codes added }
+  z : cardinal;                     { number of entries in current table }
 Begin
   { Generate counts for each bit length }
   FillChar(c,SizeOf(c),0) ;     { clear c[] }
@@ -201,13 +201,13 @@ Begin
     if (c[j] <> 0) then
       break;
   k := j ;                      { minimum code length }
-  if (uInt(l) < j) then
+  if (cardinal(l) < j) then
     l := j;
   for i := BMAX downto 1 do
     if (c[i] <> 0) then
       break ;
   g := i ;                      { maximum code length }
-  if (uInt(l) > i) then
+  if (cardinal(l) > i) then
      l := i;
   m := l;
 
@@ -301,7 +301,7 @@ Begin
 
         { table size upper limit }
         z := g - w;
-        If (z > uInt(l)) Then
+        If (z > cardinal(l)) Then
           z := l;
 
         { try a k-w bit table }
@@ -362,11 +362,11 @@ Begin
         if (h <> 0) then
         begin
           x[h] := i;             { save pattern for backing up }
-          r.bits := Byte(l);     { bits to dump before this table }
-          r.exop := Byte(j);     { bits in this table }
+          r.bits := byte(l);     { bits to dump before this table }
+          r.exop := byte(j);     { bits in this table }
           j := i shr (w - l);
-          {r.base := uInt( q - u[h-1] -j);}   { offset to this table }
-          r.base := (ptr2int(q) - ptr2int(u[h-1]) ) div sizeof(q^) - j;
+          {r.base := cardinal( q - u[h-1] -j);}   { offset to this table }
+          r.base := (ptrint(q) - ptrint(u[h-1]) ) div sizeof(q^) - j;
           huft_Ptr(u[h-1])^[j] := r;  { connect to last table }
         end
         else
@@ -374,11 +374,11 @@ Begin
       end;
 
       { set up table entry in r }
-      r.bits := Byte(k - w);
+      r.bits := byte(k - w);
 
       { C-code: if (p >= v + n) - see ZUTIL.PAS for comments }
 
-      if ptr2int(p)>=ptr2int(@(v[n])) then  { also works under DPMI ?? }
+      if ptrint(p)>=ptrint(@(v[n])) then  { also works under DPMI ?? }
         r.exop := 128 + 64                  { out of values--invalid code }
       else
         if (p^ < s) then
@@ -392,7 +392,7 @@ Begin
         end
         Else
         begin
-          r.exop := Byte(e[p^-s] + 16 + 64);  { non-simple--look up in lists }
+          r.exop := byte(e[p^-s] + 16 + 64);  { non-simple--look up in lists }
           r.base := d[p^-s];
           Inc (p);
         end ;
@@ -438,27 +438,27 @@ end; { huft_build}
 
 
 function inflate_trees_bits(
-  var c : array of uIntf;  { 19 code lengths }
-  var bb : uIntf;          { bits tree desired/actual depth }
+  var c : array of cardinal;  { 19 code lengths }
+  var bb : cardinal;          { bits tree desired/actual depth }
   var tb : pinflate_huft;  { bits tree result }
   var hp : array of Inflate_huft;      { space for trees }
   var z : z_stream         { for messages }
-    ) : int;
+    ) : integer;
 var
-  r : int;
-  hn : uInt;          { hufts used in space }
+  r : integer;
+  hn : cardinal;          { hufts used in space }
   v : PuIntArray;     { work area for huft_build }
 begin
   hn := 0;
-  v := PuIntArray( ZALLOC(z, 19, sizeof(uInt)) );
-  if (v = Z_NULL) then
+  v := PuIntArray( ZALLOC(z, 19, sizeof(cardinal)) );
+  if (v = nil) then
   begin
     inflate_trees_bits := Z_MEM_ERROR;
     exit;
   end;
 
   r := huft_build(c, 19, 19, cplens, cplext,
-                             {puIntf(Z_NULL), puIntf(Z_NULL),}
+                             {Pcardinal(nil), Pcardinal(nil),}
                   @tb, bb, hp, hn, v^);
   if (r = Z_DATA_ERROR) then
     z.msg := 'oversubscribed dynamic bit lengths tree'
@@ -474,25 +474,25 @@ end;
 
 
 function inflate_trees_dynamic(
-    nl : uInt;                    { number of literal/length codes }
-    nd : uInt;                    { number of distance codes }
-    var c : Array of uIntf;           { that many (total) code lengths }
-    var bl : uIntf;          { literal desired/actual bit depth }
-    var bd : uIntf;          { distance desired/actual bit depth }
+    nl : cardinal;                    { number of literal/length codes }
+    nd : cardinal;                    { number of distance codes }
+    var c : Array of cardinal;           { that many (total) code lengths }
+    var bl : cardinal;          { literal desired/actual bit depth }
+    var bd : cardinal;          { distance desired/actual bit depth }
 var tl : pInflate_huft;           { literal/length tree result }
 var td : pInflate_huft;           { distance tree result }
 var hp : array of Inflate_huft;   { space for trees }
 var z : z_stream                  { for messages }
-     ) : int;
+     ) : integer;
 var
-  r : int;
-  hn : uInt;          { hufts used in space }
+  r : integer;
+  hn : cardinal;          { hufts used in space }
   v : PuIntArray;     { work area for huft_build }
 begin
   hn := 0;
   { allocate work area }
-  v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
-  if (v = Z_NULL) then
+  v := PuIntArray( ZALLOC(z, 288, sizeof(cardinal)) );
+  if (v = nil) then
   begin
     inflate_trees_dynamic := Z_MEM_ERROR;
     exit;
@@ -560,8 +560,8 @@ const
   FIXEDH = 544;      { number of hufts used by fixed tables }
 var
   fixed_mem : array[0..FIXEDH-1] of inflate_huft;
-  fixed_bl : uInt;
-  fixed_bd : uInt;
+  fixed_bl : cardinal;
+  fixed_bd : cardinal;
   fixed_tl : pInflate_huft;
   fixed_td : pInflate_huft;
 
@@ -571,18 +571,18 @@ var
 
 {local}
 const
-  fixed_bl = uInt(9);
+  fixed_bl = 9;
 {local}
 const
-  fixed_bd = uInt(5);
+  fixed_bd = 5;
 {local}
 const
   fixed_tl : array [0..288-1] of inflate_huft = (
     Exop,             { number of extra bits or operation }
-    bits : Byte;      { number of bits in this code or subcode }
-    {pad : uInt;}       { pad structure to a power of 2 (4 bytes for }
-                      {  16-bit, 8 bytes for 32-bit int's) }
-    base : uInt;      { literal, length base, or distance base }
+    bits : byte;      { number of bits in this code or subcode }
+    {pad : cardinal;}       { pad structure to a power of 2 (4 bytes for }
+                      {  16-bit, 8 bytes for 32-bit integer's) }
+    base : cardinal;      { literal, length base, or distance base }
                       { or table offset }
 
     ((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115), ((82,7),31),
@@ -708,21 +708,21 @@ const
 {$ENDIF}
 
 function inflate_trees_fixed(
-var bl : uInt;               { literal desired/actual bit depth }
-var bd : uInt;               { distance desired/actual bit depth }
+var bl : cardinal;               { literal desired/actual bit depth }
+var bd : cardinal;               { distance desired/actual bit depth }
 var tl : pInflate_huft;      { literal/length tree result }
 var td : pInflate_huft;      { distance tree result }
 var  z : z_stream            { for memory allocation }
-      ) : int;
+      ) : integer;
 type
   pFixed_table = ^fixed_table;
-  fixed_table = array[0..288-1] of uIntf;
+  fixed_table = array[0..288-1] of cardinal;
 var
-  k : int;                   { temporary variable }
+  k : integer;                   { temporary variable }
   c : pFixed_table;          { length list for huft_build }
   v : PuIntArray;            { work area for huft_build }
 var
-  f : uInt;                  { number of hufts used in fixed_mem }
+  f : cardinal;                  { number of hufts used in fixed_mem }
 begin
   { build fixed tables if not already (multiple overlapped executions ok) }
   if not fixed_built then
@@ -730,14 +730,14 @@ begin
     f := 0;
 
     { allocate memory }
-    c := pFixed_table( ZALLOC(z, 288, sizeof(uInt)) );
-    if (c = Z_NULL) then
+    c := pFixed_table( ZALLOC(z, 288, sizeof(cardinal)) );
+    if (c = nil) then
     begin
       inflate_trees_fixed := Z_MEM_ERROR;
       exit;
     end;
-    v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
-    if (v = Z_NULL) then
+    v := PuIntArray( ZALLOC(z, 288, sizeof(cardinal)) );
+    if (v = nil) then
     begin
       ZFREE(z, c);
       inflate_trees_fixed := Z_MEM_ERROR;

+ 40 - 40
packages/base/paszlib/infutil.pas

@@ -22,41 +22,41 @@ uses
 { copy as much as possible from the sliding window to the output area }
 function inflate_flush(var s : inflate_blocks_state;
                        var z : z_stream;
-                       r : int) : int;
+                       r : integer) : integer;
 
 { And'ing with mask[n] masks the lower n bits }
 const
-  inflate_mask : array[0..17-1] of uInt = (
+  inflate_mask : array[0..17-1] of cardinal = (
     $0000,
     $0001, $0003, $0007, $000f, $001f, $003f, $007f, $00ff,
     $01ff, $03ff, $07ff, $0fff, $1fff, $3fff, $7fff, $ffff);
 
-{procedure GRABBITS(j : int);}
-{procedure DUMPBITS(j : int);}
-{procedure NEEDBITS(j : int);}
+{procedure GRABBITS(j : integer);}
+{procedure DUMPBITS(j : integer);}
+{procedure NEEDBITS(j : integer);}
 
 implementation
 
 { macros for bit input with no checking and for returning unused bytes }
-procedure GRABBITS(j : int);
+procedure GRABBITS(j : integer);
 begin
   {while (k < j) do
   begin
-    Dec(z^.avail_in);
-    Inc(z^.total_in);
+    dec(z^.avail_in);
+    inc(z^.total_in);
     b := b or (uLong(z^.next_in^) shl k);
-    Inc(z^.next_in);
-    Inc(k, 8);
+    inc(z^.next_in);
+    inc(k, 8);
   end;}
 end;
 
-procedure DUMPBITS(j : int);
+procedure DUMPBITS(j : integer);
 begin
   {b := b shr j;
-  Dec(k, j);}
+  dec(k, j);}
 end;
 
-procedure NEEDBITS(j : int);
+procedure NEEDBITS(j : integer);
 begin
  (*
           while (k < j) do
@@ -70,16 +70,16 @@ begin
               s.bitb := b;
               s.bitk := k;
               z.avail_in := n;
-              Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
+              inc(z.total_in, LongInt(p)-LongInt(z.next_in));
               z.next_in := p;
               s.write := q;
               result := inflate_flush(s,z,r);
               exit;
             end;
-            Dec(n);
+            dec(n);
             b := b or (uLong(p^) shl k);
-            Inc(p);
-            Inc(k, 8);
+            inc(p);
+            inc(k, 8);
           end;
  *)
 end;
@@ -94,9 +94,9 @@ begin
     begin
       q := s.window;
       if LongInt(q) < LongInt(s.read) then
-        m := uInt(LongInt(s.read)-LongInt(q)-1)
+        m := cardinal(LongInt(s.read)-LongInt(q)-1)
       else
-        m := uInt(LongInt(s.zend)-LongInt(q));
+        m := cardinal(LongInt(s.zend)-LongInt(q));
     end;
 
     if (m = 0) then
@@ -106,18 +106,18 @@ begin
       r := inflate_flush(s,z,r);
       q := s.write;
       if LongInt(q) < LongInt(s.read) then
-        m := uInt(LongInt(s.read)-LongInt(q)-1)
+        m := cardinal(LongInt(s.read)-LongInt(q)-1)
       else
-        m := uInt(LongInt(s.zend)-LongInt(q));
+        m := cardinal(LongInt(s.zend)-LongInt(q));
 
       {WRAP}
       if (q = s.zend) and (s.read <> s.window) then
       begin
         q := s.window;
         if LongInt(q) < LongInt(s.read) then
-          m := uInt(LongInt(s.read)-LongInt(q)-1)
+          m := cardinal(LongInt(s.read)-LongInt(q)-1)
         else
-          m := uInt(LongInt(s.zend)-LongInt(q));
+          m := cardinal(LongInt(s.zend)-LongInt(q));
       end;
 
       if (m = 0) then
@@ -126,7 +126,7 @@ begin
         s.bitb := b;
         s.bitk := k;
         z.avail_in := n;
-        Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
+        inc(z.total_in, LongInt(p)-LongInt(z.next_in));
         z.next_in := p;
         s.write := q;
         result := inflate_flush(s,z,r);
@@ -141,29 +141,29 @@ end;
 { copy as much as possible from the sliding window to the output area }
 function inflate_flush(var s : inflate_blocks_state;
                        var z : z_stream;
-                       r : int) : int;
+                       r : integer) : integer;
 var
-  n : uInt;
-  p : pBytef;
-  q : pBytef;
+  n : cardinal;
+  p : Pbyte;
+  q : Pbyte;
 begin
   { local copies of source and destination pointers }
   p := z.next_out;
   q := s.read;
 
   { compute number of bytes to copy as far as end of window }
-  if ptr2int(q) <= ptr2int(s.write) then
-    n := uInt(ptr2int(s.write) - ptr2int(q))
+  if ptrint(q) <= ptrint(s.write) then
+    n := cardinal(ptrint(s.write) - ptrint(q))
   else
-    n := uInt(ptr2int(s.zend) - ptr2int(q));
+    n := cardinal(ptrint(s.zend) - ptrint(q));
   if (n > z.avail_out) then
     n := z.avail_out;
   if (n <> 0) and (r = Z_BUF_ERROR) then
     r := Z_OK;
 
   { update counters }
-  Dec(z.avail_out, n);
-  Inc(z.total_out, n);
+  dec(z.avail_out, n);
+  inc(z.total_out, n);
 
 
   { update check information }
@@ -175,8 +175,8 @@ begin
 
   { copy as far as end of window }
   zmemcpy(p, q, n);
-  Inc(p, n);
-  Inc(q, n);
+  inc(p, n);
+  inc(q, n);
 
   { see if more to copy at beginning of window }
   if (q = s.zend) then
@@ -187,15 +187,15 @@ begin
       s.write := s.window;
 
     { compute bytes to copy }
-    n := uInt(ptr2int(s.write) - ptr2int(q));
+    n := cardinal(ptrint(s.write) - ptrint(q));
     if (n > z.avail_out) then
       n := z.avail_out;
     if (n <> 0) and (r = Z_BUF_ERROR) then
       r := Z_OK;
 
     { update counters }
-    Dec( z.avail_out, n);
-    Inc( z.total_out, n);
+    dec( z.avail_out, n);
+    inc( z.total_out, n);
 
     { update check information }
     if Assigned(s.checkfn) then
@@ -206,8 +206,8 @@ begin
 
     { copy }
     zmemcpy(p, q, n);
-    Inc(p, n);
-    Inc(q, n);
+    inc(p, n);
+    inc(q, n);
   end;
 
 

+ 5 - 8
packages/base/paszlib/minigzip.pas

@@ -18,9 +18,6 @@ program minigzip;
 }
 
 uses
-  {$IFDEF VER80}
-  WinCrt,
-  {$ENDIF}
   gzio, zutil;
 
 const
@@ -54,9 +51,9 @@ end;
 
 procedure gz_compress (var infile:file; outfile:gzFile);
 var
-  len   : uInt;
+  len   : cardinal;
   ioerr : integer;
-  err   : int;
+  err   : integer;
 begin
 
   while true do begin
@@ -91,10 +88,10 @@ end;
 
 procedure gz_uncompress (infile:gzFile; var outfile:file);
 var
-  len     : int;
-  written : uInt;
+  len     : integer;
+  written : cardinal;
   ioerr   : integer;
-  err     : int;
+  err     : integer;
 begin
   while true do begin
 

+ 41 - 46
packages/base/paszlib/paszlib.pas

@@ -10,14 +10,9 @@ const
 
 type
   { Compatibility types }
-  PByte   = ^Byte;
-  Uint    = Cardinal;
-  Ulong   = Cardinal;
-  Ulongf  = ULong;
-  Pulongf = ^Ulongf;
   z_off_t = longint;
 
-  TAllocfunc = function (opaque:pointer; items:uInt; size:uInt):pointer;
+  TAllocfunc = function (opaque:pointer; items:cardinal; size:cardinal):pointer;
   TFreeFunc = procedure (opaque:pointer; address:pointer);
 
   TInternalState = record
@@ -63,29 +58,29 @@ const
 
   Z_DEFLATED = 8;
 
-  Z_NULL = 0;
+  Z_NULL = nil;
 
 function zlibVersion:string;
 function deflate(var strm:TZstream; flush:longint):longint;
 function deflateEnd(var strm:TZstream):longint;
 function inflate(var strm:TZstream; flush:longint):longint;
 function inflateEnd(var strm:TZstream):longint;
-function deflateSetDictionary(var strm:TZstream;dictionary : pchar; dictLength:uInt):longint;
+function deflateSetDictionary(var strm:TZstream;dictionary : Pchar; dictLength:cardinal):longint;
 function deflateCopy(var dest,source:TZstream):longint;
 function deflateReset(var strm:TZstream):longint;
 function deflateParams(var strm:TZstream; level:longint; strategy:longint):longint;
-function inflateSetDictionary(var strm:TZStream;dictionary : pchar; dictLength:uInt):longint;
+function inflateSetDictionary(var strm:TZStream;dictionary : Pchar; dictLength:cardinal):longint;
 function inflateSync(var strm:TZStream):longint;
 function inflateReset(var strm:TZStream):longint;
-function compress(dest:pchar;var destLen:uLongf; source : pchar; sourceLen:uLong):longint;
-function compress2(dest:pchar;var destLen:uLongf; source : pchar; sourceLen:uLong; level:longint):longint;
-function uncompress(dest:pchar;var destLen:uLongf; source : pchar; sourceLen:uLong):longint;
-function gzopen(path:pchar; mode:pchar):gzFile;
+function compress(dest:Pchar;var destLen:cardinal; source : Pchar; sourceLen:cardinal):longint;
+function compress2(dest:Pchar;var destLen:cardinal; source : Pchar; sourceLen:cardinal; level:longint):longint;
+function uncompress(dest:Pchar;var destLen:cardinal; source : Pchar; sourceLen:cardinal):longint;
+function gzopen(path:Pchar; mode:Pchar):gzFile;
 function gzsetparams(Thefile:gzFile; level:longint; strategy:longint):longint;
 function gzread(thefile:gzFile; buf : pointer; len:cardinal):longint;
 function gzwrite(thefile:gzFile; buf: pointer; len:cardinal):longint;
-function gzputs(thefile:gzFile; s:pchar):longint;
-function gzgets(thefile:gzFile; buf:pchar; len:longint):pchar;
+function gzputs(thefile:gzFile; s:Pchar):longint;
+function gzgets(thefile:gzFile; buf:Pchar; len:longint):Pchar;
 function gzputc(thefile:gzFile; c:char):longint;
 function gzgetc(thefile:gzFile):char;
 function gzflush(thefile:gzFile; flush:longint):longint;
@@ -94,13 +89,13 @@ function gzrewind(thefile:gzFile):longint;
 function gztell(thefile:gzFile):z_off_t;
 function gzeof(thefile:gzFile):longbool;
 function gzclose(thefile:gzFile):longint;
-function gzerror(thefile:gzFile; var errnum:longint):string;
-function adler32(theadler:uLong;buf : pchar; len:uInt):uLong;
-function crc32(thecrc:uLong;buf : pchar; len:uInt):uLong;
-{function deflateInit_(var strm:TZStream; level:longint; version:pchar; stream_size:longint):longint;
-function inflateInit_(var strm:TZStream; version:pchar; stream_size:longint):longint;
-function deflateInit2_(var strm:TZStream; level:longint; method:longint; windowBits:longint; memLevel:longint;strategy:longint; version:pchar; stream_size:longint):longint;
-function inflateInit2_(var strm:TZStream; windowBits:longint; version:pchar; stream_size:longint):longint;}
+function gzerror(thefile:gzFile; var errnum:smallint):string;
+function adler32(theadler:cardinal;buf : Pchar; len:cardinal):cardinal;
+function crc32(thecrc:cardinal;buf : Pchar; len:cardinal):cardinal;
+{function deflateInit_(var strm:TZStream; level:longint; version:Pchar; stream_size:longint):longint;
+function inflateInit_(var strm:TZStream; version:Pchar; stream_size:longint):longint;
+function deflateInit2_(var strm:TZStream; level:longint; method:longint; windowBits:longint; memLevel:longint;strategy:longint; version:Pchar; stream_size:longint):longint;
+function inflateInit2_(var strm:TZStream; windowBits:longint; version:Pchar; stream_size:longint):longint;}
 function deflateInit(var strm:TZStream;level : longint) : longint;
 function inflateInit(var strm:TZStream) : longint;
 function deflateInit2(var strm:TZStream;level,method,windowBits,memLevel,strategy : longint) : longint;
@@ -112,7 +107,7 @@ function get_crc_table:pointer;
 implementation
 
 uses
-  zutil,zdeflate,zinflate,zcompres,zuncompr,gzio,adler,gzcrc;
+  zutil,zdeflate,zinflate,zcompres,zuncompr,gzio,adler,crc;
 
 function zlibVersion:string;
 begin
@@ -139,9 +134,9 @@ begin
   inflateEnd:=zinflate.inflateEnd(strm);
 end;
 
-function deflateSetDictionary(var strm:TZstream;dictionary : pchar; dictLength:uInt):longint;
+function deflateSetDictionary(var strm:TZstream;dictionary : Pchar; dictLength:cardinal):longint;
 begin
-  deflateSetDictionary:=zdeflate.deflateSetDictionary(strm,pbytef(dictionary),dictlength);
+  deflateSetDictionary:=zdeflate.deflateSetDictionary(strm,Pbyte(dictionary),dictlength);
 end;
 
 function deflateCopy(var dest,source:TZstream):longint;
@@ -159,9 +154,9 @@ begin
   deflateParams:=zdeflate.deflateParams(strm,level,strategy);
 end;
 
-function inflateSetDictionary(var strm:TZStream;dictionary : pchar; dictLength:uInt):longint;
+function inflateSetDictionary(var strm:TZStream;dictionary : Pchar; dictLength:cardinal):longint;
 begin
-  inflateSetDictionary:=zinflate.inflateSetDictionary(strm,pbytef(dictionary),dictlength);
+  inflateSetDictionary:=zinflate.inflateSetDictionary(strm,Pbyte(dictionary),dictlength);
 end;
 
 function inflateSync(var strm:TZStream):longint;
@@ -174,34 +169,34 @@ begin
   inflateReset:=zinflate.inflateReset(strm);
 end;
 
-function compress(dest:pchar;var destLen:uLongf; source : pchar; sourceLen:uLong):longint;
+function compress(dest:Pchar;var destLen:cardinal; source : Pchar; sourceLen:cardinal):longint;
 
 type Pbytearray=^Tbytearray;
      Tbytearray=array[0..0] of byte;
 
 begin
-  compress:=zcompres.compress(pbytef(dest),destlen,Pbytearray(source)^,sourcelen);
+  compress:=zcompres.compress(Pbyte(dest),destlen,Pbytearray(source)^,sourcelen);
 end;
 
-function compress2(dest:pchar;var destLen:uLongf; source : pchar; sourceLen:uLong; level:longint):longint;
+function compress2(dest:Pchar;var destLen:cardinal; source : Pchar; sourceLen:cardinal; level:longint):longint;
 
 type Pbytearray=^Tbytearray;
      Tbytearray=array[0..0] of byte;
 
 begin
-  compress2:=zcompres.compress2(pbytef(dest),destlen,Pbytearray(source)^,sourcelen,level);
+  compress2:=zcompres.compress2(Pbyte(dest),destlen,Pbytearray(source)^,sourcelen,level);
 end;
 
-function uncompress(dest:pchar;var destLen:uLongf; source : pchar; sourceLen:uLong):longint;
+function uncompress(dest:Pchar;var destLen:cardinal; source : Pchar; sourceLen:cardinal):longint;
 
 type Pbytearray=^Tbytearray;
      Tbytearray=array[0..0] of byte;
 
 begin
-  uncompress:=zuncompr.uncompress(pbytef(dest),destlen,Pbytearray(source)^,sourcelen);
+  uncompress:=zuncompr.uncompress(Pbyte(dest),destlen,Pbytearray(source)^,sourcelen);
 end;
 
-function gzopen(path:pchar; mode:pchar):gzFile;
+function gzopen(path:Pchar; mode:Pchar):gzFile;
 begin
   gzopen:=gzio.gzopen(path,mode);
 end;
@@ -221,12 +216,12 @@ begin
   gzwrite:=gzio.gzwrite(thefile,buf,len);
 end;
 
-function gzputs(thefile:gzFile; s:pchar):longint;
+function gzputs(thefile:gzFile; s:Pchar):longint;
 begin
   gzputs:=gzio.gzputs(thefile,s);
 end;
 
-function gzgets(thefile:gzFile; buf:pchar; len:longint):pchar;
+function gzgets(thefile:gzFile; buf:Pchar; len:longint):Pchar;
 begin
   gzgets:=gzio.gzgets(thefile,buf,len);
 end;
@@ -271,37 +266,37 @@ begin
   gzclose:=gzio.gzclose(thefile);
 end;
 
-function gzerror(thefile:gzFile; var errnum:longint):string;
+function gzerror(thefile:gzFile; var errnum:smallint):string;
 begin
   gzerror:=gzio.gzerror(thefile,errnum);
 end;
 
-function adler32(theadler:uLong;buf : pchar; len:uInt):uLong;
+function adler32(theadler:cardinal;buf : Pchar; len:cardinal):cardinal;
 begin
-  adler32:=adler.adler32(theadler,pbytef(buf),len);
+  adler32:=adler.adler32(theadler,Pbyte(buf),len);
 end;
 
-function crc32(thecrc:uLong;buf : pchar; len:uInt):uLong;
+function crc32(thecrc:cardinal;buf : Pchar; len:cardinal):cardinal;
 begin
-  crc32:=gzcrc.crc32(thecrc,pbytef(buf),len);
+  crc32:=crc.crc32(thecrc,Pbyte(buf),len);
 end;
 {
-function deflateInit_(var strm:TZStream; level:longint; version:pchar; stream_size:longint):longint;
+function deflateInit_(var strm:TZStream; level:longint; version:Pchar; stream_size:longint):longint;
 begin
   deflateInit_:=zdeflate.deflateInit_(@strm,level,version,stream_size);
 end;
 
-function inflateInit_(var strm:TZStream; version:pchar; stream_size:longint):longint;
+function inflateInit_(var strm:TZStream; version:Pchar; stream_size:longint):longint;
 begin
   inflateInit_:=zinflate.inflateInit_(@strm,version,stream_size);
 end;
 
-function deflateInit2_(var strm:TZStream; level:longint; method:longint; windowBits:longint; memLevel:longint;strategy:longint; version:pchar; stream_size:longint):longint;
+function deflateInit2_(var strm:TZStream; level:longint; method:longint; windowBits:longint; memLevel:longint;strategy:longint; version:Pchar; stream_size:longint):longint;
 begin
   deflateInit2_:=zdeflate.deflateInit2_(strm,level,method,windowBits,memlevel,strategy,version,stream_size);
 end;
 
-function inflateInit2_(var strm:TZStream; windowBits:longint; version:pchar; stream_size:longint):longint;
+function inflateInit2_(var strm:TZStream; windowBits:longint; version:Pchar; stream_size:longint):longint;
 begin
   inflateInit2_:=zinflate.inflateInit2_(strm,windowBits,version,stream_size);
 end;
@@ -338,7 +333,7 @@ end;
 
 function get_crc_table:pointer;
 begin
-  get_crc_table:=gzcrc.get_crc_table;
+  get_crc_table:=crc.get_crc_table;
 end;
 
 end.

Diferenças do arquivo suprimidas por serem muito extensas
+ 213 - 216
packages/base/paszlib/trees.pas


+ 50 - 50
packages/base/paszlib/zbase.pas

@@ -69,7 +69,7 @@ uses
 
 
 { Compile with -DMAXSEG_64K if the alloc function cannot allocate more
-  than 64k bytes at a time (needed on systems with 16-bit int). }
+  than 64k bytes at a time (needed on systems with 16-bit integer). }
 
 { Maximum value for memLevel in deflateInit2 }
 {$ifdef MAXSEG_64K}
@@ -121,9 +121,9 @@ type
   inflate_huft = Record
     Exop,             { number of extra bits or operation }
     bits : Byte;      { number of bits in this code or subcode }
-    {pad : uInt;}       { pad structure to a power of 2 (4 bytes for }
-                      {  16-bit, 8 bytes for 32-bit int's) }
-    base : uInt;      { literal, length base, or distance base }
+    {pad : cardinal;}       { pad structure to a power of 2 (4 bytes for }
+                      {  16-bit, 8 bytes for 32-bit integer's) }
+    base : cardinal;      { literal, length base, or distance base }
                       { or table offset }
   End;
 
@@ -154,17 +154,17 @@ type
     mode : inflate_codes_mode;        { current inflate_codes mode }
 
     { mode dependent information }
-    len : uInt;
+    len : cardinal;
     sub : record                      { submode }
       Case Byte of
       0:(code : record                { if LEN or DIST, where in tree }
           tree : pInflate_huft;       { pointer into tree }
-          need : uInt;                { bits needed }
+          need : cardinal;                { bits needed }
          end);
-      1:(lit : uInt);                 { if LIT, literal }
+      1:(lit : cardinal);                 { if LIT, literal }
       2:(copy: record                 { if EXT or COPY, where and how much }
-           get : uInt;                { bits to get for extra }
-           dist : uInt;               { distance back to copy from }
+           get : cardinal;                { bits to get for extra }
+           dist : cardinal;               { distance back to copy from }
          end);
     end;
 
@@ -176,10 +176,10 @@ type
   end;
 
 type
-  check_func = function(check : uLong;
-                        buf : pBytef;
+  check_func = function(check : cardinal;
+                        buf : Pbyte;
                         {const buf : array of byte;}
-	                len : uInt) : uLong;
+	                len : cardinal) : cardinal;
 type
   inflate_block_mode =
      (ZTYPE,    { get type bits (3, including end bit) }
@@ -204,12 +204,12 @@ type
     { mode dependent information }
     sub : record                  { submode }
     case Byte of
-    0:(left : uInt);              { if STORED, bytes left to copy }
+    0:(left : cardinal);              { if STORED, bytes left to copy }
     1:(trees : record             { if DTREE, decoding info for trees }
-        table : uInt;               { table lengths (14 bits) }
-        index : uInt;               { index into blens (or border) }
+        table : cardinal;               { table lengths (14 bits) }
+        index : cardinal;               { index into blens (or border) }
         blens : PuIntArray;         { bit lengths of codes }
-        bb : uInt;                  { bit length tree depth }
+        bb : cardinal;                  { bit length tree depth }
         tb : pInflate_huft;         { bit length decoding tree }
       end);
     2:(decode : record            { if CODES, current state }
@@ -221,15 +221,15 @@ type
     last : boolean;               { true if this block is the last block }
 
     { mode independent information }
-    bitk : uInt;            { bits in bit buffer }
-    bitb : uLong;           { bit buffer }
+    bitk : cardinal;            { bits in bit buffer }
+    bitb : cardinal;           { bit buffer }
     hufts : huft_ptr; {pInflate_huft;}  { single malloc for tree space }
-    window : pBytef;        { sliding window }
-    zend : pBytef;          { one byte after sliding window }
-    read : pBytef;          { window read pointer }
-    write : pBytef;         { window write pointer }
+    window : Pbyte;        { sliding window }
+    zend : Pbyte;          { one byte after sliding window }
+    read : Pbyte;          { window read pointer }
+    write : Pbyte;         { window write pointer }
     checkfn : check_func;   { check function }
-    check : uLong;          { check on output }
+    check : cardinal;          { check on output }
   end;
 
 type
@@ -259,45 +259,45 @@ type
      { mode dependent information }
      sub : record          { submode }
        case byte of
-       0:(method : uInt);  { if FLAGS, method byte }
+       0:(method : cardinal);  { if FLAGS, method byte }
        1:(check : record   { if CHECK, check values to compare }
-           was : uLong;        { computed check value }
-           need : uLong;       { stream check value }
+           was : cardinal;        { computed check value }
+           need : cardinal;       { stream check value }
           end);
-       2:(marker : uInt);  { if BAD, inflateSync's marker bytes count }
+       2:(marker : cardinal);  { if BAD, inflateSync's marker bytes count }
      end;
 
      { mode independent information }
      nowrap : boolean;      { flag for no wrapper }
-     wbits : uInt;          { log2(window size)  (8..15, defaults to 15) }
+     wbits : cardinal;          { log2(window size)  (8..15, defaults to 15) }
      blocks : pInflate_blocks_state;    { current inflate_blocks state }
    end;
 
 type
-  alloc_func = function(opaque : voidpf; items : uInt; size : uInt) : voidpf;
-  free_func = procedure(opaque : voidpf; address : voidpf);
+  alloc_func = function(opaque : pointer; items : cardinal; size : cardinal) : pointer;
+  free_func = procedure(opaque : pointer; address : pointer);
 
 type
   z_streamp = ^z_stream;
   z_stream = record
-    next_in : pBytef;     { next input byte }
-    avail_in : uInt;      { number of bytes available at next_in }
-    total_in : uLong;     { total nb of input bytes read so far }
+    next_in : Pbyte;     { next input byte }
+    avail_in : cardinal;      { number of bytes available at next_in }
+    total_in : cardinal;     { total nb of input bytes read so far }
 
-    next_out : pBytef;    { next output byte should be put there }
-    avail_out : uInt;     { remaining free space at next_out }
-    total_out : uLong;    { total nb of bytes output so far }
+    next_out : Pbyte;    { next output byte should be put there }
+    avail_out : cardinal;     { remaining free space at next_out }
+    total_out : cardinal;    { total nb of bytes output so far }
 
     msg : string[255];         { last error message, '' if no error }
     state : pInternal_state; { not visible by applications }
 
     zalloc : alloc_func;  { used to allocate the internal state }
     zfree : free_func;    { used to free the internal state }
-    opaque : voidpf;      { private data object passed to zalloc and zfree }
+    opaque : pointer;      { private data object passed to zalloc and zfree }
 
-    data_type : int;      { best guess about the data type: ascii or binary }
-    adler : uLong;        { adler32 value of the uncompressed data }
-    reserved : uLong;     { reserved for future use }
+    data_type : integer;      { best guess about the data type: ascii or binary }
+    adler : cardinal;        { adler32 value of the uncompressed data }
+    reserved : cardinal;     { reserved for future use }
   end;
 
 
@@ -371,7 +371,7 @@ const  { constants }
 
   {$IFDEF GZIO}
 var
-  errno : int;
+  errno : integer;
   {$ENDIF}
 
         { common constants }
@@ -412,13 +412,13 @@ function zlibVersion : string;
   not compatible with the zlib.h header file used by the application.
   This check is automatically made by deflateInit and inflateInit. }
 
-function zError(err : int) : string;
+function zError(err : integer) : string;
 
-function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;
+function ZALLOC (var strm : z_stream; items : cardinal; size : cardinal) : pointer;
 
-procedure ZFREE (var strm : z_stream; ptr : voidpf);
+procedure ZFREE (var strm : z_stream; ptr : pointer);
 
-procedure TRY_FREE (var strm : z_stream; ptr : voidpf);
+procedure TRY_FREE (var strm : z_stream; ptr : pointer);
 
 const
   ZLIB_VERSION : string[10] = '1.1.2';
@@ -437,7 +437,7 @@ const
             'incompatible version',{ Z_VERSION_ERROR (-6) }
             '');
 const
-  z_verbose : int = 1;
+  z_verbose : integer = 1;
 
 {$IFDEF DEBUG}
 procedure z_error (m : string);
@@ -445,7 +445,7 @@ procedure z_error (m : string);
 
 implementation
 
-function zError(err : int) : string;
+function zError(err : integer) : string;
 begin
   zError := z_errmsg[Z_NEED_DICT-err];
 end;
@@ -504,17 +504,17 @@ begin
     WriteLn(x);
 end;
 
-function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;
+function ZALLOC (var strm : z_stream; items : cardinal; size : cardinal) : pointer;
 begin
   ZALLOC := strm.zalloc(strm.opaque, items, size);
 end;
 
-procedure ZFREE (var strm : z_stream; ptr : voidpf);
+procedure ZFREE (var strm : z_stream; ptr : pointer);
 begin
   strm.zfree(strm.opaque, ptr);
 end;
 
-procedure TRY_FREE (var strm : z_stream; ptr : voidpf);
+procedure TRY_FREE (var strm : z_stream; ptr : pointer);
 begin
   {if @strm <> Z_NULL then}
     strm.zfree(strm.opaque, ptr);

+ 20 - 20
packages/base/paszlib/zcompres.pas

@@ -18,10 +18,10 @@ uses
                         { utility functions }
 
 {EXPORT}
-function compress (dest : pBytef;
-                   var destLen : uLong;
+function compress (dest : Pbyte;
+                   var destLen : cardinal;
                    const source : array of Byte;
-                   sourceLen : uLong) : int;
+                   sourceLen : cardinal) : integer;
 
  { Compresses the source buffer into the destination buffer.  sourceLen is
    the byte length of the source buffer. Upon entry, destLen is the total
@@ -35,11 +35,11 @@ function compress (dest : pBytef;
    buffer. }
 
 {EXPORT}
-function compress2 (dest : pBytef;
-                    var destLen : uLong;
+function compress2 (dest : Pbyte;
+                    var destLen : cardinal;
                     const source : array of byte;
-                    sourceLen : uLong;
-                    level : int) : int;
+                    sourceLen : cardinal;
+                    level : integer) : integer;
 {  Compresses the source buffer into the destination buffer. The level
    parameter has the same meaning as in deflateInit.  sourceLen is the byte
    length of the source buffer. Upon entry, destLen is the total size of the
@@ -54,28 +54,28 @@ implementation
 
 { ===========================================================================
 }
-function compress2 (dest : pBytef;
-                    var destLen : uLong;
+function compress2 (dest : Pbyte;
+                    var destLen : cardinal;
                     const source : array of byte;
-                    sourceLen : uLong;
-                    level : int) : int;
+                    sourceLen : cardinal;
+                    level : integer) : integer;
 var
   stream : z_stream;
-  err : int;
+  err : integer;
 begin
-  stream.next_in := pBytef(@source);
-  stream.avail_in := uInt(sourceLen);
+  stream.next_in := Pbyte(@source);
+  stream.avail_in := cardinal(sourceLen);
 {$ifdef MAXSEG_64K}
   { Check for source > 64K on 16-bit machine: }
-  if (uLong(stream.avail_in) <> sourceLen) then
+  if (cardinal(stream.avail_in) <> sourceLen) then
   begin
     compress2 := Z_BUF_ERROR;
     exit;
   end;
 {$endif}
   stream.next_out := dest;
-  stream.avail_out := uInt(destLen);
-  if (uLong(stream.avail_out) <> destLen) then
+  stream.avail_out := cardinal(destLen);
+  if (cardinal(stream.avail_out) <> destLen) then
   begin
     compress2 := Z_BUF_ERROR;
     exit;
@@ -110,10 +110,10 @@ end;
 
 { ===========================================================================
  }
-function compress (dest : pBytef;
-                   var destLen : uLong;
+function compress (dest : Pbyte;
+                   var destLen : cardinal;
                    const source : array of Byte;
-                   sourceLen : uLong) : int;
+                   sourceLen : cardinal) : integer;
 begin
   compress := compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
 end;

Diferenças do arquivo suprimidas por serem muito extensas
+ 209 - 209
packages/base/paszlib/zdeflate.pas


+ 56 - 56
packages/base/paszlib/zinflate.pas

@@ -15,7 +15,7 @@ interface
 uses
   zutil, zbase, infblock, infutil;
 
-function inflateInit(var z : z_stream) : int;
+function inflateInit(var z : z_stream) : integer;
 
 {    Initializes the internal stream state for decompression. The fields
    zalloc, zfree and opaque must be initialized before by the caller.  If
@@ -32,16 +32,16 @@ function inflateInit(var z : z_stream) : int;
 
 function inflateInit_(z : z_streamp;
                       const version : string;
-                      stream_size : int) : int;
+                      stream_size : integer) : integer;
 
 
 function inflateInit2_(var z: z_stream;
-                       w : int;
+                       w : integer;
                        const version : string;
-                       stream_size : int) : int;
+                       stream_size : integer) : integer;
 
 function inflateInit2(var z: z_stream;
-                       windowBits : int) : int;
+                       windowBits : integer) : integer;
 
 {
      This is another version of inflateInit with an extra parameter. The
@@ -65,7 +65,7 @@ function inflateInit2(var z: z_stream;
 
 
 
-function inflateEnd(var z : z_stream) : int;
+function inflateEnd(var z : z_stream) : integer;
 
 {
    All dynamically allocated data structures for this stream are freed.
@@ -77,7 +77,7 @@ function inflateEnd(var z : z_stream) : int;
    static string (which must not be deallocated).
 }
 
-function inflateReset(var z : z_stream) : int;
+function inflateReset(var z : z_stream) : integer;
 
 {
    This function is equivalent to inflateEnd followed by inflateInit,
@@ -90,7 +90,7 @@ function inflateReset(var z : z_stream) : int;
 
 
 function inflate(var z : z_stream;
-                 f : int) : int;
+                 f : integer) : integer;
 {
   inflate decompresses as much data as possible, and stops when the input
   buffer becomes empty or the output buffer becomes full. It may introduce
@@ -160,8 +160,8 @@ function inflate(var z : z_stream;
 
 
 function inflateSetDictionary(var z : z_stream;
-                              dictionary : pBytef; {const array of byte}
-                              dictLength : uInt) : int;
+                              dictionary : Pbyte; {const array of byte}
+                              dictLength : cardinal) : integer;
 
 {
      Initializes the decompression dictionary from the given uncompressed byte
@@ -179,7 +179,7 @@ function inflateSetDictionary(var z : z_stream;
    inflate().
 }
 
-function inflateSync(var z : z_stream) : int;
+function inflateSync(var z : z_stream) : integer;
 
 {
   Skips invalid compressed data until a full flush point (see above the
@@ -196,7 +196,7 @@ function inflateSync(var z : z_stream) : int;
 }
 
 
-function inflateSyncPoint(var z : z_stream) : int;
+function inflateSyncPoint(var z : z_stream) : integer;
 
 
 implementation
@@ -204,7 +204,7 @@ implementation
 uses
   adler;
 
-function inflateReset(var z : z_stream) : int;
+function inflateReset(var z : z_stream) : integer;
 begin
   if (z.state = Z_NULL) then
   begin
@@ -226,7 +226,7 @@ begin
 end;
 
 
-function inflateEnd(var z : z_stream) : int;
+function inflateEnd(var z : z_stream) : integer;
 begin
   if (z.state = Z_NULL) or not Assigned(z.zfree) then
   begin
@@ -245,9 +245,9 @@ end;
 
 
 function inflateInit2_(var z: z_stream;
-                       w : int;
+                       w : integer;
                        const version : string;
-                       stream_size : int) : int;
+                       stream_size : integer) : integer;
 begin
   if (version = '') or (version[1] <> ZLIB_VERSION[1]) or
       (stream_size <> sizeof(z_stream)) then
@@ -263,7 +263,7 @@ begin
     {$IFDEF FPC}  z.zalloc := @zcalloc;  {$ELSE}
     z.zalloc := zcalloc;
     {$endif}
-    z.opaque := voidpf(0);
+    z.opaque := nil;
   end;
   if not Assigned(z.zfree) then
     {$IFDEF FPC}  z.zfree := @zcfree;  {$ELSE}
@@ -294,16 +294,16 @@ begin
     inflateInit2_ := Z_STREAM_ERROR;
     exit;
   end;
-  z.state^.wbits := uInt(w);
+  z.state^.wbits := cardinal(w);
 
   { create inflate_blocks state }
   if z.state^.nowrap then
-    z.state^.blocks := inflate_blocks_new(z, NIL, uInt(1) shl w)
+    z.state^.blocks := inflate_blocks_new(z, NIL, cardinal(1) shl w)
   else
   {$IFDEF FPC}
-    z.state^.blocks := inflate_blocks_new(z, @adler32, uInt(1) shl w);
+    z.state^.blocks := inflate_blocks_new(z, @adler32, cardinal(1) shl w);
   {$ELSE}
-    z.state^.blocks := inflate_blocks_new(z, adler32, uInt(1) shl w);
+    z.state^.blocks := inflate_blocks_new(z, adler32, cardinal(1) shl w);
   {$ENDIF}
   if (z.state^.blocks = Z_NULL) then
   begin
@@ -319,13 +319,13 @@ begin
   inflateInit2_ :=  Z_OK;
 end;
 
-function inflateInit2(var z: z_stream; windowBits : int) : int;
+function inflateInit2(var z: z_stream; windowBits : integer) : integer;
 begin
   inflateInit2 := inflateInit2_(z, windowBits, ZLIB_VERSION, sizeof(z_stream));
 end;
 
 
-function inflateInit(var z : z_stream) : int;
+function inflateInit(var z : z_stream) : integer;
 { inflateInit is a macro to allow checking the zlib version
   and the compiler's view of z_stream:  }
 begin
@@ -334,7 +334,7 @@ end;
 
 function inflateInit_(z : z_streamp;
                       const version : string;
-                      stream_size : int) : int;
+                      stream_size : integer) : integer;
 begin
   { initialize state }
   if (z = Z_NULL) then
@@ -344,10 +344,10 @@ begin
 end;
 
 function inflate(var z : z_stream;
-                 f : int) : int;
+                 f : integer) : integer;
 var
-  r : int;
-  b : uInt;
+  r : integer;
+  b : cardinal;
 begin
   if (z.state = Z_NULL) or (z.next_in = Z_NULL) then
   begin
@@ -396,10 +396,10 @@ begin
         end;
         r := f;
 
-        {z.state^.sub.check.need := uLong(NEXTBYTE(z)) shl 24;}
+        {z.state^.sub.check.need := cardinal(NEXTBYTE(z)) shl 24;}
         Dec(z.avail_in);
         Inc(z.total_in);
-        z.state^.sub.check.need := uLong(z.next_in^) shl 24;
+        z.state^.sub.check.need := cardinal(z.next_in^) shl 24;
         Inc(z.next_in);
 
         z.state^.mode := CHECK3;   { falltrough }
@@ -413,10 +413,10 @@ begin
           exit;
         end;
         r := f;
-        {Inc( z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 16);}
+        {Inc( z.state^.sub.check.need, cardinal(NEXTBYTE(z)) shl 16);}
         Dec(z.avail_in);
         Inc(z.total_in);
-        Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 16);
+        Inc(z.state^.sub.check.need, cardinal(z.next_in^) shl 16);
         Inc(z.next_in);
 
         z.state^.mode := CHECK2;   { falltrough }
@@ -431,10 +431,10 @@ begin
         end;
         r := f;
 
-        {Inc( z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 8);}
+        {Inc( z.state^.sub.check.need, cardinal(NEXTBYTE(z)) shl 8);}
         Dec(z.avail_in);
         Inc(z.total_in);
-        Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 8);
+        Inc(z.state^.sub.check.need, cardinal(z.next_in^) shl 8);
         Inc(z.next_in);
 
         z.state^.mode := CHECK1;   { falltrough }
@@ -448,10 +448,10 @@ begin
           exit;
         end;
         r := f;
-        {Inc( z.state^.sub.check.need, uLong(NEXTBYTE(z)) );}
+        {Inc( z.state^.sub.check.need, cardinal(NEXTBYTE(z)) );}
         Dec(z.avail_in);
         Inc(z.total_in);
-        Inc(z.state^.sub.check.need, uLong(z.next_in^) );
+        Inc(z.state^.sub.check.need, cardinal(z.next_in^) );
         Inc(z.next_in);
 
 
@@ -547,10 +547,10 @@ begin
         end;
         r := f;
 
-        {z.state^.sub.check.need := uLong(NEXTBYTE(z)) shl 24;}
+        {z.state^.sub.check.need := cardinal(NEXTBYTE(z)) shl 24;}
         Dec(z.avail_in);
         Inc(z.total_in);
-        z.state^.sub.check.need :=  uLong(z.next_in^) shl 24;
+        z.state^.sub.check.need :=  cardinal(z.next_in^) shl 24;
         Inc(z.next_in);
 
         z.state^.mode := DICT3;        { falltrough }
@@ -563,10 +563,10 @@ begin
           exit;
         end;
         r := f;
-        {Inc(z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 16);}
+        {Inc(z.state^.sub.check.need, cardinal(NEXTBYTE(z)) shl 16);}
         Dec(z.avail_in);
         Inc(z.total_in);
-        Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 16);
+        Inc(z.state^.sub.check.need, cardinal(z.next_in^) shl 16);
         Inc(z.next_in);
 
         z.state^.mode := DICT2;        { falltrough }
@@ -580,10 +580,10 @@ begin
         end;
         r := f;
 
-        {Inc(z.state^.sub.check.need, uLong(NEXTBYTE(z)) shl 8);}
+        {Inc(z.state^.sub.check.need, cardinal(NEXTBYTE(z)) shl 8);}
         Dec(z.avail_in);
         Inc(z.total_in);
-        Inc(z.state^.sub.check.need, uLong(z.next_in^) shl 8);
+        Inc(z.state^.sub.check.need, cardinal(z.next_in^) shl 8);
         Inc(z.next_in);
 
         z.state^.mode := DICT1;        { falltrough }
@@ -596,10 +596,10 @@ begin
           exit;
         end;
         { r := f;    ---  wird niemals benutzt }
-        {Inc(z.state^.sub.check.need, uLong(NEXTBYTE(z)) );}
+        {Inc(z.state^.sub.check.need, cardinal(NEXTBYTE(z)) );}
         Dec(z.avail_in);
         Inc(z.total_in);
-        Inc(z.state^.sub.check.need, uLong(z.next_in^) );
+        Inc(z.state^.sub.check.need, cardinal(z.next_in^) );
         Inc(z.next_in);
 
         z.adler := z.state^.sub.check.need;
@@ -632,10 +632,10 @@ begin
 end;
 
 function inflateSetDictionary(var z : z_stream;
-                              dictionary : pBytef; {const array of byte}
-                              dictLength : uInt) : int;
+                              dictionary : Pbyte; {const array of byte}
+                              dictLength : cardinal) : integer;
 var
-  length : uInt;
+  length : cardinal;
 begin
   length := dictLength;
 
@@ -644,14 +644,14 @@ begin
     inflateSetDictionary := Z_STREAM_ERROR;
     exit;
   end;
-  if (adler32(Long(1), dictionary, dictLength) <> z.adler) then
+  if (adler32(1, dictionary, dictLength) <> z.adler) then
   begin
     inflateSetDictionary := Z_DATA_ERROR;
     exit;
   end;
-  z.adler := Long(1);
+  z.adler := 1;
 
-  if (length >= (uInt(1) shl z.state^.wbits)) then
+  if (length >= (1 shl z.state^.wbits)) then
   begin
     length := (1 shl z.state^.wbits)-1;
     Inc( dictionary, dictLength - length);
@@ -662,14 +662,14 @@ begin
 end;
 
 
-function inflateSync(var z : z_stream) : int;
+function inflateSync(var z : z_stream) : integer;
 const
   mark : packed array[0..3] of byte = (0, 0, $ff, $ff);
 var
-  n : uInt;       { number of bytes to look at }
-  p : pBytef;     { pointer to bytes }
-  m : uInt;       { number of marker bytes found in a row }
-  r, w : uLong;   { temporaries to save total_in and total_out }
+  n : cardinal;       { number of bytes to look at }
+  p : Pbyte;     { pointer to bytes }
+  m : cardinal;       { number of marker bytes found in a row }
+  r, w : cardinal;   { temporaries to save total_in and total_out }
 begin
   { set up }
   if (z.state = Z_NULL) then
@@ -706,7 +706,7 @@ begin
   end;
 
   { restore }
-  Inc(z.total_in, ptr2int(p) - ptr2int(z.next_in));
+  Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
   z.next_in := p;
   z.avail_in := n;
   z.state^.sub.marker := m;
@@ -737,7 +737,7 @@ end;
   waiting for these length bytes.
 }
 
-function inflateSyncPoint(var z : z_stream) : int;
+function inflateSyncPoint(var z : z_stream) : integer;
 begin
   if (z.state = Z_NULL) or (z.state^.blocks = Z_NULL) then
   begin

+ 14 - 14
packages/base/paszlib/zuncompr.pas

@@ -31,40 +31,40 @@ uses
    buffer, or Z_DATA_ERROR if the input data was corrupted.
 }
 
-function uncompress (dest : pBytef;
-                     var destLen : uLong;
+function uncompress (dest : Pbyte;
+                     var destLen : cardinal;
                      const source : array of byte;
-                     sourceLen : uLong) : int;
+                     sourceLen : cardinal) : integer;
 
 implementation
 
-function uncompress (dest : pBytef;
-                     var destLen : uLong;
+function uncompress (dest : Pbyte;
+                     var destLen : cardinal;
                      const source : array of byte;
-                     sourceLen : uLong) : int;
+                     sourceLen : cardinal) : integer;
 var
   stream : z_stream;
-  err : int;
+  err : integer;
 begin
-  stream.next_in := pBytef(@source);
-  stream.avail_in := uInt(sourceLen);
+  stream.next_in := Pbyte(@source);
+  stream.avail_in := cardinal(sourceLen);
   { Check for source > 64K on 16-bit machine: }
-  if (uLong(stream.avail_in) <> sourceLen) then
+  if (cardinal(stream.avail_in) <> sourceLen) then
   begin
     uncompress := Z_BUF_ERROR;
     exit;
   end;
 
   stream.next_out := dest;
-  stream.avail_out := uInt(destLen);
-  if (uLong(stream.avail_out) <> destLen) then
+  stream.avail_out := cardinal(destLen);
+  if (cardinal(stream.avail_out) <> destLen) then
   begin
     uncompress := Z_BUF_ERROR;
     exit;
   end;
 
-  stream.zalloc := NIL;       { alloc_func(0); }
-  stream.zfree := NIL;        { free_func(0); }
+  stream.zalloc := nil;       { alloc_func(0); }
+  stream.zfree := nil;        { free_func(0); }
 
   err := inflateInit(stream);
   if (err <> Z_OK) then

+ 29 - 85
packages/base/paszlib/zutil.pas

@@ -9,47 +9,6 @@ interface
 
 {$I zconf.inc}
 
-{ Type declarations }
-
-type
-  {Byte   = usigned char;  8 bits}
-  Bytef  = byte;
-  charf  = byte;
-
-{$IFDEF FPC}
-  int    = longint;
-{$ELSE}
-  int    = integer;
-{$ENDIF}
-
-  intf   = int;
-{$IFDEF MSDOS}
-  uInt   = Word;
-{$ELSE}
-  {$IFDEF FPC}
-    uInt   = longint;     { 16 bits or more }
-    {$INFO Cardinal}
-  {$ELSE}
-    uInt   = cardinal;     { 16 bits or more }
-  {$ENDIF}
-{$ENDIF}
-  uIntf  = uInt;
-
-  Long   = longint;
-  uLong  = Cardinal;
-  uLongf = uLong;
-
-  voidp  = pointer;
-  voidpf = voidp;
-  pBytef = ^Bytef;
-  pIntf  = ^intf;
-  puIntf = ^uIntf;
-  puLong = ^uLongf;
-
-  ptr2int = uInt;
-{ a pointer to integer casting is used to do pointer arithmetic.
-  ptr2int must be an integer type and sizeof(ptr2int) must be less
-  than sizeof(pointer) - Nomssi }
 
 const
   {$IFDEF MAXSEG_64K}
@@ -59,42 +18,27 @@ const
   {$ENDIF}
 
 type
-  zByteArray = array[0..(MaxMemBlock div SizeOf(Bytef))-1] of Bytef;
+  zByteArray = array[0..(MaxMemBlock div SizeOf(byte))-1] of byte;
   pzByteArray = ^zByteArray;
 type
-  zIntfArray = array[0..(MaxMemBlock div SizeOf(Intf))-1] of Intf;
+  zIntfArray = array[0..(MaxMemBlock div SizeOf(byte))-1] of integer;
   pzIntfArray = ^zIntfArray;
 type
-  zuIntArray = array[0..(MaxMemBlock div SizeOf(uInt))-1] of uInt;
+  zuIntArray = array[0..(MaxMemBlock div SizeOf(cardinal))-1] of cardinal;
   PuIntArray = ^zuIntArray;
 
-{ Type declarations - only for deflate }
-
-type
-  uch  = Byte;
-  uchf = uch; { FAR }
-  ush  = Word;
-  ushf = ush;
-  ulg  = LongInt;
-
-  unsigned = uInt;
-
-  pcharf = ^charf;
-  puchf = ^uchf;
-  pushf = ^ushf;
-
 type
   zuchfArray = zByteArray;
   puchfArray = ^zuchfArray;
 type
-  zushfArray = array[0..(MaxMemBlock div SizeOf(ushf))-1] of ushf;
+  zushfArray = array[0..(MaxMemBlock div SizeOf(word))-1] of word;
   pushfArray = ^zushfArray;
 
-procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
-function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
-procedure zmemzero(destp : pBytef; len : uInt);
-procedure zcfree(opaque : voidpf; ptr : voidpf);
-function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
+procedure zmemcpy(destp : Pbyte; sourcep : Pbyte; len : cardinal);
+function zmemcmp(s1p, s2p : Pbyte; len : cardinal) : integer;
+procedure zmemzero(destp : Pbyte; len : cardinal);
+procedure zcfree(opaque : pointer; ptr : pointer);
+function zcalloc (opaque : pointer; items : cardinal; size : cardinal) : pointer;
 
 implementation
 
@@ -205,7 +149,7 @@ type
     size: Pointer;
   end;
 type
-  HugePtr = voidpf;
+  HugePtr = pointer;
 
 
  procedure IncPtr(var p:pointer;count:word);
@@ -295,7 +239,7 @@ begin
   end;
 end;
 
-procedure GetMemHuge(var p:HugePtr;memsize:Longint);
+procedure GetMemHuge(var p:HugePtr;memsize:longint);
 const
   blocksize = $FFF0;
 var
@@ -376,16 +320,16 @@ end;
 
 {$ENDIF}
 
-procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
+procedure zmemcpy(destp : Pbyte; sourcep : Pbyte; len : cardinal);
 begin
   Move(sourcep^, destp^, len);
 end;
 
-function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
+function zmemcmp(s1p, s2p : Pbyte; len : cardinal) : integer;
 var
-  j : uInt;
+  j : cardinal;
   source,
-  dest : pBytef;
+  dest : Pbyte;
 begin
   source := s1p;
   dest := s2p;
@@ -393,7 +337,7 @@ begin
   begin
     if (source^ <> dest^) then
     begin
-      zmemcmp := 2*Ord(source^ > dest^)-1;
+      zmemcmp := 2*ord(source^ > dest^)-1;
       exit;
     end;
     Inc(source);
@@ -402,19 +346,19 @@ begin
   zmemcmp := 0;
 end;
 
-procedure zmemzero(destp : pBytef; len : uInt);
+procedure zmemzero(destp : Pbyte; len : cardinal);
 begin
   FillChar(destp^, len, 0);
 end;
 
-procedure zcfree(opaque : voidpf; ptr : voidpf);
+procedure zcfree(opaque : pointer; ptr : pointer);
 {$ifdef Delphi16}
 var
   Handle : THandle;
 {$endif}
 {$IFDEF FPC}
 var
-  memsize : uint;
+  memsize : cardinal;
 {$ENDIF}
 begin
   {$IFDEF DPMI}
@@ -432,9 +376,9 @@ begin
         GlobalFree(Handle);
         {$else}
           {$IFDEF FPC}
-          Dec(puIntf(ptr));
-          memsize := puIntf(ptr)^;
-          FreeMem(ptr, memsize+SizeOf(uInt));
+          dec(Pcardinal(ptr));
+          memsize := Pcardinal(ptr)^;
+          FreeMem(ptr, memsize+SizeOf(cardinal));
           {$ELSE}
           FreeMem(ptr);  { Delphi 2,3,4 }
           {$ENDIF}
@@ -444,15 +388,15 @@ begin
   {$ENDIF}
 end;
 
-function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
+function zcalloc (opaque : pointer; items : cardinal; size : cardinal) : pointer;
 var
-  p : voidpf;
-  memsize : uLong;
+  p : pointer;
+  memsize : cardinal;
 {$ifdef Delphi16}
   handle : THandle;
 {$endif}
 begin
-  memsize := uLong(items) * size;
+  memsize := items * size;
   {$IFDEF DPMI}
   p := GlobalAllocPtr(gmem_moveable, memsize);
   {$ELSE}
@@ -467,9 +411,9 @@ begin
         p := GlobalLock(Handle);
         {$else}
           {$IFDEF FPC}
-          GetMem(p, memsize+SizeOf(uInt));
-          puIntf(p)^:= memsize;
-          Inc(puIntf(p));
+          getmem(p, memsize+sizeOf(cardinal));
+          Pcardinal(p)^:= memsize;
+          inc(Pcardinal(p));
           {$ELSE}
           GetMem(p, memsize);  { Delphi: p := AllocMem(memsize); }
           {$ENDIF}

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff