Browse Source

public: optimize MD5_Print function.

pull/2/head
Andrey Akhmichin 4 years ago committed by Alibek Omarov
parent
commit
23ea7ecbcc
  1. 6
      public/crclib.c
  2. 28
      public/crtlib.c
  3. 2
      public/crtlib.h

6
public/crclib.c

@ -438,16 +438,12 @@ transform hash to hexadecimal printable symbols
char *MD5_Print( byte hash[16] ) char *MD5_Print( byte hash[16] )
{ {
static char szReturn[64]; static char szReturn[64];
char szChunk[10];
int i; int i;
memset( szReturn, 0, 64 ); memset( szReturn, 0, 64 );
for( i = 0; i < 16; i++ ) for( i = 0; i < 16; i++ )
{ COM_Hex2String( hash[i], &szReturn[i * 2] );
Q_snprintf( szChunk, sizeof( szChunk ), "%02X", hash[i] );
Q_strncat( szReturn, szChunk, sizeof( szReturn ));
}
return szReturn; return szReturn;
} }

28
public/crtlib.c

@ -918,6 +918,33 @@ void COM_PathSlashFix( char *path )
Q_strcpy( &path[len], "/" ); Q_strcpy( &path[len], "/" );
} }
/*
============
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';
}
int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive ) int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive )
{ {
return matchpattern_with_separator( in, pattern, caseinsensitive, "/\\:", false ); return matchpattern_with_separator( in, pattern, caseinsensitive, "/\\:", false );
@ -983,3 +1010,4 @@ int matchpattern_with_separator( const char *in, const char *pattern, qboolean c
return 0; // reached end of pattern but not end of input return 0; // reached end of pattern but not end of input
return 1; // success return 1; // success
} }

2
public/crtlib.h

@ -84,6 +84,8 @@ const char *COM_FileWithoutPath( const char *in );
void COM_StripExtension( char *path ); void COM_StripExtension( char *path );
void COM_RemoveLineFeed( char *str ); void COM_RemoveLineFeed( char *str );
void COM_PathSlashFix( char *path ); void COM_PathSlashFix( char *path );
char COM_Hex2Char( uint8_t hex );
void COM_Hex2String( uint8_t hex, char *str );
#define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 ) #define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 )
int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive ); int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive );
int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one ); int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one );

Loading…
Cancel
Save