imzutil.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. Unit imzutil;
  2. {
  3. Copyright (C) 1998 by Jacques Nomssi Nzali
  4. For conditions of distribution and use, see copyright notice in readme.txt
  5. }
  6. interface
  7. {$I imzconf.inc}
  8. { Type declarations }
  9. type
  10. {Byte = usigned char; 8 bits}
  11. Bytef = byte;
  12. charf = byte;
  13. int = longint;
  14. intf = int;
  15. uInt = cardinal; { 16 bits or more }
  16. uIntf = uInt;
  17. Long = longint;
  18. uLong = Cardinal;
  19. uLongf = uLong;
  20. voidp = pointer;
  21. voidpf = voidp;
  22. pBytef = ^Bytef;
  23. pIntf = ^intf;
  24. puIntf = ^uIntf;
  25. puLong = ^uLongf;
  26. {$IF Defined(FPC)}
  27. ptr2int = PtrUInt;
  28. {$ELSEIF CompilerVersion >= 20}
  29. ptr2int = NativeUInt;
  30. {$ELSE}
  31. ptr2int = Cardinal;
  32. {$IFEND}
  33. { a pointer to integer casting is used to do pointer arithmetic. }
  34. type
  35. zByteArray = array[0..(MaxInt div SizeOf(Bytef))-1] of Bytef;
  36. pzByteArray = ^zByteArray;
  37. type
  38. zIntfArray = array[0..(MaxInt div SizeOf(Intf))-1] of Intf;
  39. pzIntfArray = ^zIntfArray;
  40. type
  41. zuIntArray = array[0..(MaxInt div SizeOf(uInt))-1] of uInt;
  42. PuIntArray = ^zuIntArray;
  43. { Type declarations - only for deflate }
  44. type
  45. uch = Byte;
  46. uchf = uch; { FAR }
  47. ush = Word;
  48. ushf = ush;
  49. ulg = LongInt;
  50. unsigned = uInt;
  51. pcharf = ^charf;
  52. puchf = ^uchf;
  53. pushf = ^ushf;
  54. type
  55. zuchfArray = zByteArray;
  56. puchfArray = ^zuchfArray;
  57. type
  58. zushfArray = array[0..(MaxInt div SizeOf(ushf))-1] of ushf;
  59. pushfArray = ^zushfArray;
  60. procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
  61. function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
  62. procedure zmemzero(destp : pBytef; len : uInt);
  63. procedure zcfree(opaque : voidpf; ptr : voidpf);
  64. function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
  65. implementation
  66. procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
  67. begin
  68. Move(sourcep^, destp^, len);
  69. end;
  70. function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
  71. var
  72. j : uInt;
  73. source,
  74. dest : pBytef;
  75. begin
  76. source := s1p;
  77. dest := s2p;
  78. for j := 0 to pred(len) do
  79. begin
  80. if (source^ <> dest^) then
  81. begin
  82. zmemcmp := 2*Ord(source^ > dest^)-1;
  83. exit;
  84. end;
  85. Inc(source);
  86. Inc(dest);
  87. end;
  88. zmemcmp := 0;
  89. end;
  90. procedure zmemzero(destp : pBytef; len : uInt);
  91. begin
  92. FillChar(destp^, len, 0);
  93. end;
  94. procedure zcfree(opaque : voidpf; ptr : voidpf);
  95. {$ifdef Delphi16}
  96. var
  97. Handle : THandle;
  98. {$endif}
  99. {$IFDEF FPC}
  100. var
  101. memsize : uint;
  102. {$ENDIF}
  103. begin
  104. (*
  105. {$IFDEF DPMI}
  106. {h :=} GlobalFreePtr(ptr);
  107. {$ELSE}
  108. {$IFDEF CALL_DOS}
  109. dosFree(ptr);
  110. {$ELSE}
  111. {$ifdef HugeMem}
  112. FreeMemHuge(ptr);
  113. {$else}
  114. {$ifdef Delphi16}
  115. Handle := GlobalHandle(LH(ptr).H); { HiWord(LongInt(ptr)) }
  116. GlobalUnLock(Handle);
  117. GlobalFree(Handle);
  118. {$else}
  119. {$IFDEF FPC}
  120. Dec(puIntf(ptr));
  121. memsize := puIntf(ptr)^;
  122. FreeMem(ptr, memsize+SizeOf(uInt));
  123. {$ELSE}
  124. FreeMem(ptr); { Delphi 2,3,4 }
  125. {$ENDIF}
  126. {$endif}
  127. {$endif}
  128. {$ENDIF}
  129. {$ENDIF}
  130. *)
  131. FreeMem(ptr);
  132. end;
  133. function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
  134. var
  135. p : voidpf;
  136. memsize : uLong;
  137. {$ifdef Delphi16}
  138. handle : THandle;
  139. {$endif}
  140. begin
  141. memsize := uLong(items) * size;
  142. (*
  143. { $IFDEF DPMI}
  144. p := GlobalAllocPtr(gmem_moveable, memsize);
  145. { $ELSE}
  146. { $IFDEF CALLDOS}
  147. p := dosAlloc(memsize);
  148. { $ELSE}
  149. {$ifdef HugeMem}
  150. GetMemHuge(p, memsize);
  151. { $else}
  152. { $ifdef Delphi16}
  153. Handle := GlobalAlloc(HeapAllocFlags, memsize);
  154. p := GlobalLock(Handle);
  155. { $else}
  156. { $IFDEF FPC}
  157. GetMem(p, memsize+SizeOf(uInt));
  158. puIntf(p)^:= memsize;
  159. Inc(puIntf(p));
  160. { $ELSE}
  161. GetMem(p, memsize); { Delphi: p := AllocMem(memsize); }
  162. { $ENDIF}
  163. { $endif}
  164. { $endif}
  165. { $ENDIF}
  166. { $ENDIF}
  167. *)
  168. GetMem(p, memsize);
  169. zcalloc := p;
  170. end;
  171. end.