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