|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if !defined(__H_UTL_H__) |
|
17 #define __H_UTL_H__ |
|
18 // |
|
19 #include <stdio.h> |
|
20 |
|
21 #ifdef __VC32__ |
|
22 #ifdef __MSVCDOTNET__ |
|
23 #include <iostream> |
|
24 #include <strstream> |
|
25 #include <fstream> |
|
26 using namespace std; |
|
27 #else //!__MSVCDOTNET__ |
|
28 #include <iostream.h> |
|
29 #include <strstrea.h> |
|
30 #include <fstream.h> |
|
31 #endif //__MSVCDOTNET__ |
|
32 #else //!__VC32__ |
|
33 #ifdef __TOOLS2__ |
|
34 #include <fstream> |
|
35 #include <iostream> |
|
36 #include <sstream> |
|
37 #include <iomanip> |
|
38 using namespace std; |
|
39 #else // !__TOOLS2__ OR __VC32__ OR __MSVCDOTNET__ |
|
40 #include <iostream.h> |
|
41 #include <strstream.h> |
|
42 #include <fstream.h> |
|
43 #endif |
|
44 #endif |
|
45 |
|
46 #ifdef __LINUX__ |
|
47 #include <sys/types.h> |
|
48 #include <sys/stat.h> |
|
49 #include <unistd.h> |
|
50 #include <ctype.h> |
|
51 |
|
52 |
|
53 #define _close close |
|
54 #define _filelength filelength |
|
55 #define _lseek lseek |
|
56 #define _read read |
|
57 #define _snprintf snprintf |
|
58 #define _vsnprintf vsnprintf |
|
59 |
|
60 // linux case insensitive stromg comparisons have different names |
|
61 #define stricmp strcasecmp |
|
62 #define _stricmp strcasecmp |
|
63 #define strnicmp strncasecmp |
|
64 |
|
65 // to fix the linux problem: memcpy does not work with overlapped areas. |
|
66 #define memcpy memmove |
|
67 |
|
68 // hand-rolled strupr function for converting a string to all uppercase |
|
69 char* strupr(char *a); |
|
70 |
|
71 // return the length of a file |
|
72 off_t filelength (int filedes); |
|
73 #endif |
|
74 |
|
75 |
|
76 #include <e32cmn.h> |
|
77 #include <e32def.h> |
|
78 #include <e32def_private.h> |
|
79 |
|
80 #define ALIGN4K(a) ((a+0xfff)&0xfffff000) |
|
81 #define ALIGN4(a) ((a+0x3)&0xfffffffc) |
|
82 |
|
83 |
|
84 #ifdef HEAPCHK |
|
85 #define NOIMAGE |
|
86 #define WIN32_LEAN_AND_MEAN |
|
87 #include <windows.h> |
|
88 void HeapCheck(); |
|
89 #endif |
|
90 #define Print H.PrintString |
|
91 // |
|
92 const TInt KMaxStringLength=0x400; |
|
93 // |
|
94 class HFile |
|
95 { |
|
96 public: |
|
97 static TBool Open(const TText * const aFileName, TInt32 * const aFileHandle); |
|
98 static TBool Read(const TInt32 aFileHandle, TAny * const aBuffer, const TUint32 aCount); |
|
99 static TBool Seek(const TInt32 aFileHandle, const TUint32 aOffset); |
|
100 static TUint32 GetPos(const TInt32 aFileHandle); |
|
101 static TAny Close(const TInt32 aFileHandle); |
|
102 static TUint32 GetLength(const TInt32 aFileHandle); |
|
103 static TUint32 GetLength(TText *aName); |
|
104 static TUint32 Read(TText *aName, TAny *someMem); |
|
105 }; |
|
106 // |
|
107 //inline TAny* operator new(TUint /*aSize*/, TAny* aBase) |
|
108 // {return aBase;} |
|
109 |
|
110 class HMem |
|
111 { |
|
112 public: |
|
113 static TAny *Alloc(TAny * const aBaseAddress,const TUint32 aImageSize); |
|
114 static void Free(TAny * const aMem); |
|
115 static void Copy(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength); |
|
116 static void Move(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength); |
|
117 static void Set(TAny * const aDestAddr, const TUint8 aFillChar, const TUint32 aLength); |
|
118 static void FillZ(TAny * const aDestAddr, const TUint32 aLength); |
|
119 |
|
120 static TUint CheckSum(TUint *aPtr, TInt aSize); |
|
121 static TUint CheckSum8(TUint8 *aPtr, TInt aSize); |
|
122 static TUint CheckSumOdd8(TUint8 *aPtr, TInt aSize); |
|
123 static TUint CheckSumEven8(TUint8 *aPtr, TInt aSize); |
|
124 |
|
125 static void Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength); |
|
126 }; |
|
127 // |
|
128 enum TPrintType {EAlways, EScreen, ELog, EWarning, EError, EPeError, ESevereError, EDiagnostic}; |
|
129 // |
|
130 class HPrint |
|
131 { |
|
132 public: |
|
133 ~HPrint(); |
|
134 void SetLogFile(TText *aFileName); |
|
135 void CloseLogFile(); // Added to close intermediate log files. |
|
136 TInt PrintString(TPrintType aType,const char *aFmt,...); |
|
137 public: |
|
138 TText iText[KMaxStringLength]; |
|
139 TBool iVerbose; |
|
140 private: |
|
141 ofstream iLogFile; |
|
142 }; |
|
143 // |
|
144 extern HPrint H; |
|
145 extern TBool PVerbose; |
|
146 // |
|
147 TAny *operator new(TUint aSize); |
|
148 void operator delete(TAny *aPtr); |
|
149 // |
|
150 #ifdef __TOOLS2__ |
|
151 istringstream &operator>>(istringstream &is, TVersion &aVersion); |
|
152 #else |
|
153 istrstream &operator>>(istrstream &is, TVersion &aVersion); |
|
154 #endif |
|
155 // |
|
156 TInt StringToTime(TInt64 &aTime, char *aString); |
|
157 |
|
158 void ByteSwap(TUint &aVal); |
|
159 void ByteSwap(TUint16 &aVal); |
|
160 void ByteSwap(TUint *aPtr, TInt aSize); |
|
161 |
|
162 extern TBool gLittleEndian; |
|
163 |
|
164 |
|
165 /** |
|
166 Convert string to number. |
|
167 */ |
|
168 template <class T> |
|
169 TInt Val(T& aVal, char* aStr) |
|
170 { |
|
171 |
|
172 T x; |
|
173 #ifdef __TOOLS2__ |
|
174 istringstream val(aStr); |
|
175 #else |
|
176 istrstream val(aStr,strlen(aStr)); |
|
177 #endif |
|
178 #if defined(__MSVCDOTNET__) || defined (__TOOLS2__) |
|
179 val >> setbase(0); |
|
180 #endif //__MSVCDOTNET__ |
|
181 val >> x; |
|
182 if (!val.eof() || val.fail()) |
|
183 return KErrGeneral; |
|
184 aVal=x; |
|
185 return KErrNone; |
|
186 } |
|
187 |
|
188 // Filename decompose routines |
|
189 enum TDecomposeFlag |
|
190 { |
|
191 EUidPresent=1, |
|
192 EVerPresent=2 |
|
193 }; |
|
194 |
|
195 class TFileNameInfo |
|
196 { |
|
197 public: |
|
198 TFileNameInfo(const char* aFileName, TBool aLookForUid); |
|
199 public: |
|
200 const char* iFileName; |
|
201 TInt iTotalLength; |
|
202 TInt iBaseLength; |
|
203 TInt iExtPos; |
|
204 TUint32 iUid3; |
|
205 TUint32 iModuleVersion; |
|
206 TUint32 iFlags; |
|
207 }; |
|
208 |
|
209 extern char* NormaliseFileName(const char* aName); |
|
210 extern char* SplitFileName(const char* aName, TUint32& aUid, TUint32& aModuleVersion, TUint32& aFlags); |
|
211 extern char* SplitFileName(const char* aName, TUint32& aModuleVersion, TUint32& aFlags); |
|
212 extern TInt ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText); |
|
213 extern TInt ParseBoolArg(TBool& aValue, const char *aText); |
|
214 |
|
215 #endif |
|
216 |