|
|
@ -1,6 +1,7 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
crtlib.c - internal stdlib |
|
|
|
crtlib.c - internal stdlib |
|
|
|
Copyright (C) 2011 Uncle Mike |
|
|
|
Copyright (C) 2011 Uncle Mike |
|
|
|
|
|
|
|
Copyright (c) QuakeSpasm contributors |
|
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
|
|
|
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 |
|
|
|
it under the terms of the GNU General Public License as published by |
|
|
@ -578,40 +579,37 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) |
|
|
|
COM_FileBase |
|
|
|
COM_FileBase |
|
|
|
|
|
|
|
|
|
|
|
Extracts the base name of a file (no path, no extension, assumes '/' as path separator) |
|
|
|
Extracts the base name of a file (no path, no extension, assumes '/' as path separator) |
|
|
|
|
|
|
|
a1ba: adapted and simplified version from QuakeSpasm |
|
|
|
============ |
|
|
|
============ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void COM_FileBase( const char *in, char *out ) |
|
|
|
void COM_FileBase( const char *in, char *out, size_t size ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int len, start, end; |
|
|
|
const char *dot, *slash, *s; |
|
|
|
|
|
|
|
size_t len; |
|
|
|
len = Q_strlen( in ); |
|
|
|
|
|
|
|
if( !len ) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// scan backward for '.'
|
|
|
|
|
|
|
|
end = len - 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( end && in[end] != '.' && in[end] != '/' && in[end] != '\\' ) |
|
|
|
|
|
|
|
end--; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( in[end] != '.' ) |
|
|
|
if( unlikely( !COM_CheckString( in ) || size <= 1 )) |
|
|
|
end = len-1; // no '.', copy to end
|
|
|
|
{ |
|
|
|
else end--; // found ',', copy to left of '.'
|
|
|
|
out[0] = 0; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// scan backward for '/'
|
|
|
|
slash = in; |
|
|
|
start = len - 1; |
|
|
|
dot = NULL; |
|
|
|
|
|
|
|
for( s = in; *s; s++ ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( *s == '/' || *s == '\\' ) |
|
|
|
|
|
|
|
slash = s + 1; |
|
|
|
|
|
|
|
|
|
|
|
while( start >= 0 && in[start] != '/' && in[start] != '\\' ) |
|
|
|
if( *s == '.' ) |
|
|
|
start--; |
|
|
|
dot = s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( start < 0 || ( in[start] != '/' && in[start] != '\\' )) |
|
|
|
if( dot == NULL || dot < slash ) |
|
|
|
start = 0; |
|
|
|
dot = s; |
|
|
|
else start++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// length of new sting
|
|
|
|
len = Q_min( size - 1, dot - slash ); |
|
|
|
len = end - start + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy partial string
|
|
|
|
memcpy( out, slash, len ); |
|
|
|
Q_strncpy( out, &in[start], len + 1 ); |
|
|
|
|
|
|
|
out[len] = 0; |
|
|
|
out[len] = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|