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