#include "TSystem.h"
#include "TFGroup.h"
ClassImp(TFFilePath)
#ifdef WIN32
#define DOT_DOT "\\..\\"
#define DOT "\\.\\"
#define DOT_DOT_SLASH "..\\"
#define DS '\\' // Directory Seperator
#define DS2 "\\" // Directory Seperator
#else
#define DOT_DOT "/../"
#define DOT "/./"
#define DOT_DOT_SLASH "../"
#define DS '/' // Directory Seperator
#define DS2 "/" // Directory Seperator
#endif
static void RemoveDots(char * str)
{
char * pos2 = str;
while (pos2 = strstr(pos2, DOT))
strcpy(pos2 + 1, pos2 + 3);
pos2 = str;
while (char * pos = strstr(pos2, DOT_DOT))
{
pos2 = pos -1;
while (*pos2 != DS && pos2 != str)
pos2--;
strcpy(pos2, pos + 3);
}
}
Bool_t TFFilePath::IsRelativePath() const
{
#ifdef WIN32
if (Data()[1] == ':' || Data()[0] == DS)
return kFALSE;
#else
if (Data()[0] == DS)
return kFALSE;
#endif
return kTRUE;
}
void TFFilePath::MakeAbsolutePath(const char * isRelativeTo)
{
const char * currDir = gSystem->WorkingDirectory();
size_t maxLength;
char * str;
maxLength = strlen(currDir) + strlen(isRelativeTo) + Length() + 3;
str = new char[maxLength];
#ifdef WIN32
if (Data()[1] == ':')
str[0] = 0;
else if (Data()[0] == DS)
{
str[0] = currDir[0];
str[1] = currDir[1];
str[2] = 0;
}
#else
if (Data()[0] == DS)
{
str[0] = 0;
}
#endif
else
{
#ifdef WIN32
if (isRelativeTo[1] == ':')
{
strcpy(str, isRelativeTo);
}
else if (isRelativeTo[0] == DS)
{
str[0] = currDir[0];
str[1] = currDir[1];
str[2] = 0;
strcat(str, isRelativeTo);
}
#else
if (isRelativeTo[0] == DS)
{
strcpy(str, isRelativeTo);
}
#endif
else
{
strcpy(str, currDir);
strcat(str, DS2);
strcat(str, isRelativeTo);
}
char * pos = strrchr(str, DS);
if (pos) *(pos+1) = 0;
}
strcat(str, Data());
RemoveDots(str);
*this = str;
delete [] str;
}
void TFFilePath::MakeRelativePath(const char * relativeTo)
{
const char * currDir = gSystem->WorkingDirectory();
size_t maxLength;
char * base;
maxLength = strlen(currDir) + strlen(relativeTo) + 3;
base = new char[maxLength];
#ifdef WIN32
if (relativeTo[1] == ':')
{
strcpy(base, relativeTo);
}
else if (relativeTo[0] == DS)
{
base[0] = currDir[0];
base[1] = currDir[1];
base[2] = 0;
strcat(base, relativeTo);
}
#else
if (relativeTo[0] == DS)
{
strcpy(base, relativeTo);
}
#endif
else
{
strcpy(base, currDir);
strcat(base, DS2);
strcat(base, relativeTo);
}
char * pos = strrchr(base, DS);
if (pos) *(pos+1) = 0;
RemoveDots(base);
char * str;
char * basePos1, *basePos2;
char * strPos1, *strPos2;
str = new char[Length() + 1];
strcpy(str, Data());
strPos1 = str;
basePos1 = base;
do
{
basePos2 = strchr(basePos1, DS);
if (basePos2 == NULL)
break;
strPos2 = strchr(strPos1, DS);
if (strPos2 == NULL)
break;
if (basePos2 - basePos1 != strPos2 - strPos1)
break;
if (strncmp(strPos1, basePos1, strPos2 - strPos1))
break;
strPos1 = strPos2 + 1;
basePos1 = basePos2 + 1;
} while(1);
char * result;
result = new char[2 * strlen(basePos1) + strlen(strPos1) +2];
result[0] = 0;
while (basePos1 = strchr(basePos1 + 1, DS))
{
strcat(result, DOT_DOT_SLASH);
}
strcat(result, strPos1);
* this = result;
delete [] result;
delete [] str;
delete [] base;
}
Last update: Fri Mar 14 13:55:15 2008
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.