7 #include <Standard_NumericError.hxx>
8 #include <Standard_NullObject.hxx>
9 #include <Standard_ProgramError.hxx>
10 #include <Standard_ConstructionError.hxx>
11 #include <OSD_Path.ixx>
12 #include <OSD_WhoAmI.hxx>
14 #ifdef HAVE_SYS_UTSNAME_H
15 //# include <sys/utsname.h>
18 static OSD_SysType whereAmI(){
19 #if defined(__digital__) || defined(__FreeBSD__) || defined(SUNOS) || defined(__APPLE__)
22 #elif defined(sgi) || defined(IRIX) || defined(__sun) || defined(SOLARIS) || defined(__sco__) || defined(__hpux) || defined(HPUX)
23 return OSD_UnixSystemV;
25 #elif defined(__osf__) || defined(DECOSF1)
34 #elif defined(__CYGWIN32_) || defined(__MINGW32__)
37 #elif defined(vax) || defined(__vms)
40 #elif defined(__linux__) || defined(LIN)
41 return OSD_LinuxREDHAT;
43 #elif defined(_AIX) || defined(AIX)
49 cout << info.sysname << endl;
50 cout << info.nodename << endl;
51 cout << info.release << endl;
52 cout << info.version << endl;
53 cout << info.machine << endl;
64 static void VmsExtract(const TCollection_AsciiString& what,
65 TCollection_AsciiString& node,
66 TCollection_AsciiString& username,
67 TCollection_AsciiString& password,
68 TCollection_AsciiString& disk,
69 TCollection_AsciiString& trek,
70 TCollection_AsciiString& name,
71 TCollection_AsciiString& ext){
73 TCollection_AsciiString buffer;
78 if (buffer.Search("\"") != -1){ // a username to extract
80 if (buffer.Value(1) != '"') { // Begins with Node
81 node = buffer.Token("\"");
82 buffer.Remove(1,node.Length());
86 username = buffer.Token("\" ");
87 buffer.Remove(1,username.Length()+2); // Removes <<"username ' ' or '"' >>
89 if (buffer.Search("\"") != -1){ // a password to extract
90 password = buffer.Token("\"");
91 buffer.Remove(1,password.Length()+1); // removes <<password">>
94 // If we found a node then we must find "::"
95 if (buffer.Search("::") != -1)
96 buffer.Remove(1,2); // Removes <<::>>
98 else // No name or password
99 if (buffer.Search("::") != -1){ // a node to extract
100 node = buffer.Token(":");
101 buffer.Remove(1,node.Length()+2); // Removes <<node::>
104 if (buffer.Search(":") != -1){ // a disk to extract
105 disk = buffer.Token(":");
106 buffer.Remove(1,disk.Length()+1); // Removes <<disk:>>
112 if (buffer.Search("[") != -1){ // There is atrek to extract
113 trek = buffer.Token("[]");
115 if (trek.Value(1) == '.') trek.Remove(1,1); // Removes first '.'
116 else trek.Insert(1,'|'); // Add root
118 trek.ChangeAll('.','|'); // Translates to portable syntax
119 trek.ChangeAll('-','^');
121 pos = trek.Search("000000");
123 trek.Remove(pos,6); // on VMS [000000] is the root
124 if (trek.Search("||") != -1) trek.Remove(1,1); // When [000000.xxx] -> ||xxx
127 name = buffer.Token("]",2);
131 if (name.Search(".") != -1){
132 ext = name.Token(".",2);
134 name.Remove(name.Search("."),ext.Length());
141 //=======================================================================
142 //function : UnixExtract
144 //=======================================================================
145 static void UnixExtract(const TCollection_AsciiString& what,
146 TCollection_AsciiString& node,
147 TCollection_AsciiString& username,
148 TCollection_AsciiString& password,
149 TCollection_AsciiString& trek,
150 TCollection_AsciiString& name,
151 TCollection_AsciiString& ext){
153 Standard_Integer pos;
154 TCollection_AsciiString buffer; // To manipulate 'what' without modifying it
156 Standard_PCharacter p;
159 #ifdef TOTO // Username, password and node are no longer given in the string (LD)
161 if (buffer.Search("@") != -1){ // There is a name to extract
162 username = buffer.Token("\"@");
163 buffer.Remove(1,username.Length()+1); // Removes << user@ >>
165 if (buffer.Search("\"") != -1){ // There is a password to extract
166 password = buffer.Token("\"");
167 buffer.Remove(1,password.Length()+2); // Removes << "password" >>
176 #endif // node must be given (for DBT, DM) (ADN 29/8/96)
178 if (buffer.Search(":/") != -1){ // There is a node to extract
179 node = buffer.Token(":/");
180 buffer.Remove(1,node.Length()+1); // Removes << node: >>
190 trek.ChangeAll('/','|'); // Translates to portable syntax
192 pos = trek.SearchFromEnd("|"); // Extract name
194 p = (Standard_PCharacter)trek.ToCString();
196 if(name.Length()) trek.Remove(pos+1,name.Length());
198 else { // No '|' means no trek but a name
203 pos = trek.Search("..");
204 while (pos != -1){ // Changes every ".." by '^'
205 trek.SetValue(pos,'^');
206 trek.Remove(pos+1,1);
207 pos = trek.Search("..");
210 pos = name.SearchFromEnd(".") ; // LD : debug
211 if (pos != -1) // There is an extension to extract
212 ext = name.Split(pos - 1) ;
215 // if (name.Search(".") != -1){ // There is an extension to extract
216 // if ( name.Value(1) == '.' ) {
221 // ext = name.Token(".",2);
222 // ext.Insert(1,'.'); // Prepends 'dot'
223 // pos = name.Search("."); // Removes extension from buffer
225 // name.Remove(pos,ext.Length());
232 //=======================================================================
233 //function : DosExtract
235 //=======================================================================
236 static void DosExtract(const TCollection_AsciiString& what,
237 TCollection_AsciiString& disk,
238 TCollection_AsciiString& trek,
239 TCollection_AsciiString& name,
240 TCollection_AsciiString& ext){
242 TCollection_AsciiString buffer;
243 Standard_Integer pos;
244 Standard_PCharacter p;
248 if (buffer.Search(":") != -1){ // There is a disk to extract
249 disk = buffer.Token(":");
251 buffer.Remove(1,disk.Length()); // Removes <<disk:>>
254 if (buffer.Search(".") != -1){ // There is an extension to extract
255 ext = buffer.Token(".",2);
256 ext.Insert(1,'.'); // Prepends 'dot'
257 pos = buffer.Search("."); // Removes extension from buffer
259 buffer.Remove(pos,ext.Length());
264 trek.ChangeAll('\\','|');
266 pos = trek.Search("..");
267 while (pos != -1){ // Changes every ".." by '^'
268 trek.SetValue(pos,'^');
269 trek.Remove(pos+1,1);
270 pos = trek.Search("..");
273 pos = trek.SearchFromEnd("|"); // Extract name
275 p = (Standard_PCharacter)trek.ToCString();
277 trek.Remove(trek.Search(name),name.Length());
279 else { // No '|' means no trek but a name
286 //=======================================================================
287 //function : MacExtract
289 //=======================================================================
290 static void MacExtract(const TCollection_AsciiString& what,
291 TCollection_AsciiString& ,
292 TCollection_AsciiString& trek,
293 TCollection_AsciiString& name,
294 TCollection_AsciiString& ){
296 Standard_Integer pos;
297 Standard_PCharacter p;
299 // I don't know how to distingish a disk from a trek !
303 pos = trek.Search("::");
304 while (pos != -1){ // Changes every "::" by '^'
305 trek.SetValue(pos,'^');
306 trek.Remove(pos+1,1);
307 pos = trek.Search("::");
310 trek.ChangeAll(':','|'); // Translates to portable syntax
312 pos = trek.SearchFromEnd("|"); // Extract name
314 p = (Standard_PCharacter)trek.ToCString();
316 trek.Remove(trek.Search(name),name.Length());
318 else { // No '|' means no trek but a name
325 OSD_Path::OSD_Path(const TCollection_AsciiString& aDependentName,
326 const OSD_SysType aSysType){
330 if (!IsValid(aDependentName,aSysType))
331 Standard_ProgramError::Raise("OSD_Path::OSD_Path : Invalid dependent name");
334 // Standard_Integer i,l;
336 if (aSysType == OSD_Default) {
344 VmsExtract(aDependentName,myNode,myUserName,myPassword,myDisk,myTrek,myName,myExtension);
346 case OSD_LinuxREDHAT:
348 case OSD_UnixSystemV:
351 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
355 DosExtract(aDependentName,myDisk,myTrek,myName,myExtension);
358 MacExtract(aDependentName,myDisk,myTrek,myName,myExtension);
362 cout << " WARNING WARNING : OSD Path for an Unknown SYSTEM : " << (Standard_Integer)todo << endl;
370 OSD_Path::OSD_Path(const TCollection_AsciiString& Nod,
371 const TCollection_AsciiString& UsrNm,
372 const TCollection_AsciiString& Passwd,
373 const TCollection_AsciiString& Dsk,
374 const TCollection_AsciiString& Trk,
375 const TCollection_AsciiString& Nam,
376 const TCollection_AsciiString& ext){
380 SetValues ( Nod, UsrNm, Passwd, Dsk, Trk, Nam, ext);
386 void OSD_Path::Values(TCollection_AsciiString& Nod,
387 TCollection_AsciiString& UsrNm,
388 TCollection_AsciiString& Passwd,
389 TCollection_AsciiString& Dsk,
390 TCollection_AsciiString& Trk,
391 TCollection_AsciiString& Nam,
392 TCollection_AsciiString& ext)const{
404 void OSD_Path::SetValues(const TCollection_AsciiString& Nod,
405 const TCollection_AsciiString& UsrNm,
406 const TCollection_AsciiString& Passwd,
407 const TCollection_AsciiString& Dsk,
408 const TCollection_AsciiString& Trk,
409 const TCollection_AsciiString& Nam,
410 const TCollection_AsciiString& ext){
413 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Node");
414 if (!UsrNm.IsAscii())
415 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : User Name");
417 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Disk");
419 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Trek");
421 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Name");
423 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Extension");
435 static Standard_Boolean Analyse_VMS(const TCollection_AsciiString& name){
436 if (name.Search("/") != -1)
437 return(Standard_False);
438 if (name.Search("@") != -1)
439 return(Standard_False);
440 if (name.Search("\\") != -1)
441 return(Standard_False);
444 return Standard_True;
447 static Standard_Boolean Analyse_DOS(const TCollection_AsciiString& name){
449 // if (name.Search("$") != -1)
450 // return(Standard_False);
451 // if (name.Search(" ") != -1)
452 // return(Standard_False);
454 if (name.Search("/") != -1)
455 return(Standard_False);
456 if (name.Search(":") != -1)
457 return(Standard_False);
458 if (name.Search("*") != -1)
459 return(Standard_False);
460 if (name.Search("?") != -1)
461 return(Standard_False);
462 if (name.Search(".") != name.SearchFromEnd("."))
463 return(Standard_False);
464 if (name.Search("\"") != -1)
465 return(Standard_False);
466 if (name.Search("<") != -1)
467 return(Standard_False);
468 if (name.Search(">") != -1)
469 return(Standard_False);
470 if (name.Search("|") != -1)
471 return(Standard_False);
473 return Standard_True;
474 // Rajouter les tests sur les noms de 8 caracteres au maximum et
475 // l'extension de 3 caracteres.
478 static Standard_Boolean Analyse_MACOS(const TCollection_AsciiString& name){
479 Standard_Integer i = name.Search(":");
480 Standard_Integer l = name.Length();
484 return(Standard_False);
486 return(Standard_True);
488 return(Standard_True);
491 static Standard_Boolean Analyse_UNIX(const TCollection_AsciiString& /*name*/)
493 // if (name.Search("$") != -1) Unix filename can have a "$" (LD)
494 // return(Standard_False);
496 // all characters are allowed in UNIX file name, except null '\0' and slash '/'
498 // if (name.Search("[") != -1)
499 // return(Standard_False);
500 // if (name.Search("]") != -1)
501 // return(Standard_False);
502 // if (name.Search("\\") != -1)
503 // return(Standard_False);
504 // if (name.Search(" ") != -1)
505 // return(Standard_False);
507 return(Standard_True);
515 Standard_Boolean OSD_Path::IsValid(const TCollection_AsciiString& aDependentName,
516 const OSD_SysType aSysType)const{
517 if (aDependentName.Length()==0) return(Standard_True);
518 if (!aDependentName.IsAscii()) return(Standard_False);
521 if (aSysType == OSD_Default) provSys = SysDep;
522 else provSys = aSysType;
526 return(Analyse_VMS(aDependentName));
529 return(Analyse_DOS(aDependentName));
531 return(Analyse_MACOS(aDependentName));
533 return(Analyse_UNIX(aDependentName));
539 void OSD_Path::UpTrek(){
540 Standard_Integer length=TrekLength();
542 if (length == 0) return;
544 Standard_Integer awhere,aHowmany;
545 TCollection_AsciiString tok;
547 tok = myTrek.Token("|",length);
548 awhere = myTrek.SearchFromEnd(tok);
549 aHowmany = tok.Length();
550 myTrek.Remove(awhere,aHowmany);
552 awhere = myTrek.Search("||"); // Searches leaving "||"
554 myTrek.Remove(awhere);
558 void OSD_Path::DownTrek(const TCollection_AsciiString& aName){
560 // Pb signale par GG : pour ne pas avoir "||" ;
561 if ( aName.ToCString()[ aName.Length() - 1 ] != '|' )
566 Standard_Integer OSD_Path::TrekLength()const{
567 Standard_Integer cpt=0;
569 while (myTrek.Token("|",cpt+1) != "") // Counts token separated by '|'
576 void OSD_Path::RemoveATrek(const Standard_Integer thewhere){
577 Standard_Integer length=TrekLength();
579 if (length <= 0 || thewhere > length)
580 Standard_NumericError::Raise("OSD_Path::RemoveATrek : where has an invalid value");
582 Standard_Integer posit,aHowmany;
583 TCollection_AsciiString tok;
585 tok = myTrek.Token("|",thewhere);
586 posit = myTrek.Search(tok);
587 aHowmany = tok.Length();
588 myTrek.Remove(posit,aHowmany);
590 posit = myTrek.Search("||"); // Searches leaving "||"
592 myTrek.Remove(posit);
596 void OSD_Path::RemoveATrek(const TCollection_AsciiString& aName){
597 Standard_Integer length=TrekLength();
599 if (length == 0) return;
601 Standard_Integer awhere;
603 awhere = myTrek.Search(aName);
605 myTrek.Remove(awhere,aName.Length());
607 awhere = myTrek.Search("||"); // Searches leaving "||"
609 myTrek.Remove(awhere);
614 TCollection_AsciiString OSD_Path::TrekValue(const Standard_Integer thewhere)const{
615 TCollection_AsciiString result=myTrek.Token("|",thewhere);
618 Standard_NumericError::Raise("OSD_Path::TrekValue : where is invalid");
623 void OSD_Path::InsertATrek(const TCollection_AsciiString& aName,
624 const Standard_Integer thewhere){
625 Standard_Integer length=TrekLength();
627 if (thewhere <= 0 || thewhere > length)
628 Standard_NumericError::Raise("OSD_Path::InsertATrek : where has an invalid value");
630 TCollection_AsciiString tok=myTrek.Token("|",thewhere);
631 Standard_Integer wwhere = myTrek.Search(tok);
632 TCollection_AsciiString what = aName;
635 myTrek.Insert(wwhere,what);
639 // The 4 following methods will be PUBLIC in the future
641 // Converts a VMS disk to other system syntax
643 static void VMSDisk2Other(TCollection_AsciiString & Disk){
648 // Convert a Trek to VMS syntax
650 static void P2VMS (TCollection_AsciiString & Way){
651 Standard_Integer length = Way.Length();
653 if (length == 0) return;
655 if (Way.Value(1) == '|') // If begin with '|' remove '|'
656 if (Way.Value(1) != '\0')
658 else Way = "000000"; // Si uniquement la racine -> [000000]
661 Way.Insert(1,'|'); // Else insert '|' at beginning if not empty;
663 Way.ChangeAll('|','.');
664 Way.ChangeAll('^','-');
668 // Convert a Trek to MAC syntax
670 static void P2MAC (TCollection_AsciiString & Way){
672 Way.ChangeAll('|',':');
674 l = (int)Way.Length();
675 for (i=1; i <= l; i++) // Replace '^' by "::"
676 if (Way.Value(i) == '^'){
684 // Convert a Trek to UNIX syntax
686 static void P2UNIX (TCollection_AsciiString & Way){
688 Standard_Integer length = Way.Length();
690 if (length == 0) return;
692 // if (Way.Value(length) == '|') // If Finishes with "|" removes it
693 // Way.Trunc(length-1);
695 Way.ChangeAll('|','/');
697 l = (int)Way.Length();
698 for (i=1; i <= l; i++) // Replace '^' by "../"
699 if (Way.Value(i) == '^'){
702 //Way.Insert(i+2,'/');
708 // Convert a Trek to DOS like syntax
710 static void P2DOS (TCollection_AsciiString & Way){
712 Standard_Integer len = Way.Length();
714 if (len == 0) return;
716 if (Way.Value(len) == '|') // If Finishes with "|" removes it
719 Way.ChangeAll('|','\\');
721 l = (int)Way.Length();
722 for (i=1; i <= l; i++) // Replace '^' by ".."
723 if (Way.Value(i) == '^'){
734 // Convert a path to system dependant syntax
736 void OSD_Path::SystemName (TCollection_AsciiString& FullName,
737 const OSD_SysType aType)const{
738 TCollection_AsciiString Way;
739 TCollection_AsciiString pNode;
740 TCollection_AsciiString pDisk;
743 if (aType == OSD_Default) {
756 P2VMS (Way); // Convert path
758 if (myNode.Length()!=0) FullName += myNode; // Append Node
760 if (myUserName.Length()!=0){ // Append User name
762 if (pNode.Length()==0) { // If a user name but no node, catenate "0"
769 FullName += myUserName;
771 if (myPassword.Length()!=0){ // Append password
773 FullName += myPassword;
779 if (pNode.Length()!=0) FullName += "::";
781 if (myDisk.Length()!=0){ // Append Disk
787 if (Way.Length()!=0) // Append VMS path
788 FullName = FullName + "[" + Way + "]" + myName + myExtension;
790 // FullName.UpperCase();
795 case OSD_WindowsNT : // MSDOS-like syntax
797 int length = (int)myDisk.Length();
802 if (myDisk.Length()!=0){
805 (length == 1 && IsAlphabetic(myDisk.Value(1))) || // 'A/a' to 'Z/z'
807 IsAlphabetic(myDisk.Value(1)) &&
808 myDisk.Value(2) == ':') // 'A:' to 'Z:'
809 ) // This is a MSDOS disk syntax
812 if (myDisk.Value(length) != ':') FullName += ":";
814 else // This is an assigned Disk
818 VMSDisk2Other(pDisk);
820 if (Way.Value(1) != '\\') FullName += "\\";
825 FullName = FullName + Way + "\\";
828 FullName += myExtension;
829 // FullName.UpperCase();
833 case OSD_MacOs : // Mackintosh-like syntax
834 if (myDisk.Length()!=0){
840 FullName += myExtension;
845 default : // UNIX-like syntax
848 // user"password"@host:/disk/xxx/xxx/filename
851 if (myUserName.Length()!=0 && myNode.Length()!=0){ // If USER name
852 FullName += myUserName; // appends user name
854 if (myPassword.Length()!=0)
855 FullName = FullName + "\"" + myPassword + "\""; // a password if not empty
857 FullName += "@"; // and character '@'
860 if (myNode.Length()!=0){ // Appends HOST name
865 if (myDisk.Length()!=0) { // Appends Disk name as path
868 VMSDisk2Other(pDisk);
872 // if (FullName.Length()) { // Adds a "/" if necessary
876 if (Way.Length()!=0) { // Appends a path if not empty
880 if (FullName.Length()){
881 if (FullName.Value(FullName.Length()) != '/') {
882 FullName += "/"; // Adds a / if necessary
886 if (myName.Length()){ // Adds the file name
890 if (myExtension.Length()) { // Adds the extension
891 FullName += myExtension;
897 #ifdef TOTO // A reactiver...
899 void OSD_Path::SetSystemName(const TCollection_AsciiString& aDependentName,
900 const OSD_SysType aSysType){
901 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
905 TCollection_AsciiString OSD_Path::Node()const{
910 TCollection_AsciiString OSD_Path::UserName()const{
915 TCollection_AsciiString OSD_Path::Password()const{
920 TCollection_AsciiString OSD_Path::Disk()const{
925 TCollection_AsciiString OSD_Path::Trek()const{
930 // Return extension (suffix) of file/directory name
932 TCollection_AsciiString OSD_Path::Extension()const{
937 TCollection_AsciiString OSD_Path::Name()const{
942 void OSD_Path::SetNode(const TCollection_AsciiString& aName){
943 if (!aName.IsAscii())
944 Standard_ConstructionError::Raise("OSD_Path::SetNode bad name");
951 void OSD_Path::SetUserName(const TCollection_AsciiString& aName){
952 if (!aName.IsAscii())
953 Standard_ConstructionError::Raise("OSD_Path::SetUserName bad name");
960 void OSD_Path::SetPassword(const TCollection_AsciiString& aName){
961 if (!aName.IsAscii())
962 Standard_ConstructionError::Raise("OSD_Path::SetPassword bad name");
969 void OSD_Path::SetDisk(const TCollection_AsciiString& aName){
970 if (!aName.IsAscii())
971 Standard_ConstructionError::Raise("OSD_Path::SetDisk bad name");
978 void OSD_Path::SetTrek(const TCollection_AsciiString& aName){
979 if (!aName.IsAscii())
980 Standard_ConstructionError::Raise("OSD_Path::SetTrek bad name");
987 void OSD_Path::SetName(const TCollection_AsciiString& aName){
988 if (!aName.IsAscii())
989 Standard_ConstructionError::Raise("OSD_Path::SetName bad name");
996 void OSD_Path::SetExtension(const TCollection_AsciiString& aName){
997 if (!aName.IsAscii())
998 Standard_ConstructionError::Raise("OSD_Path::SetExtension bad name");
1004 //------------------------------------------------------------------------
1005 //------------------- Windows NT sources for OSD_Path -------------------
1006 //------------------------------------------------------------------------
1008 #include <OSD_Path.hxx>
1009 #include <Standard_ProgramError.hxx>
1011 #include <windows.h>
1015 #define TEST_RAISE( type, arg ) _test_raise ( ( type ), ( arg ) )
1017 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
1018 static void __fastcall _remove_dup ( TCollection_AsciiString& );
1020 OSD_Path :: OSD_Path () {
1022 } // end constructor ( 1 )
1024 OSD_Path :: OSD_Path (
1025 const TCollection_AsciiString& aDependentName,
1026 const OSD_SysType aSysType
1029 Standard_Integer i, j, len;
1030 static char __drive [ _MAX_DRIVE ];
1031 static char __dir [ _MAX_DIR ];
1032 static char __trek [ _MAX_DIR ];
1033 static char __fname [ _MAX_FNAME ];
1034 static char __ext [ _MAX_EXT ];
1036 memset(__drive, 0,_MAX_DRIVE);
1037 memset(__dir, 0,_MAX_DRIVE);
1038 memset(__trek, 0,_MAX_DRIVE);
1039 memset(__fname, 0,_MAX_DRIVE);
1040 memset(__ext, 0,_MAX_DRIVE);
1041 Standard_Character chr;
1043 TEST_RAISE( aSysType, TEXT( "OSD_Path" ) );
1045 _splitpath ( aDependentName.ToCString (), __drive, __dir, __fname, __ext );
1051 myExtension = __ext;
1054 TCollection_AsciiString dir = __dir;
1055 len = dir.UsefullLength ();
1058 for ( i = j = 0; i < len; ++i, ++j ) {
1062 if ( chr == TEXT( '\\' ) || chr == TEXT( '/' ) )
1064 __trek[j] = TEXT( '|' );
1066 else if ( chr == TEXT( '.' )&& (i+1) < len && __dir[i+1] == TEXT( '.' ) ) {
1068 __trek[j] = TEXT( '^' );
1077 TCollection_AsciiString trek = __trek;
1078 _remove_dup ( trek );
1081 } // end constructor ( 2 )
1083 OSD_Path :: OSD_Path (
1084 const TCollection_AsciiString& aNode,
1085 const TCollection_AsciiString& aUsername,
1086 const TCollection_AsciiString& aPassword,
1087 const TCollection_AsciiString& aDisk,
1088 const TCollection_AsciiString& aTrek,
1089 const TCollection_AsciiString& aName,
1090 const TCollection_AsciiString& anExtension
1093 SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
1095 } // end constructor ( 3 )
1097 void OSD_Path :: Values (
1098 TCollection_AsciiString& aNode,
1099 TCollection_AsciiString& aUsername,
1100 TCollection_AsciiString& aPassword,
1101 TCollection_AsciiString& aDisk,
1102 TCollection_AsciiString& aTrek,
1103 TCollection_AsciiString& aName,
1104 TCollection_AsciiString& anExtension
1108 aUsername = myUserName;
1109 aPassword = myPassword;
1112 if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1113 aTrek += "|" ; // (LD)
1115 anExtension = myExtension;
1117 } // end OSD_Path :: Values
1119 void OSD_Path :: SetValues (
1120 const TCollection_AsciiString& aNode,
1121 const TCollection_AsciiString& aUsername,
1122 const TCollection_AsciiString& aPassword,
1123 const TCollection_AsciiString& aDisk,
1124 const TCollection_AsciiString& aTrek,
1125 const TCollection_AsciiString& aName,
1126 const TCollection_AsciiString& anExtension
1130 myUserName = aUsername;
1131 myPassword = aPassword;
1135 myExtension = anExtension;
1137 if ( myExtension.UsefullLength () && myExtension.Value ( 1 ) != TEXT( '.' ) )
1139 myExtension.Insert ( 1, TEXT( '.' ) );
1141 _remove_dup ( myTrek );
1143 } // end OSD_Path :: SetValues
1145 void OSD_Path :: SystemName (
1146 TCollection_AsciiString& FullName,
1147 const OSD_SysType aType
1150 Standard_Integer i, j;
1151 TCollection_AsciiString fullPath;
1152 static Standard_Character trek [ _MAX_PATH ];
1153 Standard_Character chr;
1155 memset(trek,0,_MAX_PATH);
1157 TEST_RAISE( aType, TEXT( "SystemName" ) );
1159 for ( i = j = 1; i <= myTrek.UsefullLength () && j <= _MAX_PATH; ++i, ++j ) {
1161 chr = myTrek.Value ( i );
1163 if ( chr == TEXT( '|' ) ) {
1165 trek[j-1] = TEXT( '/' );
1167 } else if ( chr == TEXT( '^' ) && j <= _MAX_PATH - 1 ) {
1169 strcpy(&(trek[(j++) - 1]),TEXT( ".." ));
1177 fullPath = myDisk + TCollection_AsciiString(trek);
1179 if ( trek[0] ) fullPath += TEXT( "/" );
1181 fullPath += ( myName + myExtension );
1183 if ( fullPath.UsefullLength () > 0 )
1185 FullName = fullPath;
1191 } // end OSD_Path :: SystemName
1193 Standard_Boolean OSD_Path :: IsValid (
1194 const TCollection_AsciiString& aDependentName,
1195 const OSD_SysType aSysType
1198 TEST_RAISE( aSysType, TEXT( "IsValid" ) );
1200 return Standard_True;
1202 } // end OSD_Path :: IsValid
1204 void OSD_Path :: UpTrek () {
1206 Standard_Integer pos = myTrek.SearchFromEnd ( TEXT( "|" ) );
1212 else if ( pos > 1 ) {
1214 while ( myTrek.Value ( pos ) == TEXT( '|' ) && pos != 1 ) --pos;
1218 myTrek.Trunc ( pos );
1220 } // end OSD_Path :: UpTrek
1222 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1224 Standard_Integer pos = myTrek.UsefullLength ();
1226 if ( aName.Value ( 1 ) != TEXT( '|' ) &&
1228 myTrek.Value ( pos ) != TEXT( '|' )
1231 myTrek += TEXT( "|" );
1235 _remove_dup ( myTrek );
1237 } // end OSD_Path :: DownTrek
1239 Standard_Integer OSD_Path :: TrekLength () const {
1241 Standard_Integer i = 1;
1242 Standard_Integer retVal = 0;
1244 if ( myTrek.IsEmpty () || myTrek.UsefullLength () == 1 && myTrek.Value ( 1 ) == TEXT( '|' ) )
1248 while ( Standard_True ) {
1250 if ( myTrek.Token ( TEXT( "|" ), i++ ).IsEmpty () )
1262 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1264 Standard_Integer i, j;
1265 Standard_Boolean flag = Standard_False;
1267 if ( TrekLength () < thewhere )
1271 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1273 flag = Standard_True;
1274 myTrek.Insert ( 1, TEXT( '|' ) );
1278 i = myTrek.Location (
1279 thewhere, TEXT( '|' ),
1280 1, myTrek.UsefullLength ()
1285 j = myTrek.Location (
1286 thewhere + 1, TEXT( '|' ),
1287 1, myTrek.UsefullLength ()
1292 j = myTrek.UsefullLength () + 1;
1294 myTrek.Remove ( i, j - i );
1300 myTrek.Remove ( 1 );
1302 } // end OSD_Path :: RemoveATrek ( 1 )
1304 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1307 Standard_Boolean flag = Standard_False;
1308 TCollection_AsciiString tmp;
1310 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1312 flag = Standard_True;
1313 myTrek.Insert ( 1, TEXT( '|' ) );
1317 myTrek += TEXT( '|' );
1321 if ( tmp.Value ( 1 ) != TEXT( '|' ) )
1323 tmp.Insert ( 1, TEXT( '|' ) );
1325 if ( tmp.Value ( tmp.UsefullLength () ) != TEXT( '|' ) )
1329 i = myTrek.Search ( tmp );
1333 myTrek.Remove ( i + 1, tmp.UsefullLength () - 1 );
1337 myTrek.Remove ( 1 );
1339 if ( myTrek.Value ( myTrek.UsefullLength () ) == TEXT( '|' ) )
1341 myTrek.Trunc ( myTrek.UsefullLength () - 1 );
1343 } // end OSD_Path :: RemoveATrek ( 2 )
1345 TCollection_AsciiString OSD_Path :: TrekValue (
1346 const Standard_Integer thewhere
1349 TCollection_AsciiString retVal;
1350 TCollection_AsciiString trek = myTrek;
1352 if ( trek.Value ( 1 ) != TEXT( '|' ) )
1354 trek.Insert ( 1, TEXT( '|' ) );
1356 retVal = trek.Token ( TEXT( "|" ), thewhere );
1360 } // end OSD_Path :: TrekValue
1362 void OSD_Path :: InsertATrek (
1363 const TCollection_AsciiString& aName,
1364 const Standard_Integer thewhere
1367 Standard_Integer pos;
1368 TCollection_AsciiString tmp = aName;
1369 Standard_Boolean flag = Standard_False;
1371 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1373 flag = Standard_True;
1374 myTrek.Insert ( 1, TEXT( '|' ) );
1378 myTrek += TEXT( '|' );
1380 pos = myTrek.Location (
1381 thewhere, TEXT( '|' ),
1382 1, myTrek.UsefullLength ()
1387 if ( tmp.Value ( tmp.UsefullLength () ) != TEXT( '|' ) )
1391 myTrek.Insert ( pos + 1, tmp );
1397 myTrek.Remove ( 1 );
1399 if ( myTrek.Value ( myTrek.UsefullLength () ) == TEXT( '|' ) )
1401 myTrek.Trunc ( myTrek.UsefullLength () - 1 );
1403 _remove_dup ( myTrek );
1405 } // end OSD_Path :: InsertATrek
1407 TCollection_AsciiString OSD_Path :: Node () const {
1411 } // end OSD_Path :: Node
1413 TCollection_AsciiString OSD_Path :: UserName () const {
1417 } // end OSD_Path :: UserName
1419 TCollection_AsciiString OSD_Path :: Password () const {
1423 } // end OSD_Path :: Password
1425 TCollection_AsciiString OSD_Path :: Disk () const {
1429 } // end OSD_Path :: Disk
1431 TCollection_AsciiString OSD_Path :: Trek () const {
1433 TCollection_AsciiString retVal ;
1435 if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1436 retVal += "|" ; // (LD)
1439 } // end OSD_Path :: Trek
1441 TCollection_AsciiString OSD_Path :: Name () const {
1445 } // end OSD_Path :: Name
1447 TCollection_AsciiString OSD_Path :: Extension () const {
1451 } // end OSD_Path :: Extension
1453 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1457 } // end OSD_Path :: SetNode
1459 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1463 } // end OSD_Path :: SetUserName
1465 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1469 } // end OSD_Path :: SetPassword
1471 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1475 } // end OSD_Path :: SetDisk
1477 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1481 _remove_dup ( myTrek );
1483 } // end OSD_Path :: SetTrek
1485 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1489 } // end OSD_Path :: SetName
1491 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1493 myExtension = aName;
1495 } // end OSD_Path :: SetExtension
1497 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1499 Standard_Character buff[ 64 ];
1501 if ( type != OSD_Default && type != OSD_WindowsNT ) {
1503 _tcscpy ( buff, TEXT( "OSD_Path :: " ) );
1504 _tcscat ( buff, str );
1505 _tcscat ( buff, TEXT( " (): unknown system type" ) );
1507 Standard_ProgramError :: Raise ( buff );
1511 } // end _test_raise
1513 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1515 Standard_Integer pos = 1, orgLen, len = str.UsefullLength ();
1519 while ( pos <= len ) {
1521 if ( str.Value ( pos ) == TEXT( '|' ) && pos != len &&
1522 str.Value ( pos + 1 ) == TEXT( '|' ) && pos != 1
1527 while ( pos <= len && str.Value ( pos ) == TEXT( '|' ) ) str.Remove ( pos ), --len;
1535 if ( orgLen > 1 && len > 0 && str.Value ( len ) == TEXT( '|' ) ) str.Remove ( len );
1538 orgLen = len = str.UsefullLength ();
1540 while ( pos <= len ) {
1542 if ( str.Value ( pos ) == TEXT( '^' ) && pos != len && str.Value ( pos + 1 ) == TEXT( '^' ) ) {
1546 while ( pos <= len && str.Value ( pos ) == TEXT( '^' ) ) str.Remove ( pos ), --len;
1554 // if ( orgLen > 1 && len > 0 && str.Value ( len ) == TEXT( '^' ) ) str.Remove ( len );
1556 } // end _remove_dup
1560 // ---------------------------------------------------------------------------
1562 // Elimine les separateurs inutiles
1565 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1567 Standard_Integer i, j, len ;
1569 len = aString.Length() ;
1570 for (i = j = 1 ; j <= len ; i++,j++) {
1571 Standard_Character c = aString.Value(j) ;
1572 aString.SetValue(i,c) ;
1574 while(j < len && aString.Value(j+1) == '/') j++ ;
1577 if (aString.Value(len) == '/') len-- ;
1578 aString.Trunc(len) ;
1582 // ---------------------------------------------------------------------------
1584 TCollection_AsciiString OSD_Path::RelativePath(
1585 const TCollection_AsciiString& aDirPath,
1586 const TCollection_AsciiString& aAbsFilePath)
1588 TCollection_AsciiString EmptyString = "" ;
1589 TCollection_AsciiString FilePath ;
1590 Standard_Integer len ;
1591 Standard_Integer i, n ;
1592 Standard_Boolean Wnt = 0 ;
1594 FilePath = aAbsFilePath ;
1596 if (aDirPath.Search(":") == 2) { // Cas WNT
1598 if (FilePath.Search(":") != 2 ||
1599 UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1601 return EmptyString ;
1603 FilePath.ChangeAll('\\','/') ;
1604 if (FilePath.Search("/") != 3 )
1605 return EmptyString ;
1608 if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1609 return EmptyString ;
1612 // Eliminer les separateurs redondants
1614 len = RemoveExtraSeparator(FilePath) ;
1618 return EmptyString ;
1619 FilePath = FilePath.SubString(2,len) ;
1621 TCollection_AsciiString DirToken, FileToken ;
1622 Standard_Boolean Sibling = 0 ;
1624 for (i = n = 1 ;; n++) {
1625 DirToken = aDirPath.Token("/\\",n) ;
1626 if (DirToken.IsEmpty())
1630 len = FilePath.Length() ;
1631 i = FilePath.Search("/") ;
1634 return EmptyString ;
1636 FileToken = FilePath.SubString(1,i-1) ;
1638 DirToken.UpperCase() ;
1639 FileToken.UpperCase() ;
1641 if (DirToken == FileToken) {
1642 FilePath = FilePath.SubString(i+1,len) ;
1646 else if (DirToken == FilePath)
1647 return EmptyString ;
1652 FilePath.Insert(1,"../") ;
1656 // ---------------------------------------------------------------------------
1658 TCollection_AsciiString OSD_Path::AbsolutePath(
1659 const TCollection_AsciiString& aDirPath,
1660 const TCollection_AsciiString& aRelFilePath)
1662 TCollection_AsciiString EmptyString = "" ;
1663 if (aRelFilePath.Search("/") == 1 || aRelFilePath.Search(":") == 2)
1664 return aRelFilePath ;
1665 TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
1666 Standard_Integer i,len ;
1668 if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1669 return EmptyString ;
1671 if ( DirPath.Search(":") == 2)
1672 DirPath.ChangeAll('\\','/') ;
1673 RelFilePath.ChangeAll('\\','/') ;
1674 RemoveExtraSeparator(DirPath) ;
1675 len = RemoveExtraSeparator(RelFilePath) ;
1677 while (RelFilePath.Search("../") == 1) {
1679 return EmptyString ;
1680 RelFilePath = RelFilePath.SubString(4,len) ;
1682 if (DirPath.IsEmpty())
1683 return EmptyString ;
1684 i = DirPath.SearchFromEnd("/") ;
1686 return EmptyString ;
1687 DirPath.Trunc(i-1) ;
1690 DirPath += RelFilePath ;
1694 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1695 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1699 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1700 Standard_Boolean LocateExecFile(OSD_Path& )
1702 return Standard_False ;