b311480e |
1 | // Created on: 1997-11-24 |
2 | // Created by: Mister rmi |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <UTL.ixx> |
18 | #include <OSD_Host.hxx> |
19 | #include <OSD_Path.hxx> |
20 | #include <TCollection_ExtendedString.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
22 | #include <Resource_Unicode.hxx> |
23 | #include <OSD_Environment.hxx> |
24 | #include <OSD_FileIterator.hxx> |
25 | #include <OSD_File.hxx> |
26 | #include <OSD_Protection.hxx> |
27 | #include <OSD_SingleProtection.hxx> |
28 | #define MaxChar 10000 |
29 | |
30 | |
31 | static Standard_Character longtc[MaxChar]; |
32 | static Standard_PCharacter aLongCString = longtc; |
33 | static TCollection_ExtendedString outExtendedString; |
34 | |
35 | static TCollection_AsciiString ASCII(const TCollection_ExtendedString& anXString) { |
36 | Resource_Unicode::ConvertUnicodeToFormat(anXString,aLongCString,MaxChar); |
37 | return TCollection_AsciiString(aLongCString); |
38 | } |
39 | |
40 | |
41 | static TCollection_ExtendedString UNICODE(const TCollection_AsciiString& aCString) { |
42 | Resource_Unicode::ConvertFormatToUnicode(aCString.ToCString(),outExtendedString); |
43 | return outExtendedString; |
44 | } |
45 | |
46 | TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) { |
47 | TCollection_ExtendedString x; |
48 | OSD_Environment theEnv(aCString); |
49 | TCollection_AsciiString theValue=theEnv.Value(); |
50 | if( ! theValue.IsEmpty()) x=UNICODE(theValue); |
51 | return x; |
52 | } |
53 | TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName) { |
54 | OSD_Path p = OSD_Path(ASCII(aFileName)); |
55 | |
56 | TCollection_AsciiString theExtension=p.Extension(); |
57 | |
58 | TCollection_AsciiString theGoodExtension=theExtension;; |
59 | |
60 | if(TCollection_AsciiString(theExtension.Value(1))==".") |
61 | theGoodExtension=theExtension.Split(1); |
62 | |
63 | return UNICODE(theGoodExtension); |
64 | } |
65 | Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver, const TCollection_ExtendedString& aFileName, const Storage_OpenMode aMode) { |
66 | return aDriver.Open(ASCII(aFileName),aMode); |
67 | } |
68 | |
69 | void UTL::AddToUserInfo(const Handle(Storage_Data)& aData, const TCollection_ExtendedString& anInfo) { |
70 | aData->AddToUserInfo(ASCII(anInfo)); |
71 | } |
72 | OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName) { |
73 | |
74 | // cout << "Path : " << aFileName << endl; |
75 | // TCollection_AsciiString theAciiString=ASCII(aFileName); |
76 | // OSD_Path p = OSD_Path(theAciiString); |
77 | OSD_Path p = OSD_Path(ASCII(aFileName)); |
78 | return p; |
79 | } |
80 | TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath) { |
81 | return UNICODE(aPath.Disk()); |
82 | } |
83 | TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath) { |
84 | return UNICODE(aPath.Trek()); |
85 | } |
86 | TCollection_ExtendedString UTL::Name(const OSD_Path& aPath) { |
87 | return UNICODE(aPath.Name()); |
88 | } |
89 | TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath) { |
90 | return UNICODE(aPath.Extension()); |
91 | } |
92 | OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask) { |
93 | OSD_FileIterator it = OSD_FileIterator(aPath,ASCII(aMask)); |
94 | return it; |
95 | } |
96 | TCollection_ExtendedString UTL::LocalHost() { |
97 | OSD_Host h; |
98 | return UNICODE(h.HostName()); |
99 | } |
100 | TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString) { |
101 | return UNICODE(anAsciiString); |
102 | } |
103 | Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString) { |
104 | return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString()); |
105 | } |
106 | Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) { |
107 | return aResourceManager->Find(ASCII(aResourceName).ToCString()); |
108 | } |
109 | TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) { |
110 | return UNICODE(aResourceManager->Value(ASCII(aResourceName).ToCString())); |
111 | } |
112 | |
113 | Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString) { |
114 | TCollection_AsciiString a=ASCII(anExtendedString); |
115 | return a.IntegerValue(); |
116 | } |
117 | Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString) { |
118 | static TCollection_AsciiString theValue; |
119 | theValue=ASCII(anExtendedString); |
120 | return theValue.ToCString(); |
121 | } |
122 | Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName) { |
123 | |
124 | switch (OSD_File(UTL::Path(aFileName)).Protection().User()) { |
125 | case OSD_W: |
126 | case OSD_RW: |
127 | case OSD_WX: |
128 | case OSD_RWX: |
129 | case OSD_RWD: |
130 | case OSD_WXD: |
131 | case OSD_RWXD: |
132 | return Standard_False; |
133 | default: |
134 | return Standard_True; |
135 | } |
136 | } |