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