From c7f12f3a741f597c57feb40016af1ea9313cd76c Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sat, 27 Jan 2001 15:30:12 +0000 Subject: [PATCH] Compute an adler32 checksum. committer: mfx 980609412 +0000 --- src/stub/scripts/bin2h.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/stub/scripts/bin2h.pl b/src/stub/scripts/bin2h.pl index 2fe0a908..b4d3c3d2 100644 --- a/src/stub/scripts/bin2h.pl +++ b/src/stub/scripts/bin2h.pl @@ -89,6 +89,11 @@ print <<"EOF"; EOF } +$s = $ident; +$s =~ tr/a-z/A-Z/; +$s .= "_ADLER32"; +printf("#define %s 0x%08x\n\n", $s, &adler32($data)); + printf("unsigned char %s[%d] = {", $ident, $n); for ($i = 0; $i < $n; $i++) { if ($i % 16 == 0) { @@ -113,4 +118,26 @@ select(STDOUT); undef $delim; exit(0); + +# /*********************************************************************** +# // +# ************************************************************************/ + +sub adler32 { + local($d) = @_; + local($n) = length($d); + local($i); + local($s1) = 1; + local($s2) = 0; + + for ($i = 0; $i < $n; $i++) { + $s1 += ord(substr($d, $i, 1)); + $s2 += $s1; + $s1 %= 65521; + $s2 %= 65521; + } + + return ($s2 << 16) | $s1; +} + # vi:ts=4:et