Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
4.8 KiB

3 years ago
  1. Unit iminfutil;
  2. { types and macros common to blocks and codes
  3. Copyright (C) 1995-1998 Mark Adler
  4. WARNING: this file should *not* be used by applications. It is
  5. part of the implementation of the compression library and is
  6. subject to change.
  7. Pascal tranlastion
  8. Copyright (C) 1998 by Jacques Nomssi Nzali
  9. For conditions of distribution and use, see copyright notice in readme.txt
  10. }
  11. interface
  12. {$I imzconf.inc}
  13. uses
  14. imzutil, impaszlib;
  15. { copy as much as possible from the sliding window to the output area }
  16. function inflate_flush(var s : inflate_blocks_state;
  17. var z : z_stream;
  18. r : int) : int;
  19. { And'ing with mask[n] masks the lower n bits }
  20. const
  21. inflate_mask : array[0..17-1] of uInt = (
  22. $0000,
  23. $0001, $0003, $0007, $000f, $001f, $003f, $007f, $00ff,
  24. $01ff, $03ff, $07ff, $0fff, $1fff, $3fff, $7fff, $ffff);
  25. {procedure GRABBITS(j : int);}
  26. {procedure DUMPBITS(j : int);}
  27. {procedure NEEDBITS(j : int);}
  28. implementation
  29. { macros for bit input with no checking and for returning unused bytes }
  30. procedure GRABBITS(j : int);
  31. begin
  32. {while (k < j) do
  33. begin
  34. Dec(z^.avail_in);
  35. Inc(z^.total_in);
  36. b := b or (uLong(z^.next_in^) shl k);
  37. Inc(z^.next_in);
  38. Inc(k, 8);
  39. end;}
  40. end;
  41. procedure DUMPBITS(j : int);
  42. begin
  43. {b := b shr j;
  44. Dec(k, j);}
  45. end;
  46. procedure NEEDBITS(j : int);
  47. begin
  48. (*
  49. while (k < j) do
  50. begin
  51. {NEEDBYTE;}
  52. if (n <> 0) then
  53. r :=Z_OK
  54. else
  55. begin
  56. {UPDATE}
  57. s.bitb := b;
  58. s.bitk := k;
  59. z.avail_in := n;
  60. Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
  61. z.next_in := p;
  62. s.write := q;
  63. result := inflate_flush(s,z,r);
  64. exit;
  65. end;
  66. Dec(n);
  67. b := b or (uLong(p^) shl k);
  68. Inc(p);
  69. Inc(k, 8);
  70. end;
  71. *)
  72. end;
  73. procedure NEEDOUT;
  74. begin
  75. (*
  76. if (m = 0) then
  77. begin
  78. {WRAP}
  79. if (q = s.zend) and (s.read <> s.window) then
  80. begin
  81. q := s.window;
  82. if LongInt(q) < LongInt(s.read) then
  83. m := uInt(LongInt(s.read)-LongInt(q)-1)
  84. else
  85. m := uInt(LongInt(s.zend)-LongInt(q));
  86. end;
  87. if (m = 0) then
  88. begin
  89. {FLUSH}
  90. s.write := q;
  91. r := inflate_flush(s,z,r);
  92. q := s.write;
  93. if LongInt(q) < LongInt(s.read) then
  94. m := uInt(LongInt(s.read)-LongInt(q)-1)
  95. else
  96. m := uInt(LongInt(s.zend)-LongInt(q));
  97. {WRAP}
  98. if (q = s.zend) and (s.read <> s.window) then
  99. begin
  100. q := s.window;
  101. if LongInt(q) < LongInt(s.read) then
  102. m := uInt(LongInt(s.read)-LongInt(q)-1)
  103. else
  104. m := uInt(LongInt(s.zend)-LongInt(q));
  105. end;
  106. if (m = 0) then
  107. begin
  108. {UPDATE}
  109. s.bitb := b;
  110. s.bitk := k;
  111. z.avail_in := n;
  112. Inc(z.total_in, LongInt(p)-LongInt(z.next_in));
  113. z.next_in := p;
  114. s.write := q;
  115. result := inflate_flush(s,z,r);
  116. exit;
  117. end;
  118. end;
  119. end;
  120. r := Z_OK;
  121. *)
  122. end;
  123. { copy as much as possible from the sliding window to the output area }
  124. function inflate_flush(var s : inflate_blocks_state;
  125. var z : z_stream;
  126. r : int) : int;
  127. var
  128. n : uInt;
  129. p : pBytef;
  130. q : pBytef;
  131. begin
  132. { local copies of source and destination pointers }
  133. p := z.next_out;
  134. q := s.read;
  135. { compute number of bytes to copy as far as end of window }
  136. if ptr2int(q) <= ptr2int(s.write) then
  137. n := uInt(ptr2int(s.write) - ptr2int(q))
  138. else
  139. n := uInt(ptr2int(s.zend) - ptr2int(q));
  140. if (n > z.avail_out) then
  141. n := z.avail_out;
  142. if (n <> 0) and (r = Z_BUF_ERROR) then
  143. r := Z_OK;
  144. { update counters }
  145. Dec(z.avail_out, n);
  146. Inc(z.total_out, n);
  147. { update check information }
  148. if Assigned(s.checkfn) then
  149. begin
  150. s.check := s.checkfn(s.check, q, n);
  151. z.adler := s.check;
  152. end;
  153. { copy as far as end of window }
  154. zmemcpy(p, q, n);
  155. Inc(p, n);
  156. Inc(q, n);
  157. { see if more to copy at beginning of window }
  158. if (q = s.zend) then
  159. begin
  160. { wrap pointers }
  161. q := s.window;
  162. if (s.write = s.zend) then
  163. s.write := s.window;
  164. { compute bytes to copy }
  165. n := uInt(ptr2int(s.write) - ptr2int(q));
  166. if (n > z.avail_out) then
  167. n := z.avail_out;
  168. if (n <> 0) and (r = Z_BUF_ERROR) then
  169. r := Z_OK;
  170. { update counters }
  171. Dec( z.avail_out, n);
  172. Inc( z.total_out, n);
  173. { update check information }
  174. if Assigned(s.checkfn) then
  175. begin
  176. s.check := s.checkfn(s.check, q, n);
  177. z.adler := s.check;
  178. end;
  179. { copy }
  180. zmemcpy(p, q, n);
  181. Inc(p, n);
  182. Inc(q, n);
  183. end;
  184. { update pointers }
  185. z.next_out := p;
  186. s.read := q;
  187. { done }
  188. inflate_flush := r;
  189. end;
  190. end.