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.
16 #include <OSD_OSDError.hxx>
17 #include <OSD_Path.hxx>
18 #include <Standard_ConstructionError.hxx>
19 #include <Standard_NullObject.hxx>
20 #include <Standard_NumericError.hxx>
21 #include <Standard_ProgramError.hxx>
22 #include <TCollection_AsciiString.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)
37 #elif defined(_WIN32) || defined(__WIN32__)
40 #elif defined(__CYGWIN32_) || defined(__MINGW32__)
43 #elif defined(vax) || defined(__vms)
46 #elif defined(__linux__) || defined(__linux)
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;
64 #if !(defined(_WIN32) || defined(__WIN32__))
66 #include <Standard_NumericError.hxx>
67 #include <Standard_NullObject.hxx>
68 #include <Standard_ProgramError.hxx>
69 #include <Standard_ConstructionError.hxx>
70 #include <OSD_WhoAmI.hxx>
73 mySysDep = whereAmI();
76 static void VmsExtract(const TCollection_AsciiString& what,
77 TCollection_AsciiString& node,
78 TCollection_AsciiString& username,
79 TCollection_AsciiString& password,
80 TCollection_AsciiString& disk,
81 TCollection_AsciiString& trek,
82 TCollection_AsciiString& name,
83 TCollection_AsciiString& ext){
85 TCollection_AsciiString buffer;
90 if (buffer.Search("\"") != -1){ // a username to extract
92 if (buffer.Value(1) != '"') { // Begins with Node
93 node = buffer.Token("\"");
94 buffer.Remove(1,node.Length());
98 username = buffer.Token("\" ");
99 buffer.Remove(1,username.Length()+2); // Removes <<"username ' ' or '"' >>
101 if (buffer.Search("\"") != -1){ // a password to extract
102 password = buffer.Token("\"");
103 buffer.Remove(1,password.Length()+1); // removes <<password">>
106 // If we found a node then we must find "::"
107 if (buffer.Search("::") != -1)
108 buffer.Remove(1,2); // Removes <<::>>
110 else // No name or password
111 if (buffer.Search("::") != -1){ // a node to extract
112 node = buffer.Token(":");
113 buffer.Remove(1,node.Length()+2); // Removes <<node::>
116 if (buffer.Search(":") != -1){ // a disk to extract
117 disk = buffer.Token(":");
118 buffer.Remove(1,disk.Length()+1); // Removes <<disk:>>
124 if (buffer.Search("[") != -1){ // There is atrek to extract
125 trek = buffer.Token("[]");
127 if (trek.Value(1) == '.') trek.Remove(1,1); // Removes first '.'
128 else trek.Insert(1,'|'); // Add root
130 trek.ChangeAll('.','|'); // Translates to portable syntax
131 trek.ChangeAll('-','^');
133 pos = trek.Search("000000");
135 trek.Remove(pos,6); // on VMS [000000] is the root
136 if (trek.Search("||") != -1) trek.Remove(1,1); // When [000000.xxx] -> ||xxx
139 name = buffer.Token("]",2);
143 if (name.Search(".") != -1){
144 ext = name.Token(".",2);
146 name.Remove(name.Search("."),ext.Length());
153 //=======================================================================
154 //function : UnixExtract
156 //=======================================================================
157 static void UnixExtract(const TCollection_AsciiString& what,
158 TCollection_AsciiString& node,
159 TCollection_AsciiString& username,
160 TCollection_AsciiString& password,
161 TCollection_AsciiString& trek,
162 TCollection_AsciiString& name,
163 TCollection_AsciiString& ext){
165 Standard_Integer pos;
166 TCollection_AsciiString buffer; // To manipulate 'what' without modifying it
168 Standard_PCharacter p;
171 #ifdef TOTO // Username, password and node are no longer given in the string (LD)
173 if (buffer.Search("@") != -1){ // There is a name to extract
174 username = buffer.Token("\"@");
175 buffer.Remove(1,username.Length()+1); // Removes << user@ >>
177 if (buffer.Search("\"") != -1){ // There is a password to extract
178 password = buffer.Token("\"");
179 buffer.Remove(1,password.Length()+2); // Removes << "password" >>
188 #endif // node must be given (for DBT, DM) (ADN 29/8/96)
190 if (buffer.Search(":/") != -1){ // There is a node to extract
191 node = buffer.Token(":/");
192 buffer.Remove(1,node.Length()+1); // Removes << node: >>
202 trek.ChangeAll('/','|'); // Translates to portable syntax
204 pos = trek.SearchFromEnd("|"); // Extract name
206 p = (Standard_PCharacter)trek.ToCString();
208 if(name.Length()) trek.Remove(pos+1,name.Length());
210 else { // No '|' means no trek but a name
215 pos = trek.Search("..");
216 while (pos != -1){ // Changes every ".." by '^'
217 trek.SetValue(pos,'^');
218 trek.Remove(pos+1,1);
219 pos = trek.Search("..");
222 pos = name.SearchFromEnd(".") ; // LD : debug
223 if (pos != -1) // There is an extension to extract
224 ext = name.Split(pos - 1) ;
227 // if (name.Search(".") != -1){ // There is an extension to extract
228 // if ( name.Value(1) == '.' ) {
233 // ext = name.Token(".",2);
234 // ext.Insert(1,'.'); // Prepends 'dot'
235 // pos = name.Search("."); // Removes extension from buffer
237 // name.Remove(pos,ext.Length());
244 //=======================================================================
245 //function : DosExtract
247 //=======================================================================
248 static void DosExtract(const TCollection_AsciiString& what,
249 TCollection_AsciiString& disk,
250 TCollection_AsciiString& trek,
251 TCollection_AsciiString& name,
252 TCollection_AsciiString& ext){
254 TCollection_AsciiString buffer;
255 Standard_Integer pos;
256 Standard_PCharacter p;
260 if (buffer.Search(":") != -1){ // There is a disk to extract
261 disk = buffer.Token(":");
263 buffer.Remove(1,disk.Length()); // Removes <<disk:>>
266 if (buffer.Search(".") != -1){ // There is an extension to extract
267 ext = buffer.Token(".",2);
268 ext.Insert(1,'.'); // Prepends 'dot'
269 pos = buffer.Search("."); // Removes extension from buffer
271 buffer.Remove(pos,ext.Length());
276 trek.ChangeAll('\\','|');
278 pos = trek.Search("..");
279 while (pos != -1){ // Changes every ".." by '^'
280 trek.SetValue(pos,'^');
281 trek.Remove(pos+1,1);
282 pos = trek.Search("..");
285 pos = trek.SearchFromEnd("|"); // Extract name
287 p = (Standard_PCharacter)trek.ToCString();
289 trek.Remove(trek.Search(name),name.Length());
291 else { // No '|' means no trek but a name
298 //=======================================================================
299 //function : MacExtract
301 //=======================================================================
302 static void MacExtract(const TCollection_AsciiString& what,
303 TCollection_AsciiString& ,
304 TCollection_AsciiString& trek,
305 TCollection_AsciiString& name,
306 TCollection_AsciiString& ){
308 Standard_Integer pos;
309 Standard_PCharacter p;
311 // I don't know how to distingish a disk from a trek !
315 pos = trek.Search("::");
316 while (pos != -1){ // Changes every "::" by '^'
317 trek.SetValue(pos,'^');
318 trek.Remove(pos+1,1);
319 pos = trek.Search("::");
322 trek.ChangeAll(':','|'); // Translates to portable syntax
324 pos = trek.SearchFromEnd("|"); // Extract name
326 p = (Standard_PCharacter)trek.ToCString();
328 trek.Remove(trek.Search(name),name.Length());
330 else { // No '|' means no trek but a name
337 OSD_Path::OSD_Path(const TCollection_AsciiString& aDependentName,
338 const OSD_SysType aSysType){
340 mySysDep = whereAmI();
343 // Standard_Integer i,l;
345 if (aSysType == OSD_Default) {
353 VmsExtract(aDependentName,myNode,myUserName,myPassword,myDisk,myTrek,myName,myExtension);
355 case OSD_LinuxREDHAT:
357 case OSD_UnixSystemV:
360 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
364 DosExtract(aDependentName,myDisk,myTrek,myName,myExtension);
367 MacExtract(aDependentName,myDisk,myTrek,myName,myExtension);
371 cout << " WARNING WARNING : OSD Path for an Unknown SYSTEM : " << (Standard_Integer)todo << endl;
379 OSD_Path::OSD_Path(const TCollection_AsciiString& Nod,
380 const TCollection_AsciiString& UsrNm,
381 const TCollection_AsciiString& Passwd,
382 const TCollection_AsciiString& Dsk,
383 const TCollection_AsciiString& Trk,
384 const TCollection_AsciiString& Nam,
385 const TCollection_AsciiString& ext){
387 mySysDep = whereAmI();
389 SetValues ( Nod, UsrNm, Passwd, Dsk, Trk, Nam, ext);
395 void OSD_Path::Values(TCollection_AsciiString& Nod,
396 TCollection_AsciiString& UsrNm,
397 TCollection_AsciiString& Passwd,
398 TCollection_AsciiString& Dsk,
399 TCollection_AsciiString& Trk,
400 TCollection_AsciiString& Nam,
401 TCollection_AsciiString& ext)const{
413 void OSD_Path::SetValues(const TCollection_AsciiString& Nod,
414 const TCollection_AsciiString& UsrNm,
415 const TCollection_AsciiString& Passwd,
416 const TCollection_AsciiString& Dsk,
417 const TCollection_AsciiString& Trk,
418 const TCollection_AsciiString& Nam,
419 const TCollection_AsciiString& ext){
422 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Node");
423 if (!UsrNm.IsAscii())
424 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : User Name");
426 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Disk");
428 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Trek");
430 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Name");
432 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Extension");
443 void OSD_Path::UpTrek(){
444 Standard_Integer length=TrekLength();
446 if (length == 0) return;
448 Standard_Integer awhere,aHowmany;
449 TCollection_AsciiString tok;
451 tok = myTrek.Token("|",length);
452 awhere = myTrek.SearchFromEnd(tok);
453 aHowmany = tok.Length();
454 myTrek.Remove(awhere,aHowmany);
456 awhere = myTrek.Search("||"); // Searches leaving "||"
458 myTrek.Remove(awhere);
462 void OSD_Path::DownTrek(const TCollection_AsciiString& aName){
464 // Pb signale par GG : pour ne pas avoir "||" ;
465 if ( aName.ToCString()[ aName.Length() - 1 ] != '|' )
470 Standard_Integer OSD_Path::TrekLength()const{
471 Standard_Integer cpt=0;
473 while (myTrek.Token("|",cpt+1) != "") // Counts token separated by '|'
480 void OSD_Path::RemoveATrek(const Standard_Integer thewhere){
481 Standard_Integer length=TrekLength();
483 if (length <= 0 || thewhere > length)
484 Standard_NumericError::Raise("OSD_Path::RemoveATrek : where has an invalid value");
486 Standard_Integer posit,aHowmany;
487 TCollection_AsciiString tok;
489 tok = myTrek.Token("|",thewhere);
490 posit = myTrek.Search(tok);
491 aHowmany = tok.Length();
492 myTrek.Remove(posit,aHowmany);
494 posit = myTrek.Search("||"); // Searches leaving "||"
496 myTrek.Remove(posit);
500 void OSD_Path::RemoveATrek(const TCollection_AsciiString& aName){
501 Standard_Integer length=TrekLength();
503 if (length == 0) return;
505 Standard_Integer awhere;
507 awhere = myTrek.Search(aName);
509 myTrek.Remove(awhere,aName.Length());
511 awhere = myTrek.Search("||"); // Searches leaving "||"
513 myTrek.Remove(awhere);
518 TCollection_AsciiString OSD_Path::TrekValue(const Standard_Integer thewhere)const{
519 TCollection_AsciiString result=myTrek.Token("|",thewhere);
522 Standard_NumericError::Raise("OSD_Path::TrekValue : where is invalid");
527 void OSD_Path::InsertATrek(const TCollection_AsciiString& aName,
528 const Standard_Integer thewhere){
529 Standard_Integer length=TrekLength();
531 if (thewhere <= 0 || thewhere > length)
532 Standard_NumericError::Raise("OSD_Path::InsertATrek : where has an invalid value");
534 TCollection_AsciiString tok=myTrek.Token("|",thewhere);
535 Standard_Integer wwhere = myTrek.Search(tok);
536 TCollection_AsciiString what = aName;
539 myTrek.Insert(wwhere,what);
543 // The 4 following methods will be PUBLIC in the future
545 // Converts a VMS disk to other system syntax
547 static void VMSDisk2Other(TCollection_AsciiString & Disk){
552 // Convert a Trek to VMS syntax
554 static void P2VMS (TCollection_AsciiString & Way){
555 Standard_Integer length = Way.Length();
557 if (length == 0) return;
559 if (Way.Value(1) == '|') // If begin with '|' remove '|'
560 if (Way.Value(1) != '\0')
562 else Way = "000000"; // Si uniquement la racine -> [000000]
565 Way.Insert(1,'|'); // Else insert '|' at beginning if not empty;
567 Way.ChangeAll('|','.');
568 Way.ChangeAll('^','-');
572 // Convert a Trek to MAC syntax
574 static void P2MAC (TCollection_AsciiString & Way){
576 Way.ChangeAll('|',':');
578 l = (int)Way.Length();
579 for (i=1; i <= l; i++) // Replace '^' by "::"
580 if (Way.Value(i) == '^'){
588 // Convert a Trek to UNIX syntax
590 static void P2UNIX (TCollection_AsciiString & Way){
592 Standard_Integer length = Way.Length();
594 if (length == 0) return;
596 // if (Way.Value(length) == '|') // If Finishes with "|" removes it
597 // Way.Trunc(length-1);
599 Way.ChangeAll('|','/');
601 l = (int)Way.Length();
602 for (i=1; i <= l; i++) // Replace '^' by "../"
603 if (Way.Value(i) == '^'){
606 //Way.Insert(i+2,'/');
612 // Convert a Trek to DOS like syntax
614 static void P2DOS (TCollection_AsciiString & Way){
616 Standard_Integer len = Way.Length();
618 if (len == 0) return;
620 if (Way.Value(len) == '|') // If Finishes with "|" removes it
623 Way.ChangeAll('|','\\');
625 l = (int)Way.Length();
626 for (i=1; i <= l; i++) // Replace '^' by ".."
627 if (Way.Value(i) == '^'){
638 // Convert a path to system dependant syntax
640 void OSD_Path::SystemName (TCollection_AsciiString& FullName,
641 const OSD_SysType aType)const{
642 TCollection_AsciiString Way;
643 TCollection_AsciiString pNode;
644 TCollection_AsciiString pDisk;
647 if (aType == OSD_Default) {
660 P2VMS (Way); // Convert path
662 if (myNode.Length()!=0) FullName += myNode; // Append Node
664 if (myUserName.Length()!=0){ // Append User name
666 if (pNode.Length()==0) { // If a user name but no node, catenate "0"
673 FullName += myUserName;
675 if (myPassword.Length()!=0){ // Append password
677 FullName += myPassword;
683 if (pNode.Length()!=0) FullName += "::";
685 if (myDisk.Length()!=0){ // Append Disk
691 if (Way.Length()!=0) // Append VMS path
692 FullName = FullName + "[" + Way + "]" + myName + myExtension;
694 // FullName.UpperCase();
699 case OSD_WindowsNT : // MSDOS-like syntax
701 int length = (int)myDisk.Length();
706 if (myDisk.Length()!=0){
709 (length == 1 && IsAlphabetic(myDisk.Value(1))) || // 'A/a' to 'Z/z'
711 IsAlphabetic(myDisk.Value(1)) &&
712 myDisk.Value(2) == ':') // 'A:' to 'Z:'
713 ) // This is a MSDOS disk syntax
716 if (myDisk.Value(length) != ':') FullName += ":";
718 else // This is an assigned Disk
722 VMSDisk2Other(pDisk);
724 if (Way.Value(1) != '\\') FullName += "\\";
729 FullName = FullName + Way + "\\";
732 FullName += myExtension;
733 // FullName.UpperCase();
737 case OSD_MacOs : // Mackintosh-like syntax
738 if (myDisk.Length()!=0){
744 FullName += myExtension;
749 default : // UNIX-like syntax
752 // user"password"@host:/disk/xxx/xxx/filename
755 if (myUserName.Length()!=0 && myNode.Length()!=0){ // If USER name
756 FullName += myUserName; // appends user name
758 if (myPassword.Length()!=0)
759 FullName = FullName + "\"" + myPassword + "\""; // a password if not empty
761 FullName += "@"; // and character '@'
764 if (myNode.Length()!=0){ // Appends HOST name
769 if (myDisk.Length()!=0) { // Appends Disk name as path
772 VMSDisk2Other(pDisk);
776 // if (FullName.Length()) { // Adds a "/" if necessary
780 if (Way.Length()!=0) { // Appends a path if not empty
784 if (FullName.Length()){
785 if (FullName.Value(FullName.Length()) != '/') {
786 FullName += "/"; // Adds a / if necessary
790 if (myName.Length()){ // Adds the file name
794 if (myExtension.Length()) { // Adds the extension
795 FullName += myExtension;
801 #ifdef TOTO // A reactiver...
803 void OSD_Path::SetSystemName(const TCollection_AsciiString& aDependentName,
804 const OSD_SysType aSysType){
805 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
809 TCollection_AsciiString OSD_Path::Node()const{
814 TCollection_AsciiString OSD_Path::UserName()const{
819 TCollection_AsciiString OSD_Path::Password()const{
824 TCollection_AsciiString OSD_Path::Disk()const{
829 TCollection_AsciiString OSD_Path::Trek()const{
834 // Return extension (suffix) of file/directory name
836 TCollection_AsciiString OSD_Path::Extension()const{
841 TCollection_AsciiString OSD_Path::Name()const{
846 void OSD_Path::SetNode(const TCollection_AsciiString& aName){
847 if (!aName.IsAscii())
848 Standard_ConstructionError::Raise("OSD_Path::SetNode bad name");
855 void OSD_Path::SetUserName(const TCollection_AsciiString& aName){
856 if (!aName.IsAscii())
857 Standard_ConstructionError::Raise("OSD_Path::SetUserName bad name");
864 void OSD_Path::SetPassword(const TCollection_AsciiString& aName){
865 if (!aName.IsAscii())
866 Standard_ConstructionError::Raise("OSD_Path::SetPassword bad name");
873 void OSD_Path::SetDisk(const TCollection_AsciiString& aName){
874 if (!aName.IsAscii())
875 Standard_ConstructionError::Raise("OSD_Path::SetDisk bad name");
882 void OSD_Path::SetTrek(const TCollection_AsciiString& aName){
883 if (!aName.IsAscii())
884 Standard_ConstructionError::Raise("OSD_Path::SetTrek bad name");
891 void OSD_Path::SetName(const TCollection_AsciiString& aName){
892 if (!aName.IsAscii())
893 Standard_ConstructionError::Raise("OSD_Path::SetName bad name");
900 void OSD_Path::SetExtension(const TCollection_AsciiString& aName){
901 if (!aName.IsAscii())
902 Standard_ConstructionError::Raise("OSD_Path::SetExtension bad name");
908 //------------------------------------------------------------------------
909 //------------------- Windows sources for OSD_Path -------------------
910 //------------------------------------------------------------------------
912 #include <Standard_ProgramError.hxx>
917 #define TEST_RAISE( type, arg ) _test_raise ( ( type ), ( arg ) )
919 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
920 static void __fastcall _remove_dup ( TCollection_AsciiString& );
922 OSD_Path :: OSD_Path () {
924 } // end constructor ( 1 )
926 OSD_Path :: OSD_Path (
927 const TCollection_AsciiString& aDependentName,
928 const OSD_SysType aSysType
930 myUNCFlag(Standard_False),
931 mySysDep(OSD_WindowsNT)
934 Standard_Integer i, j, len;
935 static char __drive [ _MAX_DRIVE ];
936 static char __dir [ _MAX_DIR ];
937 static char __trek [ _MAX_DIR ];
938 static char __fname [ _MAX_FNAME ];
939 static char __ext [ _MAX_EXT ];
941 memset(__drive, 0,_MAX_DRIVE);
942 memset(__dir, 0,_MAX_DIR);
943 memset(__trek, 0,_MAX_DIR);
944 memset(__fname, 0,_MAX_FNAME);
945 memset(__ext, 0,_MAX_EXT);
946 Standard_Character chr;
948 TEST_RAISE( aSysType, "OSD_Path" );
950 _splitpath ( aDependentName.ToCString (), __drive, __dir, __fname, __ext );
959 TCollection_AsciiString dir = __dir;
963 for ( i = j = 0; i < len; ++i, ++j ) {
967 if ( chr == '\\' || chr == '/' )
971 else if ( chr == '.'&& (i+1) < len && __dir[i+1] == '.' ) {
982 TCollection_AsciiString trek = __trek;
983 _remove_dup ( trek );
986 } // end constructor ( 2 )
988 OSD_Path :: OSD_Path (
989 const TCollection_AsciiString& aNode,
990 const TCollection_AsciiString& aUsername,
991 const TCollection_AsciiString& aPassword,
992 const TCollection_AsciiString& aDisk,
993 const TCollection_AsciiString& aTrek,
994 const TCollection_AsciiString& aName,
995 const TCollection_AsciiString& anExtension
997 myUNCFlag(Standard_False),
998 mySysDep(OSD_WindowsNT)
1001 SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
1003 } // end constructor ( 3 )
1005 void OSD_Path :: Values (
1006 TCollection_AsciiString& aNode,
1007 TCollection_AsciiString& aUsername,
1008 TCollection_AsciiString& aPassword,
1009 TCollection_AsciiString& aDisk,
1010 TCollection_AsciiString& aTrek,
1011 TCollection_AsciiString& aName,
1012 TCollection_AsciiString& anExtension
1016 aUsername = myUserName;
1017 aPassword = myPassword;
1020 if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1021 aTrek += "|" ; // (LD)
1023 anExtension = myExtension;
1025 } // end OSD_Path :: Values
1027 void OSD_Path :: SetValues (
1028 const TCollection_AsciiString& aNode,
1029 const TCollection_AsciiString& aUsername,
1030 const TCollection_AsciiString& aPassword,
1031 const TCollection_AsciiString& aDisk,
1032 const TCollection_AsciiString& aTrek,
1033 const TCollection_AsciiString& aName,
1034 const TCollection_AsciiString& anExtension
1038 myUserName = aUsername;
1039 myPassword = aPassword;
1043 myExtension = anExtension;
1045 if ( myExtension.Length () && myExtension.Value ( 1 ) != '.' )
1047 myExtension.Insert ( 1, '.' );
1049 _remove_dup ( myTrek );
1051 } // end OSD_Path :: SetValues
1053 void OSD_Path :: SystemName (
1054 TCollection_AsciiString& FullName,
1055 const OSD_SysType aType
1058 Standard_Integer i, j;
1059 TCollection_AsciiString fullPath;
1060 static Standard_Character trek [ _MAX_PATH ];
1061 Standard_Character chr;
1063 memset(trek,0,_MAX_PATH);
1065 TEST_RAISE( aType, "SystemName" );
1067 for ( i = j = 1; i <= myTrek.Length () && j <= _MAX_PATH; ++i, ++j ) {
1069 chr = myTrek.Value ( i );
1075 } else if ( chr == '^' && j <= _MAX_PATH - 1 ) {
1077 strcpy(&(trek[(j++) - 1]),"..");
1085 fullPath = myDisk + TCollection_AsciiString(trek);
1087 if ( trek[0] ) fullPath += "/";
1089 fullPath += ( myName + myExtension );
1091 if ( fullPath.Length () > 0 )
1093 FullName = fullPath;
1099 } // end OSD_Path :: SystemName
1101 void OSD_Path :: UpTrek () {
1103 Standard_Integer pos = myTrek.SearchFromEnd ( "|" );
1109 else if ( pos > 1 ) {
1111 while ( myTrek.Value ( pos ) == '|' && pos != 1 ) --pos;
1115 myTrek.Trunc ( pos );
1117 } // end OSD_Path :: UpTrek
1119 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1121 Standard_Integer pos = myTrek.Length ();
1123 if ( aName.Value ( 1 ) != '|' &&
1125 myTrek.Value ( pos ) != '|'
1132 _remove_dup ( myTrek );
1134 } // end OSD_Path :: DownTrek
1136 Standard_Integer OSD_Path :: TrekLength () const {
1138 Standard_Integer i = 1;
1139 Standard_Integer retVal = 0;
1141 if ( myTrek.IsEmpty () || myTrek.Length () == 1 && myTrek.Value ( 1 ) == '|' )
1147 if ( myTrek.Token ( "|", i++ ).IsEmpty () )
1159 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1161 Standard_Integer i, j;
1162 Standard_Boolean flag = Standard_False;
1164 if ( TrekLength () < thewhere )
1168 if ( myTrek.Value ( 1 ) != '|' ) {
1170 flag = Standard_True;
1171 myTrek.Insert ( 1, '|' );
1175 i = myTrek.Location (
1182 j = myTrek.Location (
1189 j = myTrek.Length () + 1;
1191 myTrek.Remove ( i, j - i );
1197 myTrek.Remove ( 1 );
1199 } // end OSD_Path :: RemoveATrek ( 1 )
1201 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1204 Standard_Boolean flag = Standard_False;
1205 TCollection_AsciiString tmp;
1207 if ( myTrek.Value ( 1 ) != '|' ) {
1209 flag = Standard_True;
1210 myTrek.Insert ( 1, '|' );
1218 if ( tmp.Value ( 1 ) != '|' )
1220 tmp.Insert ( 1, '|' );
1222 if ( tmp.Value ( tmp.Length () ) != '|' )
1226 i = myTrek.Search ( tmp );
1230 myTrek.Remove ( i + 1, tmp.Length () - 1 );
1234 myTrek.Remove ( 1 );
1236 if ( myTrek.Value ( myTrek.Length () ) == '|' )
1238 myTrek.Trunc ( myTrek.Length () - 1 );
1240 } // end OSD_Path :: RemoveATrek ( 2 )
1242 TCollection_AsciiString OSD_Path :: TrekValue (
1243 const Standard_Integer thewhere
1246 TCollection_AsciiString retVal;
1247 TCollection_AsciiString trek = myTrek;
1249 if ( trek.Value ( 1 ) != '|' )
1251 trek.Insert ( 1, '|' );
1253 retVal = trek.Token ( "|", thewhere );
1257 } // end OSD_Path :: TrekValue
1259 void OSD_Path :: InsertATrek (
1260 const TCollection_AsciiString& aName,
1261 const Standard_Integer thewhere
1264 Standard_Integer pos;
1265 TCollection_AsciiString tmp = aName;
1266 Standard_Boolean flag = Standard_False;
1268 if ( myTrek.Value ( 1 ) != '|' ) {
1270 flag = Standard_True;
1271 myTrek.Insert ( 1, '|' );
1277 pos = myTrek.Location (
1284 if ( tmp.Value ( tmp.Length () ) != '|' )
1288 myTrek.Insert ( pos + 1, tmp );
1294 myTrek.Remove ( 1 );
1296 if ( myTrek.Value ( myTrek.Length () ) == '|' )
1298 myTrek.Trunc ( myTrek.Length () - 1 );
1300 _remove_dup ( myTrek );
1302 } // end OSD_Path :: InsertATrek
1304 TCollection_AsciiString OSD_Path :: Node () const {
1308 } // end OSD_Path :: Node
1310 TCollection_AsciiString OSD_Path :: UserName () const {
1314 } // end OSD_Path :: UserName
1316 TCollection_AsciiString OSD_Path :: Password () const {
1320 } // end OSD_Path :: Password
1322 TCollection_AsciiString OSD_Path :: Disk () const {
1326 } // end OSD_Path :: Disk
1328 TCollection_AsciiString OSD_Path :: Trek () const {
1330 TCollection_AsciiString retVal ;
1332 if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1333 retVal += "|" ; // (LD)
1336 } // end OSD_Path :: Trek
1338 TCollection_AsciiString OSD_Path :: Name () const {
1342 } // end OSD_Path :: Name
1344 TCollection_AsciiString OSD_Path :: Extension () const {
1348 } // end OSD_Path :: Extension
1350 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1354 } // end OSD_Path :: SetNode
1356 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1360 } // end OSD_Path :: SetUserName
1362 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1366 } // end OSD_Path :: SetPassword
1368 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1372 } // end OSD_Path :: SetDisk
1374 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1378 _remove_dup ( myTrek );
1380 } // end OSD_Path :: SetTrek
1382 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1386 } // end OSD_Path :: SetName
1388 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1390 myExtension = aName;
1392 } // end OSD_Path :: SetExtension
1394 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1396 Standard_Character buff[ 64 ];
1398 if ( type != OSD_Default && type != OSD_WindowsNT ) {
1400 strcpy ( buff, "OSD_Path :: " );
1401 strcat ( buff, str );
1402 strcat ( buff, " (): unknown system type" );
1404 Standard_ProgramError :: Raise ( buff );
1408 } // end _test_raise
1410 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1412 Standard_Integer pos = 1, orgLen, len = str.Length ();
1416 while ( pos <= len ) {
1418 if ( str.Value ( pos ) == '|' && pos != len &&
1419 str.Value ( pos + 1 ) == '|' && pos != 1
1424 while ( pos <= len && str.Value ( pos ) == '|' ) str.Remove ( pos ), --len;
1432 if ( orgLen > 1 && len > 0 && str.Value ( len ) == '|' ) str.Remove ( len );
1435 orgLen = len = str.Length ();
1437 while ( pos <= len ) {
1439 if ( str.Value ( pos ) == '^' && pos != len && str.Value ( pos + 1 ) == '^' ) {
1443 while ( pos <= len && str.Value ( pos ) == '^' ) str.Remove ( pos ), --len;
1451 // if ( orgLen > 1 && len > 0 && str.Value ( len ) == '^' ) str.Remove ( len );
1453 } // end _remove_dup
1455 #endif // Windows sources for OSD_Path
1457 // =======================================================================
1458 // function : Analyse_VMS
1460 // =======================================================================
1461 static Standard_Boolean Analyse_VMS (const TCollection_AsciiString& theName)
1463 if (theName.Search ("/") != -1
1464 || theName.Search ("@") != -1
1465 || theName.Search ("\\") != -1)
1467 return Standard_False;
1470 return Standard_True;
1473 // =======================================================================
1474 // function : Analyse_DOS
1476 // =======================================================================
1477 static Standard_Boolean Analyse_DOS(const TCollection_AsciiString& theName)
1479 if (theName.Search ("/") != -1
1480 || theName.Search (":") != -1
1481 || theName.Search ("*") != -1
1482 || theName.Search ("?") != -1
1483 || theName.Search ("\"") != -1
1484 || theName.Search ("<") != -1
1485 || theName.Search (">") != -1
1486 || theName.Search ("|") != -1)
1488 return Standard_False;
1491 return Standard_True;
1494 // =======================================================================
1495 // function : Analyse_MACOS
1497 // =======================================================================
1498 static Standard_Boolean Analyse_MACOS (const TCollection_AsciiString& theName)
1500 return theName.Search(":") == -1 ? theName.Length() <= 31 : Standard_True;
1503 // =======================================================================
1504 // function : IsValid
1506 // =======================================================================
1507 Standard_Boolean OSD_Path::IsValid (const TCollection_AsciiString& theDependentName,
1508 const OSD_SysType theSysType)
1510 if (theDependentName.Length() == 0)
1512 return Standard_True;
1515 switch (theSysType == OSD_Default ? whereAmI() : theSysType)
1518 return Analyse_VMS (theDependentName);
1521 return Analyse_DOS (theDependentName);
1523 return Analyse_MACOS (theDependentName);
1525 return Standard_True;
1529 // ---------------------------------------------------------------------------
1531 // Elimine les separateurs inutiles
1534 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1536 Standard_Integer i, j, len,start = 1 ;
1538 len = aString.Length() ;
1540 if (len > 1 && aString.Value(1) == '/' && aString.Value(2) == '/')
1543 for (i = j = start ; j <= len ; i++,j++) {
1544 Standard_Character c = aString.Value(j) ;
1545 aString.SetValue(i,c) ;
1547 while(j < len && aString.Value(j+1) == '/') j++ ;
1550 if (aString.Value(len) == '/') len-- ;
1551 aString.Trunc(len) ;
1555 // ---------------------------------------------------------------------------
1557 TCollection_AsciiString OSD_Path::RelativePath(
1558 const TCollection_AsciiString& aDirPath,
1559 const TCollection_AsciiString& aAbsFilePath)
1561 TCollection_AsciiString EmptyString = "" ;
1562 TCollection_AsciiString FilePath ;
1563 Standard_Integer len ;
1564 Standard_Integer i, n ;
1565 Standard_Boolean Wnt = 0 ;
1567 FilePath = aAbsFilePath ;
1569 if (aDirPath.Search(":") == 2) { // Cas WNT
1571 if (FilePath.Search(":") != 2 ||
1572 UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1574 return EmptyString ;
1576 FilePath.ChangeAll('\\','/') ;
1577 if (FilePath.Search("/") != 3 )
1578 return EmptyString ;
1581 if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1582 return EmptyString ;
1585 // Eliminer les separateurs redondants
1587 len = RemoveExtraSeparator(FilePath) ;
1591 return EmptyString ;
1592 FilePath = FilePath.SubString(2,len) ;
1594 TCollection_AsciiString DirToken, FileToken ;
1595 Standard_Boolean Sibling = 0 ;
1597 for (i = n = 1 ;; n++) {
1598 DirToken = aDirPath.Token("/\\",n) ;
1599 if (DirToken.IsEmpty())
1603 len = FilePath.Length() ;
1604 i = FilePath.Search("/") ;
1607 return EmptyString ;
1609 FileToken = FilePath.SubString(1,i-1) ;
1611 DirToken.UpperCase() ;
1612 FileToken.UpperCase() ;
1614 if (DirToken == FileToken) {
1615 FilePath = FilePath.SubString(i+1,len) ;
1619 else if (DirToken == FilePath)
1620 return EmptyString ;
1625 FilePath.Insert(1,"../") ;
1629 // ---------------------------------------------------------------------------
1631 TCollection_AsciiString OSD_Path::AbsolutePath(
1632 const TCollection_AsciiString& aDirPath,
1633 const TCollection_AsciiString& aRelFilePath)
1635 TCollection_AsciiString EmptyString = "" ;
1636 if (aRelFilePath.Search("/") == 1 || aRelFilePath.Search(":") == 2)
1637 return aRelFilePath ;
1638 TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
1639 Standard_Integer i,len ;
1641 if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1642 return EmptyString ;
1644 if ( DirPath.Search(":") == 2)
1645 DirPath.ChangeAll('\\','/') ;
1646 RelFilePath.ChangeAll('\\','/') ;
1647 RemoveExtraSeparator(DirPath) ;
1648 len = RemoveExtraSeparator(RelFilePath) ;
1650 while (RelFilePath.Search("../") == 1) {
1652 return EmptyString ;
1653 RelFilePath = RelFilePath.SubString(4,len) ;
1655 if (DirPath.IsEmpty())
1656 return EmptyString ;
1657 i = DirPath.SearchFromEnd("/") ;
1659 return EmptyString ;
1660 DirPath.Trunc(i-1) ;
1663 DirPath += RelFilePath ;
1667 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1668 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1672 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1673 Standard_Boolean LocateExecFile(OSD_Path& )
1675 return Standard_False ;