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.
17 #include <Standard_NumericError.hxx>
18 #include <Standard_NullObject.hxx>
19 #include <Standard_ProgramError.hxx>
20 #include <Standard_ConstructionError.hxx>
21 #include <OSD_Path.ixx>
22 #include <OSD_WhoAmI.hxx>
24 static OSD_SysType whereAmI(){
25 #if defined(__digital__) || defined(__FreeBSD__) || defined(SUNOS) || defined(__APPLE__)
28 #elif defined(sgi) || defined(IRIX) || defined(__sun) || defined(SOLARIS) || defined(__sco__) || defined(__hpux) || defined(HPUX)
29 return OSD_UnixSystemV;
31 #elif defined(__osf__) || defined(DECOSF1)
40 #elif defined(__CYGWIN32_) || defined(__MINGW32__)
43 #elif defined(vax) || defined(__vms)
46 #elif defined(__linux__) || defined(LIN)
47 return OSD_LinuxREDHAT;
49 #elif defined(_AIX) || defined(AIX)
55 cout << info.sysname << endl;
56 cout << info.nodename << endl;
57 cout << info.release << endl;
58 cout << info.version << endl;
59 cout << info.machine << endl;
70 static void VmsExtract(const TCollection_AsciiString& what,
71 TCollection_AsciiString& node,
72 TCollection_AsciiString& username,
73 TCollection_AsciiString& password,
74 TCollection_AsciiString& disk,
75 TCollection_AsciiString& trek,
76 TCollection_AsciiString& name,
77 TCollection_AsciiString& ext){
79 TCollection_AsciiString buffer;
84 if (buffer.Search("\"") != -1){ // a username to extract
86 if (buffer.Value(1) != '"') { // Begins with Node
87 node = buffer.Token("\"");
88 buffer.Remove(1,node.Length());
92 username = buffer.Token("\" ");
93 buffer.Remove(1,username.Length()+2); // Removes <<"username ' ' or '"' >>
95 if (buffer.Search("\"") != -1){ // a password to extract
96 password = buffer.Token("\"");
97 buffer.Remove(1,password.Length()+1); // removes <<password">>
100 // If we found a node then we must find "::"
101 if (buffer.Search("::") != -1)
102 buffer.Remove(1,2); // Removes <<::>>
104 else // No name or password
105 if (buffer.Search("::") != -1){ // a node to extract
106 node = buffer.Token(":");
107 buffer.Remove(1,node.Length()+2); // Removes <<node::>
110 if (buffer.Search(":") != -1){ // a disk to extract
111 disk = buffer.Token(":");
112 buffer.Remove(1,disk.Length()+1); // Removes <<disk:>>
118 if (buffer.Search("[") != -1){ // There is atrek to extract
119 trek = buffer.Token("[]");
121 if (trek.Value(1) == '.') trek.Remove(1,1); // Removes first '.'
122 else trek.Insert(1,'|'); // Add root
124 trek.ChangeAll('.','|'); // Translates to portable syntax
125 trek.ChangeAll('-','^');
127 pos = trek.Search("000000");
129 trek.Remove(pos,6); // on VMS [000000] is the root
130 if (trek.Search("||") != -1) trek.Remove(1,1); // When [000000.xxx] -> ||xxx
133 name = buffer.Token("]",2);
137 if (name.Search(".") != -1){
138 ext = name.Token(".",2);
140 name.Remove(name.Search("."),ext.Length());
147 //=======================================================================
148 //function : UnixExtract
150 //=======================================================================
151 static void UnixExtract(const TCollection_AsciiString& what,
152 TCollection_AsciiString& node,
153 TCollection_AsciiString& username,
154 TCollection_AsciiString& password,
155 TCollection_AsciiString& trek,
156 TCollection_AsciiString& name,
157 TCollection_AsciiString& ext){
159 Standard_Integer pos;
160 TCollection_AsciiString buffer; // To manipulate 'what' without modifying it
162 Standard_PCharacter p;
165 #ifdef TOTO // Username, password and node are no longer given in the string (LD)
167 if (buffer.Search("@") != -1){ // There is a name to extract
168 username = buffer.Token("\"@");
169 buffer.Remove(1,username.Length()+1); // Removes << user@ >>
171 if (buffer.Search("\"") != -1){ // There is a password to extract
172 password = buffer.Token("\"");
173 buffer.Remove(1,password.Length()+2); // Removes << "password" >>
182 #endif // node must be given (for DBT, DM) (ADN 29/8/96)
184 if (buffer.Search(":/") != -1){ // There is a node to extract
185 node = buffer.Token(":/");
186 buffer.Remove(1,node.Length()+1); // Removes << node: >>
196 trek.ChangeAll('/','|'); // Translates to portable syntax
198 pos = trek.SearchFromEnd("|"); // Extract name
200 p = (Standard_PCharacter)trek.ToCString();
202 if(name.Length()) trek.Remove(pos+1,name.Length());
204 else { // No '|' means no trek but a name
209 pos = trek.Search("..");
210 while (pos != -1){ // Changes every ".." by '^'
211 trek.SetValue(pos,'^');
212 trek.Remove(pos+1,1);
213 pos = trek.Search("..");
216 pos = name.SearchFromEnd(".") ; // LD : debug
217 if (pos != -1) // There is an extension to extract
218 ext = name.Split(pos - 1) ;
221 // if (name.Search(".") != -1){ // There is an extension to extract
222 // if ( name.Value(1) == '.' ) {
227 // ext = name.Token(".",2);
228 // ext.Insert(1,'.'); // Prepends 'dot'
229 // pos = name.Search("."); // Removes extension from buffer
231 // name.Remove(pos,ext.Length());
238 //=======================================================================
239 //function : DosExtract
241 //=======================================================================
242 static void DosExtract(const TCollection_AsciiString& what,
243 TCollection_AsciiString& disk,
244 TCollection_AsciiString& trek,
245 TCollection_AsciiString& name,
246 TCollection_AsciiString& ext){
248 TCollection_AsciiString buffer;
249 Standard_Integer pos;
250 Standard_PCharacter p;
254 if (buffer.Search(":") != -1){ // There is a disk to extract
255 disk = buffer.Token(":");
257 buffer.Remove(1,disk.Length()); // Removes <<disk:>>
260 if (buffer.Search(".") != -1){ // There is an extension to extract
261 ext = buffer.Token(".",2);
262 ext.Insert(1,'.'); // Prepends 'dot'
263 pos = buffer.Search("."); // Removes extension from buffer
265 buffer.Remove(pos,ext.Length());
270 trek.ChangeAll('\\','|');
272 pos = trek.Search("..");
273 while (pos != -1){ // Changes every ".." by '^'
274 trek.SetValue(pos,'^');
275 trek.Remove(pos+1,1);
276 pos = trek.Search("..");
279 pos = trek.SearchFromEnd("|"); // Extract name
281 p = (Standard_PCharacter)trek.ToCString();
283 trek.Remove(trek.Search(name),name.Length());
285 else { // No '|' means no trek but a name
292 //=======================================================================
293 //function : MacExtract
295 //=======================================================================
296 static void MacExtract(const TCollection_AsciiString& what,
297 TCollection_AsciiString& ,
298 TCollection_AsciiString& trek,
299 TCollection_AsciiString& name,
300 TCollection_AsciiString& ){
302 Standard_Integer pos;
303 Standard_PCharacter p;
305 // I don't know how to distingish a disk from a trek !
309 pos = trek.Search("::");
310 while (pos != -1){ // Changes every "::" by '^'
311 trek.SetValue(pos,'^');
312 trek.Remove(pos+1,1);
313 pos = trek.Search("::");
316 trek.ChangeAll(':','|'); // Translates to portable syntax
318 pos = trek.SearchFromEnd("|"); // Extract name
320 p = (Standard_PCharacter)trek.ToCString();
322 trek.Remove(trek.Search(name),name.Length());
324 else { // No '|' means no trek but a name
331 OSD_Path::OSD_Path(const TCollection_AsciiString& aDependentName,
332 const OSD_SysType aSysType){
336 if (!IsValid(aDependentName,aSysType))
337 Standard_ProgramError::Raise("OSD_Path::OSD_Path : Invalid dependent name");
340 // Standard_Integer i,l;
342 if (aSysType == OSD_Default) {
350 VmsExtract(aDependentName,myNode,myUserName,myPassword,myDisk,myTrek,myName,myExtension);
352 case OSD_LinuxREDHAT:
354 case OSD_UnixSystemV:
357 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
361 DosExtract(aDependentName,myDisk,myTrek,myName,myExtension);
364 MacExtract(aDependentName,myDisk,myTrek,myName,myExtension);
368 cout << " WARNING WARNING : OSD Path for an Unknown SYSTEM : " << (Standard_Integer)todo << endl;
376 OSD_Path::OSD_Path(const TCollection_AsciiString& Nod,
377 const TCollection_AsciiString& UsrNm,
378 const TCollection_AsciiString& Passwd,
379 const TCollection_AsciiString& Dsk,
380 const TCollection_AsciiString& Trk,
381 const TCollection_AsciiString& Nam,
382 const TCollection_AsciiString& ext){
386 SetValues ( Nod, UsrNm, Passwd, Dsk, Trk, Nam, ext);
392 void OSD_Path::Values(TCollection_AsciiString& Nod,
393 TCollection_AsciiString& UsrNm,
394 TCollection_AsciiString& Passwd,
395 TCollection_AsciiString& Dsk,
396 TCollection_AsciiString& Trk,
397 TCollection_AsciiString& Nam,
398 TCollection_AsciiString& ext)const{
410 void OSD_Path::SetValues(const TCollection_AsciiString& Nod,
411 const TCollection_AsciiString& UsrNm,
412 const TCollection_AsciiString& Passwd,
413 const TCollection_AsciiString& Dsk,
414 const TCollection_AsciiString& Trk,
415 const TCollection_AsciiString& Nam,
416 const TCollection_AsciiString& ext){
419 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Node");
420 if (!UsrNm.IsAscii())
421 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : User Name");
423 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Disk");
425 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Trek");
427 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Name");
429 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Extension");
441 static Standard_Boolean Analyse_VMS(const TCollection_AsciiString& name){
442 if (name.Search("/") != -1)
443 return(Standard_False);
444 if (name.Search("@") != -1)
445 return(Standard_False);
446 if (name.Search("\\") != -1)
447 return(Standard_False);
450 return Standard_True;
453 static Standard_Boolean Analyse_DOS(const TCollection_AsciiString& name){
455 // if (name.Search("$") != -1)
456 // return(Standard_False);
457 // if (name.Search(" ") != -1)
458 // return(Standard_False);
460 if (name.Search("/") != -1)
461 return(Standard_False);
462 if (name.Search(":") != -1)
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(".") != name.SearchFromEnd("."))
469 return(Standard_False);
470 if (name.Search("\"") != -1)
471 return(Standard_False);
472 if (name.Search("<") != -1)
473 return(Standard_False);
474 if (name.Search(">") != -1)
475 return(Standard_False);
476 if (name.Search("|") != -1)
477 return(Standard_False);
479 return Standard_True;
480 // Rajouter les tests sur les noms de 8 caracteres au maximum et
481 // l'extension de 3 caracteres.
484 static Standard_Boolean Analyse_MACOS(const TCollection_AsciiString& name){
485 Standard_Integer i = name.Search(":");
486 Standard_Integer l = name.Length();
490 return(Standard_False);
492 return(Standard_True);
494 return(Standard_True);
497 static Standard_Boolean Analyse_UNIX(const TCollection_AsciiString& /*name*/)
499 // if (name.Search("$") != -1) Unix filename can have a "$" (LD)
500 // return(Standard_False);
502 // all characters are allowed in UNIX file name, except null '\0' and slash '/'
504 // if (name.Search("[") != -1)
505 // return(Standard_False);
506 // if (name.Search("]") != -1)
507 // return(Standard_False);
508 // if (name.Search("\\") != -1)
509 // return(Standard_False);
510 // if (name.Search(" ") != -1)
511 // return(Standard_False);
513 return(Standard_True);
521 Standard_Boolean OSD_Path::IsValid(const TCollection_AsciiString& aDependentName,
522 const OSD_SysType aSysType)const{
523 if (aDependentName.Length()==0) return(Standard_True);
524 if (!aDependentName.IsAscii()) return(Standard_False);
527 if (aSysType == OSD_Default) provSys = SysDep;
528 else provSys = aSysType;
532 return(Analyse_VMS(aDependentName));
535 return(Analyse_DOS(aDependentName));
537 return(Analyse_MACOS(aDependentName));
539 return(Analyse_UNIX(aDependentName));
545 void OSD_Path::UpTrek(){
546 Standard_Integer length=TrekLength();
548 if (length == 0) return;
550 Standard_Integer awhere,aHowmany;
551 TCollection_AsciiString tok;
553 tok = myTrek.Token("|",length);
554 awhere = myTrek.SearchFromEnd(tok);
555 aHowmany = tok.Length();
556 myTrek.Remove(awhere,aHowmany);
558 awhere = myTrek.Search("||"); // Searches leaving "||"
560 myTrek.Remove(awhere);
564 void OSD_Path::DownTrek(const TCollection_AsciiString& aName){
566 // Pb signale par GG : pour ne pas avoir "||" ;
567 if ( aName.ToCString()[ aName.Length() - 1 ] != '|' )
572 Standard_Integer OSD_Path::TrekLength()const{
573 Standard_Integer cpt=0;
575 while (myTrek.Token("|",cpt+1) != "") // Counts token separated by '|'
582 void OSD_Path::RemoveATrek(const Standard_Integer thewhere){
583 Standard_Integer length=TrekLength();
585 if (length <= 0 || thewhere > length)
586 Standard_NumericError::Raise("OSD_Path::RemoveATrek : where has an invalid value");
588 Standard_Integer posit,aHowmany;
589 TCollection_AsciiString tok;
591 tok = myTrek.Token("|",thewhere);
592 posit = myTrek.Search(tok);
593 aHowmany = tok.Length();
594 myTrek.Remove(posit,aHowmany);
596 posit = myTrek.Search("||"); // Searches leaving "||"
598 myTrek.Remove(posit);
602 void OSD_Path::RemoveATrek(const TCollection_AsciiString& aName){
603 Standard_Integer length=TrekLength();
605 if (length == 0) return;
607 Standard_Integer awhere;
609 awhere = myTrek.Search(aName);
611 myTrek.Remove(awhere,aName.Length());
613 awhere = myTrek.Search("||"); // Searches leaving "||"
615 myTrek.Remove(awhere);
620 TCollection_AsciiString OSD_Path::TrekValue(const Standard_Integer thewhere)const{
621 TCollection_AsciiString result=myTrek.Token("|",thewhere);
624 Standard_NumericError::Raise("OSD_Path::TrekValue : where is invalid");
629 void OSD_Path::InsertATrek(const TCollection_AsciiString& aName,
630 const Standard_Integer thewhere){
631 Standard_Integer length=TrekLength();
633 if (thewhere <= 0 || thewhere > length)
634 Standard_NumericError::Raise("OSD_Path::InsertATrek : where has an invalid value");
636 TCollection_AsciiString tok=myTrek.Token("|",thewhere);
637 Standard_Integer wwhere = myTrek.Search(tok);
638 TCollection_AsciiString what = aName;
641 myTrek.Insert(wwhere,what);
645 // The 4 following methods will be PUBLIC in the future
647 // Converts a VMS disk to other system syntax
649 static void VMSDisk2Other(TCollection_AsciiString & Disk){
654 // Convert a Trek to VMS syntax
656 static void P2VMS (TCollection_AsciiString & Way){
657 Standard_Integer length = Way.Length();
659 if (length == 0) return;
661 if (Way.Value(1) == '|') // If begin with '|' remove '|'
662 if (Way.Value(1) != '\0')
664 else Way = "000000"; // Si uniquement la racine -> [000000]
667 Way.Insert(1,'|'); // Else insert '|' at beginning if not empty;
669 Way.ChangeAll('|','.');
670 Way.ChangeAll('^','-');
674 // Convert a Trek to MAC syntax
676 static void P2MAC (TCollection_AsciiString & Way){
678 Way.ChangeAll('|',':');
680 l = (int)Way.Length();
681 for (i=1; i <= l; i++) // Replace '^' by "::"
682 if (Way.Value(i) == '^'){
690 // Convert a Trek to UNIX syntax
692 static void P2UNIX (TCollection_AsciiString & Way){
694 Standard_Integer length = Way.Length();
696 if (length == 0) return;
698 // if (Way.Value(length) == '|') // If Finishes with "|" removes it
699 // Way.Trunc(length-1);
701 Way.ChangeAll('|','/');
703 l = (int)Way.Length();
704 for (i=1; i <= l; i++) // Replace '^' by "../"
705 if (Way.Value(i) == '^'){
708 //Way.Insert(i+2,'/');
714 // Convert a Trek to DOS like syntax
716 static void P2DOS (TCollection_AsciiString & Way){
718 Standard_Integer len = Way.Length();
720 if (len == 0) return;
722 if (Way.Value(len) == '|') // If Finishes with "|" removes it
725 Way.ChangeAll('|','\\');
727 l = (int)Way.Length();
728 for (i=1; i <= l; i++) // Replace '^' by ".."
729 if (Way.Value(i) == '^'){
740 // Convert a path to system dependant syntax
742 void OSD_Path::SystemName (TCollection_AsciiString& FullName,
743 const OSD_SysType aType)const{
744 TCollection_AsciiString Way;
745 TCollection_AsciiString pNode;
746 TCollection_AsciiString pDisk;
749 if (aType == OSD_Default) {
762 P2VMS (Way); // Convert path
764 if (myNode.Length()!=0) FullName += myNode; // Append Node
766 if (myUserName.Length()!=0){ // Append User name
768 if (pNode.Length()==0) { // If a user name but no node, catenate "0"
775 FullName += myUserName;
777 if (myPassword.Length()!=0){ // Append password
779 FullName += myPassword;
785 if (pNode.Length()!=0) FullName += "::";
787 if (myDisk.Length()!=0){ // Append Disk
793 if (Way.Length()!=0) // Append VMS path
794 FullName = FullName + "[" + Way + "]" + myName + myExtension;
796 // FullName.UpperCase();
801 case OSD_WindowsNT : // MSDOS-like syntax
803 int length = (int)myDisk.Length();
808 if (myDisk.Length()!=0){
811 (length == 1 && IsAlphabetic(myDisk.Value(1))) || // 'A/a' to 'Z/z'
813 IsAlphabetic(myDisk.Value(1)) &&
814 myDisk.Value(2) == ':') // 'A:' to 'Z:'
815 ) // This is a MSDOS disk syntax
818 if (myDisk.Value(length) != ':') FullName += ":";
820 else // This is an assigned Disk
824 VMSDisk2Other(pDisk);
826 if (Way.Value(1) != '\\') FullName += "\\";
831 FullName = FullName + Way + "\\";
834 FullName += myExtension;
835 // FullName.UpperCase();
839 case OSD_MacOs : // Mackintosh-like syntax
840 if (myDisk.Length()!=0){
846 FullName += myExtension;
851 default : // UNIX-like syntax
854 // user"password"@host:/disk/xxx/xxx/filename
857 if (myUserName.Length()!=0 && myNode.Length()!=0){ // If USER name
858 FullName += myUserName; // appends user name
860 if (myPassword.Length()!=0)
861 FullName = FullName + "\"" + myPassword + "\""; // a password if not empty
863 FullName += "@"; // and character '@'
866 if (myNode.Length()!=0){ // Appends HOST name
871 if (myDisk.Length()!=0) { // Appends Disk name as path
874 VMSDisk2Other(pDisk);
878 // if (FullName.Length()) { // Adds a "/" if necessary
882 if (Way.Length()!=0) { // Appends a path if not empty
886 if (FullName.Length()){
887 if (FullName.Value(FullName.Length()) != '/') {
888 FullName += "/"; // Adds a / if necessary
892 if (myName.Length()){ // Adds the file name
896 if (myExtension.Length()) { // Adds the extension
897 FullName += myExtension;
903 #ifdef TOTO // A reactiver...
905 void OSD_Path::SetSystemName(const TCollection_AsciiString& aDependentName,
906 const OSD_SysType aSysType){
907 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
911 TCollection_AsciiString OSD_Path::Node()const{
916 TCollection_AsciiString OSD_Path::UserName()const{
921 TCollection_AsciiString OSD_Path::Password()const{
926 TCollection_AsciiString OSD_Path::Disk()const{
931 TCollection_AsciiString OSD_Path::Trek()const{
936 // Return extension (suffix) of file/directory name
938 TCollection_AsciiString OSD_Path::Extension()const{
943 TCollection_AsciiString OSD_Path::Name()const{
948 void OSD_Path::SetNode(const TCollection_AsciiString& aName){
949 if (!aName.IsAscii())
950 Standard_ConstructionError::Raise("OSD_Path::SetNode bad name");
957 void OSD_Path::SetUserName(const TCollection_AsciiString& aName){
958 if (!aName.IsAscii())
959 Standard_ConstructionError::Raise("OSD_Path::SetUserName bad name");
966 void OSD_Path::SetPassword(const TCollection_AsciiString& aName){
967 if (!aName.IsAscii())
968 Standard_ConstructionError::Raise("OSD_Path::SetPassword bad name");
975 void OSD_Path::SetDisk(const TCollection_AsciiString& aName){
976 if (!aName.IsAscii())
977 Standard_ConstructionError::Raise("OSD_Path::SetDisk bad name");
984 void OSD_Path::SetTrek(const TCollection_AsciiString& aName){
985 if (!aName.IsAscii())
986 Standard_ConstructionError::Raise("OSD_Path::SetTrek bad name");
993 void OSD_Path::SetName(const TCollection_AsciiString& aName){
994 if (!aName.IsAscii())
995 Standard_ConstructionError::Raise("OSD_Path::SetName bad name");
1002 void OSD_Path::SetExtension(const TCollection_AsciiString& aName){
1003 if (!aName.IsAscii())
1004 Standard_ConstructionError::Raise("OSD_Path::SetExtension bad name");
1005 myExtension = aName;
1010 //------------------------------------------------------------------------
1011 //------------------- Windows NT sources for OSD_Path -------------------
1012 //------------------------------------------------------------------------
1014 #include <OSD_Path.hxx>
1015 #include <Standard_ProgramError.hxx>
1017 #include <windows.h>
1021 #define TEST_RAISE( type, arg ) _test_raise ( ( type ), ( arg ) )
1023 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
1024 static void __fastcall _remove_dup ( TCollection_AsciiString& );
1026 OSD_Path :: OSD_Path () {
1028 } // end constructor ( 1 )
1030 OSD_Path :: OSD_Path (
1031 const TCollection_AsciiString& aDependentName,
1032 const OSD_SysType aSysType
1034 myUNCFlag(Standard_False),
1035 SysDep(OSD_WindowsNT)
1038 Standard_Integer i, j, len;
1039 static char __drive [ _MAX_DRIVE ];
1040 static char __dir [ _MAX_DIR ];
1041 static char __trek [ _MAX_DIR ];
1042 static char __fname [ _MAX_FNAME ];
1043 static char __ext [ _MAX_EXT ];
1045 memset(__drive, 0,_MAX_DRIVE);
1046 memset(__dir, 0,_MAX_DIR);
1047 memset(__trek, 0,_MAX_DIR);
1048 memset(__fname, 0,_MAX_FNAME);
1049 memset(__ext, 0,_MAX_EXT);
1050 Standard_Character chr;
1052 TEST_RAISE( aSysType, TEXT( "OSD_Path" ) );
1054 _splitpath ( aDependentName.ToCString (), __drive, __dir, __fname, __ext );
1060 myExtension = __ext;
1063 TCollection_AsciiString dir = __dir;
1064 len = dir.UsefullLength ();
1067 for ( i = j = 0; i < len; ++i, ++j ) {
1071 if ( chr == TEXT( '\\' ) || chr == TEXT( '/' ) )
1073 __trek[j] = TEXT( '|' );
1075 else if ( chr == TEXT( '.' )&& (i+1) < len && __dir[i+1] == TEXT( '.' ) ) {
1077 __trek[j] = TEXT( '^' );
1086 TCollection_AsciiString trek = __trek;
1087 _remove_dup ( trek );
1090 } // end constructor ( 2 )
1092 OSD_Path :: OSD_Path (
1093 const TCollection_AsciiString& aNode,
1094 const TCollection_AsciiString& aUsername,
1095 const TCollection_AsciiString& aPassword,
1096 const TCollection_AsciiString& aDisk,
1097 const TCollection_AsciiString& aTrek,
1098 const TCollection_AsciiString& aName,
1099 const TCollection_AsciiString& anExtension
1101 myUNCFlag(Standard_False),
1102 SysDep(OSD_WindowsNT)
1105 SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
1107 } // end constructor ( 3 )
1109 void OSD_Path :: Values (
1110 TCollection_AsciiString& aNode,
1111 TCollection_AsciiString& aUsername,
1112 TCollection_AsciiString& aPassword,
1113 TCollection_AsciiString& aDisk,
1114 TCollection_AsciiString& aTrek,
1115 TCollection_AsciiString& aName,
1116 TCollection_AsciiString& anExtension
1120 aUsername = myUserName;
1121 aPassword = myPassword;
1124 if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1125 aTrek += "|" ; // (LD)
1127 anExtension = myExtension;
1129 } // end OSD_Path :: Values
1131 void OSD_Path :: SetValues (
1132 const TCollection_AsciiString& aNode,
1133 const TCollection_AsciiString& aUsername,
1134 const TCollection_AsciiString& aPassword,
1135 const TCollection_AsciiString& aDisk,
1136 const TCollection_AsciiString& aTrek,
1137 const TCollection_AsciiString& aName,
1138 const TCollection_AsciiString& anExtension
1142 myUserName = aUsername;
1143 myPassword = aPassword;
1147 myExtension = anExtension;
1149 if ( myExtension.UsefullLength () && myExtension.Value ( 1 ) != TEXT( '.' ) )
1151 myExtension.Insert ( 1, TEXT( '.' ) );
1153 _remove_dup ( myTrek );
1155 } // end OSD_Path :: SetValues
1157 void OSD_Path :: SystemName (
1158 TCollection_AsciiString& FullName,
1159 const OSD_SysType aType
1162 Standard_Integer i, j;
1163 TCollection_AsciiString fullPath;
1164 static Standard_Character trek [ _MAX_PATH ];
1165 Standard_Character chr;
1167 memset(trek,0,_MAX_PATH);
1169 TEST_RAISE( aType, TEXT( "SystemName" ) );
1171 for ( i = j = 1; i <= myTrek.UsefullLength () && j <= _MAX_PATH; ++i, ++j ) {
1173 chr = myTrek.Value ( i );
1175 if ( chr == TEXT( '|' ) ) {
1177 trek[j-1] = TEXT( '/' );
1179 } else if ( chr == TEXT( '^' ) && j <= _MAX_PATH - 1 ) {
1181 strcpy(&(trek[(j++) - 1]),TEXT( ".." ));
1189 fullPath = myDisk + TCollection_AsciiString(trek);
1191 if ( trek[0] ) fullPath += TEXT( "/" );
1193 fullPath += ( myName + myExtension );
1195 if ( fullPath.UsefullLength () > 0 )
1197 FullName = fullPath;
1203 } // end OSD_Path :: SystemName
1205 Standard_Boolean OSD_Path :: IsValid (
1206 const TCollection_AsciiString& /*aDependentName*/,
1207 const OSD_SysType aSysType
1210 TEST_RAISE( aSysType, TEXT( "IsValid" ) );
1212 return Standard_True;
1214 } // end OSD_Path :: IsValid
1216 void OSD_Path :: UpTrek () {
1218 Standard_Integer pos = myTrek.SearchFromEnd ( TEXT( "|" ) );
1224 else if ( pos > 1 ) {
1226 while ( myTrek.Value ( pos ) == TEXT( '|' ) && pos != 1 ) --pos;
1230 myTrek.Trunc ( pos );
1232 } // end OSD_Path :: UpTrek
1234 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1236 Standard_Integer pos = myTrek.UsefullLength ();
1238 if ( aName.Value ( 1 ) != TEXT( '|' ) &&
1240 myTrek.Value ( pos ) != TEXT( '|' )
1243 myTrek += TEXT( "|" );
1247 _remove_dup ( myTrek );
1249 } // end OSD_Path :: DownTrek
1251 Standard_Integer OSD_Path :: TrekLength () const {
1253 Standard_Integer i = 1;
1254 Standard_Integer retVal = 0;
1256 if ( myTrek.IsEmpty () || myTrek.UsefullLength () == 1 && myTrek.Value ( 1 ) == TEXT( '|' ) )
1262 if ( myTrek.Token ( TEXT( "|" ), i++ ).IsEmpty () )
1274 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1276 Standard_Integer i, j;
1277 Standard_Boolean flag = Standard_False;
1279 if ( TrekLength () < thewhere )
1283 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1285 flag = Standard_True;
1286 myTrek.Insert ( 1, TEXT( '|' ) );
1290 i = myTrek.Location (
1291 thewhere, TEXT( '|' ),
1292 1, myTrek.UsefullLength ()
1297 j = myTrek.Location (
1298 thewhere + 1, TEXT( '|' ),
1299 1, myTrek.UsefullLength ()
1304 j = myTrek.UsefullLength () + 1;
1306 myTrek.Remove ( i, j - i );
1312 myTrek.Remove ( 1 );
1314 } // end OSD_Path :: RemoveATrek ( 1 )
1316 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1319 Standard_Boolean flag = Standard_False;
1320 TCollection_AsciiString tmp;
1322 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1324 flag = Standard_True;
1325 myTrek.Insert ( 1, TEXT( '|' ) );
1329 myTrek += TEXT( '|' );
1333 if ( tmp.Value ( 1 ) != TEXT( '|' ) )
1335 tmp.Insert ( 1, TEXT( '|' ) );
1337 if ( tmp.Value ( tmp.UsefullLength () ) != TEXT( '|' ) )
1341 i = myTrek.Search ( tmp );
1345 myTrek.Remove ( i + 1, tmp.UsefullLength () - 1 );
1349 myTrek.Remove ( 1 );
1351 if ( myTrek.Value ( myTrek.UsefullLength () ) == TEXT( '|' ) )
1353 myTrek.Trunc ( myTrek.UsefullLength () - 1 );
1355 } // end OSD_Path :: RemoveATrek ( 2 )
1357 TCollection_AsciiString OSD_Path :: TrekValue (
1358 const Standard_Integer thewhere
1361 TCollection_AsciiString retVal;
1362 TCollection_AsciiString trek = myTrek;
1364 if ( trek.Value ( 1 ) != TEXT( '|' ) )
1366 trek.Insert ( 1, TEXT( '|' ) );
1368 retVal = trek.Token ( TEXT( "|" ), thewhere );
1372 } // end OSD_Path :: TrekValue
1374 void OSD_Path :: InsertATrek (
1375 const TCollection_AsciiString& aName,
1376 const Standard_Integer thewhere
1379 Standard_Integer pos;
1380 TCollection_AsciiString tmp = aName;
1381 Standard_Boolean flag = Standard_False;
1383 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1385 flag = Standard_True;
1386 myTrek.Insert ( 1, TEXT( '|' ) );
1390 myTrek += TEXT( '|' );
1392 pos = myTrek.Location (
1393 thewhere, TEXT( '|' ),
1394 1, myTrek.UsefullLength ()
1399 if ( tmp.Value ( tmp.UsefullLength () ) != TEXT( '|' ) )
1403 myTrek.Insert ( pos + 1, tmp );
1409 myTrek.Remove ( 1 );
1411 if ( myTrek.Value ( myTrek.UsefullLength () ) == TEXT( '|' ) )
1413 myTrek.Trunc ( myTrek.UsefullLength () - 1 );
1415 _remove_dup ( myTrek );
1417 } // end OSD_Path :: InsertATrek
1419 TCollection_AsciiString OSD_Path :: Node () const {
1423 } // end OSD_Path :: Node
1425 TCollection_AsciiString OSD_Path :: UserName () const {
1429 } // end OSD_Path :: UserName
1431 TCollection_AsciiString OSD_Path :: Password () const {
1435 } // end OSD_Path :: Password
1437 TCollection_AsciiString OSD_Path :: Disk () const {
1441 } // end OSD_Path :: Disk
1443 TCollection_AsciiString OSD_Path :: Trek () const {
1445 TCollection_AsciiString retVal ;
1447 if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1448 retVal += "|" ; // (LD)
1451 } // end OSD_Path :: Trek
1453 TCollection_AsciiString OSD_Path :: Name () const {
1457 } // end OSD_Path :: Name
1459 TCollection_AsciiString OSD_Path :: Extension () const {
1463 } // end OSD_Path :: Extension
1465 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1469 } // end OSD_Path :: SetNode
1471 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1475 } // end OSD_Path :: SetUserName
1477 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1481 } // end OSD_Path :: SetPassword
1483 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1487 } // end OSD_Path :: SetDisk
1489 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1493 _remove_dup ( myTrek );
1495 } // end OSD_Path :: SetTrek
1497 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1501 } // end OSD_Path :: SetName
1503 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1505 myExtension = aName;
1507 } // end OSD_Path :: SetExtension
1509 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1511 Standard_Character buff[ 64 ];
1513 if ( type != OSD_Default && type != OSD_WindowsNT ) {
1515 _tcscpy ( buff, TEXT( "OSD_Path :: " ) );
1516 _tcscat ( buff, str );
1517 _tcscat ( buff, TEXT( " (): unknown system type" ) );
1519 Standard_ProgramError :: Raise ( buff );
1523 } // end _test_raise
1525 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1527 Standard_Integer pos = 1, orgLen, len = str.UsefullLength ();
1531 while ( pos <= len ) {
1533 if ( str.Value ( pos ) == TEXT( '|' ) && pos != len &&
1534 str.Value ( pos + 1 ) == TEXT( '|' ) && pos != 1
1539 while ( pos <= len && str.Value ( pos ) == TEXT( '|' ) ) str.Remove ( pos ), --len;
1547 if ( orgLen > 1 && len > 0 && str.Value ( len ) == TEXT( '|' ) ) str.Remove ( len );
1550 orgLen = len = str.UsefullLength ();
1552 while ( pos <= len ) {
1554 if ( str.Value ( pos ) == TEXT( '^' ) && pos != len && str.Value ( pos + 1 ) == TEXT( '^' ) ) {
1558 while ( pos <= len && str.Value ( pos ) == TEXT( '^' ) ) str.Remove ( pos ), --len;
1566 // if ( orgLen > 1 && len > 0 && str.Value ( len ) == TEXT( '^' ) ) str.Remove ( len );
1568 } // end _remove_dup
1572 // ---------------------------------------------------------------------------
1574 // Elimine les separateurs inutiles
1577 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1579 Standard_Integer i, j, len,start = 1 ;
1581 len = aString.Length() ;
1583 if (len > 1 && aString.Value(1) == '/' && aString.Value(2) == '/')
1586 for (i = j = start ; j <= len ; i++,j++) {
1587 Standard_Character c = aString.Value(j) ;
1588 aString.SetValue(i,c) ;
1590 while(j < len && aString.Value(j+1) == '/') j++ ;
1593 if (aString.Value(len) == '/') len-- ;
1594 aString.Trunc(len) ;
1598 // ---------------------------------------------------------------------------
1600 TCollection_AsciiString OSD_Path::RelativePath(
1601 const TCollection_AsciiString& aDirPath,
1602 const TCollection_AsciiString& aAbsFilePath)
1604 TCollection_AsciiString EmptyString = "" ;
1605 TCollection_AsciiString FilePath ;
1606 Standard_Integer len ;
1607 Standard_Integer i, n ;
1608 Standard_Boolean Wnt = 0 ;
1610 FilePath = aAbsFilePath ;
1612 if (aDirPath.Search(":") == 2) { // Cas WNT
1614 if (FilePath.Search(":") != 2 ||
1615 UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1617 return EmptyString ;
1619 FilePath.ChangeAll('\\','/') ;
1620 if (FilePath.Search("/") != 3 )
1621 return EmptyString ;
1624 if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1625 return EmptyString ;
1628 // Eliminer les separateurs redondants
1630 len = RemoveExtraSeparator(FilePath) ;
1634 return EmptyString ;
1635 FilePath = FilePath.SubString(2,len) ;
1637 TCollection_AsciiString DirToken, FileToken ;
1638 Standard_Boolean Sibling = 0 ;
1640 for (i = n = 1 ;; n++) {
1641 DirToken = aDirPath.Token("/\\",n) ;
1642 if (DirToken.IsEmpty())
1646 len = FilePath.Length() ;
1647 i = FilePath.Search("/") ;
1650 return EmptyString ;
1652 FileToken = FilePath.SubString(1,i-1) ;
1654 DirToken.UpperCase() ;
1655 FileToken.UpperCase() ;
1657 if (DirToken == FileToken) {
1658 FilePath = FilePath.SubString(i+1,len) ;
1662 else if (DirToken == FilePath)
1663 return EmptyString ;
1668 FilePath.Insert(1,"../") ;
1672 // ---------------------------------------------------------------------------
1674 TCollection_AsciiString OSD_Path::AbsolutePath(
1675 const TCollection_AsciiString& aDirPath,
1676 const TCollection_AsciiString& aRelFilePath)
1678 TCollection_AsciiString EmptyString = "" ;
1679 if (aRelFilePath.Search("/") == 1 || aRelFilePath.Search(":") == 2)
1680 return aRelFilePath ;
1681 TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
1682 Standard_Integer i,len ;
1684 if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1685 return EmptyString ;
1687 if ( DirPath.Search(":") == 2)
1688 DirPath.ChangeAll('\\','/') ;
1689 RelFilePath.ChangeAll('\\','/') ;
1690 RemoveExtraSeparator(DirPath) ;
1691 len = RemoveExtraSeparator(RelFilePath) ;
1693 while (RelFilePath.Search("../") == 1) {
1695 return EmptyString ;
1696 RelFilePath = RelFilePath.SubString(4,len) ;
1698 if (DirPath.IsEmpty())
1699 return EmptyString ;
1700 i = DirPath.SearchFromEnd("/") ;
1702 return EmptyString ;
1703 DirPath.Trunc(i-1) ;
1706 DirPath += RelFilePath ;
1710 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1711 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1715 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1716 Standard_Boolean LocateExecFile(OSD_Path& )
1718 return Standard_False ;