0023024: Update headers of OCCT files
[occt.git] / src / UTL / UTL.cxx
CommitLineData
b311480e 1// Created on: 1997-11-24
2// Created by: Mister rmi
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <UTL.ixx>
24#include <OSD_Host.hxx>
25#include <OSD_Path.hxx>
26#include <TCollection_ExtendedString.hxx>
27#include <TCollection_AsciiString.hxx>
28#include <Resource_Unicode.hxx>
29#include <OSD_Environment.hxx>
30#include <OSD_FileIterator.hxx>
31#include <OSD_File.hxx>
32#include <OSD_Protection.hxx>
33#include <OSD_SingleProtection.hxx>
34#define MaxChar 10000
35
36
37static Standard_Character longtc[MaxChar];
38static Standard_PCharacter aLongCString = longtc;
39static TCollection_ExtendedString outExtendedString;
40
41static TCollection_AsciiString ASCII(const TCollection_ExtendedString& anXString) {
42 Resource_Unicode::ConvertUnicodeToFormat(anXString,aLongCString,MaxChar);
43 return TCollection_AsciiString(aLongCString);
44}
45
46
47static TCollection_ExtendedString UNICODE(const TCollection_AsciiString& aCString) {
48 Resource_Unicode::ConvertFormatToUnicode(aCString.ToCString(),outExtendedString);
49 return outExtendedString;
50}
51
52TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
53 TCollection_ExtendedString x;
54 OSD_Environment theEnv(aCString);
55 TCollection_AsciiString theValue=theEnv.Value();
56 if( ! theValue.IsEmpty()) x=UNICODE(theValue);
57 return x;
58}
59TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName) {
60 OSD_Path p = OSD_Path(ASCII(aFileName));
61
62 TCollection_AsciiString theExtension=p.Extension();
63
64 TCollection_AsciiString theGoodExtension=theExtension;;
65
66 if(TCollection_AsciiString(theExtension.Value(1))==".")
67 theGoodExtension=theExtension.Split(1);
68
69 return UNICODE(theGoodExtension);
70}
71Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver, const TCollection_ExtendedString& aFileName, const Storage_OpenMode aMode) {
72 return aDriver.Open(ASCII(aFileName),aMode);
73}
74
75void UTL::AddToUserInfo(const Handle(Storage_Data)& aData, const TCollection_ExtendedString& anInfo) {
76 aData->AddToUserInfo(ASCII(anInfo));
77}
78OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName) {
79
80// cout << "Path : " << aFileName << endl;
81// TCollection_AsciiString theAciiString=ASCII(aFileName);
82// OSD_Path p = OSD_Path(theAciiString);
83 OSD_Path p = OSD_Path(ASCII(aFileName));
84 return p;
85}
86TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath) {
87 return UNICODE(aPath.Disk());
88}
89TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath) {
90 return UNICODE(aPath.Trek());
91}
92TCollection_ExtendedString UTL::Name(const OSD_Path& aPath) {
93 return UNICODE(aPath.Name());
94}
95TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath) {
96 return UNICODE(aPath.Extension());
97}
98OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask) {
99 OSD_FileIterator it = OSD_FileIterator(aPath,ASCII(aMask));
100 return it;
101}
102TCollection_ExtendedString UTL::LocalHost() {
103 OSD_Host h;
104 return UNICODE(h.HostName());
105}
106TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString) {
107 return UNICODE(anAsciiString);
108}
109Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString) {
110 return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
111}
112Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
113 return aResourceManager->Find(ASCII(aResourceName).ToCString());
114}
115TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
116 return UNICODE(aResourceManager->Value(ASCII(aResourceName).ToCString()));
117}
118
119Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString) {
120 TCollection_AsciiString a=ASCII(anExtendedString);
121 return a.IntegerValue();
122}
123Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString) {
124 static TCollection_AsciiString theValue;
125 theValue=ASCII(anExtendedString);
126 return theValue.ToCString();
127}
128Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName) {
129
130 switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
131 case OSD_W:
132 case OSD_RW:
133 case OSD_WX:
134 case OSD_RWX:
135 case OSD_RWD:
136 case OSD_WXD:
137 case OSD_RWXD:
138 return Standard_False;
139 default:
140 return Standard_True;
141 }
142}