MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / makeRelativePathName

Method makeRelativePathName

Engine/source/platform/platformFileIO.cpp:437–543  ·  view source on GitHub ↗

----------------------------------------------------------------------------- TODO: wow really shouldn't be adding everything to the string table, use the string class!

Source from the content-addressed store, hash-verified

435//-----------------------------------------------------------------------------
436// TODO: wow really shouldn't be adding everything to the string table, use the string class!
437StringTableEntry Platform::makeRelativePathName(const char *path, const char *to)
438{
439 // Make sure 'to' is a proper absolute path terminated with a forward slash.
440
441 char buffer[ 2048 ];
442 if( !to )
443 {
444 dSprintf( buffer, sizeof( buffer ), "%s/", Platform::getMainDotCsDir() );
445 to = buffer;
446 }
447 else if( !Platform::isFullPath( to ) )
448 {
449 dSprintf( buffer, sizeof( buffer ), "%s/%s/", Platform::getMainDotCsDir(), to );
450 makeCleanPathInPlace( buffer );
451 to = buffer;
452 }
453 else if( to[ dStrlen( to ) - 1 ] != '/' )
454 {
455 U32 length = getMin( (U32)dStrlen( to ), sizeof( buffer ) - 2 );
456 dMemcpy( buffer, to, length );
457 buffer[ length ] = '/';
458 buffer[ length + 1 ] = '\0';
459 to = buffer;
460 }
461
462 // If 'path' isn't absolute, make it now. Let's us use a single
463 // absolute/absolute merge path from here on.
464
465 char buffer2[ 1024 ];
466 if( !Platform::isFullPath( path ) )
467 {
468 dSprintf( buffer2, sizeof( buffer2 ), "%s/%s", Platform::getMainDotCsDir(), path );
469 makeCleanPathInPlace( buffer2 );
470 path = buffer2;
471 }
472
473 // First, find the common prefix and see where 'path' branches off from 'to'.
474
475 const char *pathPtr, *toPtr, *branch = path;
476 for(pathPtr = path, toPtr = to;*pathPtr && *toPtr && dTolower(*pathPtr) == dTolower(*toPtr);++pathPtr, ++toPtr)
477 {
478 if(*pathPtr == '/')
479 branch = pathPtr;
480 }
481
482 // If there's no common part, the two paths are on different drives and
483 // there's nothing we can do.
484
485 if( pathPtr == path )
486 return StringTable->insert( path );
487
488 // If 'path' and 'to' are identical (minus trailing slash or so), we can just return './'.
489
490 else if((*pathPtr == 0 || (*pathPtr == '/' && *(pathPtr + 1) == 0)) &&
491 (*toPtr == 0 || (*toPtr == '/' && *(toPtr + 1) == 0)))
492 {
493 char* bufPtr = buffer;
494 *bufPtr ++ = '.';

Callers

nothing calls this directly

Calls 7

dSprintfFunction · 0.85
makeCleanPathInPlaceFunction · 0.85
dTolowerFunction · 0.85
dStrcpyFunction · 0.85
dStrlenFunction · 0.50
dMemcpyFunction · 0.50
insertMethod · 0.45

Tested by

no test coverage detected