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>
1020 #define TEST_RAISE( type, arg ) _test_raise ( ( type ), ( arg ) )
1022 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
1023 static void __fastcall _remove_dup ( TCollection_AsciiString& );
1025 OSD_Path :: OSD_Path () {
1027 } // end constructor ( 1 )
1029 OSD_Path :: OSD_Path (
1030 const TCollection_AsciiString& aDependentName,
1031 const OSD_SysType aSysType
1033 myUNCFlag(Standard_False),
1034 SysDep(OSD_WindowsNT)
1037 Standard_Integer i, j, len;
1038 static char __drive [ _MAX_DRIVE ];
1039 static char __dir [ _MAX_DIR ];
1040 static char __trek [ _MAX_DIR ];
1041 static char __fname [ _MAX_FNAME ];
1042 static char __ext [ _MAX_EXT ];
1044 memset(__drive, 0,_MAX_DRIVE);
1045 memset(__dir, 0,_MAX_DIR);
1046 memset(__trek, 0,_MAX_DIR);
1047 memset(__fname, 0,_MAX_FNAME);
1048 memset(__ext, 0,_MAX_EXT);
1049 Standard_Character chr;
1051 TEST_RAISE( aSysType, "OSD_Path" );
1053 _splitpath ( aDependentName.ToCString (), __drive, __dir, __fname, __ext );
1059 myExtension = __ext;
1062 TCollection_AsciiString dir = __dir;
1063 len = dir.Length ();
1066 for ( i = j = 0; i < len; ++i, ++j ) {
1070 if ( chr == '\\' || chr == '/' )
1074 else if ( chr == '.'&& (i+1) < len && __dir[i+1] == '.' ) {
1085 TCollection_AsciiString trek = __trek;
1086 _remove_dup ( trek );
1089 } // end constructor ( 2 )
1091 OSD_Path :: OSD_Path (
1092 const TCollection_AsciiString& aNode,
1093 const TCollection_AsciiString& aUsername,
1094 const TCollection_AsciiString& aPassword,
1095 const TCollection_AsciiString& aDisk,
1096 const TCollection_AsciiString& aTrek,
1097 const TCollection_AsciiString& aName,
1098 const TCollection_AsciiString& anExtension
1100 myUNCFlag(Standard_False),
1101 SysDep(OSD_WindowsNT)
1104 SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
1106 } // end constructor ( 3 )
1108 void OSD_Path :: Values (
1109 TCollection_AsciiString& aNode,
1110 TCollection_AsciiString& aUsername,
1111 TCollection_AsciiString& aPassword,
1112 TCollection_AsciiString& aDisk,
1113 TCollection_AsciiString& aTrek,
1114 TCollection_AsciiString& aName,
1115 TCollection_AsciiString& anExtension
1119 aUsername = myUserName;
1120 aPassword = myPassword;
1123 if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1124 aTrek += "|" ; // (LD)
1126 anExtension = myExtension;
1128 } // end OSD_Path :: Values
1130 void OSD_Path :: SetValues (
1131 const TCollection_AsciiString& aNode,
1132 const TCollection_AsciiString& aUsername,
1133 const TCollection_AsciiString& aPassword,
1134 const TCollection_AsciiString& aDisk,
1135 const TCollection_AsciiString& aTrek,
1136 const TCollection_AsciiString& aName,
1137 const TCollection_AsciiString& anExtension
1141 myUserName = aUsername;
1142 myPassword = aPassword;
1146 myExtension = anExtension;
1148 if ( myExtension.Length () && myExtension.Value ( 1 ) != '.' )
1150 myExtension.Insert ( 1, '.' );
1152 _remove_dup ( myTrek );
1154 } // end OSD_Path :: SetValues
1156 void OSD_Path :: SystemName (
1157 TCollection_AsciiString& FullName,
1158 const OSD_SysType aType
1161 Standard_Integer i, j;
1162 TCollection_AsciiString fullPath;
1163 static Standard_Character trek [ _MAX_PATH ];
1164 Standard_Character chr;
1166 memset(trek,0,_MAX_PATH);
1168 TEST_RAISE( aType, "SystemName" );
1170 for ( i = j = 1; i <= myTrek.Length () && j <= _MAX_PATH; ++i, ++j ) {
1172 chr = myTrek.Value ( i );
1178 } else if ( chr == '^' && j <= _MAX_PATH - 1 ) {
1180 strcpy(&(trek[(j++) - 1]),"..");
1188 fullPath = myDisk + TCollection_AsciiString(trek);
1190 if ( trek[0] ) fullPath += "/";
1192 fullPath += ( myName + myExtension );
1194 if ( fullPath.Length () > 0 )
1196 FullName = fullPath;
1202 } // end OSD_Path :: SystemName
1204 Standard_Boolean OSD_Path :: IsValid (
1205 const TCollection_AsciiString& /*aDependentName*/,
1206 const OSD_SysType aSysType
1209 TEST_RAISE( aSysType, "IsValid" );
1211 return Standard_True;
1213 } // end OSD_Path :: IsValid
1215 void OSD_Path :: UpTrek () {
1217 Standard_Integer pos = myTrek.SearchFromEnd ( "|" );
1223 else if ( pos > 1 ) {
1225 while ( myTrek.Value ( pos ) == '|' && pos != 1 ) --pos;
1229 myTrek.Trunc ( pos );
1231 } // end OSD_Path :: UpTrek
1233 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1235 Standard_Integer pos = myTrek.Length ();
1237 if ( aName.Value ( 1 ) != '|' &&
1239 myTrek.Value ( pos ) != '|'
1246 _remove_dup ( myTrek );
1248 } // end OSD_Path :: DownTrek
1250 Standard_Integer OSD_Path :: TrekLength () const {
1252 Standard_Integer i = 1;
1253 Standard_Integer retVal = 0;
1255 if ( myTrek.IsEmpty () || myTrek.Length () == 1 && myTrek.Value ( 1 ) == '|' )
1261 if ( myTrek.Token ( "|", i++ ).IsEmpty () )
1273 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1275 Standard_Integer i, j;
1276 Standard_Boolean flag = Standard_False;
1278 if ( TrekLength () < thewhere )
1282 if ( myTrek.Value ( 1 ) != '|' ) {
1284 flag = Standard_True;
1285 myTrek.Insert ( 1, '|' );
1289 i = myTrek.Location (
1296 j = myTrek.Location (
1303 j = myTrek.Length () + 1;
1305 myTrek.Remove ( i, j - i );
1311 myTrek.Remove ( 1 );
1313 } // end OSD_Path :: RemoveATrek ( 1 )
1315 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1318 Standard_Boolean flag = Standard_False;
1319 TCollection_AsciiString tmp;
1321 if ( myTrek.Value ( 1 ) != '|' ) {
1323 flag = Standard_True;
1324 myTrek.Insert ( 1, '|' );
1332 if ( tmp.Value ( 1 ) != '|' )
1334 tmp.Insert ( 1, '|' );
1336 if ( tmp.Value ( tmp.Length () ) != '|' )
1340 i = myTrek.Search ( tmp );
1344 myTrek.Remove ( i + 1, tmp.Length () - 1 );
1348 myTrek.Remove ( 1 );
1350 if ( myTrek.Value ( myTrek.Length () ) == '|' )
1352 myTrek.Trunc ( myTrek.Length () - 1 );
1354 } // end OSD_Path :: RemoveATrek ( 2 )
1356 TCollection_AsciiString OSD_Path :: TrekValue (
1357 const Standard_Integer thewhere
1360 TCollection_AsciiString retVal;
1361 TCollection_AsciiString trek = myTrek;
1363 if ( trek.Value ( 1 ) != '|' )
1365 trek.Insert ( 1, '|' );
1367 retVal = trek.Token ( "|", thewhere );
1371 } // end OSD_Path :: TrekValue
1373 void OSD_Path :: InsertATrek (
1374 const TCollection_AsciiString& aName,
1375 const Standard_Integer thewhere
1378 Standard_Integer pos;
1379 TCollection_AsciiString tmp = aName;
1380 Standard_Boolean flag = Standard_False;
1382 if ( myTrek.Value ( 1 ) != '|' ) {
1384 flag = Standard_True;
1385 myTrek.Insert ( 1, '|' );
1391 pos = myTrek.Location (
1398 if ( tmp.Value ( tmp.Length () ) != '|' )
1402 myTrek.Insert ( pos + 1, tmp );
1408 myTrek.Remove ( 1 );
1410 if ( myTrek.Value ( myTrek.Length () ) == '|' )
1412 myTrek.Trunc ( myTrek.Length () - 1 );
1414 _remove_dup ( myTrek );
1416 } // end OSD_Path :: InsertATrek
1418 TCollection_AsciiString OSD_Path :: Node () const {
1422 } // end OSD_Path :: Node
1424 TCollection_AsciiString OSD_Path :: UserName () const {
1428 } // end OSD_Path :: UserName
1430 TCollection_AsciiString OSD_Path :: Password () const {
1434 } // end OSD_Path :: Password
1436 TCollection_AsciiString OSD_Path :: Disk () const {
1440 } // end OSD_Path :: Disk
1442 TCollection_AsciiString OSD_Path :: Trek () const {
1444 TCollection_AsciiString retVal ;
1446 if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1447 retVal += "|" ; // (LD)
1450 } // end OSD_Path :: Trek
1452 TCollection_AsciiString OSD_Path :: Name () const {
1456 } // end OSD_Path :: Name
1458 TCollection_AsciiString OSD_Path :: Extension () const {
1462 } // end OSD_Path :: Extension
1464 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1468 } // end OSD_Path :: SetNode
1470 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1474 } // end OSD_Path :: SetUserName
1476 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1480 } // end OSD_Path :: SetPassword
1482 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1486 } // end OSD_Path :: SetDisk
1488 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1492 _remove_dup ( myTrek );
1494 } // end OSD_Path :: SetTrek
1496 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1500 } // end OSD_Path :: SetName
1502 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1504 myExtension = aName;
1506 } // end OSD_Path :: SetExtension
1508 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1510 Standard_Character buff[ 64 ];
1512 if ( type != OSD_Default && type != OSD_WindowsNT ) {
1514 strcpy ( buff, "OSD_Path :: " );
1515 strcat ( buff, str );
1516 strcat ( buff, " (): unknown system type" );
1518 Standard_ProgramError :: Raise ( buff );
1522 } // end _test_raise
1524 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1526 Standard_Integer pos = 1, orgLen, len = str.Length ();
1530 while ( pos <= len ) {
1532 if ( str.Value ( pos ) == '|' && pos != len &&
1533 str.Value ( pos + 1 ) == '|' && pos != 1
1538 while ( pos <= len && str.Value ( pos ) == '|' ) str.Remove ( pos ), --len;
1546 if ( orgLen > 1 && len > 0 && str.Value ( len ) == '|' ) str.Remove ( len );
1549 orgLen = len = str.Length ();
1551 while ( pos <= len ) {
1553 if ( str.Value ( pos ) == '^' && pos != len && str.Value ( pos + 1 ) == '^' ) {
1557 while ( pos <= len && str.Value ( pos ) == '^' ) str.Remove ( pos ), --len;
1565 // if ( orgLen > 1 && len > 0 && str.Value ( len ) == '^' ) str.Remove ( len );
1567 } // end _remove_dup
1571 // ---------------------------------------------------------------------------
1573 // Elimine les separateurs inutiles
1576 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1578 Standard_Integer i, j, len,start = 1 ;
1580 len = aString.Length() ;
1582 if (len > 1 && aString.Value(1) == '/' && aString.Value(2) == '/')
1585 for (i = j = start ; j <= len ; i++,j++) {
1586 Standard_Character c = aString.Value(j) ;
1587 aString.SetValue(i,c) ;
1589 while(j < len && aString.Value(j+1) == '/') j++ ;
1592 if (aString.Value(len) == '/') len-- ;
1593 aString.Trunc(len) ;
1597 // ---------------------------------------------------------------------------
1599 TCollection_AsciiString OSD_Path::RelativePath(
1600 const TCollection_AsciiString& aDirPath,
1601 const TCollection_AsciiString& aAbsFilePath)
1603 TCollection_AsciiString EmptyString = "" ;
1604 TCollection_AsciiString FilePath ;
1605 Standard_Integer len ;
1606 Standard_Integer i, n ;
1607 Standard_Boolean Wnt = 0 ;
1609 FilePath = aAbsFilePath ;
1611 if (aDirPath.Search(":") == 2) { // Cas WNT
1613 if (FilePath.Search(":") != 2 ||
1614 UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1616 return EmptyString ;
1618 FilePath.ChangeAll('\\','/') ;
1619 if (FilePath.Search("/") != 3 )
1620 return EmptyString ;
1623 if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1624 return EmptyString ;
1627 // Eliminer les separateurs redondants
1629 len = RemoveExtraSeparator(FilePath) ;
1633 return EmptyString ;
1634 FilePath = FilePath.SubString(2,len) ;
1636 TCollection_AsciiString DirToken, FileToken ;
1637 Standard_Boolean Sibling = 0 ;
1639 for (i = n = 1 ;; n++) {
1640 DirToken = aDirPath.Token("/\\",n) ;
1641 if (DirToken.IsEmpty())
1645 len = FilePath.Length() ;
1646 i = FilePath.Search("/") ;
1649 return EmptyString ;
1651 FileToken = FilePath.SubString(1,i-1) ;
1653 DirToken.UpperCase() ;
1654 FileToken.UpperCase() ;
1656 if (DirToken == FileToken) {
1657 FilePath = FilePath.SubString(i+1,len) ;
1661 else if (DirToken == FilePath)
1662 return EmptyString ;
1667 FilePath.Insert(1,"../") ;
1671 // ---------------------------------------------------------------------------
1673 TCollection_AsciiString OSD_Path::AbsolutePath(
1674 const TCollection_AsciiString& aDirPath,
1675 const TCollection_AsciiString& aRelFilePath)
1677 TCollection_AsciiString EmptyString = "" ;
1678 if (aRelFilePath.Search("/") == 1 || aRelFilePath.Search(":") == 2)
1679 return aRelFilePath ;
1680 TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
1681 Standard_Integer i,len ;
1683 if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1684 return EmptyString ;
1686 if ( DirPath.Search(":") == 2)
1687 DirPath.ChangeAll('\\','/') ;
1688 RelFilePath.ChangeAll('\\','/') ;
1689 RemoveExtraSeparator(DirPath) ;
1690 len = RemoveExtraSeparator(RelFilePath) ;
1692 while (RelFilePath.Search("../") == 1) {
1694 return EmptyString ;
1695 RelFilePath = RelFilePath.SubString(4,len) ;
1697 if (DirPath.IsEmpty())
1698 return EmptyString ;
1699 i = DirPath.SearchFromEnd("/") ;
1701 return EmptyString ;
1702 DirPath.Trunc(i-1) ;
1705 DirPath += RelFilePath ;
1709 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1710 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1714 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1715 Standard_Boolean LocateExecFile(OSD_Path& )
1717 return Standard_False ;