2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
crtlib.h - internal stdlib
|
|
|
|
Copyright (C) 2011 Uncle Mike
|
|
|
|
|
|
|
|
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 3 of the License, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STDLIB_H
|
|
|
|
#define STDLIB_H
|
|
|
|
|
2021-12-09 23:12:25 +01:00
|
|
|
#include <string.h>
|
2022-06-29 01:39:18 +02:00
|
|
|
#include <stdarg.h>
|
2019-06-21 16:25:43 +02:00
|
|
|
#include "build.h"
|
2022-06-29 01:39:18 +02:00
|
|
|
#include "xash3d_types.h"
|
2019-06-06 03:33:57 +02:00
|
|
|
|
2022-07-11 02:59:35 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// timestamp modes
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TIME_FULL = 0,
|
|
|
|
TIME_DATE_ONLY,
|
|
|
|
TIME_TIME_ONLY,
|
|
|
|
TIME_NO_SECONDS,
|
|
|
|
TIME_YEAR_ONLY,
|
|
|
|
TIME_FILENAME,
|
|
|
|
};
|
|
|
|
|
2021-10-03 02:46:26 +02:00
|
|
|
// a1ba: not using BIT macro, so flags can be copypasted into
|
|
|
|
// exported APIs headers and will get nice warning in case of changing values
|
|
|
|
#define PFILE_IGNOREBRACKET (1<<0)
|
|
|
|
#define PFILE_HANDLECOLON (1<<1)
|
2022-01-27 01:25:32 +01:00
|
|
|
#define PFILE_TOKEN_MAX_LENGTH 1024
|
2022-07-10 23:34:48 +02:00
|
|
|
#define PFILE_FS_TOKEN_MAX_LENGTH 512
|
2021-10-01 18:58:03 +02:00
|
|
|
|
2022-07-26 03:10:36 +02:00
|
|
|
//
|
|
|
|
// build.c
|
|
|
|
//
|
|
|
|
int Q_buildnum( void );
|
|
|
|
int Q_buildnum_compat( void );
|
|
|
|
const char *Q_buildos( void );
|
|
|
|
const char *Q_buildarch( void );
|
|
|
|
const char *Q_buildcommit( void );
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
//
|
|
|
|
// crtlib.c
|
|
|
|
//
|
|
|
|
#define Q_strupr( in, out ) Q_strnupr( in, out, 99999 )
|
|
|
|
void Q_strnupr( const char *in, char *out, size_t size_out );
|
|
|
|
#define Q_strlwr( in, out ) Q_strnlwr( in, out, 99999 )
|
|
|
|
void Q_strnlwr( const char *in, char *out, size_t size_out );
|
2021-12-03 07:44:51 +01:00
|
|
|
#define Q_strlen( str ) (( str ) ? strlen(( str )) : 0 )
|
2021-03-10 11:18:23 +01:00
|
|
|
size_t Q_colorstr( const char *string );
|
2018-04-13 18:23:45 +02:00
|
|
|
char Q_toupper( const char in );
|
|
|
|
char Q_tolower( const char in );
|
|
|
|
#define Q_strcat( dst, src ) Q_strncat( dst, src, 99999 )
|
|
|
|
size_t Q_strncat( char *dst, const char *src, size_t siz );
|
|
|
|
#define Q_strcpy( dst, src ) Q_strncpy( dst, src, 99999 )
|
|
|
|
size_t Q_strncpy( char *dst, const char *src, size_t siz );
|
|
|
|
uint Q_hashkey( const char *string, uint hashSize, qboolean caseinsensitive );
|
|
|
|
qboolean Q_isdigit( const char *str );
|
2022-01-04 00:22:10 +01:00
|
|
|
qboolean Q_isspace( const char *str );
|
2018-04-13 18:23:45 +02:00
|
|
|
int Q_atoi( const char *str );
|
|
|
|
float Q_atof( const char *str );
|
|
|
|
void Q_atov( float *vec, const char *str, size_t siz );
|
2022-06-14 02:23:46 +02:00
|
|
|
#define Q_strchr strchr
|
|
|
|
#define Q_strrchr strrchr
|
2018-04-13 18:23:45 +02:00
|
|
|
qboolean Q_stricmpext( const char *s1, const char *s2 );
|
|
|
|
const char *Q_timestamp( int format );
|
|
|
|
#define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args )
|
|
|
|
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args );
|
2018-04-23 20:36:33 +02:00
|
|
|
int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 );
|
|
|
|
int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 );
|
2020-11-22 07:49:39 +01:00
|
|
|
char *Q_strpbrk(const char *s, const char *accept);
|
2022-06-10 17:43:04 +02:00
|
|
|
void COM_StripColors( const char *in, char *out );
|
2018-04-13 18:23:45 +02:00
|
|
|
#define Q_memprint( val ) Q_pretifymem( val, 2 )
|
|
|
|
char *Q_pretifymem( float value, int digitsafterdecimal );
|
2018-04-23 20:36:33 +02:00
|
|
|
char *va( const char *format, ... ) _format( 1 );
|
2019-03-06 14:23:33 +01:00
|
|
|
void COM_FileBase( const char *in, char *out );
|
|
|
|
const char *COM_FileExtension( const char *in );
|
|
|
|
void COM_DefaultExtension( char *path, const char *extension );
|
|
|
|
void COM_ReplaceExtension( char *path, const char *extension );
|
|
|
|
void COM_ExtractFilePath( const char *path, char *dest );
|
|
|
|
const char *COM_FileWithoutPath( const char *in );
|
|
|
|
void COM_StripExtension( char *path );
|
2020-03-04 05:08:14 +01:00
|
|
|
void COM_RemoveLineFeed( char *str );
|
|
|
|
void COM_PathSlashFix( char *path );
|
2020-09-03 17:58:57 +02:00
|
|
|
char COM_Hex2Char( uint8_t hex );
|
|
|
|
void COM_Hex2String( uint8_t hex, char *str );
|
2022-07-10 23:34:48 +02:00
|
|
|
// return 0 on empty or null string, 1 otherwise
|
2019-03-16 05:15:06 +01:00
|
|
|
#define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 )
|
2020-11-22 07:49:39 +01:00
|
|
|
#define COM_CheckStringEmpty( string ) ( ( !*string ) ? 0 : 1 )
|
2022-07-10 23:34:48 +02:00
|
|
|
char *COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *len, qboolean *quoted );
|
|
|
|
#define COM_ParseFile( data, token, size ) COM_ParseFileSafe( data, token, size, 0, NULL, NULL )
|
2019-07-09 15:36:15 +02:00
|
|
|
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 );
|
2019-03-16 05:15:06 +01:00
|
|
|
|
2022-06-29 01:39:18 +02:00
|
|
|
// libc implementations
|
|
|
|
static inline int Q_strcmp( const char *s1, const char *s2 )
|
|
|
|
{
|
|
|
|
return unlikely(!s1) ?
|
|
|
|
( !s2 ? 0 : -1 ) :
|
|
|
|
( unlikely(!s2) ? 1 : strcmp( s1, s2 ));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int Q_strncmp( const char *s1, const char *s2, size_t n )
|
|
|
|
{
|
|
|
|
return unlikely(!s1) ?
|
|
|
|
( !s2 ? 0 : -1 ) :
|
|
|
|
( unlikely(!s2) ? 1 : strncmp( s1, s2, n ));
|
|
|
|
}
|
|
|
|
|
2022-06-29 02:56:42 +02:00
|
|
|
static inline char *Q_strstr( const char *s1, const char *s2 )
|
2022-06-29 01:39:18 +02:00
|
|
|
{
|
2022-06-29 02:56:42 +02:00
|
|
|
return unlikely( !s1 || !s2 ) ? NULL : (char*)strstr( s1, s2 );
|
2022-06-29 01:39:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// libc extensions, be careful
|
|
|
|
|
|
|
|
#if XASH_WIN32
|
|
|
|
#define strcasecmp stricmp
|
|
|
|
#define strncasecmp strnicmp
|
|
|
|
#endif // XASH_WIN32
|
|
|
|
|
|
|
|
static inline int Q_stricmp( const char *s1, const char *s2 )
|
|
|
|
{
|
|
|
|
return unlikely(!s1) ?
|
|
|
|
( !s2 ? 0 : -1 ) :
|
|
|
|
( unlikely(!s2) ? 1 : strcasecmp( s1, s2 ));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int Q_strnicmp( const char *s1, const char *s2, size_t n )
|
|
|
|
{
|
|
|
|
return unlikely(!s1) ?
|
|
|
|
( !s2 ? 0 : -1 ) :
|
|
|
|
( unlikely(!s2) ? 1 : strncasecmp( s1, s2, n ));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined( HAVE_STRCASESTR )
|
|
|
|
#if XASH_WIN32
|
|
|
|
#define strcasestr stristr
|
|
|
|
#endif
|
2022-06-29 02:56:42 +02:00
|
|
|
static inline char *Q_stristr( const char *s1, const char *s2 )
|
2022-06-29 01:39:18 +02:00
|
|
|
{
|
2022-06-29 02:56:42 +02:00
|
|
|
return unlikely( !s1 || !s2 ) ? NULL : (char *)strcasestr( s1, s2 );
|
2022-06-29 01:39:18 +02:00
|
|
|
}
|
|
|
|
#else // defined( HAVE_STRCASESTR )
|
2022-06-29 02:56:42 +02:00
|
|
|
char *Q_stristr( const char *s1, const char *s2 );
|
2022-06-29 01:39:18 +02:00
|
|
|
#endif // defined( HAVE_STRCASESTR )
|
|
|
|
|
2022-07-11 02:59:35 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2022-06-29 01:39:18 +02:00
|
|
|
|
2018-04-23 20:36:33 +02:00
|
|
|
#endif//STDLIB_H
|