0026823: Configuration - use EGL on another platform without GLX
[occt.git] / src / OSD / OSD_Path.cxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
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>
23
24 static OSD_SysType whereAmI() {
25 #if defined(__digital__) || defined(__FreeBSD__) || defined(SUNOS) || defined(__APPLE__) || defined(__QNX__)
26   return OSD_UnixBSD;
27 }
28 #elif defined(sgi)  || defined(IRIX) || defined(__sun)  || defined(SOLARIS) ||  defined(__sco__) || defined(__hpux) || defined(HPUX)
29   return OSD_UnixSystemV;
30 }
31 #elif defined(__osf__) || defined(DECOSF1)
32   return OSD_OSF;
33 }
34 #elif defined(OS2)
35   return OSD_WindowsNT;
36 }
37 #elif defined(_WIN32) || defined(__WIN32__)
38   return OSD_WindowsNT;
39 }
40 #elif defined(__CYGWIN32_) || defined(__MINGW32__)
41   return OSD_WindowsNT;
42 }
43 #elif defined(vax) || defined(__vms)
44   return OSD_VMS;
45 }
46 #elif defined(__linux__) || defined(__linux)
47   return OSD_LinuxREDHAT;
48 }
49 #elif defined(_AIX) || defined(AIX)
50   return OSD_Aix;
51 }
52 #else
53   struct utsname info;
54   uname(&info);
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;
60   return OSD_Default;
61 }
62 #endif
63
64 #if !(defined(_WIN32) || defined(__WIN32__))
65
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>
71
72 OSD_Path::OSD_Path(){
73  mySysDep = whereAmI();
74 }
75
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){
84
85  TCollection_AsciiString buffer;
86  Standard_Integer pos;
87
88  buffer = what;
89
90  if (buffer.Search("\"") != -1){  // a username to extract
91
92    if (buffer.Value(1) != '"') { // Begins with Node
93     node = buffer.Token("\"");
94     buffer.Remove(1,node.Length());
95    }
96    else node = "";
97
98    username = buffer.Token("\" ");
99    buffer.Remove(1,username.Length()+2); // Removes <<"username ' ' or '"' >>
100
101    if (buffer.Search("\"") != -1){ // a password to extract
102     password = buffer.Token("\"");
103     buffer.Remove(1,password.Length()+1);  // removes <<password">>
104    }
105
106    // If we found a node then we must find "::"
107    if (buffer.Search("::") != -1)
108     buffer.Remove(1,2);            // Removes <<::>>
109  }
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::>
114  }
115
116  if (buffer.Search(":") != -1){ // a disk to extract
117    disk = buffer.Token(":");
118    buffer.Remove(1,disk.Length()+1);  // Removes <<disk:>>
119  }
120  else disk = "";
121
122  // Analyse trek
123
124  if (buffer.Search("[") != -1){  // There is atrek to extract
125   trek = buffer.Token("[]");
126
127   if (trek.Value(1) == '.') trek.Remove(1,1);  // Removes first '.'
128     else trek.Insert(1,'|');                   // Add root
129
130   trek.ChangeAll('.','|');   // Translates to portable syntax
131   trek.ChangeAll('-','^');  
132
133   pos = trek.Search("000000");
134   if (pos != -1) {
135    trek.Remove(pos,6); // on VMS [000000] is the root
136    if (trek.Search("||") != -1) trek.Remove(1,1); // When [000000.xxx] -> ||xxx
137   }
138
139   name = buffer.Token("]",2);
140  }
141  else name = buffer;
142
143  if (name.Search(".") != -1){
144   ext = name.Token(".",2);
145   ext.Insert(1,'.');
146   name.Remove(name.Search("."),ext.Length());
147  }
148  else ext = "";
149   
150 }
151
152
153 //=======================================================================
154 //function : UnixExtract
155 //purpose  : 
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){
164
165  Standard_Integer pos;
166  TCollection_AsciiString buffer;   // To manipulate 'what' without modifying it
167
168  Standard_PCharacter p;
169  buffer = what;
170
171 #ifdef TOTO  // Username, password and node are no longer given in the string (LD)
172
173  if (buffer.Search("@") != -1){  // There is a name to extract
174   username = buffer.Token("\"@");
175   buffer.Remove(1,username.Length()+1);   // Removes << user@ >>
176
177   if (buffer.Search("\"") != -1){       // There is a password to extract
178    password = buffer.Token("\"");
179    buffer.Remove(1,password.Length()+2);  // Removes << "password" >>
180   }
181
182  }
183  else {
184   username = "";
185   password = "";
186  }
187
188 #endif  // node must be given (for DBT, DM) (ADN 29/8/96)
189
190  if (buffer.Search(":/") != -1){      // There is a node to extract
191   node = buffer.Token(":/");
192   buffer.Remove(1,node.Length()+1);  // Removes << node: >>
193  }
194  else node = ""; 
195
196   username = "";
197   password = "";
198 //  node = ""; 
199  
200  trek = buffer;
201
202  trek.ChangeAll('/','|');  // Translates to portable syntax
203
204  pos = trek.SearchFromEnd("|");  // Extract name
205  if (pos != -1) {
206   p = (Standard_PCharacter)trek.ToCString();
207   name = &p[pos];
208   if(name.Length()) trek.Remove(pos+1,name.Length());
209  }
210  else {   // No '|' means no trek but a name
211   name = buffer;
212   trek = "";
213  }
214
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("..");
220  }
221
222   pos = name.SearchFromEnd(".") ;   // LD : debug
223   if (pos != -1)      // There is an extension to extract
224     ext = name.Split(pos - 1) ;  
225
226
227 // if (name.Search(".") != -1){ // There is an extension to extract
228 //   if ( name.Value(1) == '.' ) {
229 //     ext = name;
230 //     name.Clear();
231 //   }
232 //   else {
233 //     ext = name.Token(".",2); 
234 //     ext.Insert(1,'.');            // Prepends 'dot'
235 //     pos = name.Search(".");     // Removes extension from buffer
236 //     if (pos != -1)
237 //       name.Remove(pos,ext.Length());
238 //   }
239 // }
240
241 }
242
243
244 //=======================================================================
245 //function : DosExtract
246 //purpose  : 
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){
253
254  TCollection_AsciiString buffer;
255  Standard_Integer pos;
256  Standard_PCharacter p;
257
258  buffer = what;
259
260  if (buffer.Search(":") != -1){ // There is a disk to extract
261   disk = buffer.Token(":");
262   disk += ":";
263   buffer.Remove(1,disk.Length());  // Removes <<disk:>>
264  }
265
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
270   if (pos != -1)
271    buffer.Remove(pos,ext.Length());
272  }
273
274  trek = buffer;
275
276  trek.ChangeAll('\\','|');  
277
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("..");
283  }
284
285  pos = trek.SearchFromEnd("|");  // Extract name
286  if (pos != -1) {
287   p = (Standard_PCharacter)trek.ToCString();
288   name = &p[pos];
289   trek.Remove(trek.Search(name),name.Length());
290  }
291  else {   // No '|' means no trek but a name
292   name = buffer;
293   trek = "";
294  }
295 }
296
297
298 //=======================================================================
299 //function : MacExtract
300 //purpose  : 
301 //=======================================================================
302 static void MacExtract(const TCollection_AsciiString& what,
303                 TCollection_AsciiString& ,
304                 TCollection_AsciiString& trek,
305                 TCollection_AsciiString& name,
306                 TCollection_AsciiString& ){
307
308   Standard_Integer pos;
309   Standard_PCharacter p;
310   
311   // I don't know how to distingish a disk from a trek !
312   
313   trek = what;
314   
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("::");
320   }
321
322   trek.ChangeAll(':','|');  // Translates to portable syntax
323
324   pos = trek.SearchFromEnd("|");  // Extract name
325   if (pos != -1) {
326     p = (Standard_PCharacter)trek.ToCString();
327     name = &p[pos+1];
328     trek.Remove(trek.Search(name),name.Length());
329   }
330   else {   // No '|' means no trek but a name
331     name = what;
332     trek = "";
333   }
334 }
335
336
337 OSD_Path::OSD_Path(const TCollection_AsciiString& aDependentName,
338                    const OSD_SysType aSysType){
339
340  mySysDep = whereAmI();
341
342  OSD_SysType todo;
343 //  Standard_Integer i,l;
344
345   if (aSysType == OSD_Default) {
346     todo = mySysDep;
347   } else {
348     todo = aSysType;
349   }
350
351  switch (todo){
352   case OSD_VMS:
353      VmsExtract(aDependentName,myNode,myUserName,myPassword,myDisk,myTrek,myName,myExtension);
354      break;
355   case OSD_LinuxREDHAT:
356   case OSD_UnixBSD:
357   case OSD_UnixSystemV:
358   case OSD_Aix:
359   case OSD_OSF:
360      UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
361      break;
362   case OSD_OS2:
363   case OSD_WindowsNT:
364      DosExtract(aDependentName,myDisk,myTrek,myName,myExtension);
365      break;
366   case OSD_MacOs:
367      MacExtract(aDependentName,myDisk,myTrek,myName,myExtension);
368      break;
369   default:
370 #ifdef OCCT_DEBUG
371        cout << " WARNING WARNING : OSD Path for an Unknown SYSTEM : " << (Standard_Integer)todo << endl;
372 #endif 
373      break ;
374  } 
375 }
376
377
378
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){
386
387  mySysDep = whereAmI();
388
389  SetValues ( Nod, UsrNm, Passwd, Dsk, Trk, Nam, ext);
390
391
392 }
393
394
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{
402
403  Nod = myNode;
404  UsrNm = myUserName;
405  Passwd = myPassword;
406  Dsk = myDisk;
407  Trk = myTrek;
408  Nam = myName;
409  ext = myExtension;
410 }
411
412
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){
420
421  if (!Nod.IsAscii())
422   Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Node");
423  if (!UsrNm.IsAscii())
424   Standard_ConstructionError::Raise("OSD_Path::SetValues argument : User Name");
425  if (!Dsk.IsAscii())
426   Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Disk");
427  if (!Trk.IsAscii())
428   Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Trek");
429  if (!Nam.IsAscii())
430   Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Name");
431  if (!ext.IsAscii())
432   Standard_ConstructionError::Raise("OSD_Path::SetValues argument : Extension");
433
434  myNode = Nod;
435  myUserName = UsrNm;
436  myPassword = Passwd;
437  myDisk = Dsk;
438  myTrek = Trk;
439  myName = Nam;
440  myExtension = ext;
441 }
442
443 void OSD_Path::UpTrek(){
444  Standard_Integer length=TrekLength();
445
446  if (length == 0) return;
447
448  Standard_Integer awhere,aHowmany;
449  TCollection_AsciiString tok;
450
451  tok = myTrek.Token("|",length);
452  awhere = myTrek.SearchFromEnd(tok);
453  aHowmany = tok.Length();
454  myTrek.Remove(awhere,aHowmany);
455
456  awhere = myTrek.Search("||");   // Searches leaving "||"
457  if (awhere != -1)
458   myTrek.Remove(awhere);
459 }
460
461
462 void OSD_Path::DownTrek(const TCollection_AsciiString& aName){
463  myTrek += aName;
464 // Pb signale par GG : pour ne pas avoir "||" ;
465  if ( aName.ToCString()[ aName.Length() - 1 ] != '|' )
466    myTrek += "|";
467 }
468
469
470 Standard_Integer OSD_Path::TrekLength()const{
471  Standard_Integer cpt=0;
472
473  while (myTrek.Token("|",cpt+1) != "")  // Counts token separated by '|'
474   cpt++;
475
476  return(cpt);
477 }
478
479
480 void OSD_Path::RemoveATrek(const Standard_Integer thewhere){
481  Standard_Integer length=TrekLength();
482
483  if (length <= 0 || thewhere > length)
484   Standard_NumericError::Raise("OSD_Path::RemoveATrek : where has an invalid value");
485
486  Standard_Integer posit,aHowmany;
487  TCollection_AsciiString tok;
488
489  tok = myTrek.Token("|",thewhere);
490  posit = myTrek.Search(tok);
491  aHowmany = tok.Length();
492  myTrek.Remove(posit,aHowmany);
493
494  posit = myTrek.Search("||");   // Searches leaving "||"
495  if (posit != -1)
496   myTrek.Remove(posit);
497 }
498
499
500 void OSD_Path::RemoveATrek(const TCollection_AsciiString& aName){
501  Standard_Integer length=TrekLength();
502
503  if (length == 0) return;
504
505  Standard_Integer awhere;
506
507  awhere = myTrek.Search(aName);
508  if (awhere != -1){
509   myTrek.Remove(awhere,aName.Length());
510
511   awhere = myTrek.Search("||");   // Searches leaving "||"
512   if (awhere != -1)
513    myTrek.Remove(awhere); 
514  } 
515 }
516
517
518 TCollection_AsciiString OSD_Path::TrekValue(const Standard_Integer thewhere)const{
519  TCollection_AsciiString result=myTrek.Token("|",thewhere);
520
521  if (result == "")
522   Standard_NumericError::Raise("OSD_Path::TrekValue : where is invalid");
523
524  return(result);
525 }
526
527 void OSD_Path::InsertATrek(const TCollection_AsciiString& aName,
528                            const Standard_Integer thewhere){
529  Standard_Integer length=TrekLength();
530
531  if (thewhere <= 0 || thewhere > length)
532   Standard_NumericError::Raise("OSD_Path::InsertATrek : where has an invalid value");
533
534  TCollection_AsciiString tok=myTrek.Token("|",thewhere);
535  Standard_Integer wwhere = myTrek.Search(tok);
536  TCollection_AsciiString what = aName;
537  what += "|";
538
539  myTrek.Insert(wwhere,what);
540 }
541
542
543 // The 4 following methods will be PUBLIC in the future
544
545 // Converts a VMS disk to other system syntax
546
547 static void VMSDisk2Other(TCollection_AsciiString & Disk){
548  Disk.RemoveAll('$');
549 }
550
551
552 // Convert a Trek to VMS syntax
553
554 static void P2VMS (TCollection_AsciiString & Way){
555  Standard_Integer length = Way.Length();
556
557  if (length == 0) return;
558
559  if (Way.Value(1) == '|')             // If begin with '|' remove '|'
560   if (Way.Value(1) != '\0')
561    Way.Remove(1,1);
562   else Way = "000000";             // Si uniquement la racine -> [000000]
563  else
564   if (Way.Length()!=0)
565    Way.Insert(1,'|');          // Else insert '|' at beginning if not empty;
566
567  Way.ChangeAll('|','.');
568  Way.ChangeAll('^','-');
569
570 }
571
572 // Convert a Trek to MAC syntax
573
574 static void P2MAC (TCollection_AsciiString & Way){
575  int i,l;
576  Way.ChangeAll('|',':');
577
578  l = (int)Way.Length();
579  for (i=1; i <= l; i++)             // Replace '^' by "::"
580   if (Way.Value(i) == '^'){
581    Way.SetValue(i,':');
582    Way.Insert(i,':');
583    i++; l++;
584   } 
585 }
586
587
588 // Convert a Trek to UNIX syntax
589
590 static void P2UNIX (TCollection_AsciiString & Way){
591  int i,l;
592  Standard_Integer length = Way.Length();
593
594  if (length == 0) return;
595
596  // if (Way.Value(length) == '|') // If Finishes with "|" removes it
597  // Way.Trunc(length-1);
598
599  Way.ChangeAll('|','/');
600  
601  l = (int)Way.Length();
602  for (i=1; i <= l; i++)             // Replace '^' by "../"
603   if (Way.Value(i) == '^'){
604    Way.SetValue(i,'.');
605    Way.Insert(i+1,'.');
606    //Way.Insert(i+2,'/');
607    i +=1; l +=1;
608   } 
609 }
610
611
612 // Convert a Trek to DOS like syntax
613
614 static void P2DOS (TCollection_AsciiString & Way){
615  int i,l;
616  Standard_Integer len = Way.Length();
617
618  if (len == 0) return;
619
620  if (Way.Value(len) == '|')   // If Finishes with "|" removes it
621   Way.Trunc(len-1);
622
623  Way.ChangeAll('|','\\');
624  
625  l = (int)Way.Length();
626  for (i=1; i <= l; i++)             // Replace '^' by ".."
627   if (Way.Value(i) == '^'){
628    Way.SetValue(i,'.');
629    Way.Insert(i,'.');
630    i++; l++;
631   } 
632
633 }
634
635
636
637
638 // Convert a path to system dependant syntax
639
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;
645 OSD_SysType pType;
646
647  if (aType == OSD_Default) {
648    pType = mySysDep;
649  } else {
650    pType = aType;
651  }
652
653  Way = myTrek;
654  FullName.Clear();
655
656  switch (pType){
657   case OSD_VMS :
658    pNode = myNode;
659
660    P2VMS (Way);    // Convert path
661
662    if (myNode.Length()!=0) FullName += myNode;      // Append Node
663
664    if (myUserName.Length()!=0){   // Append User name
665
666     if (pNode.Length()==0) {    // If a user name but no node, catenate "0"
667      pNode = "0";
668      FullName += pNode;
669     }
670
671
672     FullName += "\"";
673     FullName += myUserName;
674
675     if (myPassword.Length()!=0){  // Append password
676      FullName += " ";
677      FullName += myPassword;
678     }
679
680     FullName += "\"";
681    }
682
683    if (pNode.Length()!=0) FullName += "::";
684
685    if (myDisk.Length()!=0){       // Append Disk
686     FullName += myDisk;
687     FullName += ":";
688    }
689     
690
691    if (Way.Length()!=0)         // Append VMS path
692     FullName = FullName + "[" + Way + "]" + myName + myExtension;
693
694 //   FullName.UpperCase();
695    break;
696
697
698    case OSD_OS2 :
699    case OSD_WindowsNT :            // MSDOS-like syntax
700     {
701     int length = (int)myDisk.Length();
702
703     P2DOS (Way);
704     if (length != 1)
705
706     if (myDisk.Length()!=0){
707
708      if (
709          (length == 1 && IsAlphabetic(myDisk.Value(1))) ||     // 'A/a' to 'Z/z'
710          (length == 2 &&
711           IsAlphabetic(myDisk.Value(1)) &&
712           myDisk.Value(2) == ':')                         // 'A:' to 'Z:'
713         )    // This is a MSDOS disk syntax
714      {
715       FullName += myDisk;
716       if (myDisk.Value(length) != ':') FullName += ":";
717      }
718      else   // This is an assigned Disk
719      {
720       FullName += "\\";
721       pDisk = myDisk;
722       VMSDisk2Other(pDisk);
723       FullName += pDisk;
724       if (Way.Value(1) != '\\') FullName += "\\";
725      }
726     }
727
728     if (Way.Length()!=0)
729      FullName = FullName + Way + "\\";
730     
731     FullName += myName; 
732     FullName += myExtension;
733 //    FullName.UpperCase();
734     break;
735    }
736
737    case OSD_MacOs :                // Mackintosh-like syntax
738     if (myDisk.Length()!=0){
739      FullName += myDisk ;
740      FullName += ":";
741     }
742     P2MAC(Way); 
743     FullName += myName;
744     FullName += myExtension;
745    break;
746
747
748
749    default :                      // UNIX-like syntax
750
751  // Syntax :
752  //             user"password"@host:/disk/xxx/xxx/filename
753     P2UNIX (Way);
754
755     if (myUserName.Length()!=0 && myNode.Length()!=0){  // If USER name
756      FullName += myUserName;                        // appends user name 
757
758      if (myPassword.Length()!=0)
759       FullName = FullName + "\"" + myPassword + "\""; // a password if not empty
760
761      FullName += "@";                            // and character '@'
762     }
763
764     if (myNode.Length()!=0){                     // Appends HOST name
765      FullName += myNode;
766      FullName += ":";
767     }
768
769     if (myDisk.Length()!=0) {                    // Appends Disk name as path
770      FullName += "/";
771      pDisk = myDisk;
772      VMSDisk2Other(pDisk);
773      FullName += pDisk;
774     }
775
776 //    if (FullName.Length()) {                     // Adds a "/" if necessary
777 //      FullName += "/";
778 //    }
779
780     if (Way.Length()!=0) {                       // Appends a path if not empty
781       FullName += Way ; 
782     }
783
784     if (FullName.Length()){
785         if (FullName.Value(FullName.Length()) != '/') {
786            FullName += "/";                      // Adds a / if necessary
787        }
788     }
789
790     if (myName.Length()){                        // Adds the file name
791       FullName += myName;
792     }
793
794     if (myExtension.Length()) {                  // Adds the extension
795       FullName += myExtension;
796     }
797     break;
798  }
799 }
800
801 #ifdef TOTO  // A reactiver...
802
803 void OSD_Path::SetSystemName(const TCollection_AsciiString& aDependentName,
804                    const OSD_SysType aSysType){
805   UnixExtract(aDependentName,myNode,myUserName,myPassword,myTrek,myName,myExtension);
806 }
807 #endif
808
809 TCollection_AsciiString OSD_Path::Node()const{
810  return(myNode);
811 }
812
813
814 TCollection_AsciiString OSD_Path::UserName()const{
815  return(myUserName);
816 }
817
818
819 TCollection_AsciiString OSD_Path::Password()const{
820  return(myPassword);
821 }
822
823
824 TCollection_AsciiString OSD_Path::Disk()const{
825  return(myDisk);
826 }
827
828
829 TCollection_AsciiString OSD_Path::Trek()const{
830  return(myTrek);
831 }
832
833
834 // Return extension (suffix) of file/directory name
835
836 TCollection_AsciiString OSD_Path::Extension()const{
837  return(myExtension);
838 }
839
840
841 TCollection_AsciiString OSD_Path::Name()const{
842  return(myName);
843 }
844
845
846 void OSD_Path::SetNode(const TCollection_AsciiString& aName){
847  if (!aName.IsAscii())
848   Standard_ConstructionError::Raise("OSD_Path::SetNode bad name");
849  myNode = aName;
850 }
851
852
853
854
855 void OSD_Path::SetUserName(const TCollection_AsciiString& aName){
856  if (!aName.IsAscii())
857   Standard_ConstructionError::Raise("OSD_Path::SetUserName bad name");
858  myUserName = aName;
859 }
860
861
862
863
864 void OSD_Path::SetPassword(const TCollection_AsciiString& aName){
865  if (!aName.IsAscii())
866   Standard_ConstructionError::Raise("OSD_Path::SetPassword bad name");
867   myPassword = aName;
868 }
869
870
871
872
873 void OSD_Path::SetDisk(const TCollection_AsciiString& aName){
874  if (!aName.IsAscii())
875   Standard_ConstructionError::Raise("OSD_Path::SetDisk bad name");
876   myDisk = aName;
877 }
878
879
880
881
882 void OSD_Path::SetTrek(const TCollection_AsciiString& aName){
883  if (!aName.IsAscii())
884   Standard_ConstructionError::Raise("OSD_Path::SetTrek bad name");
885   myTrek = aName;
886 }
887
888
889
890
891 void OSD_Path::SetName(const TCollection_AsciiString& aName){
892  if (!aName.IsAscii())
893   Standard_ConstructionError::Raise("OSD_Path::SetName bad name");
894   myName = aName;
895 }
896
897
898
899
900 void OSD_Path::SetExtension(const TCollection_AsciiString& aName){
901  if (!aName.IsAscii())
902   Standard_ConstructionError::Raise("OSD_Path::SetExtension bad name");
903   myExtension = aName;
904 }
905
906 #else
907
908 //------------------------------------------------------------------------
909 //-------------------  Windows sources for OSD_Path -------------------
910 //------------------------------------------------------------------------
911
912 #include <Standard_ProgramError.hxx>
913
914 #include <windows.h>
915 #include <stdlib.h>
916
917 #define TEST_RAISE( type, arg ) _test_raise (  ( type ), ( arg )  )
918
919 static void __fastcall _test_raise ( OSD_SysType, Standard_CString );
920 static void __fastcall _remove_dup ( TCollection_AsciiString& );
921
922 OSD_Path :: OSD_Path () {
923
924 }  // end constructor ( 1 )
925
926 OSD_Path ::  OSD_Path (
927               const TCollection_AsciiString& aDependentName,
928               const OSD_SysType aSysType
929                           ) :
930   myUNCFlag(Standard_False),
931   mySysDep(OSD_WindowsNT)
932 {
933
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 ];
940
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;
947
948  TEST_RAISE(  aSysType, "OSD_Path"  );
949
950  _splitpath (  aDependentName.ToCString (), __drive, __dir, __fname, __ext );
951  
952  
953
954  myDisk      = __drive;
955  myName      = __fname;
956  myExtension = __ext;
957
958  {
959    TCollection_AsciiString dir   = __dir;
960    len = dir.Length ();
961  }
962
963  for ( i = j = 0; i < len; ++i, ++j ) {
964
965   chr = __dir[i];
966  
967   if (  chr == '\\' || chr == '/'  )
968
969    __trek[j] = '|';
970
971   else if (  chr == '.'&& (i+1) < len && __dir[i+1] == '.'  ) {
972   
973    __trek[j] = '^';
974    ++i;
975   
976   } else
977
978    __trek[j] = chr;
979  
980  }  // end for
981  __trek[j] = '\0';
982  TCollection_AsciiString trek  = __trek;
983  _remove_dup ( trek );
984  myTrek = trek;
985
986 }  // end constructor ( 2 )
987
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
996                          ) :
997   myUNCFlag(Standard_False),
998   mySysDep(OSD_WindowsNT)
999 {
1000
1001  SetValues ( aNode, aUsername, aPassword, aDisk, aTrek, aName, anExtension );
1002
1003 }  // end constructor ( 3 )
1004
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
1013                  ) const {
1014
1015  aNode       = myNode;
1016  aUsername   = myUserName;
1017  aPassword   = myPassword;
1018  aDisk       = myDisk;
1019  aTrek       = myTrek;
1020  if (!aTrek.IsEmpty() && aTrek.Value(aTrek.Length()) != '|')
1021    aTrek += "|" ; // (LD)
1022  aName       = myName;
1023  anExtension = myExtension;
1024
1025 }  // end OSD_Path :: Values
1026
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
1035                  ) {
1036
1037  myNode      = aNode;
1038  myUserName  = aUsername;
1039  myPassword  = aPassword;
1040  myDisk      = aDisk;
1041  myTrek      = aTrek;
1042  myName      = aName;
1043  myExtension = anExtension;
1044
1045  if (  myExtension.Length () && myExtension.Value ( 1 ) != '.'  )
1046
1047   myExtension.Insert (  1, '.'  );
1048
1049  _remove_dup ( myTrek );
1050
1051 }  // end OSD_Path :: SetValues
1052
1053 void OSD_Path :: SystemName (
1054                   TCollection_AsciiString& FullName,
1055                   const OSD_SysType aType
1056                  ) const {
1057
1058  Standard_Integer        i, j;
1059  TCollection_AsciiString fullPath;
1060  static Standard_Character trek [ _MAX_PATH ];
1061  Standard_Character      chr;
1062
1063  memset(trek,0,_MAX_PATH);
1064
1065  TEST_RAISE(  aType, "SystemName"  );
1066
1067  for ( i = j = 1; i <= myTrek.Length () && j <= _MAX_PATH; ++i, ++j ) {
1068
1069   chr = myTrek.Value ( i );   
1070
1071   if (  chr == '|'  ) {
1072   
1073    trek[j-1] = '/';
1074   
1075   } else if (  chr == '^' && j <= _MAX_PATH - 1  ) {
1076    
1077    strcpy(&(trek[(j++) - 1]),"..");
1078
1079   } else
1080
1081    trek[j-1] = chr ;
1082  
1083  }  //end for
1084
1085  fullPath = myDisk + TCollection_AsciiString(trek);
1086  
1087  if ( trek[0] ) fullPath += "/";
1088  
1089  fullPath += ( myName + myExtension );
1090
1091  if (  fullPath.Length () > 0  )
1092
1093   FullName = fullPath;
1094
1095  else
1096
1097   FullName.Clear ();
1098
1099 }  // end OSD_Path :: SystemName
1100
1101 void OSD_Path :: UpTrek () {
1102
1103  Standard_Integer pos = myTrek.SearchFromEnd (  "|"  );
1104
1105  if ( pos == -1 )
1106
1107   pos = 0;
1108
1109  else if ( pos > 1 ) {
1110
1111   while (  myTrek.Value ( pos ) == '|' && pos != 1  ) --pos;
1112
1113  }  // end if
1114
1115  myTrek.Trunc ( pos );
1116
1117 }  // end OSD_Path :: UpTrek
1118
1119 void OSD_Path :: DownTrek ( const TCollection_AsciiString& aName ) {
1120
1121  Standard_Integer pos = myTrek.Length ();
1122
1123  if (  aName.Value ( 1 ) != '|'    &&
1124        pos                                 &&
1125        myTrek.Value ( pos ) != '|'
1126  )
1127
1128   myTrek += "|";
1129
1130  myTrek += aName;
1131
1132  _remove_dup ( myTrek );
1133
1134 }  // end OSD_Path :: DownTrek
1135
1136 Standard_Integer OSD_Path :: TrekLength () const {
1137
1138  Standard_Integer i      = 1;
1139  Standard_Integer retVal = 0;
1140
1141  if (  myTrek.IsEmpty () || myTrek.Length () == 1 && myTrek.Value ( 1 ) == '|'  )
1142
1143   return retVal;
1144
1145  for (;;) {
1146  
1147   if (  myTrek.Token (  "|", i++  ).IsEmpty ()  )
1148
1149    break;
1150
1151   ++retVal;
1152  
1153  }  //end while
1154
1155  return retVal;
1156
1157 }  // end TrekLength
1158
1159 void OSD_Path :: RemoveATrek ( const Standard_Integer thewhere ) {
1160
1161  Standard_Integer i, j;
1162  Standard_Boolean flag = Standard_False;
1163
1164  if (  TrekLength () < thewhere  )
1165
1166   return;
1167
1168  if (  myTrek.Value ( 1 ) != '|'  ) {
1169  
1170   flag = Standard_True;
1171   myTrek.Insert (  1, '|'  );
1172  
1173  }  // end if
1174
1175  i = myTrek.Location (
1176              thewhere, '|',
1177              1, myTrek.Length ()
1178             );
1179
1180  if ( i ) {
1181
1182   j = myTrek.Location (
1183               thewhere + 1, '|',
1184               1, myTrek.Length ()
1185              );
1186
1187   if ( j == 0 )
1188
1189    j = myTrek.Length () + 1;
1190
1191   myTrek.Remove ( i, j - i );
1192
1193  }  // end if
1194
1195  if ( flag )
1196
1197   myTrek.Remove ( 1 );
1198
1199 }  // end OSD_Path :: RemoveATrek ( 1 )
1200
1201 void OSD_Path :: RemoveATrek ( const TCollection_AsciiString& aName ) {
1202
1203  Standard_Integer        i;
1204  Standard_Boolean        flag = Standard_False;
1205  TCollection_AsciiString tmp;
1206
1207  if (  myTrek.Value ( 1 ) != '|'  ) {
1208  
1209   flag = Standard_True;
1210   myTrek.Insert (  1, '|'  );
1211  
1212  }  // end if
1213
1214  myTrek += '|';
1215
1216  tmp = aName;
1217
1218  if (  tmp.Value ( 1 ) != '|'  )
1219
1220   tmp.Insert (  1, '|'  );
1221
1222  if (   tmp.Value (  tmp.Length ()  ) != '|'   )
1223
1224   tmp += '|';
1225
1226  i = myTrek.Search ( tmp );
1227
1228  if ( i != -1 )
1229  
1230   myTrek.Remove (  i + 1, tmp.Length () - 1  );
1231
1232  if ( flag )
1233
1234   myTrek.Remove ( 1 );
1235  
1236  if (   myTrek.Value (  myTrek.Length ()  ) == '|'  )
1237
1238   myTrek.Trunc (  myTrek.Length () - 1  );
1239
1240 }  // end OSD_Path :: RemoveATrek ( 2 )
1241
1242 TCollection_AsciiString OSD_Path :: TrekValue (
1243                                      const Standard_Integer thewhere
1244                                     ) const {
1245
1246  TCollection_AsciiString retVal;
1247  TCollection_AsciiString trek = myTrek;
1248
1249  if (  trek.Value ( 1 ) != '|'  )
1250  
1251   trek.Insert (  1, '|'  );
1252  
1253  retVal = trek.Token (  "|", thewhere  );
1254
1255  return retVal;
1256
1257 }  // end OSD_Path :: TrekValue
1258
1259 void OSD_Path :: InsertATrek (
1260                   const TCollection_AsciiString& aName,
1261                   const Standard_Integer thewhere
1262                  ) {
1263
1264  Standard_Integer        pos;
1265  TCollection_AsciiString tmp = aName;
1266  Standard_Boolean        flag = Standard_False;
1267
1268  if (  myTrek.Value ( 1 ) != '|'  ) {
1269  
1270   flag = Standard_True;
1271   myTrek.Insert (  1, '|'  );
1272  
1273  }  // end if
1274
1275  myTrek += '|';
1276
1277  pos = myTrek.Location (
1278                thewhere, '|',
1279                1, myTrek.Length ()
1280               );
1281
1282  if ( pos ) {
1283
1284   if (   tmp.Value (  tmp.Length ()  ) != '|'   )
1285
1286    tmp += '|';
1287
1288   myTrek.Insert ( pos + 1, tmp );
1289
1290  }  // end if
1291
1292  if ( flag )
1293
1294   myTrek.Remove ( 1 );
1295
1296  if (   myTrek.Value (  myTrek.Length ()  ) == '|'  )
1297
1298   myTrek.Trunc (  myTrek.Length () - 1  );
1299
1300  _remove_dup ( myTrek );
1301
1302 }  // end OSD_Path :: InsertATrek
1303
1304 TCollection_AsciiString OSD_Path :: Node () const {
1305
1306  return myNode;
1307
1308 }  // end OSD_Path :: Node
1309
1310 TCollection_AsciiString OSD_Path :: UserName () const {
1311
1312  return myUserName;
1313
1314 }  // end OSD_Path :: UserName
1315
1316 TCollection_AsciiString OSD_Path :: Password () const {
1317
1318  return myPassword;
1319
1320 }  // end OSD_Path :: Password
1321
1322 TCollection_AsciiString OSD_Path :: Disk () const {
1323
1324  return myDisk;
1325
1326 }  // end OSD_Path :: Disk
1327
1328 TCollection_AsciiString OSD_Path :: Trek () const {
1329
1330  TCollection_AsciiString retVal ;
1331  retVal = myTrek ;
1332  if (!retVal.IsEmpty() && retVal.Value(retVal.Length()) != '|')
1333    retVal += "|" ;          // (LD)
1334  return retVal;
1335
1336 }  // end OSD_Path :: Trek
1337
1338 TCollection_AsciiString OSD_Path :: Name () const {
1339
1340  return myName;
1341
1342 }  // end OSD_Path :: Name
1343
1344 TCollection_AsciiString OSD_Path :: Extension () const {
1345
1346  return myExtension;
1347
1348 }  // end OSD_Path :: Extension
1349
1350 void OSD_Path :: SetNode ( const TCollection_AsciiString& aName ) {
1351
1352  myNode = aName;
1353
1354 }  // end OSD_Path :: SetNode
1355
1356 void OSD_Path :: SetUserName (const TCollection_AsciiString& aName ) {
1357
1358  myUserName = aName;
1359
1360 }  // end OSD_Path :: SetUserName
1361
1362 void OSD_Path :: SetPassword ( const TCollection_AsciiString& aName ) {
1363
1364  myPassword = aName;
1365
1366 }  // end OSD_Path :: SetPassword
1367
1368 void OSD_Path :: SetDisk ( const TCollection_AsciiString& aName ) {
1369
1370  myDisk = aName;
1371
1372 }  // end OSD_Path :: SetDisk
1373
1374 void OSD_Path :: SetTrek (const TCollection_AsciiString& aName ) {
1375
1376  myTrek = aName;
1377
1378  _remove_dup ( myTrek );
1379
1380 }  // end OSD_Path :: SetTrek
1381
1382 void OSD_Path :: SetName ( const TCollection_AsciiString& aName ) {
1383
1384  myName = aName;
1385
1386 }  // end OSD_Path :: SetName
1387
1388 void OSD_Path :: SetExtension ( const TCollection_AsciiString& aName ) {
1389
1390  myExtension = aName;
1391
1392 }  // end OSD_Path :: SetExtension
1393
1394 static void __fastcall _test_raise ( OSD_SysType type, Standard_CString str ) {
1395
1396  Standard_Character buff[ 64 ];
1397
1398  if ( type != OSD_Default && type != OSD_WindowsNT ) {
1399  
1400   strcpy (  buff, "OSD_Path :: "  );
1401   strcat (  buff, str );
1402   strcat (  buff, " (): unknown system type"  );
1403
1404   Standard_ProgramError :: Raise ( buff );
1405  
1406  }  // end if
1407
1408 }  // end _test_raise
1409
1410 static void __fastcall _remove_dup ( TCollection_AsciiString& str ) {
1411
1412  Standard_Integer pos = 1, orgLen, len = str.Length ();
1413
1414  orgLen = len;
1415
1416  while ( pos <= len ) {
1417  
1418   if (  str.Value ( pos     ) == '|' && pos != len &&
1419         str.Value ( pos + 1 ) == '|' && pos != 1
1420   ) {
1421   
1422    ++pos;
1423
1424    while (  pos <= len && str.Value ( pos ) == '|'  ) str.Remove ( pos ), --len;
1425   
1426   } else
1427
1428    ++pos;
1429  
1430  }  // end while
1431
1432  if (  orgLen > 1 && len > 0 && str.Value ( len ) == '|'  ) str.Remove ( len );
1433
1434  pos = 1;
1435  orgLen = len = str.Length ();
1436
1437  while ( pos <= len ) {
1438  
1439   if (  str.Value ( pos ) == '^' && pos != len && str.Value ( pos + 1 ) == '^'  ) {
1440   
1441    ++pos;
1442
1443    while (  pos <= len && str.Value ( pos ) == '^'  ) str.Remove ( pos ), --len;
1444   
1445   } else
1446
1447    ++pos;
1448  
1449  }  // end while
1450
1451 // if (  orgLen > 1 && len > 0 && str.Value ( len ) == '^'  ) str.Remove ( len );
1452
1453 }  // end _remove_dup
1454
1455 #endif // Windows sources for OSD_Path
1456
1457 // =======================================================================
1458 // function : Analyse_VMS
1459 // purpose  :
1460 // =======================================================================
1461 static Standard_Boolean Analyse_VMS (const TCollection_AsciiString& theName)
1462 {
1463   if (theName.Search ("/")  != -1
1464    || theName.Search ("@")  != -1
1465    || theName.Search ("\\") != -1)
1466   {
1467     return Standard_False;
1468   }
1469
1470   return Standard_True;
1471 }
1472
1473 // =======================================================================
1474 // function : Analyse_DOS
1475 // purpose  :
1476 // =======================================================================
1477 static Standard_Boolean Analyse_DOS(const TCollection_AsciiString& theName)
1478 {
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)
1487   {
1488     return Standard_False;
1489   }
1490
1491  return Standard_True;
1492 }
1493
1494 // =======================================================================
1495 // function : Analyse_MACOS
1496 // purpose  :
1497 // =======================================================================
1498 static Standard_Boolean Analyse_MACOS (const TCollection_AsciiString& theName)
1499 {
1500   return theName.Search(":") == -1 ? theName.Length() <= 31 : Standard_True;
1501 }
1502
1503 // =======================================================================
1504 // function : IsValid
1505 // purpose  :
1506 // =======================================================================
1507 Standard_Boolean OSD_Path::IsValid (const TCollection_AsciiString& theDependentName,
1508                                     const OSD_SysType theSysType)
1509 {
1510   if (theDependentName.Length() == 0)
1511   {
1512     return Standard_True;
1513   }
1514
1515   switch (theSysType == OSD_Default ? whereAmI() : theSysType)
1516   {
1517     case OSD_VMS:
1518       return Analyse_VMS (theDependentName);
1519     case OSD_OS2:
1520     case OSD_WindowsNT:
1521       return Analyse_DOS (theDependentName);
1522     case OSD_MacOs:
1523       return Analyse_MACOS (theDependentName);
1524     default:
1525       return Standard_True;
1526   }
1527 }
1528
1529 // ---------------------------------------------------------------------------
1530
1531 // Elimine les separateurs inutiles
1532
1533
1534 static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
1535
1536   Standard_Integer i, j, len,start = 1 ;
1537
1538   len = aString.Length() ;
1539 #ifdef _WIN32
1540   if (len > 1 && aString.Value(1) == '/' && aString.Value(2) == '/')
1541     start = 2;
1542 #endif 
1543   for (i = j = start ; j <= len ; i++,j++) {
1544       Standard_Character c = aString.Value(j) ;
1545       aString.SetValue(i,c) ;
1546       if (c == '/')
1547           while(j < len && aString.Value(j+1) == '/') j++ ;
1548   }
1549   len = i-1 ;
1550   if (aString.Value(len) == '/') len-- ;  
1551   aString.Trunc(len) ;
1552   return len ;
1553 }
1554
1555 // ---------------------------------------------------------------------------
1556
1557 TCollection_AsciiString OSD_Path::RelativePath(
1558                             const TCollection_AsciiString& aDirPath,
1559                             const TCollection_AsciiString& aAbsFilePath)
1560 {
1561   TCollection_AsciiString EmptyString = "" ;
1562   TCollection_AsciiString FilePath ;
1563   Standard_Integer len ;
1564   Standard_Integer i, n ;
1565   Standard_Boolean Wnt = 0 ;
1566
1567   FilePath = aAbsFilePath ;
1568
1569   if (aDirPath.Search(":") == 2) {    // Cas WNT
1570       Wnt = 1 ;
1571       if (FilePath.Search(":") != 2 || 
1572           UpperCase(aDirPath.Value(1)) != UpperCase(FilePath.Value(1))
1573       )
1574           return  EmptyString ;
1575
1576       FilePath.ChangeAll('\\','/') ;
1577       if (FilePath.Search("/") != 3 )
1578           return  EmptyString ;
1579   }
1580   else {        // Cas Unix
1581       if (aDirPath.Value(1) != '/' || FilePath.Value(1) != '/')
1582           return  EmptyString ;
1583   }
1584
1585   // Eliminer les separateurs redondants
1586
1587   len = RemoveExtraSeparator(FilePath) ;
1588
1589   if (!Wnt) {
1590      if (len < 2)
1591          return  EmptyString ;
1592      FilePath = FilePath.SubString(2,len) ;
1593   }
1594   TCollection_AsciiString DirToken, FileToken ;
1595   Standard_Boolean Sibling = 0 ;
1596
1597   for (i = n = 1 ;; n++) {
1598       DirToken = aDirPath.Token("/\\",n) ;
1599       if (DirToken.IsEmpty())
1600           return FilePath ;
1601
1602       if (!Sibling) {
1603           len = FilePath.Length() ;
1604           i = FilePath.Search("/") ;
1605           if (i > 0) {
1606               if (i == len)
1607                   return EmptyString ;
1608
1609               FileToken = FilePath.SubString(1,i-1) ;
1610               if (Wnt) {
1611                   DirToken.UpperCase() ;
1612                   FileToken.UpperCase() ;
1613               }
1614               if (DirToken == FileToken) {
1615                   FilePath = FilePath.SubString(i+1,len) ;
1616                   continue ;
1617               }
1618           }
1619           else if (DirToken == FilePath)
1620               return EmptyString ;
1621  
1622           else
1623               Sibling = 1 ;
1624       }
1625       FilePath.Insert(1,"../") ;
1626   }
1627 }
1628       
1629 // ---------------------------------------------------------------------------
1630     
1631 TCollection_AsciiString OSD_Path::AbsolutePath(
1632                             const TCollection_AsciiString& aDirPath,
1633                             const TCollection_AsciiString& aRelFilePath)
1634 {
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 ;
1640
1641   if (DirPath.Search("/") != 1 && DirPath.Search(":") != 2)
1642       return EmptyString ;
1643
1644   if ( DirPath.Search(":") == 2)
1645       DirPath.ChangeAll('\\','/') ;
1646   RelFilePath.ChangeAll('\\','/') ;
1647   RemoveExtraSeparator(DirPath) ;
1648   len = RemoveExtraSeparator(RelFilePath) ;
1649   
1650   while (RelFilePath.Search("../") == 1) {
1651       if (len == 3)
1652           return EmptyString ;
1653       RelFilePath = RelFilePath.SubString(4,len) ;
1654       len -= 3 ;
1655       if (DirPath.IsEmpty())
1656           return EmptyString ;
1657       i = DirPath.SearchFromEnd("/") ;
1658       if (i < 0)
1659           return EmptyString ;
1660       DirPath.Trunc(i-1) ;
1661   }
1662   DirPath += '/' ;
1663   DirPath += RelFilePath ;
1664   return DirPath ;
1665 }
1666
1667 //void OSD_Path::ExpandedName(TCollection_AsciiString& aName)
1668 void OSD_Path::ExpandedName(TCollection_AsciiString& )
1669 {
1670 }
1671
1672 //Standard_Boolean LocateExecFile(OSD_Path& aPath)
1673 Standard_Boolean LocateExecFile(OSD_Path& )
1674 {
1675   return Standard_False ;
1676 }