Dear ROOTers
I need to update my program to handle WinXP-type pathnames, and have attached a small program showing my problem.
At many places in my program I use the following function:
TString Path2Name(const char *name, const char *sep, const char *exten)
{
// Extract name from full path
// sep is path separator and exten is name extension
TString outname = TString(name);
char *tmpname = new char[strlen(name) + 1];
char *delname = tmpname;
tmpname = strtok(strcpy(tmpname,name),sep);
while(tmpname) {
outname = tmpname;
tmpname = strtok(NULL,sep);
}//while
if (strcmp(exten,"") != 0) {
Int_t i = outname.Index(exten);
if (i > 0) {outname = outname.Remove(i);}
}//if
delete [] delname;
return outname;
}//Path2Name
This function works fine on both Mac and WinXP:
Path2Name("/Volumes/FAT32/Affy/libraryfiles/Test3.CDF","/",".")
Path2Name("E:\\Affy\\libraryfiles\\Test3.CDF","\\",".")
However, in my program I need to define:
#ifdef WIN32
# define dSEP "\\"
# define sSEP '\\'
#else
# define dSEP "/"
# define sSEP '/'
#endif
and use the following code fragment:
TString name = Path2Name(fullname, dSEP, ";");
When running the attached example program “myclass” on Mac everything is fine:
root [0] .L macroMyClassA.C
root [1] TestPath("/Volumes/FAT32/Affy/libraryfiles/Test3.CDF")
****** TestPath ******
fullname = /Volumes/FAT32/Affy/libraryfiles/Test3.CDF
name = Test3.CDF
path = /Volumes/FAT32/Affy/libraryfiles
root [2] TestPath("E:\\Affy\\libraryfiles\\Test3.CDF")
****** TestPath ******
fullname = E:\Affy\libraryfiles\Test3.CDF
name = E:\Affy\libraryfiles\Test3.CDF
path =
root [3]
However, running the same example on WinXP causes the following error:
root [0] .L macroMyClassA.C
root [1] TestPath("E:\\Affy\\libraryfiles\\Test3.CDF")
****** TestPath ******
fullname = E:\Affy\libraryfiles\Test3.CDF
name = Error: C++ exception caught C:\home\Rabbitus\rootcode\myclass\macroMyClassA.C(47)
(void)0
*** Interpreter error recovered ***
root [2] TestPath("/Volumes/FAT32/Affy/libraryfiles/Test3.CDF")
****** TestPath ******
root [3]
Can someone explain to me why this does not work on WinXP?
What is the correct solution?
Thank you in advance.
Best regards
Christian
myclass.zip (73 KB)