X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fpicomodel%2Fpicointernal.c;h=e1bf9d1bb98e02aed6e0d040220e62b8c60c9010;hb=887b5a3489d2a898c8b10f07902aecb6bfd097aa;hp=d8d316a0e857b3e4a70cf99c59f37c1d4e023bcb;hpb=830125fad042fad35dc029b6eb57c8156ad7e176;p=xonotic%2Fnetradiant.git diff --git a/libs/picomodel/picointernal.c b/libs/picomodel/picointernal.c index d8d316a0..e1bf9d1b 100644 --- a/libs/picomodel/picointernal.c +++ b/libs/picomodel/picointernal.c @@ -52,7 +52,7 @@ /* function pointers */ void *( *_pico_ptr_malloc )( size_t ) = malloc; void ( *_pico_ptr_free )( void* ) = free; -void ( *_pico_ptr_load_file )( char*, unsigned char**, int* ) = NULL; +void ( *_pico_ptr_load_file )( const char*, unsigned char**, int* ) = NULL; void ( *_pico_ptr_free_file )( void* ) = NULL; void ( *_pico_ptr_print )( int, const char* ) = NULL; @@ -161,35 +161,23 @@ void *_pico_realloc( void **ptr, size_t oldSize, size_t newSize ){ * as custom clone size (the string is cropped to fit into mem * if needed). -sea */ -char *_pico_clone_alloc( char *str, int size ){ - char *cloned; - size_t cloneSize; +char *_pico_clone_alloc( const char *str ){ + char* cloned; /* sanity check */ if ( str == NULL ) { return NULL; } - /* set real size of cloned string */ - cloneSize = ( size < 0 ) ? strlen( str ) : size; - /* allocate memory */ - cloned = _pico_alloc( cloneSize + 1 ); /* bugfix! */ + cloned = _pico_alloc( strlen( str ) + 1 ); if ( cloned == NULL ) { return NULL; } - /* zero out memory allocated by cloned string */ - memset( cloned,0,cloneSize ); - /* copy input string to cloned string */ - if ( cloneSize < strlen( str ) ) { - memcpy( cloned,str,cloneSize ); - cloned[ cloneSize ] = '\0'; - } - else { - strcpy( cloned,str ); - } + strcpy( cloned, str ); + /* return ptr to cloned string */ return cloned; } @@ -213,7 +201,7 @@ void _pico_free( void *ptr ){ /* _pico_load_file: * wrapper around the loadfile function pointer */ -void _pico_load_file( char *name, unsigned char **buffer, int *bufSize ){ +void _pico_load_file( const char *name, unsigned char **buffer, int *bufSize ){ /* sanity checks */ if ( name == NULL ) { *bufSize = -1; @@ -275,8 +263,21 @@ void _pico_printf( int level, const char *format, ... ){ _pico_ptr_print( level,str ); } +/* _pico_first_token: + * trims everything after the first whitespace-delimited token + */ + +void _pico_first_token( char *str ){ + if ( !str || !*str ) { + return; + } + while ( *str && !isspace( *str ) ) + str++; + *str = '\0'; +} + /* _pico_strltrim: - * left trims the given string -sea + * left trims the given string -sea */ char *_pico_strltrim( char *str ){ char *str1 = str, *str2 = str; @@ -290,7 +291,7 @@ char *_pico_strltrim( char *str ){ } /* _pico_strrtrim: - * right trims the given string -sea + * right trims the given string -sea */ char *_pico_strrtrim( char *str ){ if ( str && *str ) { @@ -541,8 +542,8 @@ float _pico_big_float( float src ){ /* _pico_stristr: * case-insensitive strstr. -sea */ -char *_pico_stristr( char *str, const char *substr ){ - const int sublen = strlen( substr ); +const char *_pico_stristr( const char *str, const char *substr ){ + const size_t sublen = strlen( substr ); while ( *str ) { if ( !_pico_strnicmp( str,substr,sublen ) ) { @@ -604,15 +605,15 @@ int _pico_nofname( const char *path, char *dest, int destSize ){ * returns ptr to filename portion in given path or an empty * string otherwise. given 'path' is not altered. -sea */ -char *_pico_nopath( const char *path ){ - char *src; - src = (char *)path + ( strlen( path ) - 1 ); +const char *_pico_nopath( const char *path ){ + const char *src; + src = path + ( strlen( path ) - 1 ); if ( path == NULL ) { - return (char *)""; + return ""; } - if ( !strchr( (char *)path,'/' ) && !strchr( (char *)path,'\\' ) ) { - return ( (char *)path ); + if ( !strchr( path,'/' ) && !strchr( path,'\\' ) ) { + return ( path ); } while ( ( src-- ) != path ) @@ -621,7 +622,7 @@ char *_pico_nopath( const char *path ){ return ( ++src ); } } - return (char *)""; + return ""; } /* _pico_setfext: @@ -737,7 +738,7 @@ void _pico_parse_skip_white( picoParser_t *p, int *hasLFs ){ /* _pico_new_parser: * allocates a new ascii parser object. */ -picoParser_t *_pico_new_parser( picoByte_t *buffer, int bufSize ){ +picoParser_t *_pico_new_parser( const picoByte_t *buffer, int bufSize ){ picoParser_t *p; /* sanity check */ @@ -761,8 +762,8 @@ picoParser_t *_pico_new_parser( picoByte_t *buffer, int bufSize ){ return NULL; } /* setup */ - p->buffer = buffer; - p->cursor = buffer; + p->buffer = (const char *) buffer; + p->cursor = (const char *) buffer; p->bufSize = bufSize; p->max = p->buffer + bufSize; p->curLine = 1; /* sea: new */ @@ -797,7 +798,7 @@ void _pico_free_parser( picoParser_t *p ){ */ int _pico_parse_ex( picoParser_t *p, int allowLFs, int handleQuoted ){ int hasLFs = 0; - char *old; + const char *old; /* sanity checks */ if ( p == NULL || p->buffer == NULL || @@ -1219,7 +1220,7 @@ int _pico_parse_vec4_def( picoParser_t *p, picoVec4_t out, picoVec4_t def ){ /* _pico_new_memstream: * allocates a new memorystream object. */ -picoMemStream_t *_pico_new_memstream( picoByte_t *buffer, int bufSize ){ +picoMemStream_t *_pico_new_memstream( const picoByte_t *buffer, int bufSize ){ picoMemStream_t *s; /* sanity check */