1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
25 #include <Standard_NumericError.hxx>
26 #include <Standard_NullObject.hxx>
27 #include <Standard_ProgramError.hxx>
28 #include <Standard_ConstructionError.hxx>
29 #include <OSD_Path.ixx>
30 #include <OSD_WhoAmI.hxx>
32 #ifdef HAVE_SYS_UTSNAME_H
33 //# include <sys/utsname.h>
36 static OSD_SysType whereAmI(){
37 #if defined(__digital__) || defined(__FreeBSD__) || defined(SUNOS) || defined(__APPLE__)
40 #elif defined(sgi) || defined(IRIX) || defined(__sun) || defined(SOLARIS) || defined(__sco__) || defined(__hpux) || defined(HPUX)
41 return OSD_UnixSystemV;
43 #elif defined(__osf__) || defined(DECOSF1)
52 #elif defined(__CYGWIN32_) || defined(__MINGW32__)
55 #elif defined(vax) || defined(__vms)
58 #elif defined(__linux__) || defined(LIN)
59 return OSD_LinuxREDHAT;
61 #elif defined(_AIX) || defined(AIX)
67 cout << info.sysname << endl;
68 cout << info.nodename << endl;
69 cout << info.release << endl;
70 cout << info.version << endl;
71 cout << info.machine << endl;
82 static void VmsExtract(const TCollection_AsciiString& what,
83 TCollection_AsciiString& node,
84 TCollection_AsciiString& username,
85 TCollection_AsciiString& password,
86 TCollection_AsciiString& disk,
87 TCollection_AsciiString& trek,
88 TCollection_AsciiString& name,
89 TCollection_AsciiString& ext){
91 TCollection_AsciiString buffer;
96 if (buffer.Search("\"") != -1){ // a username to extract
98 if (buffer.Value(1) != '"') { // Begins with Node
99 node = buffer.Token("\"");
100 buffer.Remove(1,node.Length());
104 username = buffer.Token("\" ");
105 buffer.Remove(1,username.Length()+2); // Removes <<"username ' ' or '"' >>
107 if (buffer.Search("\"") != -1){ // a password to extract
108 password = buffer.Token("\"");
109 buffer.Remove(1,password.Length()+1); // removes <<password">>
112 // If we found a node then we must find "::"
113 if (buffer.Search("::") != -1)
114 buffer.Remove(1,2); // Removes <<::>>
116 else // No name or password
117 if (buffer.Search("::") != -1){ // a node to extract
118 node = buffer.Token(":");
119 buffer.Remove(1,node.Length()+2); // Removes <<node::>
122 if (buffer.Search(":") != -1){ // a disk to extract
123 disk = buffer.Token(":");
124 buffer.Remove(1,disk.Length()+1); // Removes <<disk:>>
130 if (buffer.Search("[") != -1){ // There is atrek to extract
131 trek = buffer.Token("[]");
133 if (trek.Value(1) == '.') trek.Remove(1,1); // Removes first '.'
134 else trek.Insert(1,'|'); // Add root
136 trek.ChangeAll('.','|'); // Translates to portable syntax
137 trek.ChangeAll('-','^');
139 pos = trek.Search("000000");
141 trek.Remove(pos,6); // on VMS [000000] is the root
142 if (trek.Search("||") != -1) trek.Remove(1,1); // When [000000.xxx] -> ||xxx
145 name = buffer.Token("]",2);
149 if (name.Search(".") != -1){
150 ext = name.Token(".",2);
152 name.Remove(name.Search("."),ext.Length());
159 //=======================================================================
160 //function : UnixExtract
162 //=======================================================================
163 static void UnixExtract(const TCollection_AsciiString& what,
164 TCollection_AsciiString& node,
165 TCollection_AsciiString& username,
166 TCollection_AsciiString& password,
167 TCollection_AsciiString& trek,
168 TCollection_AsciiString& name,
169 TCollection_AsciiString& ext){
171 Standard_Integer pos;
172 TCollection_AsciiString buffer; // To manipulate 'what' without modifying it
174 Standard_PCharacter p;
177 #ifdef TOTO // Username, password and node are no longer given in the string (LD)
179 if (buffer.Search("@") != -1){ // There is a name to extract
180 username = buffer.Token("\"@");
181 buffer.Remove(1,username.Length()+1); // Removes << user@ >>
183 if (buffer.Search("\"") != -1){ // There is a password to extract
184 password = buffer.Token("\"");
185 buffer.Remove(1,password.Length()+2); // Removes << "password" >>
194 #endif // node must be given (for DBT, DM) (ADN 29/8/96)
196 if (buffer.Search(":/") != -1){ // There is a node to extract
197 node = buffer.Token(":/");
198 buffer.Remove(1,node.Length()+1); // Removes << node: >>
208 trek.ChangeAll('/','|'); // Translates to portable syntax
210 pos = trek.SearchFromEnd("|"); // Extract name
212 p = (Standard_PCharacter)trek.ToCString();
214 if(name.Length()) trek.Remove(pos+1,name.Length());
216 else { // No '|' means no trek but a name
221 pos = trek.Search("..");
222 while (pos != -1){ // Changes every ".." by '^'
223 trek.SetValue(pos,'^');
224 trek.Remove(pos+1,1);
225 pos = trek.Search("..");
228 pos = name.SearchFromEnd(".") ; // LD : debug
229 if (pos != -1) // There is an extension to extract
230 ext = name.Split(pos - 1) ;
233 // if (name.Search(".") != -1){ // There is an extension to extract
234 // if ( name.Value(1) == '.' ) {
239 // ext = name.Token(".",2);
240 // ext.Insert(1,'.'); // Prepends 'dot'
241 // pos = name.Search("."); // Removes extension from buffer
243 // name.Remove(pos,ext.Length());
250 //=======================================================================
251 //function : DosExtract
253 //=======================================================================
254 static void DosExtract(const TCollection_AsciiString& what,
255 TCollection_AsciiString& disk,
256 TCollection_AsciiString& trek,
257 TCollection_AsciiString& name,
258 TCollection_AsciiString& ext){
260 TCollection_AsciiString buffer;
261 Standard_Integer pos;
262 Standard_PCharacter p;
266 if (buffer.Search(":") != -1){ // There is a disk to extract
267 disk = buffer.Token(":");
269 buffer.Remove(1,disk.Length()); // Removes <<disk:>>
272 if (buffer.Search(".") != -1){ // There is an extension to extract
273 ext = buffer.Token(".",2);
274 ext.Insert(1,'.'); // Prepends 'dot'
275 pos = buffer.Search("."); // Removes extension from buffer
277 buffer.Remove(pos,ext.Length());
282 trek.ChangeAll('\\','|');
284 pos = trek.Search("..");
285 while (pos != -1){ // Changes every ".." by '^'
286 trek.SetValue(pos,'^');
287 trek.Remove(pos+1,1);
288 pos = trek.Search("..");
291 pos = trek.SearchFromEnd("|"); // Extract name
293 p = (Standard_PCharacter)trek.ToCString();
295 trek.Remove(trek.Search(name),name.Length());
297 else { // No '|' means no trek but a name
304 //=======================================================================
305 //function : MacExtract
307 //=======================================================================
308 static void MacExtract(const TCollection_AsciiString& what,
309 TCollection_AsciiString& ,
310 TCollection_AsciiString& trek,
311 TCollection_AsciiString& name,
312 TCollection_AsciiString& ){
314 Standard_Integer pos;
315 Standard_PCharacter p;
317 // I don't know how to distingish a disk from a trek !
321 pos = trek.Search("::");
322 while (pos != -1){ // Changes every "::" by '^'
323 trek.SetValue(pos,'^');
324 trek.Remove(pos+1,1);
325 pos = trek.Search("::");
328 trek.ChangeAll(':','|'); // Translates to portable syntax
330 pos = trek.SearchFromEnd("|"); // Extract name
332 p = (Standard_PCharacter)trek.ToCString();
334 trek.Remove(trek.Search(name),name.Length());
336 else { // No '|' means no trek but a name
343 OSD_Path::OSD_Path(const TCollection_AsciiString& aDependentName,
344 const OSD_SysType aSysType){
348 if (!IsValid(aDependentName,aSysType))
349 Standard_ProgramError::Raise("OSD_Path::OSD_Path : Invalid dependent name");
352 // Standard_Integer i,l;
354 if (aSysType == OSD_Default) {
362 VmsExtract(aDependentName,myNode,myUserName,myPassword,myDisk,myTrek,myName,myExtension);
364 case OSD_LinuxREDHAT:
366 case OSD_UnixSystemV:
369 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
373 DosExtract(aDependentName,myDisk,myTrek,myName,myExtension);
376 MacExtract(aDependentName,myDisk,myTrek,myName,myExtension);
380 cout << " WARNING WARNING : OSD Path for an Unknown SYSTEM : " << (Standard_Integer)todo << endl;
388 OSD_Path::OSD_Path(const TCollection_AsciiString& Nod,
389 const TCollection_AsciiString& UsrNm,
390 const TCollection_AsciiString& Passwd,
391 const TCollection_AsciiString& Dsk,
392 const TCollection_AsciiString& Trk,
393 const TCollection_AsciiString& Nam,
394 const TCollection_AsciiString& ext){
398 SetValues ( Nod, UsrNm, Passwd, Dsk, Trk, Nam, ext);
404 void OSD_Path::Values(TCollection_AsciiString& Nod,
405 TCollection_AsciiString& UsrNm,
406 TCollection_AsciiString& Passwd,
407 TCollection_AsciiString& Dsk,
408 TCollection_AsciiString& Trk,
409 TCollection_AsciiString& Nam,
410 TCollection_AsciiString& ext)const{
422 void OSD_Path::SetValues(const TCollection_AsciiString& Nod,
423 const TCollection_AsciiString& UsrNm,
424 const TCollection_AsciiString& Passwd,
425 const TCollection_AsciiString& Dsk,
426 const TCollection_AsciiString& Trk,
427 const TCollection_AsciiString& Nam,
428 const TCollection_AsciiString& ext){
431 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Node");
432 if (!UsrNm.IsAscii())
433 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : User Name");
435 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Disk");
437 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Trek");
439 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Name");
441 Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Extension");
453 static Standard_Boolean Analyse_VMS(const TCollection_AsciiString& name){
454 if (name.Search("/") != -1)
455 return(Standard_False);
456 if (name.Search("@") != -1)
457 return(Standard_False);
458 if (name.Search("\\") != -1)
459 return(Standard_False);
462 return Standard_True;
465 static Standard_Boolean Analyse_DOS(const TCollection_AsciiString& name){
467 // if (name.Search("$") != -1)
468 // return(Standard_False);
469 // if (name.Search(" ") != -1)
470 // 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);
478 if (name.Search("?") != -1)
479 return(Standard_False);
480 if (name.Search(".") != name.SearchFromEnd("."))
481 return(Standard_False);
482 if (name.Search("\"") != -1)
483 return(Standard_False);
484 if (name.Search("<") != -1)
485 return(Standard_False);
486 if (name.Search(">") != -1)
487 return(Standard_False);
488 if (name.Search("|") != -1)
489 return(Standard_False);
491 return Standard_True;
492 // Rajouter les tests sur les noms de 8 caracteres au maximum et
493 // l'extension de 3 caracteres.
496 static Standard_Boolean Analyse_MACOS(const TCollection_AsciiString& name){
497 Standard_Integer i = name.Search(":");
498 Standard_Integer l = name.Length();
502 return(Standard_False);
504 return(Standard_True);
506 return(Standard_True);
509 static Standard_Boolean Analyse_UNIX(const TCollection_AsciiString& /*name*/)
511 // if (name.Search("$") != -1) Unix filename can have a "$" (LD)
512 // return(Standard_False);
514 // all characters are allowed in UNIX file name, except null '\0' and slash '/'
516 // if (name.Search("[") != -1)
517 // return(Standard_False);
518 // if (name.Search("]") != -1)
519 // return(Standard_False);
520 // if (name.Search("\\") != -1)
521 // return(Standard_False);
522 // if (name.Search(" ") != -1)
523 // return(Standard_False);
525 return(Standard_True);
533 Standard_Boolean OSD_Path::IsValid(const TCollection_AsciiString& aDependentName,
534 const OSD_SysType aSysType)const{
535 if (aDependentName.Length()==0) return(Standard_True);
536 if (!aDependentName.IsAscii()) return(Standard_False);
539 if (aSysType == OSD_Default) provSys = SysDep;
540 else provSys = aSysType;
544 return(Analyse_VMS(aDependentName));
547 return(Analyse_DOS(aDependentName));
549 return(Analyse_MACOS(aDependentName));
551 return(Analyse_UNIX(aDependentName));
557 void OSD_Path::UpTrek(){
558 Standard_Integer length=TrekLength();
560 if (length == 0) return;
562 Standard_Integer awhere,aHowmany;
563 TCollection_AsciiString tok;
565 tok = myTrek.Token("|",length);
566 awhere = myTrek.SearchFromEnd(tok);
567 aHowmany = tok.Length();
568 myTrek.Remove(awhere,aHowmany);
570 awhere = myTrek.Search("||"); // Searches leaving "||"
572 myTrek.Remove(awhere);
576 void OSD_Path::DownTrek(const TCollection_AsciiString& aName){
578 // Pb signale par GG : pour ne pas avoir "||" ;
579 if ( aName.ToCString()[ aName.Length() - 1 ] != '|' )
584 Standard_Integer OSD_Path::TrekLength()const{
585 Standard_Integer cpt=0;
587 while (myTrek.Token("|",cpt+1) != "") // Counts token separated by '|'
594 void OSD_Path::RemoveATrek(const Standard_Integer thewhere){
595 Standard_Integer length=TrekLength();
597 if (length <= 0 || thewhere > length)
598 Standard_NumericError::Raise("OSD_Path::RemoveATrek : where has an invalid value");
600 Standard_Integer posit,aHowmany;
601 TCollection_AsciiString tok;
603 tok = myTrek.Token("|",thewhere);
604 posit = myTrek.Search(tok);
605 aHowmany = tok.Length();
606 myTrek.Remove(posit,aHowmany);
608 posit = myTrek.Search("||"); // Searches leaving "||"
610 myTrek.Remove(posit);
614 void OSD_Path::RemoveATrek(const TCollection_AsciiString& aName){
615 Standard_Integer length=TrekLength();
617 if (length == 0) return;
619 Standard_Integer awhere;
621 awhere = myTrek.Search(aName);
623 myTrek.Remove(awhere,aName.Length());
625 awhere = myTrek.Search("||"); // Searches leaving "||"
627 myTrek.Remove(awhere);
632 TCollection_AsciiString OSD_Path::TrekValue(const Standard_Integer thewhere)const{
633 TCollection_AsciiString result=myTrek.Token("|",thewhere);
636 Standard_NumericError::Raise("OSD_Path::TrekValue : where is invalid");
641 void OSD_Path::InsertATrek(const TCollection_AsciiString& aName,
642 const Standard_Integer thewhere){
643 Standard_Integer length=TrekLength();
645 if (thewhere <= 0 || thewhere > length)
646 Standard_NumericError::Raise("OSD_Path::InsertATrek : where has an invalid value");
648 TCollection_AsciiString tok=myTrek.Token("|",thewhere);
649 Standard_Integer wwhere = myTrek.Search(tok);
650 TCollection_AsciiString what = aName;
653 myTrek.Insert(wwhere,what);
657 // The 4 following methods will be PUBLIC in the future
659 // Converts a VMS disk to other system syntax
661 static void VMSDisk2Other(TCollection_AsciiString & Disk){
666 // Convert a Trek to VMS syntax
668 static void P2VMS (TCollection_AsciiString & Way){
669 Standard_Integer length = Way.Length();
671 if (length == 0) return;
673 if (Way.Value(1) == '|') // If begin with '|' remove '|'
674 if (Way.Value(1) != '\0')
676 else Way = "000000"; // Si uniquement la racine -> [000000]
679 Way.Insert(1,'|'); // Else insert '|' at beginning if not empty;
681 Way.ChangeAll('|','.');
682 Way.ChangeAll('^','-');
686 // Convert a Trek to MAC syntax
688 static void P2MAC (TCollection_AsciiString & Way){
690 Way.ChangeAll('|',':');
692 l = (int)Way.Length();
693 for (i=1; i <= l; i++) // Replace '^' by "::"
694 if (Way.Value(i) == '^'){
702 // Convert a Trek to UNIX syntax
704 static void P2UNIX (TCollection_AsciiString & Way){
706 Standard_Integer length = Way.Length();
708 if (length == 0) return;
710 // if (Way.Value(length) == '|') // If Finishes with "|" removes it
711 // Way.Trunc(length-1);
713 Way.ChangeAll('|','/');
715 l = (int)Way.Length();
716 for (i=1; i <= l; i++) // Replace '^' by "../"
717 if (Way.Value(i) == '^'){
720 //Way.Insert(i+2,'/');
726 // Convert a Trek to DOS like syntax
728 static void P2DOS (TCollection_AsciiString & Way){
730 Standard_Integer len = Way.Length();
732 if (len == 0) return;
734 if (Way.Value(len) == '|') // If Finishes with "|" removes it
737 Way.ChangeAll('|','\\');
739 l = (int)Way.Length();
740 for (i=1; i <= l; i++) // Replace '^' by ".."
741 if (Way.Value(i) == '^'){
752 // Convert a path to system dependant syntax
754 void OSD_Path::SystemName (TCollection_AsciiString& FullName,
755 const OSD_SysType aType)const{
756 TCollection_AsciiString Way;
757 TCollection_AsciiString pNode;
758 TCollection_AsciiString pDisk;
761 if (aType == OSD_Default) {
774 P2VMS (Way); // Convert path
776 if (myNode.Length()!=0) FullName += myNode; // Append Node
778 if (myUserName.Length()!=0){ // Append User name
780 if (pNode.Length()==0) { // If a user name but no node, catenate "0"
787 FullName += myUserName;
789 if (myPassword.Length()!=0){ // Append password
791 FullName += myPassword;
797 if (pNode.Length()!=0) FullName += "::";
799 if (myDisk.Length()!=0){ // Append Disk
805 if (Way.Length()!=0) // Append VMS path
806 FullName = FullName + "[" + Way + "]" + myName + myExtension;
808 // FullName.UpperCase();
813 case OSD_WindowsNT : // MSDOS-like syntax
815 int length = (int)myDisk.Length();
820 if (myDisk.Length()!=0){
823 (length == 1 && IsAlphabetic(myDisk.Value(1))) || // 'A/a' to 'Z/z'
825 IsAlphabetic(myDisk.Value(1)) &&
826 myDisk.Value(2) == ':') // 'A:' to 'Z:'
827 ) // This is a MSDOS disk syntax
830 if (myDisk.Value(length) != ':') FullName += ":";
832 else // This is an assigned Disk
836 VMSDisk2Other(pDisk);
838 if (Way.Value(1) != '\\') FullName += "\\";
843 FullName = FullName + Way + "\\";
846 FullName += myExtension;
847 // FullName.UpperCase();
851 case OSD_MacOs : // Mackintosh-like syntax
852 if (myDisk.Length()!=0){
858 FullName += myExtension;
863 default : // UNIX-like syntax
866 // user"password"@host:/disk/xxx/xxx/filename
869 if (myUserName.Length()!=0 && myNode.Length()!=0){ // If USER name
870 FullName += myUserName; // appends user name
872 if (myPassword.Length()!=0)
873 FullName = FullName + "\"" + myPassword + "\""; // a password if not empty
875 FullName += "@"; // and character '@'
878 if (myNode.Length()!=0){ // Appends HOST name
883 if (myDisk.Length()!=0) { // Appends Disk name as path
886 VMSDisk2Other(pDisk);
890 // if (FullName.Length()) { // Adds a "/" if necessary
894 if (Way.Length()!=0) { // Appends a path if not empty
898 if (FullName.Length()){
899 if (FullName.Value(FullName.Length()) != '/') {
900 FullName += "/"; // Adds a / if necessary
904 if (myName.Length()){ // Adds the file name
908 if (myExtension.Length()) { // Adds the extension
909 FullName += myExtension;
915 #ifdef TOTO // A reactiver...
917 void OSD_Path::SetSystemName(const TCollection_AsciiString& aDependentName,
918 const OSD_SysType aSysType){
919 UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
923 TCollection_AsciiString OSD_Path::Node()const{
928 TCollection_AsciiString OSD_Path::UserName()const{
933 TCollection_AsciiString OSD_Path::Password()const{
938 TCollection_AsciiString OSD_Path::Disk()const{
943 TCollection_AsciiString OSD_Path::Trek()const{
948 // Return extension (suffix) of file/directory name
950 TCollection_AsciiString OSD_Path::Extension()const{
955 TCollection_AsciiString OSD_Path::Name()const{
960 void OSD_Path::SetNode(const TCollection_AsciiString& aName){
961 if (!aName.IsAscii())
962 Standard_ConstructionError::Raise("OSD_Path::SetNode bad name");
969 void OSD_Path::SetUserName(const TCollection_AsciiString& aName){
970 if (!aName.IsAscii())
971 Standard_ConstructionError::Raise("OSD_Path::SetUserName bad name");
978 void OSD_Path::SetPassword(const TCollection_AsciiString& aName){
979 if (!aName.IsAscii())
980 Standard_ConstructionError::Raise("OSD_Path::SetPassword bad name");
987 void OSD_Path::SetDisk(const TCollection_AsciiString& aName){
988 if (!aName.IsAscii())
989 Standard_ConstructionError::Raise("OSD_Path::SetDisk bad name");
996 void OSD_Path::SetTrek(const TCollection_AsciiString& aName){
997 if (!aName.IsAscii())
998 Standard_ConstructionError::Raise("OSD_Path::SetTrek bad name");
1005 void OSD_Path::SetName(const TCollection_AsciiString& aName){
1006 if (!aName.IsAscii())
1007 Standard_ConstructionError::Raise("OSD_Path::SetName bad name");
1014 void OSD_Path::SetExtension(const TCollection_AsciiString& aName){
1015 if (!aName.IsAscii())
1016 Standard_ConstructionError::Raise("OSD_Path::SetExtension bad name");
1017 myExtension = aName;
1022 //------------------------------------------------------------------------
1023 //------------------- Windows NT sources for OSD_Path -------------------
1024 //------------------------------------------------------------------------
1026 #include <OSD_Path.hxx>
1027 #include <Standard_ProgramError.hxx>
1029 #include <windows.h>
1033 #define TEST_RAISE( type, arg ) _test_raise ( ( type ), ( arg ) )
1035 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
1036 static void __fastcall _remove_dup ( TCollection_AsciiString& );
1038 OSD_Path :: OSD_Path () {
1040 } // end constructor ( 1 )
1042 OSD_Path :: OSD_Path (
1043 const TCollection_AsciiString& aDependentName,
1044 const OSD_SysType aSysType
1047 Standard_Integer i, j, len;
1048 static char __drive [ _MAX_DRIVE ];
1049 static char __dir [ _MAX_DIR ];
1050 static char __trek [ _MAX_DIR ];
1051 static char __fname [ _MAX_FNAME ];
1052 static char __ext [ _MAX_EXT ];
1054 memset(__drive, 0,_MAX_DRIVE);
1055 memset(__dir, 0,_MAX_DIR);
1056 memset(__trek, 0,_MAX_DIR);
1057 memset(__fname, 0,_MAX_FNAME);
1058 memset(__ext, 0,_MAX_EXT);
1059 Standard_Character chr;
1061 TEST_RAISE( aSysType, TEXT( "OSD_Path" ) );
1063 _splitpath ( aDependentName.ToCString (), __drive, __dir, __fname, __ext );
1069 myExtension = __ext;
1072 TCollection_AsciiString dir = __dir;
1073 len = dir.UsefullLength ();
1076 for ( i = j = 0; i < len; ++i, ++j ) {
1080 if ( chr == TEXT( '\\' ) || chr == TEXT( '/' ) )
1082 __trek[j] = TEXT( '|' );
1084 else if ( chr == TEXT( '.' )&& (i+1) < len && __dir[i+1] == TEXT( '.' ) ) {
1086 __trek[j] = TEXT( '^' );
1095 TCollection_AsciiString trek = __trek;
1096 _remove_dup ( trek );
1099 } // end constructor ( 2 )
1101 OSD_Path :: OSD_Path (
1102 const TCollection_AsciiString& aNode,
1103 const TCollection_AsciiString& aUsername,
1104 const TCollection_AsciiString& aPassword,
1105 const TCollection_AsciiString& aDisk,
1106 const TCollection_AsciiString& aTrek,
1107 const TCollection_AsciiString& aName,
1108 const TCollection_AsciiString& anExtension
1111 SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
1113 } // end constructor ( 3 )
1115 void OSD_Path :: Values (
1116 TCollection_AsciiString& aNode,
1117 TCollection_AsciiString& aUsername,
1118 TCollection_AsciiString& aPassword,
1119 TCollection_AsciiString& aDisk,
1120 TCollection_AsciiString& aTrek,
1121 TCollection_AsciiString& aName,
1122 TCollection_AsciiString& anExtension
1126 aUsername = myUserName;
1127 aPassword = myPassword;
1130 if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1131 aTrek += "|" ; // (LD)
1133 anExtension = myExtension;
1135 } // end OSD_Path :: Values
1137 void OSD_Path :: SetValues (
1138 const TCollection_AsciiString& aNode,
1139 const TCollection_AsciiString& aUsername,
1140 const TCollection_AsciiString& aPassword,
1141 const TCollection_AsciiString& aDisk,
1142 const TCollection_AsciiString& aTrek,
1143 const TCollection_AsciiString& aName,
1144 const TCollection_AsciiString& anExtension
1148 myUserName = aUsername;
1149 myPassword = aPassword;
1153 myExtension = anExtension;
1155 if ( myExtension.UsefullLength () && myExtension.Value ( 1 ) != TEXT( '.' ) )
1157 myExtension.Insert ( 1, TEXT( '.' ) );
1159 _remove_dup ( myTrek );
1161 } // end OSD_Path :: SetValues
1163 void OSD_Path :: SystemName (
1164 TCollection_AsciiString& FullName,
1165 const OSD_SysType aType
1168 Standard_Integer i, j;
1169 TCollection_AsciiString fullPath;
1170 static Standard_Character trek [ _MAX_PATH ];
1171 Standard_Character chr;
1173 memset(trek,0,_MAX_PATH);
1175 TEST_RAISE( aType, TEXT( "SystemName" ) );
1177 for ( i = j = 1; i <= myTrek.UsefullLength () && j <= _MAX_PATH; ++i, ++j ) {
1179 chr = myTrek.Value ( i );
1181 if ( chr == TEXT( '|' ) ) {
1183 trek[j-1] = TEXT( '/' );
1185 } else if ( chr == TEXT( '^' ) && j <= _MAX_PATH - 1 ) {
1187 strcpy(&(trek[(j++) - 1]),TEXT( ".." ));
1195 fullPath = myDisk + TCollection_AsciiString(trek);
1197 if ( trek[0] ) fullPath += TEXT( "/" );
1199 fullPath += ( myName + myExtension );
1201 if ( fullPath.UsefullLength () > 0 )
1203 FullName = fullPath;
1209 } // end OSD_Path :: SystemName
1211 Standard_Boolean OSD_Path :: IsValid (
1212 const TCollection_AsciiString& aDependentName,
1213 const OSD_SysType aSysType
1216 TEST_RAISE( aSysType, TEXT( "IsValid" ) );
1218 return Standard_True;
1220 } // end OSD_Path :: IsValid
1222 void OSD_Path :: UpTrek () {
1224 Standard_Integer pos = myTrek.SearchFromEnd ( TEXT( "|" ) );
1230 else if ( pos > 1 ) {
1232 while ( myTrek.Value ( pos ) == TEXT( '|' ) && pos != 1 ) --pos;
1236 myTrek.Trunc ( pos );
1238 } // end OSD_Path :: UpTrek
1240 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1242 Standard_Integer pos = myTrek.UsefullLength ();
1244 if ( aName.Value ( 1 ) != TEXT( '|' ) &&
1246 myTrek.Value ( pos ) != TEXT( '|' )
1249 myTrek += TEXT( "|" );
1253 _remove_dup ( myTrek );
1255 } // end OSD_Path :: DownTrek
1257 Standard_Integer OSD_Path :: TrekLength () const {
1259 Standard_Integer i = 1;
1260 Standard_Integer retVal = 0;
1262 if ( myTrek.IsEmpty () || myTrek.UsefullLength () == 1 && myTrek.Value ( 1 ) == TEXT( '|' ) )
1266 while ( Standard_True ) {
1268 if ( myTrek.Token ( TEXT( "|" ), i++ ).IsEmpty () )
1280 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1282 Standard_Integer i, j;
1283 Standard_Boolean flag = Standard_False;
1285 if ( TrekLength () < thewhere )
1289 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1291 flag = Standard_True;
1292 myTrek.Insert ( 1, TEXT( '|' ) );
1296 i = myTrek.Location (
1297 thewhere, TEXT( '|' ),
1298 1, myTrek.UsefullLength ()
1303 j = myTrek.Location (
1304 thewhere + 1, TEXT( '|' ),
1305 1, myTrek.UsefullLength ()
1310 j = myTrek.UsefullLength () + 1;
1312 myTrek.Remove ( i, j - i );
1318 myTrek.Remove ( 1 );
1320 } // end OSD_Path :: RemoveATrek ( 1 )
1322 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1325 Standard_Boolean flag = Standard_False;
1326 TCollection_AsciiString tmp;
1328 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1330 flag = Standard_True;
1331 myTrek.Insert ( 1, TEXT( '|' ) );
1335 myTrek += TEXT( '|' );
1339 if ( tmp.Value ( 1 ) != TEXT( '|' ) )
1341 tmp.Insert ( 1, TEXT( '|' ) );
1343 if ( tmp.Value ( tmp.UsefullLength () ) != TEXT( '|' ) )
1347 i = myTrek.Search ( tmp );
1351 myTrek.Remove ( i + 1, tmp.UsefullLength () - 1 );
1355 myTrek.Remove ( 1 );
1357 if ( myTrek.Value ( myTrek.UsefullLength () ) == TEXT( '|' ) )
1359 myTrek.Trunc ( myTrek.UsefullLength () - 1 );
1361 } // end OSD_Path :: RemoveATrek ( 2 )
1363 TCollection_AsciiString OSD_Path :: TrekValue (
1364 const Standard_Integer thewhere
1367 TCollection_AsciiString retVal;
1368 TCollection_AsciiString trek = myTrek;
1370 if ( trek.Value ( 1 ) != TEXT( '|' ) )
1372 trek.Insert ( 1, TEXT( '|' ) );
1374 retVal = trek.Token ( TEXT( "|" ), thewhere );
1378 } // end OSD_Path :: TrekValue
1380 void OSD_Path :: InsertATrek (
1381 const TCollection_AsciiString& aName,
1382 const Standard_Integer thewhere
1385 Standard_Integer pos;
1386 TCollection_AsciiString tmp = aName;
1387 Standard_Boolean flag = Standard_False;
1389 if ( myTrek.Value ( 1 ) != TEXT( '|' ) ) {
1391 flag = Standard_True;
1392 myTrek.Insert ( 1, TEXT( '|' ) );
1396 myTrek += TEXT( '|' );
1398 pos = myTrek.Location (
1399 thewhere, TEXT( '|' ),
1400 1, myTrek.UsefullLength ()
1405 if ( tmp.Value ( tmp.UsefullLength () ) != TEXT( '|' ) )
1409 myTrek.Insert ( pos + 1, tmp );
1415 myTrek.Remove ( 1 );
1417 if ( myTrek.Value ( myTrek.UsefullLength () ) == TEXT( '|' ) )
1419 myTrek.Trunc ( myTrek.UsefullLength () - 1 );
1421 _remove_dup ( myTrek );
1423 } // end OSD_Path :: InsertATrek
1425 TCollection_AsciiString OSD_Path :: Node () const {
1429 } // end OSD_Path :: Node
1431 TCollection_AsciiString OSD_Path :: UserName () const {
1435 } // end OSD_Path :: UserName
1437 TCollection_AsciiString OSD_Path :: Password () const {
1441 } // end OSD_Path :: Password
1443 TCollection_AsciiString OSD_Path :: Disk () const {
1447 } // end OSD_Path :: Disk
1449 TCollection_AsciiString OSD_Path :: Trek () const {
1451 TCollection_AsciiString retVal ;
1453 if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1454 retVal += "|" ; // (LD)
1457 } // end OSD_Path :: Trek
1459 TCollection_AsciiString OSD_Path :: Name () const {
1463 } // end OSD_Path :: Name
1465 TCollection_AsciiString OSD_Path :: Extension () const {
1469 } // end OSD_Path :: Extension
1471 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1475 } // end OSD_Path :: SetNode
1477 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1481 } // end OSD_Path :: SetUserName
1483 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1487 } // end OSD_Path :: SetPassword
1489 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1493 } // end OSD_Path :: SetDisk
1495 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1499 _remove_dup ( myTrek );
1501 } // end OSD_Path :: SetTrek
1503 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1507 } // end OSD_Path :: SetName
1509 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1511 myExtension = aName;
1513 } // end OSD_Path :: SetExtension
1515 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1517 Standard_Character buff[ 64 ];
1519 if ( type != OSD_Default && type != OSD_WindowsNT ) {
1521 _tcscpy ( buff, TEXT( "OSD_Path :: " ) );
1522 _tcscat ( buff, str );
1523 _tcscat ( buff, TEXT( " (): unknown system type" ) );
1525 Standard_ProgramError :: Raise ( buff );
1529 } // end _test_raise
1531 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1533 Standard_Integer pos = 1, orgLen, len = str.UsefullLength ();
1537 while ( pos <= len ) {
1539 if ( str.Value ( pos ) == TEXT( '|' ) && pos != len &&
1540 str.Value ( pos + 1 ) == TEXT( '|' ) && pos != 1
1545 while ( pos <= len && str.Value ( pos ) == TEXT( '|' ) ) str.Remove ( pos ), --len;
1553 if ( orgLen > 1 && len > 0 && str.Value ( len ) == TEXT( '|' ) ) str.Remove ( len );
1556 orgLen = len = str.UsefullLength ();
1558 while ( pos <= len ) {
1560 if ( str.Value ( pos ) == TEXT( '^' ) && pos != len && str.Value ( pos + 1 ) == TEXT( '^' ) ) {
1564 while ( pos <= len && str.Value ( pos ) == TEXT( '^' ) ) str.Remove ( pos ), --len;
1572 // if ( orgLen > 1 && len > 0 && str.Value ( len ) == TEXT( '^' ) ) str.Remove ( len );
1574 } // end _remove_dup
1578 // ---------------------------------------------------------------------------
1580 // Elimine les separateurs inutiles
1583 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1585 Standard_Integer i, j, len ;
1587 len = aString.Length() ;
1588 for (i = j = 1 ; j <= len ; i++,j++) {
1589 Standard_Character c = aString.Value(j) ;
1590 aString.SetValue(i,c) ;
1592 while(j < len && aString.Value(j+1) == '/') j++ ;
1595 if (aString.Value(len) == '/') len-- ;
1596 aString.Trunc(len) ;
1600 // ---------------------------------------------------------------------------
1602 TCollection_AsciiString OSD_Path::RelativePath(
1603 const TCollection_AsciiString& aDirPath,
1604 const TCollection_AsciiString& aAbsFilePath)
1606 TCollection_AsciiString EmptyString = "" ;
1607 TCollection_AsciiString FilePath ;
1608 Standard_Integer len ;
1609 Standard_Integer i, n ;
1610 Standard_Boolean Wnt = 0 ;
1612 FilePath = aAbsFilePath ;
1614 if (aDirPath.Search(":") == 2) { // Cas WNT
1616 if (FilePath.Search(":") != 2 ||
1617 UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1619 return EmptyString ;
1621 FilePath.ChangeAll('\\','/') ;
1622 if (FilePath.Search("/") != 3 )
1623 return EmptyString ;
1626 if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1627 return EmptyString ;
1630 // Eliminer les separateurs redondants
1632 len = RemoveExtraSeparator(FilePath) ;
1636 return EmptyString ;
1637 FilePath = FilePath.SubString(2,len) ;
1639 TCollection_AsciiString DirToken, FileToken ;
1640 Standard_Boolean Sibling = 0 ;
1642 for (i = n = 1 ;; n++) {
1643 DirToken = aDirPath.Token("/\\",n) ;
1644 if (DirToken.IsEmpty())
1648 len = FilePath.Length() ;
1649 i = FilePath.Search("/") ;
1652 return EmptyString ;
1654 FileToken = FilePath.SubString(1,i-1) ;
1656 DirToken.UpperCase() ;
1657 FileToken.UpperCase() ;
1659 if (DirToken == FileToken) {
1660 FilePath = FilePath.SubString(i+1,len) ;
1664 else if (DirToken == FilePath)
1665 return EmptyString ;
1670 FilePath.Insert(1,"../") ;
1674 // ---------------------------------------------------------------------------
1676 TCollection_AsciiString OSD_Path::AbsolutePath(
1677 const TCollection_AsciiString& aDirPath,
1678 const TCollection_AsciiString& aRelFilePath)
1680 TCollection_AsciiString EmptyString = "" ;
1681 if (aRelFilePath.Search("/") == 1 || aRelFilePath.Search(":") == 2)
1682 return aRelFilePath ;
1683 TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
1684 Standard_Integer i,len ;
1686 if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1687 return EmptyString ;
1689 if ( DirPath.Search(":") == 2)
1690 DirPath.ChangeAll('\\','/') ;
1691 RelFilePath.ChangeAll('\\','/') ;
1692 RemoveExtraSeparator(DirPath) ;
1693 len = RemoveExtraSeparator(RelFilePath) ;
1695 while (RelFilePath.Search("../") == 1) {
1697 return EmptyString ;
1698 RelFilePath = RelFilePath.SubString(4,len) ;
1700 if (DirPath.IsEmpty())
1701 return EmptyString ;
1702 i = DirPath.SearchFromEnd("/") ;
1704 return EmptyString ;
1705 DirPath.Trunc(i-1) ;
1708 DirPath += RelFilePath ;
1712 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1713 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1717 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1718 Standard_Boolean LocateExecFile(OSD_Path& )
1720 return Standard_False ;