2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 01:45:19 +01:00

public: make crc value init functions inline, move hex2char/ex2string to crclib and make them private to it

This commit is contained in:
Alibek Omarov 2024-10-14 00:42:09 +03:00
parent 653f0841e4
commit d903187eea
4 changed files with 59 additions and 62 deletions

View File

@ -19,8 +19,6 @@ GNU General Public License for more details.
#include <stdlib.h>
#define NUM_BYTES 256
#define CRC32_INIT_VALUE 0xFFFFFFFFUL
#define CRC32_XOR_VALUE 0xFFFFFFFFUL
static const uint32_t crc32table[NUM_BYTES] =
{
@ -90,16 +88,6 @@ static const uint32_t crc32table[NUM_BYTES] =
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
void GAME_EXPORT CRC32_Init( uint32_t *pulCRC )
{
*pulCRC = CRC32_INIT_VALUE;
}
uint32_t GAME_EXPORT CRC32_Final( uint32_t pulCRC )
{
return pulCRC ^ CRC32_XOR_VALUE;
}
void GAME_EXPORT CRC32_ProcessByte( uint32_t *pulCRC, byte ch )
{
uint32_t ulCrc = *pulCRC;
@ -185,24 +173,6 @@ byte CRC32_BlockSequence( byte *base, int length, int sequence )
void MD5Transform( uint buf[4], const uint in[16] );
/*
==================
MD5Init
Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants.
==================
*/
void MD5Init( MD5Context_t *ctx )
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
}
/*
===================
MD5Update
@ -405,6 +375,33 @@ void MD5Transform( uint buf[4], const uint in[16] )
buf[3] += d;
}
/*
============
COM_Hex2Char
============
*/
static char COM_Hex2Char( uint8_t hex )
{
if( hex >= 0x0 && hex <= 0x9 )
hex += '0';
else if( hex >= 0xA && hex <= 0xF )
hex += '7';
return (char)hex;
}
/*
============
COM_Hex2String
============
*/
static void COM_Hex2String( uint8_t hex, char *str )
{
*str++ = COM_Hex2Char( hex >> 4 );
*str++ = COM_Hex2Char( hex & 0x0F );
*str = '\0';
}
/*
=================
MD5_Print

View File

@ -26,12 +26,41 @@ typedef struct
uint in[16];
} MD5Context_t;
void CRC32_Init( uint32_t *pulCRC );
#define CRC32_INIT_VALUE 0xFFFFFFFFUL
#define CRC32_XOR_VALUE 0xFFFFFFFFUL
static inline void CRC32_Init( uint32_t *pulCRC )
{
*pulCRC = CRC32_INIT_VALUE;
}
static inline uint32_t CRC32_Final( uint32_t pulCRC )
{
return pulCRC ^ CRC32_XOR_VALUE;
}
byte CRC32_BlockSequence( byte *base, int length, int sequence );
void CRC32_ProcessBuffer( uint32_t *pulCRC, const void *pBuffer, int nBuffer );
void CRC32_ProcessByte( uint32_t *pulCRC, byte ch );
uint32_t CRC32_Final( uint32_t pulCRC );
void MD5Init( MD5Context_t *ctx );
/*
==================
MD5Init
Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants.
==================
*/
static inline void MD5Init( MD5Context_t *ctx )
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
}
void MD5Update( MD5Context_t *ctx, const byte *buf, uint len );
void MD5Final( byte digest[16], MD5Context_t *ctx );
uint COM_HashKey( const char *string, uint hashSize );

View File

@ -702,33 +702,6 @@ void COM_PathSlashFix( char *path )
}
}
/*
============
COM_Hex2Char
============
*/
char COM_Hex2Char( uint8_t hex )
{
if( hex >= 0x0 && hex <= 0x9 )
hex += '0';
else if( hex >= 0xA && hex <= 0xF )
hex += '7';
return (char)hex;
}
/*
============
COM_Hex2String
============
*/
void COM_Hex2String( uint8_t hex, char *str )
{
*str++ = COM_Hex2Char( hex >> 4 );
*str++ = COM_Hex2Char( hex & 0x0F );
*str = '\0';
}
/*
==============
COM_IsSingleChar

View File

@ -94,8 +94,6 @@ void COM_StripExtension( char *path );
void COM_RemoveLineFeed( char *str, size_t bufsize );
void COM_FixSlashes( char *pname );
void COM_PathSlashFix( char *path );
char COM_Hex2Char( uint8_t hex );
void COM_Hex2String( uint8_t hex, char *str );
// return 0 on empty or null string, 1 otherwise
#define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 )
#define COM_CheckStringEmpty( string ) ( ( !*string ) ? 0 : 1 )