Problem with WinXP-type full pathnames "C:\\path\\name&

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)

Hi Christian,

remove [code]#ifdef WIN32

define dSEP “\\”

define sSEP ‘\\’

#else
[/code]
Just use forward slashes (they are valid on Windows):

root [1] .L macroMyClassA.C
root [2] TestPath("/Volumes/FAT32/Affy/libraryfiles/Test3.CDF")
****** TestPath ******
fullname = /Volumes/FAT32/Affy/libraryfiles/Test3.CDF
name = Test3.CDF
path = /Volumes/FAT32/Affy/libraryfiles
root [3]

And use gSystem->UnixPathName(some_windows_path) to make the conversion (if needed at all)…

Cheers,
Bertrand.

Dear Bertrand

Thank you for your suggestions, sadly the problem seems to be different:
On WinXP it seems that my functions Path2Name() and Name2Path() are not recognized at all,
or are causing an error when called from MyClassA.

To test the functions I have added both functions to my LinkDef file to be able to call them from my macro.
Now I can call the compiled functions from my macro w/o any problems!

Why are the functions not recognized in my class method?

Best regards
Christian

Hi Christian,

I don’t see the problem with the code you attached…
(just see my previous post)

Cheers,
Bertrand.

Dear Bertrand

Just one minute ago I found finally the error, which is very frustrating. The following code does not work with VC++:

   TString name = Path2Name(fullname, dSEP, ";");
 
   cout << "name = " << name << endl;

I have to use the following code:

   TString name = Path2Name(fullname, dSEP, ";");
 
   cout << "name = " << name.Data() << endl;

Is seems that VC++ is very picky and does not accept any non-standard code :frowning:

Best regards
Christian

It is nice to work with strict compilers, isn’t it? :wink:

Cheers, Bertrand.

Yes, but only if the compiler provides the corresponding error message!

Best regards
Christian