29 #include "../common/filesys.h"
30 #include "../ports/system.h"
39 char const*
const last = strrchr(pathname,
'/');
40 return last ? last + 1 : pathname;
52 right = s + strlen(s) - 1;
54 while (isspace(*right))
71 while (isspace(*left))
85 const size_t length = strlen(s);
108 register const char* p = pattern, *t = text;
111 while ((c = *p++) ==
'?' || c ==
'*')
112 if (c ==
'?' && *t++ ==
'\0')
124 if ((c ==
'[' || *t == c1) &&
Com_Filter(p - 1, t))
147 register const char* p = pattern, *t = text;
150 while ((c = *p++) !=
'\0')
169 register char c1 = *t++;
175 invert = ((*p ==
'!') || (*p ==
'^'));
181 register char cstart = c, cend = c;
191 if (c ==
'-' && *p !=
']') {
199 if (c1 >= cstart && c1 <= cend)
246 while ((slash = strchr(end,
'/')) != 0)
249 strcpy(end, expectedFileName);
261 char* out_ext =
nullptr;
264 while (in && *in && i < size) {
284 const char* src = path + strlen(path) - 1;
285 while (*src !=
'/' && src != path) {
304 src = path + strlen(path) - 1;
306 while (*src !=
'/' && src != path) {
313 Com_sprintf(path, len,
"%s%s", oldPath, extension);
321 const char* s = in + strlen(in) - 1;
323 while (s != in && *s !=
'/')
326 const size_t pathLength = s - in + 1;
327 if (pathLength <= size)
339 for (
int i = 0; name[
i];
i++) {
340 const unsigned int c = name[
i];
341 v = (v +
i) * 37 + tolower(c);
358 t = localtime(&aclock);
360 Com_sprintf(ts, tslen,
"%4i/%02i/%02i %02i:%02i:%02i", t->tm_year + 1900,
361 t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
374 return (*(
const float*)float1 - *(
const float*)float2);
387 const char* s1 = (
const char*)string1;
388 const char* s2 = (
const char*)string2;
391 else if (*s1 == *s2) {
405 #define VA_BUFSIZE 4096
415 static unsigned int index = 0;
418 buf =
string[index & 0x0F];
421 va_start(argptr, format);
442 *str = tolower(*str);
455 void Q_strncpyzDebug (
char*
dest,
const char* src,
size_t destsize,
const char* file,
int line)
457 void Q_strncpyz (
char* dest,
const char* src,
size_t destsize)
462 Sys_Error(
"Q_strncpyz: destsize < 1 (%s, %i)", file, line);
477 const size_t dest_length = strlen(dest);
478 if (dest_length >= destsize)
479 Sys_Error(
"Q_strcat: already overflowed");
482 va_start(argptr, format);
483 Q_vsnprintf(dest + dest_length, destsize - dest_length, format, argptr);
513 if (len > 0 && (
unsigned char) dest[len - 1] >= 0x80) {
524 assert(dest[len] ==
'\0');
540 len = _vsnprintf(str, size, format, ap);
541 str[size - 1] =
'\0';
544 Com_Printf(
"Q_vsnprintf: string (%.32s...) was truncated (%i) - target buffer too small (" UFO_SIZE_T ")\n", str, len, size);
547 len = vsnprintf(str, size, format, ap);
549 if ((
size_t)len >= size)
550 Com_Printf(
"Q_vsnprintf: string (%.32s...) was truncated (%i) - target buffer too small (" UFO_SIZE_T ")\n", str, len, size);
563 const char*
Q_stristr (
const char* str,
const char* substr)
565 const size_t sublen = strlen(substr);
589 for (; *start !=
'\0'; ++str, ++start) {
596 bool Q_strreplace (
const char* source,
const char* pattern,
const char* replace,
char* dest,
size_t destsize)
598 if (
char const*
const hit = strstr(source, pattern)) {
599 int const len = snprintf(dest, destsize,
"%.*s%s%s", (
int)(hit - source), source, replace, hit + strlen(pattern));
600 return 0 < len && (size_t)len < destsize;
621 if (strchr(input,
'"') !=
nullptr)
634 va_start(argptr, fmt);
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
void Sys_Error(const char *error,...)
const char * Com_SkipPath(const char *pathname)
Returns just the filename from a given path.
const char * Com_GetExtension(const char *path)
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
char * UTF8_strncpyz(char *dest, const char *src, size_t limit)
UTF8 capable string copy function.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
void Com_StripExtension(const char *in, char *out, const size_t size)
Removes the file extension from a filename.
int UTF8_char_len(unsigned char c)
length of UTF-8 character starting with this byte.
void Com_FilePath(const char *in, char *out, size_t size)
Returns the path up to, but not including the last /.
void Com_Printf(const char *const fmt,...)
char * Com_Trim(char *s)
Removed leading and trailing whitespaces.
#define UTF8_CONTINUATION_BYTE(c)
#define Q_strvalid(string)
void UFO_assert(bool condition, const char *fmt,...)
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
char * Com_ConvertToASCII7(char *s)
Remove high character values and only keep ascii. This can be used to print utf-8 characters to the c...
QGL_EXTERN GLuint GLsizei GLsizei * length
#define Q_strncasecmp(s1, s2, n)
int Com_Filter(const char *pattern, const char *text)
Match the pattern PATTERN against the string TEXT;.
const char * Q_stristr(const char *str, const char *substr)
Checks in case insensitive manner whether str contains substr.
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
QGL_EXTERN GLenum GLuint * dest
char * Q_strlwr(char *str)
Converts a string to lowercase.
void Com_MakeTimestamp(char *ts, const size_t tslen)
Creates a timestamp with date and time at the specified location.
int Q_FloatSort(const void *float1, const void *float2)
Compare two floats.
void Com_DefaultExtension(char *path, size_t len, const char *extension)
Sets a default extension if there is none.
QGL_EXTERN GLuint GLchar GLuint * len
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
bool Com_IsValidName(const char *input)
Checks whether the given input string is allowed to be used as a user-given name string for aircraft...
unsigned int Com_HashKey(const char *name, int hashsize)
returns hash key for a string
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
bool Q_strreplace(const char *source, const char *pattern, const char *replace, char *dest, size_t destsize)
Replaces the first occurence of the given pattern in the source string with the given replace string...
int Q_StringSort(const void *string1, const void *string2)
Compare two strings.
void Com_ReplaceFilename(const char *inputPath, const char *expectedFileName, char *outputPath, size_t size)
Replaces the filename from one path with another one.
QGL_EXTERN int GLboolean GLfloat * v
char * Com_Chop(char *s)
Removed trailing whitespaces.
static int Com_FilterAfterStar(const char *pattern, const char *text)
Like Com_Filter, but match PATTERN against any final segment of TEXT.
void format(__printf__, 1, 2)))