sum-crc.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1996-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* crc
*/
#define crc_description \
"32 bit CRC (cyclic redundancy check)."
#define crc_options "\
[+polynomial?The 32 bit crc polynomial bitmask with implicit bit 32.]:[mask:=0xedb88320]\
[+done?XOR the final crc value with \anumber\a. 0xffffffff is used if \anumber\a is omitted.]:?[number:=0]\
[+init?The initial crc value. 0xffffffff is used if \anumber\a is omitted.]:?[number:=0]\
[+rotate?XOR each input character with the high order crc byte (instead of the low order).]\
[+size?Include the total number of bytes in the crc. \anumber\a, if specified, is first XOR'd into the size.]:?[number:=0]\
"
#define crc_match "crc"
#define crc_print long_print
#define crc_scale 0
typedef struct Crc_s
{
unsigned int addsize;
unsigned int rotate;
} Crc_t;
static Sum_t*
{
register const char* s;
register const char* t;
register const char* v;
register int i;
register int j;
Crcnum_t x;
{
}
polynomial = 0xedb88320;
s = name;
while (*(t = s))
{
for (t = s, v = 0; *s && *s != '-'; s++)
if (*s == '=' && !v)
v = s;
i = (v ? v : s) - t;
else if (strneq(t, "done", i))
else if (strneq(t, "init", i))
else if (strneq(t, "rotate", i))
else if (strneq(t, "size", i))
{
if (v)
}
if (*s == '-')
s++;
}
{
Crcnum_t t;
Crcnum_t p[8];
p[0] = polynomial;
for (i = 1; i < 8; i++)
{
t = 0;
x = i;
for (j = 0; j < 8; j++)
{
if (x & 1)
t ^= p[j];
x >>= 1;
}
}
}
else
{
{
x = i;
for (j = 0; j < 8; j++)
}
}
}
static int
{
return 0;
}
static int
{
register unsigned char* b = (unsigned char*)s;
register unsigned char* e = b + n;
while (b < e)
else
while (b < e)
return 0;
}
static int
{
register Crcnum_t c;
register uintmax_t n;
int i;
int j;
{
while (n)
{
n >>= 8;
}
else
for (i = 0, j = 32; i < 4; i++)
{
j -= 8;
}
}
return 0;
}