summaryrefslogtreecommitdiff
path: root/src/UTL/UTL.cxx
blob: 7fedc2e2e2cb293e4594c5a9b0fc7261f9259e8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// File:	UTL.cxx
// Created:	Mon Nov 24 07:53:49 1997
// Author:	Mister rmi
//		<rmi@frilox.paris1.matra-dtv.fr>


#include <UTL.ixx>
#include <OSD_Host.hxx>
#include <OSD_Path.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TCollection_AsciiString.hxx>
#include <Resource_Unicode.hxx>
#include <OSD_Environment.hxx>
#include <OSD_FileIterator.hxx>
#include <OSD_File.hxx>
#include <OSD_Protection.hxx>
#include <OSD_SingleProtection.hxx>
#define MaxChar 10000


static Standard_Character longtc[MaxChar];
static Standard_PCharacter aLongCString = longtc;
static TCollection_ExtendedString outExtendedString;

static TCollection_AsciiString ASCII(const TCollection_ExtendedString& anXString) {
  Resource_Unicode::ConvertUnicodeToFormat(anXString,aLongCString,MaxChar);
  return TCollection_AsciiString(aLongCString);
}


static TCollection_ExtendedString UNICODE(const TCollection_AsciiString& aCString) {
  Resource_Unicode::ConvertFormatToUnicode(aCString.ToCString(),outExtendedString);
  return outExtendedString;
}

TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
  TCollection_ExtendedString x;
  OSD_Environment theEnv(aCString);
  TCollection_AsciiString theValue=theEnv.Value();
  if( ! theValue.IsEmpty()) x=UNICODE(theValue);
  return x;
}
TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName) {
  OSD_Path p = OSD_Path(ASCII(aFileName));

  TCollection_AsciiString theExtension=p.Extension();

  TCollection_AsciiString theGoodExtension=theExtension;;

  if(TCollection_AsciiString(theExtension.Value(1))==".") 
    theGoodExtension=theExtension.Split(1);

  return UNICODE(theGoodExtension);
}
Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver, const TCollection_ExtendedString& aFileName, const Storage_OpenMode aMode) {
  return aDriver.Open(ASCII(aFileName),aMode);
}

void UTL::AddToUserInfo(const Handle(Storage_Data)& aData, const TCollection_ExtendedString& anInfo) {
  aData->AddToUserInfo(ASCII(anInfo));
}
OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName) {

//  cout << "Path : " << aFileName << endl;
//  TCollection_AsciiString theAciiString=ASCII(aFileName);
//  OSD_Path p = OSD_Path(theAciiString);
  OSD_Path p = OSD_Path(ASCII(aFileName));
  return p;
}
TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath) {
  return UNICODE(aPath.Disk());
}
TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath) {
  return UNICODE(aPath.Trek());
}
TCollection_ExtendedString UTL::Name(const OSD_Path& aPath) {
  return UNICODE(aPath.Name());
}
TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath) {
  return UNICODE(aPath.Extension());
}
OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask) {
  OSD_FileIterator it = OSD_FileIterator(aPath,ASCII(aMask));
  return it;
}
TCollection_ExtendedString UTL::LocalHost() {
  OSD_Host h;
  return UNICODE(h.HostName());
}
TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString) {
  return UNICODE(anAsciiString);
}
Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString) {
  return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
}
Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
  return aResourceManager->Find(ASCII(aResourceName).ToCString());
}  
TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
  return UNICODE(aResourceManager->Value(ASCII(aResourceName).ToCString()));
}  

Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString) {
  TCollection_AsciiString a=ASCII(anExtendedString);
  return a.IntegerValue();
}
Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString) {
  static TCollection_AsciiString theValue;
  theValue=ASCII(anExtendedString);
  return theValue.ToCString();
}
Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName) {

  switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
  case OSD_W:
  case OSD_RW:
  case OSD_WX:
  case OSD_RWX:
  case OSD_RWD:
  case OSD_WXD:
  case OSD_RWXD:
    return Standard_False;
  default:
    return Standard_True;
  }
}