char* vfsExtractRelativePath( const char *in ){ int i; char l_in[PATH_MAX]; char check[PATH_MAX]; static char out[PATH_MAX]; out[0] = 0; #ifdef DBG_RLTPATH Sys_Printf( "vfsExtractRelativePath: %s\n", in ); #endif strcpy( l_in,in ); vfsCleanFileName( l_in ); #ifdef DBG_RLTPATH Sys_Printf( "cleaned path: %s\n", l_in ); #endif for ( i = 0; i < g_numDirs; i++ ) { strcpy( check,g_strDirs[i] ); vfsCleanFileName( check ); #ifdef DBG_RLTPATH Sys_Printf( "Matching against %s\n", check ); #endif // try to find a match if ( strstr( l_in, check ) ) { strcpy( out,l_in + strlen( check ) + 1 ); break; } } if ( out[0] != 0 ) { #ifdef DBG_RLTPATH Sys_Printf( "vfsExtractRelativePath: success\n" ); #endif return out; } #ifdef DBG_RLTPATH Sys_Printf( "vfsExtractRelativePath: failed\n" ); #endif return NULL; }
// FIXME TTimo: this and the above should be merged at some point char* vfsExtractRelativePath(const char *in) { static char out[PATH_MAX]; unsigned int i, count; char *chunk, *backup = NULL; // those point to out stuff char *ret = vfsExtractRelativePath_short(in, false); if (!ret) { #ifdef DBG_RLTPATH Sys_Printf("trying with a short version\n"); #endif ret = vfsExtractRelativePath_short(in, true); if (ret) { // ok, but we have a relative short version now // hack the long relative version out of here count = 0; for(i=0;i<strlen(ret);i++) { if (ret[i]=='/') count++; } // this is the clean, not short version strcpy(out, in); vfsCleanFileName(out); for(i=0;i<=count;i++) { chunk = strrchr(out, '/'); if (backup) backup[0] = '/'; chunk[0] = '\0'; backup = chunk; } return chunk+1; } } return ret; }
/*! \param shorten will try to match against the short version recent switch back to short path names in project settings has broken some stuff with shorten == true, we will convert in to short version before looking for root FIXME WAAA .. the stuff below is much more simple on linux .. add appropriate #ifdef */ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ int i; char l_in[PATH_MAX]; char check[PATH_MAX]; static char out[PATH_MAX]; out[0] = 0; #ifdef DBG_RLTPATH Sys_Printf( "vfsExtractRelativePath: %s\n", in ); #endif #ifdef _WIN32 if ( shorten ) { // make it short if ( GetShortPathName( in, l_in, PATH_MAX ) == 0 ) { #ifdef DBG_RLTPATH Sys_Printf( "GetShortPathName failed\n" ); #endif return NULL; } } else { strcpy( l_in,in ); } vfsCleanFileName( l_in ); #else strcpy( l_in, in ); vfsCleanFileName( l_in ); #endif // ifdef WIN32 #ifdef DBG_RLTPATH Sys_Printf( "cleaned path: %s\n", l_in ); #endif for ( i = 0; i < g_numDirs; i++ ) { strcpy( check,g_strDirs[i] ); vfsCleanFileName( check ); #ifdef DBG_RLTPATH Sys_Printf( "Matching against %s\n", check ); #endif // try to find a match if ( strstr( l_in, check ) ) { strcpy( out,l_in + strlen( check ) + 1 ); break; } } if ( out[0] != 0 ) { #ifdef DBG_RLTPATH Sys_Printf( "vfsExtractRelativePath: success\n" ); #endif return out; } #ifdef DBG_RLTPATH Sys_Printf( "vfsExtractRelativePath: failed\n" ); #endif return NULL; }