1 // Created on: 1997-11-24
2 // Created by: Mister rmi
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
31 static Standard_Character longtc[MaxChar];
32 static Standard_PCharacter aLongCString = longtc;
33 static TCollection_ExtendedString outExtendedString;
35 static TCollection_AsciiString ASCII(const TCollection_ExtendedString& anXString) {
36 Resource_Unicode::ConvertUnicodeToFormat(anXString,aLongCString,MaxChar);
37 return TCollection_AsciiString(aLongCString);
41 static TCollection_ExtendedString UNICODE(const TCollection_AsciiString& aCString) {
42 Resource_Unicode::ConvertFormatToUnicode(aCString.ToCString(),outExtendedString);
43 return outExtendedString;
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);
53 TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName) {
54 OSD_Path p = OSD_Path(ASCII(aFileName));
56 TCollection_AsciiString theExtension=p.Extension();
58 TCollection_AsciiString theGoodExtension=theExtension;;
60 if(TCollection_AsciiString(theExtension.Value(1))==".")
61 theGoodExtension=theExtension.Split(1);
63 return UNICODE(theGoodExtension);
65 Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver, const TCollection_ExtendedString& aFileName, const Storage_OpenMode aMode) {
66 return aDriver.Open(ASCII(aFileName),aMode);
69 void UTL::AddToUserInfo(const Handle(Storage_Data)& aData, const TCollection_ExtendedString& anInfo) {
70 aData->AddToUserInfo(ASCII(anInfo));
72 OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName) {
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));
80 TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath) {
81 return UNICODE(aPath.Disk());
83 TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath) {
84 return UNICODE(aPath.Trek());
86 TCollection_ExtendedString UTL::Name(const OSD_Path& aPath) {
87 return UNICODE(aPath.Name());
89 TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath) {
90 return UNICODE(aPath.Extension());
92 OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask) {
93 OSD_FileIterator it = OSD_FileIterator(aPath,ASCII(aMask));
96 TCollection_ExtendedString UTL::LocalHost() {
98 return UNICODE(h.HostName());
100 TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString) {
101 return UNICODE(anAsciiString);
103 Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString) {
104 return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
106 Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
107 return aResourceManager->Find(ASCII(aResourceName).ToCString());
109 TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
110 return UNICODE(aResourceManager->Value(ASCII(aResourceName).ToCString()));
113 Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString) {
114 TCollection_AsciiString a=ASCII(anExtendedString);
115 return a.IntegerValue();
117 Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString) {
118 static TCollection_AsciiString theValue;
119 theValue=ASCII(anExtendedString);
120 return theValue.ToCString();
122 Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName) {
124 switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
132 return Standard_False;
134 return Standard_True;