Det er jeg er kommet frem til indtil videre er:
const BASE : longword = 65521L;
const NMAX : longword = 5552;
procedure DO1 ( var s1 : longword; var s2 : longword; buf : pchar; i :
longword);
begin;
s1 := s1 + byte (buf [i]); // s1 += buf[i];
s2 := s2 + s1; // s2 += s1
end;
// #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
procedure DO2 ( var s1 : longword; var s2 : longword; buf : pchar; i :
longword);
begin;
DO1 ( s1,s2,buf, i ); DO1 ( s1,s2,buf, i+1 );
end;
// #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
procedure DO4 ( var s1 : longword; var s2 : longword; buf : pchar; i :
longword);
begin;
DO2 ( s1,s2,buf, i ); DO2 ( s1,s2,buf, i+2 );
end;
// #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
procedure DO8 ( var s1 : longword; var s2 : longword; buf : pchar; i :
longword);
begin;
DO4 ( s1,s2,buf, i ); DO4 ( s1,s2,buf, i+4 );
end;
// #define DO16(buf) DO8(buf,0); DO8(buf,8);
procedure DO16 ( var s1 : longword; var s2 : longword; buf : pchar);
begin;
DO8 ( s1,s2,buf, 0 ); DO8 ( s1,s2,buf, 8 );
end;
function Adler32 ( Adler : longword; buf : pchar; len : dword) : longword;
// LONG adler32 (LONG adler, const char *buf, DWORD len)
var
s1 : longword; // LONG er 32 bit unsigned, hvilket longword
s2 : longword; // LONG er 32 bit unsigned, hvilket longword
k : longword;
begin;
s1 := adler and $ffff; // unsigned long s1
= adler & 0xffff;
s2 := (adler shr 16) and $ffff; // unsigned long s2
= (adler >> 16) & 0xffff;
if (buf = nil) then begin; // if (buf == NULL)
return 1L;
result := 1; //
exit; //
end; //
while (len > 0) do begin; // while (len > 0)
{
if (len<NMAX) then k := len // k = len < NMAX ?
len : NMAX;
else k:= NMAX;
len := len - k; // len -= k;
while (k >= 16) do begin; // while (k >= 16) {
DO16 ( s1, s2, buf ); // DO16(buf);
buf := buf + 16; // buf += 16;
k := k - 16; // k -= 16;
end;
if not (k = 0) then begin; // if (k != 0) do {
repeat; //
s1 := s1 + byte (buf^); // s1 += *buf++;
buf := buf + 1; //
s2 := s2 + s1; // s2 += s1;
k:=k-1; // } while (--k);
until not (k>0); //
s1 := s1 mod BASE; // s1 %= BASE;
s2 := s2 mod BASE; // s2 %= BASE;
end;
end;
result := (s2 shl 16) or s1; // return (s2 << 16)
| s1;
end; // }
Koden compiler fint og crasher ikke... men c/c++ versionen giver en lidt
højere værdi end delphi versionen.
|