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.

780 lines
28 KiB

3 years ago
  1. Unit iminftrees;
  2. { inftrees.h -- header to use inftrees.c
  3. inftrees.c -- generate Huffman trees for efficient decoding
  4. Copyright (C) 1995-1998 Mark Adler
  5. WARNING: this file should *not* be used by applications. It is
  6. part of the implementation of the compression library and is
  7. subject to change.
  8. Pascal tranlastion
  9. Copyright (C) 1998 by Jacques Nomssi Nzali
  10. For conditions of distribution and use, see copyright notice in readme.txt
  11. }
  12. Interface
  13. {$I imzconf.inc}
  14. uses
  15. imzutil, impaszlib;
  16. { Maximum size of dynamic tree. The maximum found in a long but non-
  17. exhaustive search was 1004 huft structures (850 for length/literals
  18. and 154 for distances, the latter actually the result of an
  19. exhaustive search). The actual maximum is not known, but the
  20. value below is more than safe. }
  21. const
  22. MANY = 1440;
  23. {$ifdef DEBUG}
  24. var
  25. inflate_hufts : uInt;
  26. {$endif}
  27. function inflate_trees_bits(
  28. var c : array of uIntf; { 19 code lengths }
  29. var bb : uIntf; { bits tree desired/actual depth }
  30. var tb : pinflate_huft; { bits tree result }
  31. var hp : array of Inflate_huft; { space for trees }
  32. var z : z_stream { for messages }
  33. ) : int;
  34. function inflate_trees_dynamic(
  35. nl : uInt; { number of literal/length codes }
  36. nd : uInt; { number of distance codes }
  37. var c : Array of uIntf; { that many (total) code lengths }
  38. var bl : uIntf; { literal desired/actual bit depth }
  39. var bd : uIntf; { distance desired/actual bit depth }
  40. var tl : pInflate_huft; { literal/length tree result }
  41. var td : pInflate_huft; { distance tree result }
  42. var hp : array of Inflate_huft; { space for trees }
  43. var z : z_stream { for messages }
  44. ) : int;
  45. function inflate_trees_fixed (
  46. var bl : uInt; { literal desired/actual bit depth }
  47. var bd : uInt; { distance desired/actual bit depth }
  48. var tl : pInflate_huft; { literal/length tree result }
  49. var td : pInflate_huft; { distance tree result }
  50. var z : z_stream { for memory allocation }
  51. ) : int;
  52. implementation
  53. const
  54. inflate_copyright = 'inflate 1.1.2 Copyright 1995-1998 Mark Adler';
  55. {
  56. If you use the zlib library in a product, an acknowledgment is welcome
  57. in the documentation of your product. If for some reason you cannot
  58. include such an acknowledgment, I would appreciate that you keep this
  59. copyright string in the executable of your product.
  60. }
  61. const
  62. { Tables for deflate from PKZIP's appnote.txt. }
  63. cplens : Array [0..30] Of uInt { Copy lengths for literal codes 257..285 }
  64. = (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  65. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);
  66. { actually lengths - 2; also see note #13 above about 258 }
  67. invalid_code = 112;
  68. cplext : Array [0..30] Of uInt { Extra bits for literal codes 257..285 }
  69. = (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
  70. 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, invalid_code, invalid_code);
  71. cpdist : Array [0..29] Of uInt { Copy offsets for distance codes 0..29 }
  72. = (1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  73. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  74. 8193, 12289, 16385, 24577);
  75. cpdext : Array [0..29] Of uInt { Extra bits for distance codes }
  76. = (0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
  77. 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
  78. 12, 12, 13, 13);
  79. { Huffman code decoding is performed using a multi-level table lookup.
  80. The fastest way to decode is to simply build a lookup table whose
  81. size is determined by the longest code. However, the time it takes
  82. to build this table can also be a factor if the data being decoded
  83. is not very long. The most common codes are necessarily the
  84. shortest codes, so those codes dominate the decoding time, and hence
  85. the speed. The idea is you can have a shorter table that decodes the
  86. shorter, more probable codes, and then point to subsidiary tables for
  87. the longer codes. The time it costs to decode the longer codes is
  88. then traded against the time it takes to make longer tables.
  89. This results of this trade are in the variables lbits and dbits
  90. below. lbits is the number of bits the first level table for literal/
  91. length codes can decode in one step, and dbits is the same thing for
  92. the distance codes. Subsequent tables are also less than or equal to
  93. those sizes. These values may be adjusted either when all of the
  94. codes are shorter than that, in which case the longest code length in
  95. bits is used, or when the shortest code is *longer* than the requested
  96. table size, in which case the length of the shortest code in bits is
  97. used.
  98. There are two different values for the two tables, since they code a
  99. different number of possibilities each. The literal/length table
  100. codes 286 possible values, or in a flat code, a little over eight
  101. bits. The distance table codes 30 possible values, or a little less
  102. than five bits, flat. The optimum values for speed end up being
  103. about one bit more than those, so lbits is 8+1 and dbits is 5+1.
  104. The optimum values may differ though from machine to machine, and
  105. possibly even between compilers. Your mileage may vary. }
  106. { If BMAX needs to be larger than 16, then h and x[] should be uLong. }
  107. const
  108. BMAX = 15; { maximum bit length of any code }
  109. {$DEFINE USE_PTR}
  110. function huft_build(
  111. var b : array of uIntf; { code lengths in bits (all assumed <= BMAX) }
  112. n : uInt; { number of codes (assumed <= N_MAX) }
  113. s : uInt; { number of simple-valued codes (0..s-1) }
  114. const d : array of uIntf; { list of base values for non-simple codes }
  115. { array of word }
  116. const e : array of uIntf; { list of extra bits for non-simple codes }
  117. { array of byte }
  118. t : ppInflate_huft; { result: starting table }
  119. var m : uIntf; { maximum lookup bits, returns actual }
  120. var hp : array of inflate_huft; { space for trees }
  121. var hn : uInt; { hufts used in space }
  122. var v : array of uIntf { working area: values in order of bit length }
  123. ) : int;
  124. { Given a list of code lengths and a maximum table size, make a set of
  125. tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
  126. if the given code set is incomplete (the tables are still built in this
  127. case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
  128. lengths), or Z_MEM_ERROR if not enough memory. }
  129. Var
  130. a : uInt; { counter for codes of length k }
  131. c : Array [0..BMAX] Of uInt; { bit length count table }
  132. f : uInt; { i repeats in table every f entries }
  133. g : int; { maximum code length }
  134. h : int; { table level }
  135. i : uInt; {register} { counter, current code }
  136. j : uInt; {register} { counter }
  137. k : Int; {register} { number of bits in current code }
  138. l : int; { bits per table (returned in m) }
  139. mask : uInt; { (1 shl w) - 1, to avoid cc -O bug on HP }
  140. p : ^uIntf; {register} { pointer into c[], b[], or v[] }
  141. q : pInflate_huft; { points to current table }
  142. r : inflate_huft; { table entry for structure assignment }
  143. u : Array [0..BMAX-1] Of pInflate_huft; { table stack }
  144. w : int; {register} { bits before this table = (l*h) }
  145. x : Array [0..BMAX] Of uInt; { bit offsets, then code stack }
  146. {$IFDEF USE_PTR}
  147. xp : puIntf; { pointer into x }
  148. {$ELSE}
  149. xp : uInt;
  150. {$ENDIF}
  151. y : int; { number of dummy codes added }
  152. z : uInt; { number of entries in current table }
  153. Begin
  154. { Generate counts for each bit length }
  155. FillChar(c,SizeOf(c),0) ; { clear c[] }
  156. for i := 0 to n-1 do
  157. Inc (c[b[i]]); { assume all entries <= BMAX }
  158. If (c[0] = n) Then { null input--all zero length codes }
  159. Begin
  160. t^ := pInflate_huft(NIL);
  161. m := 0 ;
  162. huft_build := Z_OK ;
  163. Exit;
  164. End ;
  165. { Find minimum and maximum length, bound [m] by those }
  166. l := m;
  167. for j:=1 To BMAX do
  168. if (c[j] <> 0) then
  169. break;
  170. k := j ; { minimum code length }
  171. if (uInt(l) < j) then
  172. l := j;
  173. for i := BMAX downto 1 do
  174. if (c[i] <> 0) then
  175. break ;
  176. g := i ; { maximum code length }
  177. if (uInt(l) > i) then
  178. l := i;
  179. m := l;
  180. { Adjust last length count to fill out codes, if needed }
  181. y := 1 shl j ;
  182. while (j < i) do
  183. begin
  184. Dec(y, c[j]) ;
  185. if (y < 0) then
  186. begin
  187. huft_build := Z_DATA_ERROR; { bad input: more codes than bits }
  188. exit;
  189. end ;
  190. Inc(j) ;
  191. y := y shl 1
  192. end;
  193. Dec (y, c[i]) ;
  194. if (y < 0) then
  195. begin
  196. huft_build := Z_DATA_ERROR; { bad input: more codes than bits }
  197. exit;
  198. end;
  199. Inc(c[i], y);
  200. { Generate starting offsets into the value table FOR each length }
  201. {$IFDEF USE_PTR}
  202. x[1] := 0;
  203. j := 0;
  204. p := @c[1];
  205. xp := @x[2];
  206. dec(i); { note that i = g from above }
  207. WHILE (i > 0) DO
  208. BEGIN
  209. inc(j, p^);
  210. xp^ := j;
  211. inc(p);
  212. inc(xp);
  213. dec(i);
  214. END;
  215. {$ELSE}
  216. x[1] := 0;
  217. j := 0 ;
  218. for i := 1 to g do
  219. begin
  220. x[i] := j;
  221. Inc(j, c[i]);
  222. end;
  223. {$ENDIF}
  224. { Make a table of values in order of bit lengths }
  225. for i := 0 to n-1 do
  226. begin
  227. j := b[i];
  228. if (j <> 0) then
  229. begin
  230. v[ x[j] ] := i;
  231. Inc(x[j]);
  232. end;
  233. end;
  234. n := x[g]; { set n to length of v }
  235. { Generate the Huffman codes and for each, make the table entries }
  236. i := 0 ;
  237. x[0] := 0 ; { first Huffman code is zero }
  238. p := Addr(v) ; { grab values in bit order }
  239. h := -1 ; { no tables yet--level -1 }
  240. w := -l ; { bits decoded = (l*h) }
  241. u[0] := pInflate_huft(NIL); { just to keep compilers happy }
  242. q := pInflate_huft(NIL); { ditto }
  243. z := 0 ; { ditto }
  244. { go through the bit lengths (k already is bits in shortest code) }
  245. while (k <= g) Do
  246. begin
  247. a := c[k] ;
  248. while (a<>0) Do
  249. begin
  250. Dec (a) ;
  251. { here i is the Huffman code of length k bits for value p^ }
  252. { make tables up to required level }
  253. while (k > w + l) do
  254. begin
  255. Inc (h) ;
  256. Inc (w, l); { add bits already decoded }
  257. { previous table always l bits }
  258. { compute minimum size table less than or equal to l bits }
  259. { table size upper limit }
  260. z := g - w;
  261. If (z > uInt(l)) Then
  262. z := l;
  263. { try a k-w bit table }
  264. j := k - w;
  265. f := 1 shl j;
  266. if (f > a+1) Then { too few codes for k-w bit table }
  267. begin
  268. Dec(f, a+1); { deduct codes from patterns left }
  269. {$IFDEF USE_PTR}
  270. xp := Addr(c[k]);
  271. if (j < z) then
  272. begin
  273. Inc(j);
  274. while (j < z) do
  275. begin { try smaller tables up to z bits }
  276. f := f shl 1;
  277. Inc (xp) ;
  278. If (f <= xp^) Then
  279. break; { enough codes to use up j bits }
  280. Dec(f, xp^); { else deduct codes from patterns }
  281. Inc(j);
  282. end;
  283. end;
  284. {$ELSE}
  285. xp := k;
  286. if (j < z) then
  287. begin
  288. Inc (j) ;
  289. While (j < z) Do
  290. begin { try smaller tables up to z bits }
  291. f := f * 2;
  292. Inc (xp) ;
  293. if (f <= c[xp]) then
  294. Break ; { enough codes to use up j bits }
  295. Dec (f, c[xp]) ; { else deduct codes from patterns }
  296. Inc (j);
  297. end;
  298. end;
  299. {$ENDIF}
  300. end;
  301. z := 1 shl j; { table entries for j-bit table }
  302. { allocate new table }
  303. if (hn + z > MANY) then { (note: doesn't matter for fixed) }
  304. begin
  305. huft_build := Z_MEM_ERROR; { not enough memory }
  306. exit;
  307. end;
  308. q := @hp[hn];
  309. u[h] := q;
  310. Inc(hn, z);
  311. { connect to last table, if there is one }
  312. if (h <> 0) then
  313. begin
  314. x[h] := i; { save pattern for backing up }
  315. r.bits := Byte(l); { bits to dump before this table }
  316. r.exop := Byte(j); { bits in this table }
  317. j := i shr (w - l);
  318. {r.base := uInt( q - u[h-1] -j);} { offset to this table }
  319. r.base := (ptr2int(q) - ptr2int(u[h-1]) ) div sizeof(q^) - j;
  320. huft_Ptr(u[h-1])^[j] := r; { connect to last table }
  321. end
  322. else
  323. t^ := q; { first table is returned result }
  324. end;
  325. { set up table entry in r }
  326. r.bits := Byte(k - w);
  327. { C-code: if (p >= v + n) - see ZUTIL.PAS for comments }
  328. if ptr2int(p)>=ptr2int(@(v[n])) then { also works under DPMI ?? }
  329. r.exop := 128 + 64 { out of values--invalid code }
  330. else
  331. if (p^ < s) then
  332. begin
  333. if (p^ < 256) then { 256 is end-of-block code }
  334. r.exop := 0
  335. Else
  336. r.exop := 32 + 64; { EOB_code; }
  337. r.base := p^; { simple code is just the value }
  338. Inc(p);
  339. end
  340. Else
  341. begin
  342. r.exop := Byte(e[p^-s] + 16 + 64); { non-simple--look up in lists }
  343. r.base := d[p^-s];
  344. Inc (p);
  345. end ;
  346. { fill code-like entries with r }
  347. f := 1 shl (k - w);
  348. j := i shr w;
  349. while (j < z) do
  350. begin
  351. huft_Ptr(q)^[j] := r;
  352. Inc(j, f);
  353. end;
  354. { backwards increment the k-bit code i }
  355. j := 1 shl (k-1) ;
  356. while (i and j) <> 0 do
  357. begin
  358. i := i xor j; { bitwise exclusive or }
  359. j := j shr 1
  360. end ;
  361. i := i xor j;
  362. { backup over finished tables }
  363. mask := (1 shl w) - 1; { needed on HP, cc -O bug }
  364. while ((i and mask) <> x[h]) do
  365. begin
  366. Dec(h); { don't need to update q }
  367. Dec(w, l);
  368. mask := (1 shl w) - 1;
  369. end;
  370. end;
  371. Inc(k);
  372. end;
  373. { Return Z_BUF_ERROR if we were given an incomplete table }
  374. if (y <> 0) And (g <> 1) then
  375. huft_build := Z_BUF_ERROR
  376. else
  377. huft_build := Z_OK;
  378. end; { huft_build}
  379. function inflate_trees_bits(
  380. var c : array of uIntf; { 19 code lengths }
  381. var bb : uIntf; { bits tree desired/actual depth }
  382. var tb : pinflate_huft; { bits tree result }
  383. var hp : array of Inflate_huft; { space for trees }
  384. var z : z_stream { for messages }
  385. ) : int;
  386. var
  387. r : int;
  388. hn : uInt; { hufts used in space }
  389. v : PuIntArray; { work area for huft_build }
  390. begin
  391. hn := 0;
  392. v := PuIntArray( ZALLOC(z, 19, sizeof(uInt)) );
  393. if (v = Z_NULL) then
  394. begin
  395. inflate_trees_bits := Z_MEM_ERROR;
  396. exit;
  397. end;
  398. r := huft_build(c, 19, 19, cplens, cplext,
  399. {puIntf(Z_NULL), puIntf(Z_NULL),}
  400. @tb, bb, hp, hn, v^);
  401. if (r = Z_DATA_ERROR) then
  402. z.msg := 'oversubscribed dynamic bit lengths tree'
  403. else
  404. if (r = Z_BUF_ERROR) or (bb = 0) then
  405. begin
  406. z.msg := 'incomplete dynamic bit lengths tree';
  407. r := Z_DATA_ERROR;
  408. end;
  409. ZFREE(z, v);
  410. inflate_trees_bits := r;
  411. end;
  412. function inflate_trees_dynamic(
  413. nl : uInt; { number of literal/length codes }
  414. nd : uInt; { number of distance codes }
  415. var c : Array of uIntf; { that many (total) code lengths }
  416. var bl : uIntf; { literal desired/actual bit depth }
  417. var bd : uIntf; { distance desired/actual bit depth }
  418. var tl : pInflate_huft; { literal/length tree result }
  419. var td : pInflate_huft; { distance tree result }
  420. var hp : array of Inflate_huft; { space for trees }
  421. var z : z_stream { for messages }
  422. ) : int;
  423. var
  424. r : int;
  425. hn : uInt; { hufts used in space }
  426. v : PuIntArray; { work area for huft_build }
  427. begin
  428. hn := 0;
  429. { allocate work area }
  430. v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
  431. if (v = Z_NULL) then
  432. begin
  433. inflate_trees_dynamic := Z_MEM_ERROR;
  434. exit;
  435. end;
  436. { build literal/length tree }
  437. r := huft_build(c, nl, 257, cplens, cplext, @tl, bl, hp, hn, v^);
  438. if (r <> Z_OK) or (bl = 0) then
  439. begin
  440. if (r = Z_DATA_ERROR) then
  441. z.msg := 'oversubscribed literal/length tree'
  442. else
  443. if (r <> Z_MEM_ERROR) then
  444. begin
  445. z.msg := 'incomplete literal/length tree';
  446. r := Z_DATA_ERROR;
  447. end;
  448. ZFREE(z, v);
  449. inflate_trees_dynamic := r;
  450. exit;
  451. end;
  452. { build distance tree }
  453. r := huft_build(puIntArray(@c[nl])^, nd, 0,
  454. cpdist, cpdext, @td, bd, hp, hn, v^);
  455. if (r <> Z_OK) or ((bd = 0) and (nl > 257)) then
  456. begin
  457. if (r = Z_DATA_ERROR) then
  458. z.msg := 'oversubscribed literal/length tree'
  459. else
  460. if (r = Z_BUF_ERROR) then
  461. begin
  462. {$ifdef PKZIP_BUG_WORKAROUND}
  463. r := Z_OK;
  464. end;
  465. {$else}
  466. z.msg := 'incomplete literal/length tree';
  467. r := Z_DATA_ERROR;
  468. end
  469. else
  470. if (r <> Z_MEM_ERROR) then
  471. begin
  472. z.msg := 'empty distance tree with lengths';
  473. r := Z_DATA_ERROR;
  474. end;
  475. ZFREE(z, v);
  476. inflate_trees_dynamic := r;
  477. exit;
  478. {$endif}
  479. end;
  480. { done }
  481. ZFREE(z, v);
  482. inflate_trees_dynamic := Z_OK;
  483. end;
  484. {$UNDEF BUILDFIXED}
  485. { build fixed tables only once--keep them here }
  486. {$IFNDEF BUILDFIXED}
  487. { locals }
  488. var
  489. fixed_built : Boolean = false;
  490. const
  491. FIXEDH = 544; { number of hufts used by fixed tables }
  492. var
  493. fixed_mem : array[0..FIXEDH-1] of inflate_huft;
  494. fixed_bl : uInt;
  495. fixed_bd : uInt;
  496. fixed_tl : pInflate_huft;
  497. fixed_td : pInflate_huft;
  498. {$ELSE}
  499. { inffixed.h -- table for decoding fixed codes }
  500. {local}
  501. const
  502. fixed_bl = uInt(9);
  503. {local}
  504. const
  505. fixed_bd = uInt(5);
  506. {local}
  507. const
  508. fixed_tl : array [0..288-1] of inflate_huft = (
  509. Exop, { number of extra bits or operation }
  510. bits : Byte; { number of bits in this code or subcode }
  511. {pad : uInt;} { pad structure to a power of 2 (4 bytes for }
  512. { 16-bit, 8 bytes for 32-bit int's) }
  513. base : uInt; { literal, length base, or distance base }
  514. { or table offset }
  515. ((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115), ((82,7),31),
  516. ((0,8),112), ((0,8),48), ((0,9),192), ((80,7),10), ((0,8),96),
  517. ((0,8),32), ((0,9),160), ((0,8),0), ((0,8),128), ((0,8),64),
  518. ((0,9),224), ((80,7),6), ((0,8),88), ((0,8),24), ((0,9),144),
  519. ((83,7),59), ((0,8),120), ((0,8),56), ((0,9),208), ((81,7),17),
  520. ((0,8),104), ((0,8),40), ((0,9),176), ((0,8),8), ((0,8),136),
  521. ((0,8),72), ((0,9),240), ((80,7),4), ((0,8),84), ((0,8),20),
  522. ((85,8),227), ((83,7),43), ((0,8),116), ((0,8),52), ((0,9),200),
  523. ((81,7),13), ((0,8),100), ((0,8),36), ((0,9),168), ((0,8),4),
  524. ((0,8),132), ((0,8),68), ((0,9),232), ((80,7),8), ((0,8),92),
  525. ((0,8),28), ((0,9),152), ((84,7),83), ((0,8),124), ((0,8),60),
  526. ((0,9),216), ((82,7),23), ((0,8),108), ((0,8),44), ((0,9),184),
  527. ((0,8),12), ((0,8),140), ((0,8),76), ((0,9),248), ((80,7),3),
  528. ((0,8),82), ((0,8),18), ((85,8),163), ((83,7),35), ((0,8),114),
  529. ((0,8),50), ((0,9),196), ((81,7),11), ((0,8),98), ((0,8),34),
  530. ((0,9),164), ((0,8),2), ((0,8),130), ((0,8),66), ((0,9),228),
  531. ((80,7),7), ((0,8),90), ((0,8),26), ((0,9),148), ((84,7),67),
  532. ((0,8),122), ((0,8),58), ((0,9),212), ((82,7),19), ((0,8),106),
  533. ((0,8),42), ((0,9),180), ((0,8),10), ((0,8),138), ((0,8),74),
  534. ((0,9),244), ((80,7),5), ((0,8),86), ((0,8),22), ((192,8),0),
  535. ((83,7),51), ((0,8),118), ((0,8),54), ((0,9),204), ((81,7),15),
  536. ((0,8),102), ((0,8),38), ((0,9),172), ((0,8),6), ((0,8),134),
  537. ((0,8),70), ((0,9),236), ((80,7),9), ((0,8),94), ((0,8),30),
  538. ((0,9),156), ((84,7),99), ((0,8),126), ((0,8),62), ((0,9),220),
  539. ((82,7),27), ((0,8),110), ((0,8),46), ((0,9),188), ((0,8),14),
  540. ((0,8),142), ((0,8),78), ((0,9),252), ((96,7),256), ((0,8),81),
  541. ((0,8),17), ((85,8),131), ((82,7),31), ((0,8),113), ((0,8),49),
  542. ((0,9),194), ((80,7),10), ((0,8),97), ((0,8),33), ((0,9),162),
  543. ((0,8),1), ((0,8),129), ((0,8),65), ((0,9),226), ((80,7),6),
  544. ((0,8),89), ((0,8),25), ((0,9),146), ((83,7),59), ((0,8),121),
  545. ((0,8),57), ((0,9),210), ((81,7),17), ((0,8),105), ((0,8),41),
  546. ((0,9),178), ((0,8),9), ((0,8),137), ((0,8),73), ((0,9),242),
  547. ((80,7),4), ((0,8),85), ((0,8),21), ((80,8),258), ((83,7),43),
  548. ((0,8),117), ((0,8),53), ((0,9),202), ((81,7),13), ((0,8),101),
  549. ((0,8),37), ((0,9),170), ((0,8),5), ((0,8),133), ((0,8),69),
  550. ((0,9),234), ((80,7),8), ((0,8),93), ((0,8),29), ((0,9),154),
  551. ((84,7),83), ((0,8),125), ((0,8),61), ((0,9),218), ((82,7),23),
  552. ((0,8),109), ((0,8),45), ((0,9),186), ((0,8),13), ((0,8),141),
  553. ((0,8),77), ((0,9),250), ((80,7),3), ((0,8),83), ((0,8),19),
  554. ((85,8),195), ((83,7),35), ((0,8),115), ((0,8),51), ((0,9),198),
  555. ((81,7),11), ((0,8),99), ((0,8),35), ((0,9),166), ((0,8),3),
  556. ((0,8),131), ((0,8),67), ((0,9),230), ((80,7),7), ((0,8),91),
  557. ((0,8),27), ((0,9),150), ((84,7),67), ((0,8),123), ((0,8),59),
  558. ((0,9),214), ((82,7),19), ((0,8),107), ((0,8),43), ((0,9),182),
  559. ((0,8),11), ((0,8),139), ((0,8),75), ((0,9),246), ((80,7),5),
  560. ((0,8),87), ((0,8),23), ((192,8),0), ((83,7),51), ((0,8),119),
  561. ((0,8),55), ((0,9),206), ((81,7),15), ((0,8),103), ((0,8),39),
  562. ((0,9),174), ((0,8),7), ((0,8),135), ((0,8),71), ((0,9),238),
  563. ((80,7),9), ((0,8),95), ((0,8),31), ((0,9),158), ((84,7),99),
  564. ((0,8),127), ((0,8),63), ((0,9),222), ((82,7),27), ((0,8),111),
  565. ((0,8),47), ((0,9),190), ((0,8),15), ((0,8),143), ((0,8),79),
  566. ((0,9),254), ((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115),
  567. ((82,7),31), ((0,8),112), ((0,8),48), ((0,9),193), ((80,7),10),
  568. ((0,8),96), ((0,8),32), ((0,9),161), ((0,8),0), ((0,8),128),
  569. ((0,8),64), ((0,9),225), ((80,7),6), ((0,8),88), ((0,8),24),
  570. ((0,9),145), ((83,7),59), ((0,8),120), ((0,8),56), ((0,9),209),
  571. ((81,7),17), ((0,8),104), ((0,8),40), ((0,9),177), ((0,8),8),
  572. ((0,8),136), ((0,8),72), ((0,9),241), ((80,7),4), ((0,8),84),
  573. ((0,8),20), ((85,8),227), ((83,7),43), ((0,8),116), ((0,8),52),
  574. ((0,9),201), ((81,7),13), ((0,8),100), ((0,8),36), ((0,9),169),
  575. ((0,8),4), ((0,8),132), ((0,8),68), ((0,9),233), ((80,7),8),
  576. ((0,8),92), ((0,8),28), ((0,9),153), ((84,7),83), ((0,8),124),
  577. ((0,8),60), ((0,9),217), ((82,7),23), ((0,8),108), ((0,8),44),
  578. ((0,9),185), ((0,8),12), ((0,8),140), ((0,8),76), ((0,9),249),
  579. ((80,7),3), ((0,8),82), ((0,8),18), ((85,8),163), ((83,7),35),
  580. ((0,8),114), ((0,8),50), ((0,9),197), ((81,7),11), ((0,8),98),
  581. ((0,8),34), ((0,9),165), ((0,8),2), ((0,8),130), ((0,8),66),
  582. ((0,9),229), ((80,7),7), ((0,8),90), ((0,8),26), ((0,9),149),
  583. ((84,7),67), ((0,8),122), ((0,8),58), ((0,9),213), ((82,7),19),
  584. ((0,8),106), ((0,8),42), ((0,9),181), ((0,8),10), ((0,8),138),
  585. ((0,8),74), ((0,9),245), ((80,7),5), ((0,8),86), ((0,8),22),
  586. ((192,8),0), ((83,7),51), ((0,8),118), ((0,8),54), ((0,9),205),
  587. ((81,7),15), ((0,8),102), ((0,8),38), ((0,9),173), ((0,8),6),
  588. ((0,8),134), ((0,8),70), ((0,9),237), ((80,7),9), ((0,8),94),
  589. ((0,8),30), ((0,9),157), ((84,7),99), ((0,8),126), ((0,8),62),
  590. ((0,9),221), ((82,7),27), ((0,8),110), ((0,8),46), ((0,9),189),
  591. ((0,8),14), ((0,8),142), ((0,8),78), ((0,9),253), ((96,7),256),
  592. ((0,8),81), ((0,8),17), ((85,8),131), ((82,7),31), ((0,8),113),
  593. ((0,8),49), ((0,9),195), ((80,7),10), ((0,8),97), ((0,8),33),
  594. ((0,9),163), ((0,8),1), ((0,8),129), ((0,8),65), ((0,9),227),
  595. ((80,7),6), ((0,8),89), ((0,8),25), ((0,9),147), ((83,7),59),
  596. ((0,8),121), ((0,8),57), ((0,9),211), ((81,7),17), ((0,8),105),
  597. ((0,8),41), ((0,9),179), ((0,8),9), ((0,8),137), ((0,8),73),
  598. ((0,9),243), ((80,7),4), ((0,8),85), ((0,8),21), ((80,8),258),
  599. ((83,7),43), ((0,8),117), ((0,8),53), ((0,9),203), ((81,7),13),
  600. ((0,8),101), ((0,8),37), ((0,9),171), ((0,8),5), ((0,8),133),
  601. ((0,8),69), ((0,9),235), ((80,7),8), ((0,8),93), ((0,8),29),
  602. ((0,9),155), ((84,7),83), ((0,8),125), ((0,8),61), ((0,9),219),
  603. ((82,7),23), ((0,8),109), ((0,8),45), ((0,9),187), ((0,8),13),
  604. ((0,8),141), ((0,8),77), ((0,9),251), ((80,7),3), ((0,8),83),
  605. ((0,8),19), ((85,8),195), ((83,7),35), ((0,8),115), ((0,8),51),
  606. ((0,9),199), ((81,7),11), ((0,8),99), ((0,8),35), ((0,9),167),
  607. ((0,8),3), ((0,8),131), ((0,8),67), ((0,9),231), ((80,7),7),
  608. ((0,8),91), ((0,8),27), ((0,9),151), ((84,7),67), ((0,8),123),
  609. ((0,8),59), ((0,9),215), ((82,7),19), ((0,8),107), ((0,8),43),
  610. ((0,9),183), ((0,8),11), ((0,8),139), ((0,8),75), ((0,9),247),
  611. ((80,7),5), ((0,8),87), ((0,8),23), ((192,8),0), ((83,7),51),
  612. ((0,8),119), ((0,8),55), ((0,9),207), ((81,7),15), ((0,8),103),
  613. ((0,8),39), ((0,9),175), ((0,8),7), ((0,8),135), ((0,8),71),
  614. ((0,9),239), ((80,7),9), ((0,8),95), ((0,8),31), ((0,9),159),
  615. ((84,7),99), ((0,8),127), ((0,8),63), ((0,9),223), ((82,7),27),
  616. ((0,8),111), ((0,8),47), ((0,9),191), ((0,8),15), ((0,8),143),
  617. ((0,8),79), ((0,9),255)
  618. );
  619. {local}
  620. const
  621. fixed_td : array[0..32-1] of inflate_huft = (
  622. (Exop:80;bits:5;base:1), (Exop:87;bits:5;base:257), (Exop:83;bits:5;base:17),
  623. (Exop:91;bits:5;base:4097), (Exop:81;bits:5;base), (Exop:89;bits:5;base:1025),
  624. (Exop:85;bits:5;base:65), (Exop:93;bits:5;base:16385), (Exop:80;bits:5;base:3),
  625. (Exop:88;bits:5;base:513), (Exop:84;bits:5;base:33), (Exop:92;bits:5;base:8193),
  626. (Exop:82;bits:5;base:9), (Exop:90;bits:5;base:2049), (Exop:86;bits:5;base:129),
  627. (Exop:192;bits:5;base:24577), (Exop:80;bits:5;base:2), (Exop:87;bits:5;base:385),
  628. (Exop:83;bits:5;base:25), (Exop:91;bits:5;base:6145), (Exop:81;bits:5;base:7),
  629. (Exop:89;bits:5;base:1537), (Exop:85;bits:5;base:97), (Exop:93;bits:5;base:24577),
  630. (Exop:80;bits:5;base:4), (Exop:88;bits:5;base:769), (Exop:84;bits:5;base:49),
  631. (Exop:92;bits:5;base:12289), (Exop:82;bits:5;base:13), (Exop:90;bits:5;base:3073),
  632. (Exop:86;bits:5;base:193), (Exop:192;bits:5;base:24577)
  633. );
  634. {$ENDIF}
  635. function inflate_trees_fixed(
  636. var bl : uInt; { literal desired/actual bit depth }
  637. var bd : uInt; { distance desired/actual bit depth }
  638. var tl : pInflate_huft; { literal/length tree result }
  639. var td : pInflate_huft; { distance tree result }
  640. var z : z_stream { for memory allocation }
  641. ) : int;
  642. type
  643. pFixed_table = ^fixed_table;
  644. fixed_table = array[0..288-1] of uIntf;
  645. var
  646. k : int; { temporary variable }
  647. c : pFixed_table; { length list for huft_build }
  648. v : PuIntArray; { work area for huft_build }
  649. var
  650. f : uInt; { number of hufts used in fixed_mem }
  651. begin
  652. { build fixed tables if not already (multiple overlapped executions ok) }
  653. if not fixed_built then
  654. begin
  655. f := 0;
  656. { allocate memory }
  657. c := pFixed_table( ZALLOC(z, 288, sizeof(uInt)) );
  658. if (c = Z_NULL) then
  659. begin
  660. inflate_trees_fixed := Z_MEM_ERROR;
  661. exit;
  662. end;
  663. v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
  664. if (v = Z_NULL) then
  665. begin
  666. ZFREE(z, c);
  667. inflate_trees_fixed := Z_MEM_ERROR;
  668. exit;
  669. end;
  670. { literal table }
  671. for k := 0 to Pred(144) do
  672. c^[k] := 8;
  673. for k := 144 to Pred(256) do
  674. c^[k] := 9;
  675. for k := 256 to Pred(280) do
  676. c^[k] := 7;
  677. for k := 280 to Pred(288) do
  678. c^[k] := 8;
  679. fixed_bl := 9;
  680. huft_build(c^, 288, 257, cplens, cplext, @fixed_tl, fixed_bl,
  681. fixed_mem, f, v^);
  682. { distance table }
  683. for k := 0 to Pred(30) do
  684. c^[k] := 5;
  685. fixed_bd := 5;
  686. huft_build(c^, 30, 0, cpdist, cpdext, @fixed_td, fixed_bd,
  687. fixed_mem, f, v^);
  688. { done }
  689. ZFREE(z, v);
  690. ZFREE(z, c);
  691. fixed_built := True;
  692. end;
  693. bl := fixed_bl;
  694. bd := fixed_bd;
  695. tl := fixed_tl;
  696. td := fixed_td;
  697. inflate_trees_fixed := Z_OK;
  698. end; { inflate_trees_fixed }
  699. end.