1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <OSD_Path.ixx>
17 static OSD_SysType whereAmI(){
18 #if defined(__digital__) || defined(__FreeBSD__) || defined(SUNOS) || defined(__APPLE__)
21 #elif defined(sgi) || defined(IRIX) || defined(__sun) || defined(SOLARIS) || defined(__sco__) || defined(__hpux) || defined(HPUX)
22 return OSD_UnixSystemV;
24 #elif defined(__osf__) || defined(DECOSF1)
30 #elif defined(_WIN32) || defined(__WIN32__)
33 #elif defined(__CYGWIN32_) || defined(__MINGW32__)
36 #elif defined(vax) || defined(__vms)
39 #elif defined(__linux__) || defined(LIN)
40 return OSD_LinuxREDHAT;
42 #elif defined(_AIX) || defined(AIX)
48 cout << info.sysname << endl;
49 cout << info.nodename << endl;
50 cout << info.release << endl;
51 cout << info.version << endl;
52 cout << info.machine << endl;
57 #if !(defined(_WIN32) || defined(__WIN32__))
59 #include <Standard_NumericError.hxx>
60 #include <Standard_NullObject.hxx>
61 #include <Standard_ProgramError.hxx>
62 #include <Standard_ConstructionError.hxx>
63 #include <OSD_WhoAmI.hxx>
66 mySysDep = whereAmI();
69 static void VmsExtract(const TCollection_AsciiString& what,
70 TCollection_AsciiString& node,
71 TCollection_AsciiString& username,
72 TCollection_AsciiString& password,
73 TCollection_AsciiString& disk,
74 TCollection_AsciiString& trek,
75 TCollection_AsciiString& name,
76 TCollection_AsciiString& ext){
78 TCollection_AsciiString buffer;
83 if (buffer.Search("\"") != -1){ // a username to extract
85 if (buffer.Value(1) != '"') { // Begins with Node
86 node = buffer.Token("\"");
87 buffer.Remove(1,node.Length());
91 username = buffer.Token("\" ");
92 buffer.Remove(1,username.Length()+2); // Removes <<"username ' ' or '"' >>
94 if (buffer.Search("\"") != -1){ // a password to extract
95 password = buffer.Token("\"");
96 buffer.Remove(1,password.Length()+1); // removes <<password">>
99 // If we found a node then we must find "::"
100 if (buffer.Search("::") != -1)
101 buffer.Remove(1,2); // Removes <<::>>
103 else // No name or password
104 if (buffer.Search("::") != -1){ // a node to extract
105 node = buffer.Token(":");
106 buffer.Remove(1,node.Length()+2); // Removes <<node::>
109 if (buffer.Search(":") != -1){ // a disk to extract
110 disk = buffer.Token(":");
111 buffer.Remove(1,disk.Length()+1); // Removes <<disk:>>
117 if (buffer.Search("[") != -1){ // There is atrek to extract
118 trek = buffer.Token("[]");
120 if (trek.Value(1) == '.') trek.Remove(1,1); // Removes first '.'
121 else trek.Insert(1,'|'); // Add root
123 trek.ChangeAll('.','|'); // Translates to portable syntax
124 trek.ChangeAll('-','^');
126 pos = trek.Search("000000");
128 trek.Remove(pos,6); // on VMS [000000] is the root
129 if (trek.Search("||") != -1) trek.Remove(1,1); // When [000000.xxx] -> ||xxx
132 name = buffer.Token("]",2);
136 if (name.Search(".") != -1){
137 ext = name.Token(".",2);
139 name.Remove(name.Search("."),ext.Length());
146 //=======================================================================
147 //function : UnixExtract
149 //=======================================================================
150 static void UnixExtract(const TCollection_AsciiString& what,
151 TCollection_AsciiString& node,
152 TCollection_AsciiString& username,
153 TCollection_AsciiString& password,
154 TCollection_AsciiString& trek,
155 TCollection_AsciiString& name,
156 TCollection_AsciiString& ext){
158 Standard_Integer pos;
159 TCollection_AsciiString buffer; // To manipulate 'what' without modifying it
161 Standard_PCharacter p;
164 #ifdef TOTO // Username, password and node are no longer given in the string (LD)
166 if (buffer.Search("@") != -1){ // There is a name to extract
167 username = buffer.Token("\"@");
168 buffer.Remove(1,username.Length()+1); // Removes << user@ >>
170 if (buffer.Search("\"") != -1){ // There is a password to extract
171 password = buffer.Token("\"");
172 buffer.Remove(1,password.Length()+2); // Removes << "password" >>
181 #endif // node must be given (for DBT, DM) (ADN 29/8/96)
183 if (buffer.Search(":/") != -1){ // There is a node to extract
184 node = buffer.Token(":/");
185 buffer.Remove(1,node.Length()+1); // Removes << node: >>
195 trek.ChangeAll('/','|'); // Translates to portable syntax
197 pos = trek.SearchFromEnd("|"); // Extract name
199 p = (Standard_PCharacter)trek.ToCString();
201 if(name.Length()) trek.Remove(pos+1,name.Length());
203 else { // No '|' means no trek but a name
208 pos = trek.Search("..");
209 while (pos != -1){ // Changes every ".." by '^'
210 trek.SetValue(pos,'^');
211 trek.Remove(pos+1,1);
212 pos = trek.Search("..");
215 pos = name.SearchFromEnd(".") ; // LD : debug
216 if (pos != -1) // There is an extension to extract
217 ext = name.Split(pos - 1) ;
220 // if (name.Search(".") != -1){ // There is an extension to extract
221 // if ( name.Value(1) == '.' ) {
226 // ext = name.Token(".",2);
227 // ext.Insert(1,'.'); // Prepends 'dot'
228 // pos = name.Search("."); // Removes extension from buffer
230 // name.Remove(pos,ext.Length());
237 //=======================================================================
238 //function : DosExtract
240 //=======================================================================
241 static void DosExtract(const TCollection_AsciiString& what,
242 TCollection_AsciiString& disk,
243 TCollection_AsciiString& trek,
244 TCollection_AsciiString& name,
245 TCollection_AsciiString& ext){
247 TCollection_AsciiString buffer;
248 Standard_Integer pos;
249 Standard_PCharacter p;
253 if (buffer.Search(":") != -1){ // There is a disk to extract
254 disk = buffer.Token(":");
256 buffer.Remove(1,disk.Length()); // Removes <<disk:>>
259 if (buffer.Search(".") != -1){ // There is an extension to extract
260 ext = buffer.Token(".",2);
261 ext.Insert(1,'.'); // Prepends 'dot'
262 pos = buffer.Search("."); // Removes extension from buffer
264 buffer.Remove(pos,ext.Length());
269 trek.ChangeAll('\\','|');
271 pos = trek.Search("..");
272 while (pos != -1){ // Changes every ".." by '^'
273 trek.SetValue(pos,'^');
274 trek.Remove(pos+1,1);
275 pos = trek.Search("..");
278 pos = trek.SearchFromEnd("|"); // Extract name
280 p = (Standard_PCharacter)trek.ToCString();
282 trek.Remove(trek.Search(name),name.Length());
284 else { // No '|' means no trek but a name
291 //=======================================================================
292 //function : MacExtract
294 //=======================================================================
295 static void MacExtract(const TCollection_AsciiString& what,
296 TCollection_AsciiString& ,
297 TCollection_AsciiString& trek,
298 TCollection_AsciiString& name,
299 TCollection_AsciiString& ){
301 Standard_Integer pos;
302 Standard_PCharacter p;
304 // I don't know how to distingish a disk from a trek !
308 pos = trek.Search("::");
309 while (pos != -1){ // Changes every "::" by '^'
310 trek.SetValue(pos,'^');
311 trek.Remove(pos+1,1);
312 pos = trek.Search("::");
315 trek.ChangeAll(':','|'); // Translates to portable syntax
317 pos = trek.SearchFromEnd("|"); // Extract name
319 p = (Standard_PCharacter)trek.ToCString();
321 trek.Remove(trek.Search(name),name.Length());
323 else { // No '|' means no trek but a name
330 OSD_Path::OSD_Path(const TCollection_AsciiString& aDependentName,
331 const OSD_SysType aSysType){
333 mySysDep = whereAmI();
336 // Standard_Integer i,l;
338 if (aSysType == OSD_Default) {
346 VmsExtract(aDependentName,myNode,myUserName,myPassword,myDisk,myTrek,myName,myExtension);
348 case OSD_LinuxREDHAT:
350 case OSD_UnixSystemV:
353 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
357 DosExtract(aDependentName,myDisk,myTrek,myName,myExtension);
360 MacExtract(aDependentName,myDisk,myTrek,myName,myExtension);
364 cout << " WARNING WARNING : OSD Path for an Unknown SYSTEM : " << (Standard_Integer)todo << endl;
372 OSD_Path::OSD_Path(const TCollection_AsciiString& Nod,
373 const TCollection_AsciiString& UsrNm,
374 const TCollection_AsciiString& Passwd,
375 const TCollection_AsciiString& Dsk,
376 const TCollection_AsciiString& Trk,
377 const TCollection_AsciiString& Nam,
378 const TCollection_AsciiString& ext){
380 mySysDep = whereAmI();
382 SetValues ( Nod, UsrNm, Passwd, Dsk, Trk, Nam, ext);
388 void OSD_Path::Values(TCollection_AsciiString& Nod,
389 TCollection_AsciiString& UsrNm,
390 TCollection_AsciiString& Passwd,
391 TCollection_AsciiString& Dsk,
392 TCollection_AsciiString& Trk,
393 TCollection_AsciiString& Nam,
394 TCollection_AsciiString& ext)const{
406 void OSD_Path::SetValues(const TCollection_AsciiString& Nod,
407 const TCollection_AsciiString& UsrNm,
408 const TCollection_AsciiString& Passwd,
409 const TCollection_AsciiString& Dsk,
410 const TCollection_AsciiString& Trk,
411 const TCollection_AsciiString& Nam,
412 const TCollection_AsciiString& ext){
415 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Node");
416 if (!UsrNm.IsAscii())
417 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : User Name");
419 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Disk");
421 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Trek");
423 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Name");
425 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Extension");
436 void OSD_Path::UpTrek(){
437 Standard_Integer length=TrekLength();
439 if (length == 0) return;
441 Standard_Integer awhere,aHowmany;
442 TCollection_AsciiString tok;
444 tok = myTrek.Token("|",length);
445 awhere = myTrek.SearchFromEnd(tok);
446 aHowmany = tok.Length();
447 myTrek.Remove(awhere,aHowmany);
449 awhere = myTrek.Search("||"); // Searches leaving "||"
451 myTrek.Remove(awhere);
455 void OSD_Path::DownTrek(const TCollection_AsciiString& aName){
457 // Pb signale par GG : pour ne pas avoir "||" ;
458 if ( aName.ToCString()[ aName.Length() - 1 ] != '|' )
463 Standard_Integer OSD_Path::TrekLength()const{
464 Standard_Integer cpt=0;
466 while (myTrek.Token("|",cpt+1) != "") // Counts token separated by '|'
473 void OSD_Path::RemoveATrek(const Standard_Integer thewhere){
474 Standard_Integer length=TrekLength();
476 if (length <= 0 || thewhere > length)
477 Standard_NumericError::Raise("OSD_Path::RemoveATrek : where has an invalid value");
479 Standard_Integer posit,aHowmany;
480 TCollection_AsciiString tok;
482 tok = myTrek.Token("|",thewhere);
483 posit = myTrek.Search(tok);
484 aHowmany = tok.Length();
485 myTrek.Remove(posit,aHowmany);
487 posit = myTrek.Search("||"); // Searches leaving "||"
489 myTrek.Remove(posit);
493 void OSD_Path::RemoveATrek(const TCollection_AsciiString& aName){
494 Standard_Integer length=TrekLength();
496 if (length == 0) return;
498 Standard_Integer awhere;
500 awhere = myTrek.Search(aName);
502 myTrek.Remove(awhere,aName.Length());
504 awhere = myTrek.Search("||"); // Searches leaving "||"
506 myTrek.Remove(awhere);
511 TCollection_AsciiString OSD_Path::TrekValue(const Standard_Integer thewhere)const{
512 TCollection_AsciiString result=myTrek.Token("|",thewhere);
515 Standard_NumericError::Raise("OSD_Path::TrekValue : where is invalid");
520 void OSD_Path::InsertATrek(const TCollection_AsciiString& aName,
521 const Standard_Integer thewhere){
522 Standard_Integer length=TrekLength();
524 if (thewhere <= 0 || thewhere > length)
525 Standard_NumericError::Raise("OSD_Path::InsertATrek : where has an invalid value");
527 TCollection_AsciiString tok=myTrek.Token("|",thewhere);
528 Standard_Integer wwhere = myTrek.Search(tok);
529 TCollection_AsciiString what = aName;
532 myTrek.Insert(wwhere,what);
536 // The 4 following methods will be PUBLIC in the future
538 // Converts a VMS disk to other system syntax
540 static void VMSDisk2Other(TCollection_AsciiString & Disk){
545 // Convert a Trek to VMS syntax
547 static void P2VMS (TCollection_AsciiString & Way){
548 Standard_Integer length = Way.Length();
550 if (length == 0) return;
552 if (Way.Value(1) == '|') // If begin with '|' remove '|'
553 if (Way.Value(1) != '\0')
555 else Way = "000000"; // Si uniquement la racine -> [000000]
558 Way.Insert(1,'|'); // Else insert '|' at beginning if not empty;
560 Way.ChangeAll('|','.');
561 Way.ChangeAll('^','-');
565 // Convert a Trek to MAC syntax
567 static void P2MAC (TCollection_AsciiString & Way){
569 Way.ChangeAll('|',':');
571 l = (int)Way.Length();
572 for (i=1; i <= l; i++) // Replace '^' by "::"
573 if (Way.Value(i) == '^'){
581 // Convert a Trek to UNIX syntax
583 static void P2UNIX (TCollection_AsciiString & Way){
585 Standard_Integer length = Way.Length();
587 if (length == 0) return;
589 // if (Way.Value(length) == '|') // If Finishes with "|" removes it
590 // Way.Trunc(length-1);
592 Way.ChangeAll('|','/');
594 l = (int)Way.Length();
595 for (i=1; i <= l; i++) // Replace '^' by "../"
596 if (Way.Value(i) == '^'){
599 //Way.Insert(i+2,'/');
605 // Convert a Trek to DOS like syntax
607 static void P2DOS (TCollection_AsciiString & Way){
609 Standard_Integer len = Way.Length();
611 if (len == 0) return;
613 if (Way.Value(len) == '|') // If Finishes with "|" removes it
616 Way.ChangeAll('|','\\');
618 l = (int)Way.Length();
619 for (i=1; i <= l; i++) // Replace '^' by ".."
620 if (Way.Value(i) == '^'){
631 // Convert a path to system dependant syntax
633 void OSD_Path::SystemName (TCollection_AsciiString& FullName,
634 const OSD_SysType aType)const{
635 TCollection_AsciiString Way;
636 TCollection_AsciiString pNode;
637 TCollection_AsciiString pDisk;
640 if (aType == OSD_Default) {
653 P2VMS (Way); // Convert path
655 if (myNode.Length()!=0) FullName += myNode; // Append Node
657 if (myUserName.Length()!=0){ // Append User name
659 if (pNode.Length()==0) { // If a user name but no node, catenate "0"
666 FullName += myUserName;
668 if (myPassword.Length()!=0){ // Append password
670 FullName += myPassword;
676 if (pNode.Length()!=0) FullName += "::";
678 if (myDisk.Length()!=0){ // Append Disk
684 if (Way.Length()!=0) // Append VMS path
685 FullName = FullName + "[" + Way + "]" + myName + myExtension;
687 // FullName.UpperCase();
692 case OSD_WindowsNT : // MSDOS-like syntax
694 int length = (int)myDisk.Length();
699 if (myDisk.Length()!=0){
702 (length == 1 && IsAlphabetic(myDisk.Value(1))) || // 'A/a' to 'Z/z'
704 IsAlphabetic(myDisk.Value(1)) &&
705 myDisk.Value(2) == ':') // 'A:' to 'Z:'
706 ) // This is a MSDOS disk syntax
709 if (myDisk.Value(length) != ':') FullName += ":";
711 else // This is an assigned Disk
715 VMSDisk2Other(pDisk);
717 if (Way.Value(1) != '\\') FullName += "\\";
722 FullName = FullName + Way + "\\";
725 FullName += myExtension;
726 // FullName.UpperCase();
730 case OSD_MacOs : // Mackintosh-like syntax
731 if (myDisk.Length()!=0){
737 FullName += myExtension;
742 default : // UNIX-like syntax
745 // user"password"@host:/disk/xxx/xxx/filename
748 if (myUserName.Length()!=0 && myNode.Length()!=0){ // If USER name
749 FullName += myUserName; // appends user name
751 if (myPassword.Length()!=0)
752 FullName = FullName + "\"" + myPassword + "\""; // a password if not empty
754 FullName += "@"; // and character '@'
757 if (myNode.Length()!=0){ // Appends HOST name
762 if (myDisk.Length()!=0) { // Appends Disk name as path
765 VMSDisk2Other(pDisk);
769 // if (FullName.Length()) { // Adds a "/" if necessary
773 if (Way.Length()!=0) { // Appends a path if not empty
777 if (FullName.Length()){
778 if (FullName.Value(FullName.Length()) != '/') {
779 FullName += "/"; // Adds a / if necessary
783 if (myName.Length()){ // Adds the file name
787 if (myExtension.Length()) { // Adds the extension
788 FullName += myExtension;
794 #ifdef TOTO // A reactiver...
796 void OSD_Path::SetSystemName(const TCollection_AsciiString& aDependentName,
797 const OSD_SysType aSysType){
798 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
802 TCollection_AsciiString OSD_Path::Node()const{
807 TCollection_AsciiString OSD_Path::UserName()const{
812 TCollection_AsciiString OSD_Path::Password()const{
817 TCollection_AsciiString OSD_Path::Disk()const{
822 TCollection_AsciiString OSD_Path::Trek()const{
827 // Return extension (suffix) of file/directory name
829 TCollection_AsciiString OSD_Path::Extension()const{
834 TCollection_AsciiString OSD_Path::Name()const{
839 void OSD_Path::SetNode(const TCollection_AsciiString& aName){
840 if (!aName.IsAscii())
841 Standard_ConstructionError::Raise("OSD_Path::SetNode bad name");
848 void OSD_Path::SetUserName(const TCollection_AsciiString& aName){
849 if (!aName.IsAscii())
850 Standard_ConstructionError::Raise("OSD_Path::SetUserName bad name");
857 void OSD_Path::SetPassword(const TCollection_AsciiString& aName){
858 if (!aName.IsAscii())
859 Standard_ConstructionError::Raise("OSD_Path::SetPassword bad name");
866 void OSD_Path::SetDisk(const TCollection_AsciiString& aName){
867 if (!aName.IsAscii())
868 Standard_ConstructionError::Raise("OSD_Path::SetDisk bad name");
875 void OSD_Path::SetTrek(const TCollection_AsciiString& aName){
876 if (!aName.IsAscii())
877 Standard_ConstructionError::Raise("OSD_Path::SetTrek bad name");
884 void OSD_Path::SetName(const TCollection_AsciiString& aName){
885 if (!aName.IsAscii())
886 Standard_ConstructionError::Raise("OSD_Path::SetName bad name");
893 void OSD_Path::SetExtension(const TCollection_AsciiString& aName){
894 if (!aName.IsAscii())
895 Standard_ConstructionError::Raise("OSD_Path::SetExtension bad name");
901 //------------------------------------------------------------------------
902 //------------------- Windows sources for OSD_Path -------------------
903 //------------------------------------------------------------------------
905 #include <Standard_ProgramError.hxx>
910 #define TEST_RAISE( type, arg ) _test_raise ( ( type ), ( arg ) )
912 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
913 static void __fastcall _remove_dup ( TCollection_AsciiString& );
915 OSD_Path :: OSD_Path () {
917 } // end constructor ( 1 )
919 OSD_Path :: OSD_Path (
920 const TCollection_AsciiString& aDependentName,
921 const OSD_SysType aSysType
923 myUNCFlag(Standard_False),
924 mySysDep(OSD_WindowsNT)
927 Standard_Integer i, j, len;
928 static char __drive [ _MAX_DRIVE ];
929 static char __dir [ _MAX_DIR ];
930 static char __trek [ _MAX_DIR ];
931 static char __fname [ _MAX_FNAME ];
932 static char __ext [ _MAX_EXT ];
934 memset(__drive, 0,_MAX_DRIVE);
935 memset(__dir, 0,_MAX_DIR);
936 memset(__trek, 0,_MAX_DIR);
937 memset(__fname, 0,_MAX_FNAME);
938 memset(__ext, 0,_MAX_EXT);
939 Standard_Character chr;
941 TEST_RAISE( aSysType, "OSD_Path" );
943 _splitpath ( aDependentName.ToCString (), __drive, __dir, __fname, __ext );
952 TCollection_AsciiString dir = __dir;
956 for ( i = j = 0; i < len; ++i, ++j ) {
960 if ( chr == '\\' || chr == '/' )
964 else if ( chr == '.'&& (i+1) < len && __dir[i+1] == '.' ) {
975 TCollection_AsciiString trek = __trek;
976 _remove_dup ( trek );
979 } // end constructor ( 2 )
981 OSD_Path :: OSD_Path (
982 const TCollection_AsciiString& aNode,
983 const TCollection_AsciiString& aUsername,
984 const TCollection_AsciiString& aPassword,
985 const TCollection_AsciiString& aDisk,
986 const TCollection_AsciiString& aTrek,
987 const TCollection_AsciiString& aName,
988 const TCollection_AsciiString& anExtension
990 myUNCFlag(Standard_False),
991 mySysDep(OSD_WindowsNT)
994 SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
996 } // end constructor ( 3 )
998 void OSD_Path :: Values (
999 TCollection_AsciiString& aNode,
1000 TCollection_AsciiString& aUsername,
1001 TCollection_AsciiString& aPassword,
1002 TCollection_AsciiString& aDisk,
1003 TCollection_AsciiString& aTrek,
1004 TCollection_AsciiString& aName,
1005 TCollection_AsciiString& anExtension
1009 aUsername = myUserName;
1010 aPassword = myPassword;
1013 if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1014 aTrek += "|" ; // (LD)
1016 anExtension = myExtension;
1018 } // end OSD_Path :: Values
1020 void OSD_Path :: SetValues (
1021 const TCollection_AsciiString& aNode,
1022 const TCollection_AsciiString& aUsername,
1023 const TCollection_AsciiString& aPassword,
1024 const TCollection_AsciiString& aDisk,
1025 const TCollection_AsciiString& aTrek,
1026 const TCollection_AsciiString& aName,
1027 const TCollection_AsciiString& anExtension
1031 myUserName = aUsername;
1032 myPassword = aPassword;
1036 myExtension = anExtension;
1038 if ( myExtension.Length () && myExtension.Value ( 1 ) != '.' )
1040 myExtension.Insert ( 1, '.' );
1042 _remove_dup ( myTrek );
1044 } // end OSD_Path :: SetValues
1046 void OSD_Path :: SystemName (
1047 TCollection_AsciiString& FullName,
1048 const OSD_SysType aType
1051 Standard_Integer i, j;
1052 TCollection_AsciiString fullPath;
1053 static Standard_Character trek [ _MAX_PATH ];
1054 Standard_Character chr;
1056 memset(trek,0,_MAX_PATH);
1058 TEST_RAISE( aType, "SystemName" );
1060 for ( i = j = 1; i <= myTrek.Length () && j <= _MAX_PATH; ++i, ++j ) {
1062 chr = myTrek.Value ( i );
1068 } else if ( chr == '^' && j <= _MAX_PATH - 1 ) {
1070 strcpy(&(trek[(j++) - 1]),"..");
1078 fullPath = myDisk + TCollection_AsciiString(trek);
1080 if ( trek[0] ) fullPath += "/";
1082 fullPath += ( myName + myExtension );
1084 if ( fullPath.Length () > 0 )
1086 FullName = fullPath;
1092 } // end OSD_Path :: SystemName
1094 void OSD_Path :: UpTrek () {
1096 Standard_Integer pos = myTrek.SearchFromEnd ( "|" );
1102 else if ( pos > 1 ) {
1104 while ( myTrek.Value ( pos ) == '|' && pos != 1 ) --pos;
1108 myTrek.Trunc ( pos );
1110 } // end OSD_Path :: UpTrek
1112 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1114 Standard_Integer pos = myTrek.Length ();
1116 if ( aName.Value ( 1 ) != '|' &&
1118 myTrek.Value ( pos ) != '|'
1125 _remove_dup ( myTrek );
1127 } // end OSD_Path :: DownTrek
1129 Standard_Integer OSD_Path :: TrekLength () const {
1131 Standard_Integer i = 1;
1132 Standard_Integer retVal = 0;
1134 if ( myTrek.IsEmpty () || myTrek.Length () == 1 && myTrek.Value ( 1 ) == '|' )
1140 if ( myTrek.Token ( "|", i++ ).IsEmpty () )
1152 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1154 Standard_Integer i, j;
1155 Standard_Boolean flag = Standard_False;
1157 if ( TrekLength () < thewhere )
1161 if ( myTrek.Value ( 1 ) != '|' ) {
1163 flag = Standard_True;
1164 myTrek.Insert ( 1, '|' );
1168 i = myTrek.Location (
1175 j = myTrek.Location (
1182 j = myTrek.Length () + 1;
1184 myTrek.Remove ( i, j - i );
1190 myTrek.Remove ( 1 );
1192 } // end OSD_Path :: RemoveATrek ( 1 )
1194 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1197 Standard_Boolean flag = Standard_False;
1198 TCollection_AsciiString tmp;
1200 if ( myTrek.Value ( 1 ) != '|' ) {
1202 flag = Standard_True;
1203 myTrek.Insert ( 1, '|' );
1211 if ( tmp.Value ( 1 ) != '|' )
1213 tmp.Insert ( 1, '|' );
1215 if ( tmp.Value ( tmp.Length () ) != '|' )
1219 i = myTrek.Search ( tmp );
1223 myTrek.Remove ( i + 1, tmp.Length () - 1 );
1227 myTrek.Remove ( 1 );
1229 if ( myTrek.Value ( myTrek.Length () ) == '|' )
1231 myTrek.Trunc ( myTrek.Length () - 1 );
1233 } // end OSD_Path :: RemoveATrek ( 2 )
1235 TCollection_AsciiString OSD_Path :: TrekValue (
1236 const Standard_Integer thewhere
1239 TCollection_AsciiString retVal;
1240 TCollection_AsciiString trek = myTrek;
1242 if ( trek.Value ( 1 ) != '|' )
1244 trek.Insert ( 1, '|' );
1246 retVal = trek.Token ( "|", thewhere );
1250 } // end OSD_Path :: TrekValue
1252 void OSD_Path :: InsertATrek (
1253 const TCollection_AsciiString& aName,
1254 const Standard_Integer thewhere
1257 Standard_Integer pos;
1258 TCollection_AsciiString tmp = aName;
1259 Standard_Boolean flag = Standard_False;
1261 if ( myTrek.Value ( 1 ) != '|' ) {
1263 flag = Standard_True;
1264 myTrek.Insert ( 1, '|' );
1270 pos = myTrek.Location (
1277 if ( tmp.Value ( tmp.Length () ) != '|' )
1281 myTrek.Insert ( pos + 1, tmp );
1287 myTrek.Remove ( 1 );
1289 if ( myTrek.Value ( myTrek.Length () ) == '|' )
1291 myTrek.Trunc ( myTrek.Length () - 1 );
1293 _remove_dup ( myTrek );
1295 } // end OSD_Path :: InsertATrek
1297 TCollection_AsciiString OSD_Path :: Node () const {
1301 } // end OSD_Path :: Node
1303 TCollection_AsciiString OSD_Path :: UserName () const {
1307 } // end OSD_Path :: UserName
1309 TCollection_AsciiString OSD_Path :: Password () const {
1313 } // end OSD_Path :: Password
1315 TCollection_AsciiString OSD_Path :: Disk () const {
1319 } // end OSD_Path :: Disk
1321 TCollection_AsciiString OSD_Path :: Trek () const {
1323 TCollection_AsciiString retVal ;
1325 if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1326 retVal += "|" ; // (LD)
1329 } // end OSD_Path :: Trek
1331 TCollection_AsciiString OSD_Path :: Name () const {
1335 } // end OSD_Path :: Name
1337 TCollection_AsciiString OSD_Path :: Extension () const {
1341 } // end OSD_Path :: Extension
1343 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1347 } // end OSD_Path :: SetNode
1349 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1353 } // end OSD_Path :: SetUserName
1355 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1359 } // end OSD_Path :: SetPassword
1361 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1365 } // end OSD_Path :: SetDisk
1367 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1371 _remove_dup ( myTrek );
1373 } // end OSD_Path :: SetTrek
1375 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1379 } // end OSD_Path :: SetName
1381 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1383 myExtension = aName;
1385 } // end OSD_Path :: SetExtension
1387 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1389 Standard_Character buff[ 64 ];
1391 if ( type != OSD_Default && type != OSD_WindowsNT ) {
1393 strcpy ( buff, "OSD_Path :: " );
1394 strcat ( buff, str );
1395 strcat ( buff, " (): unknown system type" );
1397 Standard_ProgramError :: Raise ( buff );
1401 } // end _test_raise
1403 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1405 Standard_Integer pos = 1, orgLen, len = str.Length ();
1409 while ( pos <= len ) {
1411 if ( str.Value ( pos ) == '|' && pos != len &&
1412 str.Value ( pos + 1 ) == '|' && pos != 1
1417 while ( pos <= len && str.Value ( pos ) == '|' ) str.Remove ( pos ), --len;
1425 if ( orgLen > 1 && len > 0 && str.Value ( len ) == '|' ) str.Remove ( len );
1428 orgLen = len = str.Length ();
1430 while ( pos <= len ) {
1432 if ( str.Value ( pos ) == '^' && pos != len && str.Value ( pos + 1 ) == '^' ) {
1436 while ( pos <= len && str.Value ( pos ) == '^' ) str.Remove ( pos ), --len;
1444 // if ( orgLen > 1 && len > 0 && str.Value ( len ) == '^' ) str.Remove ( len );
1446 } // end _remove_dup
1448 #endif // Windows sources for OSD_Path
1450 // =======================================================================
1451 // function : Analyse_VMS
1453 // =======================================================================
1454 static Standard_Boolean Analyse_VMS (const TCollection_AsciiString& theName)
1456 if (theName.Search ("/") != -1
1457 || theName.Search ("@") != -1
1458 || theName.Search ("\\") != -1)
1460 return Standard_False;
1463 return Standard_True;
1466 // =======================================================================
1467 // function : Analyse_DOS
1469 // =======================================================================
1470 static Standard_Boolean Analyse_DOS(const TCollection_AsciiString& theName)
1472 if (theName.Search ("/") != -1
1473 || theName.Search (":") != -1
1474 || theName.Search ("*") != -1
1475 || theName.Search ("?") != -1
1476 || theName.Search ("\"") != -1
1477 || theName.Search ("<") != -1
1478 || theName.Search (">") != -1
1479 || theName.Search ("|") != -1)
1481 return Standard_False;
1484 return Standard_True;
1487 // =======================================================================
1488 // function : Analyse_MACOS
1490 // =======================================================================
1491 static Standard_Boolean Analyse_MACOS (const TCollection_AsciiString& theName)
1493 return theName.Search(":") == -1 ? theName.Length() <= 31 : Standard_True;
1496 // =======================================================================
1497 // function : IsValid
1499 // =======================================================================
1500 Standard_Boolean OSD_Path::IsValid (const TCollection_AsciiString& theDependentName,
1501 const OSD_SysType theSysType)
1503 if (theDependentName.Length() == 0)
1505 return Standard_True;
1508 switch (theSysType == OSD_Default ? whereAmI() : theSysType)
1511 return Analyse_VMS (theDependentName);
1514 return Analyse_DOS (theDependentName);
1516 return Analyse_MACOS (theDependentName);
1518 return Standard_True;
1522 // ---------------------------------------------------------------------------
1524 // Elimine les separateurs inutiles
1527 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1529 Standard_Integer i, j, len,start = 1 ;
1531 len = aString.Length() ;
1533 if (len > 1 && aString.Value(1) == '/' && aString.Value(2) == '/')
1536 for (i = j = start ; j <= len ; i++,j++) {
1537 Standard_Character c = aString.Value(j) ;
1538 aString.SetValue(i,c) ;
1540 while(j < len && aString.Value(j+1) == '/') j++ ;
1543 if (aString.Value(len) == '/') len-- ;
1544 aString.Trunc(len) ;
1548 // ---------------------------------------------------------------------------
1550 TCollection_AsciiString OSD_Path::RelativePath(
1551 const TCollection_AsciiString& aDirPath,
1552 const TCollection_AsciiString& aAbsFilePath)
1554 TCollection_AsciiString EmptyString = "" ;
1555 TCollection_AsciiString FilePath ;
1556 Standard_Integer len ;
1557 Standard_Integer i, n ;
1558 Standard_Boolean Wnt = 0 ;
1560 FilePath = aAbsFilePath ;
1562 if (aDirPath.Search(":") == 2) { // Cas WNT
1564 if (FilePath.Search(":") != 2 ||
1565 UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1567 return EmptyString ;
1569 FilePath.ChangeAll('\\','/') ;
1570 if (FilePath.Search("/") != 3 )
1571 return EmptyString ;
1574 if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1575 return EmptyString ;
1578 // Eliminer les separateurs redondants
1580 len = RemoveExtraSeparator(FilePath) ;
1584 return EmptyString ;
1585 FilePath = FilePath.SubString(2,len) ;
1587 TCollection_AsciiString DirToken, FileToken ;
1588 Standard_Boolean Sibling = 0 ;
1590 for (i = n = 1 ;; n++) {
1591 DirToken = aDirPath.Token("/\\",n) ;
1592 if (DirToken.IsEmpty())
1596 len = FilePath.Length() ;
1597 i = FilePath.Search("/") ;
1600 return EmptyString ;
1602 FileToken = FilePath.SubString(1,i-1) ;
1604 DirToken.UpperCase() ;
1605 FileToken.UpperCase() ;
1607 if (DirToken == FileToken) {
1608 FilePath = FilePath.SubString(i+1,len) ;
1612 else if (DirToken == FilePath)
1613 return EmptyString ;
1618 FilePath.Insert(1,"../") ;
1622 // ---------------------------------------------------------------------------
1624 TCollection_AsciiString OSD_Path::AbsolutePath(
1625 const TCollection_AsciiString& aDirPath,
1626 const TCollection_AsciiString& aRelFilePath)
1628 TCollection_AsciiString EmptyString = "" ;
1629 if (aRelFilePath.Search("/") == 1 || aRelFilePath.Search(":") == 2)
1630 return aRelFilePath ;
1631 TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
1632 Standard_Integer i,len ;
1634 if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1635 return EmptyString ;
1637 if ( DirPath.Search(":") == 2)
1638 DirPath.ChangeAll('\\','/') ;
1639 RelFilePath.ChangeAll('\\','/') ;
1640 RemoveExtraSeparator(DirPath) ;
1641 len = RemoveExtraSeparator(RelFilePath) ;
1643 while (RelFilePath.Search("../") == 1) {
1645 return EmptyString ;
1646 RelFilePath = RelFilePath.SubString(4,len) ;
1648 if (DirPath.IsEmpty())
1649 return EmptyString ;
1650 i = DirPath.SearchFromEnd("/") ;
1652 return EmptyString ;
1653 DirPath.Trunc(i-1) ;
1656 DirPath += RelFilePath ;
1660 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1661 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1665 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1666 Standard_Boolean LocateExecFile(OSD_Path& )
1668 return Standard_False ;