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