/* 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;
* 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;
}
/* _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;
_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;
}
/* _pico_strrtrim:
- * right trims the given string -sea
+ * right trims the given string -sea
*/
char *_pico_strrtrim( char *str ){
if ( str && *str ) {
/* _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 ) ) {
* 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 )
return ( ++src );
}
}
- return (char *)"";
+ return "";
}
/* _pico_setfext:
/* _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 */
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 */
*/
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 ||
/* _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 */