⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inftrees.pas

📁 本系统在一些大中型企业(跨多达24个区域)一直都在很好的服务过
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          Else
            r.exop := 32 + 64;   { EOB_code; }
          r.base := p^;          { simple code is just the value }
          Inc(p);
        end
        Else
        begin
          r.exop := Byte(e[p^-s] + 16 + 64);  { non-simple--look up in lists }
          r.base := d[p^-s];
          Inc (p);
        end ;

      { fill code-like entries with r }
      f := 1 shl (k - w);
      j := i shr w;
      while (j < z) do
      begin
        huft_Ptr(q)^[j] := r;
        Inc(j, f);
      end;

      { backwards increment the k-bit code i }
      j := 1 shl (k-1) ;
      while (i and j) <> 0 do
      begin
        i := i xor j;         { bitwise exclusive or }
        j := j shr 1
      end ;
      i := i xor j;

      { backup over finished tables }
      mask := (1 shl w) - 1;   { needed on HP, cc -O bug }
      while ((i and mask) <> x[h]) do
      begin
        Dec(h);                { don't need to update q }
        Dec(w, l);
        mask := (1 shl w) - 1;
      end;

    end;

    Inc(k);
  end;

  { Return Z_BUF_ERROR if we were given an incomplete table }
  if (y <> 0) And (g <> 1) then
    huft_build := Z_BUF_ERROR
  else
    huft_build := Z_OK;
end; { huft_build}


function inflate_trees_bits(
  var c : array of uIntf;  { 19 code lengths }
  var bb : uIntf;          { 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;
var
  r : int;
  hn : uInt;          { 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
  begin
    inflate_trees_bits := Z_MEM_ERROR;
    exit;
  end;

  r := huft_build(c, 19, 19, cplens, cplext,
                             {puIntf(Z_NULL), puIntf(Z_NULL),}
                  @tb, bb, hp, hn, v^);
  if (r = Z_DATA_ERROR) then
    z.msg := 'oversubscribed dynamic bit lengths tree'
  else
    if (r = Z_BUF_ERROR) or (bb = 0) then
    begin
      z.msg := 'incomplete dynamic bit lengths tree';
      r := Z_DATA_ERROR;
    end;
  ZFREE(z, v);
  inflate_trees_bits := r;
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 }
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;
var
  r : int;
  hn : uInt;          { 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
  begin
    inflate_trees_dynamic := Z_MEM_ERROR;
    exit;
  end;

  { build literal/length tree }
  r := huft_build(c, nl, 257, cplens, cplext, @tl, bl, hp, hn, v^);
  if (r <> Z_OK) or (bl = 0) then
  begin
    if (r = Z_DATA_ERROR) then
      z.msg := 'oversubscribed literal/length tree'
    else
      if (r <> Z_MEM_ERROR) then
      begin
        z.msg := 'incomplete literal/length tree';
        r := Z_DATA_ERROR;
      end;

    ZFREE(z, v);
    inflate_trees_dynamic := r;
    exit;
  end;

  { build distance tree }
  r := huft_build(puIntArray(@c[nl])^, nd, 0,
                  cpdist, cpdext, @td, bd, hp, hn, v^);
  if (r <> Z_OK) or ((bd = 0) and (nl > 257)) then
  begin
    if (r = Z_DATA_ERROR) then
      z.msg := 'oversubscribed literal/length tree'
    else
      if (r = Z_BUF_ERROR) then
      begin
{$ifdef PKZIP_BUG_WORKAROUND}
        r := Z_OK;
      end;
{$else}
        z.msg := 'incomplete literal/length tree';
        r := Z_DATA_ERROR;
      end
      else
        if (r <> Z_MEM_ERROR) then
        begin
          z.msg := 'empty distance tree with lengths';
          r := Z_DATA_ERROR;
        end;
    ZFREE(z, v);
    inflate_trees_dynamic := r;
    exit;
{$endif}
  end;

  { done }
  ZFREE(z, v);
  inflate_trees_dynamic := Z_OK;
end;

{$UNDEF BUILDFIXED}

{ build fixed tables only once--keep them here }
{$IFNDEF BUILDFIXED}
{ locals }
const
  fixed_built : Boolean = false;
  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_tl : pInflate_huft;
  fixed_td : pInflate_huft;

{$ELSE}

{ inffixed.h -- table for decoding fixed codes }

{local}
const
  fixed_bl = uInt(9);
{local}
const
  fixed_bd = uInt(5);
{local}
const
  fixed_tl : array [0..288-1] of inflate_huft = (
    {{96,7},256}, {{0,8},80}, {{0,8},16}, {{84,8},115}, {{82,7},31},
    {{0,8},112}, {{0,8},48}, {{0,9},192}, {{80,7},10}, {{0,8},96},
    {{0,8},32}, {{0,9},160}, {{0,8},0}, {{0,8},128}, {{0,8},64},
    {{0,9},224}, {{80,7},6}, {{0,8},88}, {{0,8},24}, {{0,9},144},
    {{83,7},59}, {{0,8},120}, {{0,8},56}, {{0,9},208}, {{81,7},17},
    {{0,8},104}, {{0,8},40}, {{0,9},176}, {{0,8},8}, {{0,8},136},
    {{0,8},72}, {{0,9},240}, {{80,7},4}, {{0,8},84}, {{0,8},20},
    {{85,8},227}, {{83,7},43}, {{0,8},116}, {{0,8},52}, {{0,9},200},
    {{81,7},13}, {{0,8},100}, {{0,8},36}, {{0,9},168}, {{0,8},4},
    {{0,8},132}, {{0,8},68}, {{0,9},232}, {{80,7},8}, {{0,8},92},
    {{0,8},28}, {{0,9},152}, {{84,7},83}, {{0,8},124}, {{0,8},60},
    {{0,9},216}, {{82,7},23}, {{0,8},108}, {{0,8},44}, {{0,9},184},
    {{0,8},12}, {{0,8},140}, {{0,8},76}, {{0,9},248}, {{80,7},3},
    {{0,8},82}, {{0,8},18}, {{85,8},163}, {{83,7},35}, {{0,8},114},
    {{0,8},50}, {{0,9},196}, {{81,7},11}, {{0,8},98}, {{0,8},34},
    {{0,9},164}, {{0,8},2}, {{0,8},130}, {{0,8},66}, {{0,9},228},
    {{80,7},7}, {{0,8},90}, {{0,8},26}, {{0,9},148}, {{84,7},67},
    {{0,8},122}, {{0,8},58}, {{0,9},212}, {{82,7},19}, {{0,8},106},
    {{0,8},42}, {{0,9},180}, {{0,8},10}, {{0,8},138}, {{0,8},74},
    {{0,9},244}, {{80,7},5}, {{0,8},86}, {{0,8},22}, {{192,8},0},
    {{83,7},51}, {{0,8},118}, {{0,8},54}, {{0,9},204}, {{81,7},15},
    {{0,8},102}, {{0,8},38}, {{0,9},172}, {{0,8},6}, {{0,8},134},
    {{0,8},70}, {{0,9},236}, {{80,7},9}, {{0,8},94}, {{0,8},30},
    {{0,9},156}, {{84,7},99}, {{0,8},126}, {{0,8},62}, {{0,9},220},
    {{82,7},27}, {{0,8},110}, {{0,8},46}, {{0,9},188}, {{0,8},14},
    {{0,8},142}, {{0,8},78}, {{0,9},252}, {{96,7},256}, {{0,8},81},
    {{0,8},17}, {{85,8},131}, {{82,7},31}, {{0,8},113}, {{0,8},49},
    {{0,9},194}, {{80,7},10}, {{0,8},97}, {{0,8},33}, {{0,9},162},
    {{0,8},1}, {{0,8},129}, {{0,8},65}, {{0,9},226}, {{80,7},6},
    {{0,8},89}, {{0,8},25}, {{0,9},146}, {{83,7},59}, {{0,8},121},
    {{0,8},57}, {{0,9},210}, {{81,7},17}, {{0,8},105}, {{0,8},41},
    {{0,9},178}, {{0,8},9}, {{0,8},137}, {{0,8},73}, {{0,9},242},
    {{80,7},4}, {{0,8},85}, {{0,8},21}, {{80,8},258}, {{83,7},43},
    {{0,8},117}, {{0,8},53}, {{0,9},202}, {{81,7},13}, {{0,8},101},
    {{0,8},37}, {{0,9},170}, {{0,8},5}, {{0,8},133}, {{0,8},69},
    {{0,9},234}, {{80,7},8}, {{0,8},93}, {{0,8},29}, {{0,9},154},
    {{84,7},83}, {{0,8},125}, {{0,8},61}, {{0,9},218}, {{82,7},23},
    {{0,8},109}, {{0,8},45}, {{0,9},186}, {{0,8},13}, {{0,8},141},
    {{0,8},77}, {{0,9},250}, {{80,7},3}, {{0,8},83}, {{0,8},19},
    {{85,8},195}, {{83,7},35}, {{0,8},115}, {{0,8},51}, {{0,9},198},
    {{81,7},11}, {{0,8},99}, {{0,8},35}, {{0,9},166}, {{0,8},3},
    {{0,8},131}, {{0,8},67}, {{0,9},230}, {{80,7},7}, {{0,8},91},
    {{0,8},27}, {{0,9},150}, {{84,7},67}, {{0,8},123}, {{0,8},59},
    {{0,9},214}, {{82,7},19}, {{0,8},107}, {{0,8},43}, {{0,9},182},
    {{0,8},11}, {{0,8},139}, {{0,8},75}, {{0,9},246}, {{80,7},5},
    {{0,8},87}, {{0,8},23}, {{192,8},0}, {{83,7},51}, {{0,8},119},
    {{0,8},55}, {{0,9},206}, {{81,7},15}, {{0,8},103}, {{0,8},39},
    {{0,9},174}, {{0,8},7}, {{0,8},135}, {{0,8},71}, {{0,9},238},
    {{80,7},9}, {{0,8},95}, {{0,8},31}, {{0,9},158}, {{84,7},99},
    {{0,8},127}, {{0,8},63}, {{0,9},222}, {{82,7},27}, {{0,8},111},
    {{0,8},47}, {{0,9},190}, {{0,8},15}, {{0,8},143}, {{0,8},79},
    {{0,9},254}, {{96,7},256}, {{0,8},80}, {{0,8},16}, {{84,8},115},
    {{82,7},31}, {{0,8},112}, {{0,8},48}, {{0,9},193}, {{80,7},10},
    {{0,8},96}, {{0,8},32}, {{0,9},161}, {{0,8},0}, {{0,8},128},
    {{0,8},64}, {{0,9},225}, {{80,7},6}, {{0,8},88}, {{0,8},24},
    {{0,9},145}, {{83,7},59}, {{0,8},120}, {{0,8},56}, {{0,9},209},
    {{81,7},17}, {{0,8},104}, {{0,8},40}, {{0,9},177}, {{0,8},8},
    {{0,8},136}, {{0,8},72}, {{0,9},241}, {{80,7},4}, {{0,8},84},
    {{0,8},20}, {{85,8},227}, {{83,7},43}, {{0,8},116}, {{0,8},52},
    {{0,9},201}, {{81,7},13}, {{0,8},100}, {{0,8},36}, {{0,9},169},
    {{0,8},4}, {{0,8},132}, {{0,8},68}, {{0,9},233}, {{80,7},8},
    {{0,8},92}, {{0,8},28}, {{0,9},153}, {{84,7},83}, {{0,8},124},
    {{0,8},60}, {{0,9},217}, {{82,7},23}, {{0,8},108}, {{0,8},44},
    {{0,9},185}, {{0,8},12}, {{0,8},140}, {{0,8},76}, {{0,9},249},
    {{80,7},3}, {{0,8},82}, {{0,8},18}, {{85,8},163}, {{83,7},35},
    {{0,8},114}, {{0,8},50}, {{0,9},197}, {{81,7},11}, {{0,8},98},
    {{0,8},34}, {{0,9},165}, {{0,8},2}, {{0,8},130}, {{0,8},66},
    {{0,9},229}, {{80,7},7}, {{0,8},90}, {{0,8},26}, {{0,9},149},
    {{84,7},67}, {{0,8},122}, {{0,8},58}, {{0,9},213}, {{82,7},19},
    {{0,8},106}, {{0,8},42}, {{0,9},181}, {{0,8},10}, {{0,8},138},
    {{0,8},74}, {{0,9},245}, {{80,7},5}, {{0,8},86}, {{0,8},22},
    {{192,8},0}, {{83,7},51}, {{0,8},118}, {{0,8},54}, {{0,9},205},
    {{81,7},15}, {{0,8},102}, {{0,8},38}, {{0,9},173}, {{0,8},6},
    {{0,8},134}, {{0,8},70}, {{0,9},237}, {{80,7},9}, {{0,8},94},
    {{0,8},30}, {{0,9},157}, {{84,7},99}, {{0,8},126}, {{0,8},62},
    {{0,9},221}, {{82,7},27}, {{0,8},110}, {{0,8},46}, {{0,9},189},
    {{0,8},14}, {{0,8},142}, {{0,8},78}, {{0,9},253}, {{96,7},256},
    {{0,8},81}, {{0,8},17}, {{85,8},131}, {{82,7},31}, {{0,8},113},
    {{0,8},49}, {{0,9},195}, {{80,7},10}, {{0,8},97}, {{0,8},33},
    {{0,9},163}, {{0,8},1}, {{0,8},129}, {{0,8},65}, {{0,9},227},
    {{80,7},6}, {{0,8},89}, {{0,8},25}, {{0,9},147}, {{83,7},59},
    {{0,8},121}, {{0,8},57}, {{0,9},211}, {{81,7},17}, {{0,8},105},
    {{0,8},41}, {{0,9},179}, {{0,8},9}, {{0,8},137}, {{0,8},73},
    {{0,9},243}, {{80,7},4}, {{0,8},85}, {{0,8},21}, {{80,8},258},
    {{83,7},43}, {{0,8},117}, {{0,8},53}, {{0,9},203}, {{81,7},13},
    {{0,8},101}, {{0,8},37}, {{0,9},171}, {{0,8},5}, {{0,8},133},
    {{0,8},69}, {{0,9},235}, {{80,7},8}, {{0,8},93}, {{0,8},29},
    {{0,9},155}, {{84,7},83}, {{0,8},125}, {{0,8},61}, {{0,9},219},
    {{82,7},23}, {{0,8},109}, {{0,8},45}, {{0,9},187}, {{0,8},13},
    {{0,8},141}, {{0,8},77}, {{0,9},251}, {{80,7},3}, {{0,8},83},
    {{0,8},19}, {{85,8},195}, {{83,7},35}, {{0,8},115}, {{0,8},51},
    {{0,9},199}, {{81,7},11}, {{0,8},99}, {{0,8},35}, {{0,9},167},
    {{0,8},3}, {{0,8},131}, {{0,8},67}, {{0,9},231}, {{80,7},7},
    {{0,8},91}, {{0,8},27}, {{0,9},151}, {{84,7},67}, {{0,8},123},
    {{0,8},59}, {{0,9},215}, {{82,7},19}, {{0,8},107}, {{0,8},43},
    {{0,9},183}, {{0,8},11}, {{0,8},139}, {{0,8},75}, {{0,9},247},
    {{80,7},5}, {{0,8},87}, {{0,8},23}, {{192,8},0}, {{83,7},51},
    {{0,8},119}, {{0,8},55}, {{0,9},207}, {{81,7},15}, {{0,8},103},
    {{0,8},39}, {{0,9},175}, {{0,8},7}, {{0,8},135}, {{0,8},71},
    {{0,9},239}, {{80,7},9}, {{0,8},95}, {{0,8},31}, {{0,9},159},
    {{84,7},99}, {{0,8},127}, {{0,8},63}, {{0,9},223}, {{82,7},27},
    {{0,8},111}, {{0,8},47}, {{0,9},191}, {{0,8},15}, {{0,8},143},
    {{0,8},79}, {{0,9},255}
  );

{local}
const
  fixed_td : array[0..32-1] of inflate_huft = (
(Exop:80;bits:5;base:1),      (Exop:87;bits:5;base:257),   (Exop:83;bits:5;base:17),
(Exop:91;bits:5;base:4097),   (Exop:81;bits:5;base),       (Exop:89;bits:5;base:1025),
(Exop:85;bits:5;base:65),     (Exop:93;bits:5;base:16385), (Exop:80;bits:5;base:3),
(Exop:88;bits:5;base:513),    (Exop:84;bits:5;base:33),    (Exop:92;bits:5;base:8193),
(Exop:82;bits:5;base:9),      (Exop:90;bits:5;base:2049),  (Exop:86;bits:5;base:129),
(Exop:192;bits:5;base:24577), (Exop:80;bits:5;base:2),     (Exop:87;bits:5;base:385),
(Exop:83;bits:5;base:25),     (Exop:91;bits:5;base:6145),  (Exop:81;bits:5;base:7),
(Exop:89;bits:5;base:1537),   (Exop:85;bits:5;base:97),    (Exop:93;bits:5;base:24577),
(Exop:80;bits:5;base:4),      (Exop:88;bits:5;base:769),   (Exop:84;bits:5;base:49),
(Exop:92;bits:5;base:12289),  (Exop:82;bits:5;base:13),    (Exop:90;bits:5;base:3073),
(Exop:86;bits:5;base:193),    (Exop:192;bits:5;base:24577)
  );
{$ENDIF}

function inflate_trees_fixed(
var bl : uIntf;              { literal desired/actual bit depth }
var bd : uIntf;              { 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;
type
  pFixed_table = ^fixed_table;
  fixed_table = array[0..288-1] of uIntf;
var
  k : int;                   { 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 }
begin
  { build fixed tables if not already (multiple overlapped executions ok) }
  if not fixed_built then
  begin
    f := 0;

    { allocate memory }
    c := pFixed_table( ZALLOC(z, 288, sizeof(uInt)) );
    if (c = Z_NULL) then
    begin
      inflate_trees_fixed := Z_MEM_ERROR;
      exit;
    end;
    v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
    if (v = Z_NULL) then
    begin
      ZFREE(z, c);
      inflate_trees_fixed := Z_MEM_ERROR;
      exit;
    end;

    { literal table }
    for k := 0 to Pred(144) do
      c^[k] := 8;
    for k := 144 to Pred(256) do
      c^[k] := 9;
    for k := 256 to Pred(280) do
      c^[k] := 7;
    for k := 280 to Pred(288) do
      c^[k] := 8;
    fixed_bl := 9;
    huft_build(c^, 288, 257, cplens, cplext, @fixed_tl, fixed_bl,
               fixed_mem, f, v^);

    { distance table }
    for k := 0 to Pred(30) do
      c^[k] := 5;
    fixed_bd := 5;
    huft_build(c^, 30, 0, cpdist, cpdext, @fixed_td, fixed_bd,
               fixed_mem, f, v^);

    { done }
    ZFREE(z, v);
    ZFREE(z, c);
    fixed_built := True;
  end;
  bl := fixed_bl;
  bd := fixed_bd;
  tl := fixed_tl;
  td := fixed_td;
  inflate_trees_fixed := Z_OK;
end; { inflate_trees_fixed }


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -