Filter:   InfoImg
download crc_32.c
Language: C
License: GPL
Copyright: (C) 2000 Grub, Inc. *
LOC: 28
Project Info
grub.org - Distributed Internet Crawler(grub)
Server: SourceForge
Type: cvs
...ge\g\grub\grub\client\util\
   alt_ftw.c
   alt_ftw.h
   bin_test_util.dsp
   clog.cpp
   clog.h
   ConfigFileInfo.h
   crc.h
   crc_32.c
   crc_32.cpp
   crc_32.h
   crc_test.c
   crc_test.cpp
   crc32.c
   crc32.h
   dbl_list.c
   dbl_list.h
   delay.cpp
   delay.h
   diagnose.h
   fc32.c
   file_data.c
   file_data.h
   getopt.c
   getopt.h
   grubconf.c
   grubconf.h
   GrubExp.cpp
   GrubExp.h
   Gui.cpp
   Gui.h
   intl.h
   lib_util.dsp
   lockfile.cpp
   lockfile.h
   Makefile.am
   parsecfg.c
   parsecfg.h
   platform.h
   rmfiles.c
   rmfiles.h
   ServerSettings.cpp
   ServerSettings.h
   sniptype.h
   StatusInterface.cpp
   StatusInterface.h
   strip_url.c
   strip_url.h
   test_util.cpp

/* $Id: crc_32.c,v 1.2 2001/05/15 19:14:33 ozra Exp $ */

/**************************************************************************
 *                                                                        *
 *   Copyright (C) 2000 Grub, Inc.                                        *
 *                                                                        *
 *   This program is free software; you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published by *
 *   the Free Software Foundation; either version 1, or (at your option)  *
 *   any later version.                                                   *
 *                                                                        *
 *   This program is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 *   GNU General Public License for more details.                         *
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                        *
 *   Author:  Ledio Ago - lajesus   (email: lajesus@yahoo.com)            *
 *                                                                        *
 **************************************************************************
 *									  *
 *   File: crc_32.c							  *
 *   									  *
 *   Description: This file holds function for implementation of crc.	  *
 * 	The goal is calculate the crc of individual character.		  *
 *   	- gen_crc_table: It will build the crc table			  *
 * 	- crc_reset: It will reset the value of the variable where the 	  *
 *	  will be stored.						  *
 *	- get_crc: It will calculate the crc value of single character.	  *
 *									  *
 *************************************************************************/

#include "crc_32.h"

unsigned long crc_table[256]; /* Global variable	*/

/*
 * Function: 	gen_crc_table
 *
 * Description: Function gen_crc_table will build the crc table.
 *
 * Input:	None
 * Output: 	None.	
 */

void gen_crc_table(void)                /* build the crc table */
{
    unsigned long crc, poly;
    int i, j;

    poly = 0xEDB88320L;
    for (i = 0; i < 256; i++)
        {
        crc = i;
        for (j = 8; j > 0; j--)
            {
            if (crc & 1)
                crc = (crc >> 1) ^ poly;
            else
                crc >>= 1;
            }
        crc_table[i] = crc;
        }
}

/*
 * Function: 	crc_reset
 * 
 * Description: Function crc_reset will reset the value of the variable where the 
 * 		crc will be stored.
 * 
 * Input:	crc, unsigned long type pointer variable will be used to store the 
 *		individual crc value of each character in the block of characters
 * Output:	None.
 */

void crc_reset( unsigned long *crc ) {

    *crc = 0xFFFFFFFF;
}

/* 
 * Function: 	get_crc
 *
 * Description: Function get_crc will calculate the crc of each individual character
 * 		
 * Input:	crc, unsigned long type pointer will be used store the crc value of 
 *		a character.
 * 		ch, integer type will be use to store the integer value of each 
 *		character.
 * Output: 	It will return the crc value of each character.
 */

unsigned long get_crc( unsigned long *crc, int ch )    /* calculate the crc value */
{
    	*crc = (((*crc)>>8) & 0x00FFFFFF) ^ crc_table[ ((*crc)^ch) & 0xFF ];
	return ((*crc)^0xFFFFFFFF);
}