largely loadable model assets
[convexer.git] / cxr / cxr_io.h
index ed28bb8716018632481cc10a6e402f1bcc60485a..2e944aa3bcb470251ddbd4e6fb0eac2793c29329 100644 (file)
@@ -19,7 +19,7 @@ static i64 cxr_file_size( FILE *fileptr );
 static char *cxr_findext( char *path, char const delim );
 static char *cxr_findsep( char *path );
 
-static void cxr_stripext( char *path );
+static char *cxr_stripext( char *path );
 static int cxr_path_is_abs( char const *path );
 static char *cxr_filename( char *path );
 
@@ -41,11 +41,25 @@ static i64 cxr_file_size( FILE *fileptr )
        return fsize;
 }
 
+static int cxr_file_exists( const char *path )
+{
+   FILE *fp;
+   if( (fp=fopen( path, "rb" )) )
+   {
+      fclose(fp);
+      return 1;
+   }
+
+   return 0;
+}
+
 static void *fs_disk_open_read( const char *path, int reserve_end, i64 *size )
 {
        FILE *f = fopen( path, "rb" );
        if( f )
        {
+      printf( "fs_open_read (%s)\n", path );
+
                i64 fsize = cxr_file_size( f );
                void *buf = malloc( fsize + reserve_end );
                
@@ -147,11 +161,11 @@ static char *cxr_findsep( char *path )
        return ptr;
 }
 
-static void cxr_stripext( char *path )
+static char *cxr_stripext( char *path )
 {
-       char *point, *start;
+       char *point, *start, *ret = NULL;
        
-       // Skip folders
+   /* Skip any folders */
        if( !(start = cxr_findsep( path )) )
        {
                start = path;
@@ -161,9 +175,12 @@ static void cxr_stripext( char *path )
        {
                if( point > path )
                {
-                       *(point-1) = 0x00;
+         ret = point-1;
+                       *(ret) = 0x00;
                }
        }
+
+   return ret;
 }
 
 static void cxr_downlvl( char *path )
@@ -204,8 +221,39 @@ static int cxr_path_is_abs( char const *path )
 #endif
 }
 
+static void cxr_lowercase( char *str )
+{
+   char *c = str;
+   while( *c )
+   {
+      int val = (int)*c;
+      if( val >= (int)'A' && val <= (int)'Z' )
+      {
+         val = (int)'a' + (val - (int)'A');
+         *c = (char)val;
+      }
+      
+      c ++;
+   }
+}
+
+static void cxr_unixpath( char *path )
+{
+       char *c = path;
+       while( *c )
+   {
+      if( *c == '\\' )
+         *c = '/';
+
+      c ++;
+   }
+}
+
 static char *cxr_str_clone( char const *str, int extra )
 {
+   if( !str )
+      return NULL;
+
    char *newstr = malloc(strlen(str)+1+extra);
    strcpy( newstr, str );