library/src/filesystem/BP-FilesystemRegistry.cc
// This attempts to lookup a filesystem path from an entry by crawling backwards
// to the root directory.  The result is stored in the hash table, so it
// must be free'd later with ht_free.  The result from this should be valid
// for a filesystem lookup (aka BP_FOpen etc).  This routine automatically
// strips out double slashes.
This attempts to lookup a filesystem path from an entry by crawling backwards
to the root directory.  The result is stored in the hash table, so it
must be free'd later with ht_free.  The result from this should be valid
for a filesystem lookup (aka BP_FOpen etc).  This routine automatically
strips out double slashes.
This attempts to lookup a filesystem path from an entry by crawling backwards to the root directory . The result is stored in the hash table so it must be free ' d later with ht_free . The result from this should be valid for a filesystem lookup ( aka BP_FOpen etc ) . This routine automatically strips out double slashes .
char * BP_FSRegLookupFilesystemPathFromEntry
(
		P_BP_FSREG                  fs_reg,
		P_BP_HASH_TABLE_KEYED_ENTRY lookup_entry
)
{
	if(!fs_reg)
		return NULL;
	if(!fs_reg->hreg)
		return NULL;
	if(!lookup_entry)
		return NULL;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(fs_reg->hreg);
	char *final_path = NULL;
	char * created_path = BP_HashRegCreateReasonableStringPathFromKeyedEntry
	(
		fs_reg->hreg,
		lookup_entry
	);
	if(!created_path)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(fs_reg->hreg, NULL);
	char * adjusted_path       = bpstrdup(created_path);
	char * adjusted_path_saved = NULL;
	ht_free(fs_reg->hreg, created_path);
	do
	{
		adjusted_path_saved = adjusted_path;
		adjusted_path = BP_FindReplace(adjusted_path, "//", "/", 1, 100000);
		if(!adjusted_path)
		{
			adjusted_path = adjusted_path_saved;
			break;
		}
		bpfree(adjusted_path_saved);
		adjusted_path_saved = NULL;
	} while(1);
	final_path = NULL;
	if(bpstrlen(adjusted_path) > 3)
	{
		if(memcmp(adjusted_path, "/./", 3) == 0)
		{
			final_path = bpstrdup((char *) &adjusted_path[1]);
		}
	}
	if(!final_path)
		final_path = bpstrdup(adjusted_path);
	if(adjusted_path)
		bpfree(adjusted_path);
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(fs_reg->hreg);
	return final_path;
}
char * BP_FSRegLookupFilesystemPathFromEntry ( P_BP_FSREG fs_reg , P_BP_HASH_TABLE_KEYED_ENTRY lookup_entry ) { if ( ! fs_reg ) return NULL ; if ( ! fs_reg -> hreg ) return NULL ; if ( ! lookup_entry ) return NULL ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( fs_reg -> hreg ) ; char * final_path = NULL ; char * created_path = BP_HashRegCreateReasonableStringPathFromKeyedEntry ( fs_reg -> hreg , lookup_entry ) ; if ( ! created_path ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( fs_reg -> hreg , NULL ) ; char * adjusted_path = bpstrdup ( created_path ) ; char * adjusted_path_saved = NULL ; ht_free ( fs_reg -> hreg , created_path ) ; do { adjusted_path_saved = adjusted_path ; adjusted_path = BP_FindReplace ( adjusted_path , " " , " " , 1 , 100000 ) ; if ( ! adjusted_path ) { adjusted_path = adjusted_path_saved ; break ; } bpfree ( adjusted_path_saved ) ; adjusted_path_saved = NULL ; } while ( 1 ) ; final_path = NULL ; if ( bpstrlen ( adjusted_path ) > 3 ) { if ( memcmp ( adjusted_path , " " , 3 ) == 0 ) { final_path = bpstrdup ( ( char * ) & adjusted_path [ 1 ] ) ; } } if ( ! final_path ) final_path = bpstrdup ( adjusted_path ) ; if ( adjusted_path ) bpfree ( adjusted_path ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( fs_reg -> hreg ) ; return final_path ; }
This attempts to lookup a filesystem path from an entry by crawling backwards
to the root directory.
This attempts to lookup a filesystem path from an entry by crawling backwards to the root directory .
// enter critical section // this will hold the final path to resources // attempt to create a path // ensure we can create a path // run find and replace all double slashes // destroy old created path (since it's allocated via hash table) // preserve adjusted path /// attempt find and replace // exit with the last saved adjustment if there // was no adjustment to be made during this iteration. // destroy the saved path // ensure final path is zeroed // move up path one character if we have a relative path start // set final path as adjusted path // destroy the adjusted path if necessary // leave critical section // return the created path