Code formating

This commit is contained in:
2013-10-15 20:41:26 +02:00
parent 0a0b6660b4
commit 99849ef69a
10 changed files with 976 additions and 1103 deletions

86
crc.c
View File

@@ -1,69 +1,67 @@
#include <stdio.h>
unsigned long CRCTable[256];
int CRCTable_initialized=0;
int CRCTable_initialized = 0;
#define CRC32_POLYNOMIAL 0xEDB88320L
void CRCTable_Init(){
int i;
int j;
unsigned long crc;
void CRCTable_Init() {
int i;
int j;
unsigned long crc;
if(CRCTable_initialized){
if (CRCTable_initialized) {
return;
}
CRCTable_initialized=1;
CRCTable_initialized = 1;
for (i=0;i<256;i++){
crc=i;
for (j=8;j>0;j--){
if (crc&1)
crc=(crc>>1)^CRC32_POLYNOMIAL;
else
crc>>=1;
}
CRCTable[i]=crc;
}
for (i = 0; i < 256; i++) {
crc = i;
for (j = 8; j > 0; j--) {
if (crc & 1)
crc = (crc >> 1) ^ CRC32_POLYNOMIAL;
else
crc >>= 1;
}
CRCTable[i] = crc;
}
}
unsigned long CRC_Buffer(unsigned char *buffer,int len,unsigned long crc){
unsigned char *p;
unsigned long temp1;
unsigned long temp2;
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc) {
unsigned char *p;
unsigned long temp1;
unsigned long temp2;
// Calcular CRC del buffer
p=(unsigned char*)buffer;
while(len--!=0) {
temp1=(crc>>8)&0x00FFFFFFL;
temp2=CRCTable[((int)crc^*p++)&0xff];
crc=temp1^temp2;
p = (unsigned char*) buffer;
while (len-- != 0) {
temp1 = (crc >> 8) & 0x00FFFFFFL;
temp2 = CRCTable[((int) crc ^ *p++) & 0xff];
crc = temp1 ^ temp2;
}
return(crc);
return (crc);
}
unsigned long CRC_File(FILE *file){
unsigned long crc;
int count;
unsigned char buffer[512];
unsigned char *p;
unsigned long temp1;
unsigned long temp2;
unsigned long CRC_File(FILE *file) {
unsigned long crc;
int count;
unsigned char buffer[512];
unsigned char *p;
unsigned long temp1;
unsigned long temp2;
CRCTable_Init();
crc=0xFFFFFFFFL;
for(;;){
crc = 0xFFFFFFFFL;
for (;;) {
// Llenar el buffer
count=fread(buffer,1,512,file);
if(count==0)
break;
count = fread(buffer, 1, 512, file);
if (count == 0)
break;
// Calcular CRC del buffer
crc=CRC_Buffer(buffer,count,crc);
}
return(crc^=0xFFFFFFFFL);
crc = CRC_Buffer(buffer, count, crc);
}
return (crc ^= 0xFFFFFFFFL);
}