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