mirror of
https://github.com/nzp-team/glquake.git
synced 2024-11-10 06:31:35 +00:00
Add crc16 builtin
This commit is contained in:
parent
fcbaf93c79
commit
d267d568e4
3 changed files with 40 additions and 1 deletions
21
source/crc.c
21
source/crc.c
|
@ -79,3 +79,24 @@ unsigned short CRC_Value(unsigned short crcvalue)
|
||||||
{
|
{
|
||||||
return crcvalue ^ CRC_XOR_VALUE;
|
return crcvalue ^ CRC_XOR_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// taken from darkplaces -- just a shortcut for initialization for
|
||||||
|
// use with string-hashing (just progs, likely). -- cypress (07 jan 2024)
|
||||||
|
//
|
||||||
|
|
||||||
|
unsigned short CRC_Block(const unsigned char *data, size_t size)
|
||||||
|
{
|
||||||
|
unsigned short crc = CRC_INIT_VALUE;
|
||||||
|
while (size--)
|
||||||
|
crc = (crc << 8) ^ crctable[(crc >> 8) ^ (*data++)];
|
||||||
|
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;
|
||||||
|
}
|
|
@ -22,3 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
void CRC_Init(unsigned short *crcvalue);
|
void CRC_Init(unsigned short *crcvalue);
|
||||||
void CRC_ProcessByte(unsigned short *crcvalue, byte data);
|
void CRC_ProcessByte(unsigned short *crcvalue, byte data);
|
||||||
unsigned short CRC_Value(unsigned short crcvalue);
|
unsigned short CRC_Value(unsigned short crcvalue);
|
||||||
|
|
||||||
|
unsigned short CRC_Block(const unsigned char *data, size_t size);
|
||||||
|
unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size);
|
|
@ -1356,6 +1356,21 @@ void PF_strtolower(void)
|
||||||
G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
|
G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=================
|
||||||
|
PF_crc16
|
||||||
|
|
||||||
|
float crc16 (float, string)
|
||||||
|
=================
|
||||||
|
*/
|
||||||
|
void PF_crc16(void)
|
||||||
|
{
|
||||||
|
int insens = G_FLOAT(OFS_PARM0);
|
||||||
|
char *s = G_STRING(OFS_PARM1);
|
||||||
|
|
||||||
|
G_FLOAT(OFS_RETURN) = (unsigned short) ((insens ? CRC_Block_CaseInsensitive : CRC_Block) ((unsigned char *) s, strlen(s)));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
=================
|
=================
|
||||||
PF_substring
|
PF_substring
|
||||||
|
@ -3964,7 +3979,7 @@ PF_Fixme,
|
||||||
PF_Fixme,
|
PF_Fixme,
|
||||||
PF_Fixme,
|
PF_Fixme,
|
||||||
PF_Fixme,
|
PF_Fixme,
|
||||||
PF_Fixme,
|
PF_crc16,
|
||||||
PF_Fixme,
|
PF_Fixme,
|
||||||
PF_Fixme,
|
PF_Fixme,
|
||||||
PF_Fixme,
|
PF_Fixme,
|
||||||
|
|
Loading…
Reference in a new issue