misc/libfreetype/src/gzip/adler32.c
author Xeli
Thu, 09 Feb 2012 14:12:50 +0100
changeset 6654 120e95c10532
parent 5172 88f2e05288ba
permissions -rw-r--r--
use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/* adler32.c -- compute the Adler-32 checksum of a data stream
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
 * Copyright (C) 1995-2002 Mark Adler
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
 * For conditions of distribution and use, see copyright notice in zlib.h
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/* @(#) $Id$ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
#include "zlib.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
#define BASE 65521L /* largest prime smaller than 65536 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
#define NMAX 5552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
/* ========================================================================= */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
ZEXPORT(uLong) adler32( /* adler, buf, len) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
    uLong adler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
    const Bytef *buf,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
    uInt len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
    unsigned long s1 = adler & 0xffff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
    unsigned long s2 = (adler >> 16) & 0xffff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
    int k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
    if (buf == Z_NULL) return 1L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
    while (len > 0) {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
        k = len < NMAX ? len : NMAX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
        len -= k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
        while (k >= 16) {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
            DO16(buf);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
            buf += 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
            k -= 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
        if (k != 0) do {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
            s1 += *buf++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
            s2 += s1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
        } while (--k);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
        s1 %= BASE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
        s2 %= BASE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    return (s2 << 16) | s1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
}