#include <stdio.h>
#include <sys/types.h>
int
main(int argc, char *argv[]) {
ulong crc, poly;
if (argc != 2) {
fprintf(stderr, "USAGE: crc_table <octal polynomial=120001 for ext2>\n");
return 0;
}
sscanf(argv[1], "%lo", &poly);
if (poly & 0xffff0000) {
fprintf(stderr, "ERROR: polynomial is too large, sucka.\n");
return 0;
}
printf("//! CRC 0%o table, as generated by crc_table.cpp\n", poly);
printf("static uint16 crc_table[256] = { \n");
for (int n = 0; n < 256; n++) {
if (n%8 == 0)
printf(" ");
crc = n;
for (int i = 0; i < 8; i++) {
if (crc & 0x0001)
crc = (crc >> 1) ^ poly;
else
crc >>= 1;
}
printf("0x%04x%s ", crc, (n != 255 ? "," : ""));
if (n%8 == 7)
printf("\n");
}
printf("};\n");
return 0;
}