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