]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
add a CRC_Block_CaseInsensitive that tolowers its input for use by hash functions...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 18 Dec 2007 21:08:08 +0000 (21:08 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 18 Dec 2007 21:08:08 +0000 (21:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7821 d7cf8633-e32d-0410-b094-e92efae38249

common.c
common.h
model_shared.c

index aaa9fd6859ac9c0cc89a010df177e4cca0b14f71..b648b017fc1b0dd19f8ccabec1c1d6a8bac87e86 100644 (file)
--- a/common.c
+++ b/common.c
@@ -173,6 +173,14 @@ unsigned short CRC_Block(const unsigned char *data, size_t size)
        return crc ^ CRC_XOR_VALUE;
 }
 
+unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size)
+{
+       unsigned short crc = CRC_INIT_VALUE;
+       while (size--)
+               crc = (crc << 8) ^ crctable[(crc >> 8) ^ (tolower(*data++))];
+       return crc ^ CRC_XOR_VALUE;
+}
+
 // QuakeWorld
 static unsigned char chktbl[1024 + 4] =
 {
index 3111ee229b70f5132efbb0806c274a7a7e7b5e2d..52466fd6303307a6e0a6283caa20d3a320267809 100644 (file)
--- a/common.h
+++ b/common.h
@@ -60,6 +60,7 @@ void SZ_HexDumpToConsole(const sizebuf_t *buf);
 void Com_HexDumpToConsole(const unsigned char *data, int size);
 
 unsigned short CRC_Block(const unsigned char *data, size_t size);
+unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size); // for hash lookup functions that use strcasecmp for comparison
 
 unsigned char COM_BlockSequenceCRCByteQW(unsigned char *base, int length, int sequence);
 
index 5825d1fa461df248139f273e3727769436e4a8bb..4f046300aab2bffedb9222bf16621418ec2d94b0 100644 (file)
@@ -1145,7 +1145,7 @@ static void Q3Shaders_Clear()
 
 static void Q3Shader_AddToHash (q3shaderinfo_t* shader)
 {
-       unsigned short hash = CRC_Block ((const unsigned char *)shader->name, strlen (shader->name));
+       unsigned short hash = CRC_Block_CaseInsensitive ((const unsigned char *)shader->name, strlen (shader->name));
        q3shader_hash_entry_t* entry = q3shader_data->hash + (hash % Q3SHADER_HASH_SIZE);
        q3shader_hash_entry_t* lastEntry = NULL;
        while (entry != NULL)
@@ -1666,7 +1666,7 @@ void Mod_LoadQ3Shaders(void)
 
 q3shaderinfo_t *Mod_LookupQ3Shader(const char *name)
 {
-       unsigned short hash = CRC_Block ((const unsigned char *)name, strlen (name));
+       unsigned short hash = CRC_Block_CaseInsensitive ((const unsigned char *)name, strlen (name));
        q3shader_hash_entry_t* entry = q3shader_data->hash + (hash % Q3SHADER_HASH_SIZE);
        while (entry != NULL)
        {