imgtools/imglib/inc/h_utl.h
changeset 25 223dcf462b73
equal deleted inserted replaced
24:936784880b21 25:223dcf462b73
       
     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 // 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 
       
    79 #define ALIGN4K(a) ((a+0xfff)&0xfffff000)
       
    80 #define ALIGN4(a) ((a+0x3)&0xfffffffc)
       
    81 
       
    82 
       
    83 #ifdef HEAPCHK
       
    84 #define NOIMAGE
       
    85 #define WIN32_LEAN_AND_MEAN
       
    86 #include <windows.h>
       
    87 void HeapCheck();
       
    88 #endif
       
    89 #define Print H.PrintString
       
    90 //
       
    91 const TInt KMaxStringLength=0x400;
       
    92 //
       
    93 class HFile
       
    94 	{
       
    95 public:
       
    96 	static TBool Open(const TText * const aFileName, TInt32 * const aFileHandle);
       
    97 	static TBool Read(const TInt32 aFileHandle, TAny * const aBuffer, const TUint32 aCount);
       
    98 	static TBool Seek(const TInt32 aFileHandle, const TUint32 aOffset);
       
    99 	static TUint32 GetPos(const TInt32 aFileHandle);
       
   100 	static TAny Close(const TInt32 aFileHandle);
       
   101 	static TUint32 GetLength(const TInt32 aFileHandle);
       
   102 	static TUint32 GetLength(TText *aName);
       
   103 	static TUint32 Read(TText *aName, TAny *someMem);
       
   104 	};
       
   105 //
       
   106 //inline TAny* operator new(TUint /*aSize*/, TAny* aBase)
       
   107 //	{return aBase;}
       
   108 
       
   109 class HMem
       
   110 	{
       
   111 public:
       
   112 	static TAny *Alloc(TAny * const aBaseAddress,const TUint32 aImageSize);
       
   113 	static void Free(TAny * const aMem);
       
   114 	static void Copy(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength);
       
   115 	static void Move(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength);
       
   116 	static void Set(TAny * const aDestAddr, const TUint8 aFillChar, const TUint32 aLength);
       
   117 	static void FillZ(TAny * const aDestAddr, const TUint32 aLength);
       
   118 
       
   119 	static TUint CheckSum(TUint *aPtr, TInt aSize);
       
   120 	static TUint CheckSum8(TUint8 *aPtr, TInt aSize);
       
   121 	static TUint CheckSumOdd8(TUint8 *aPtr, TInt aSize);
       
   122 	static TUint CheckSumEven8(TUint8 *aPtr, TInt aSize);
       
   123 
       
   124 	static void Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength);
       
   125 	};
       
   126 //
       
   127 enum TPrintType {EAlways, EScreen, ELog, EWarning, EError, EPeError, ESevereError, EDiagnostic};
       
   128 //
       
   129 class HPrint
       
   130 	{
       
   131 public:
       
   132 	~HPrint();
       
   133 	void SetLogFile(TText *aFileName);
       
   134 	void CloseLogFile();						//	Added to close intermediate log files.
       
   135 	TInt PrintString(TPrintType aType,const char *aFmt,...);
       
   136 public:
       
   137 	TText iText[KMaxStringLength];
       
   138 	TBool iVerbose;
       
   139 private:
       
   140 	ofstream iLogFile;
       
   141 	};
       
   142 //
       
   143 extern HPrint H;
       
   144 extern TBool PVerbose;
       
   145 //
       
   146 TAny *operator new(TUint aSize);
       
   147 void operator delete(TAny *aPtr);
       
   148 //
       
   149 #ifdef __TOOLS2__
       
   150 istringstream &operator>>(istringstream &is, TVersion &aVersion);
       
   151 #else
       
   152 istrstream &operator>>(istrstream &is, TVersion &aVersion);
       
   153 #endif
       
   154 //
       
   155 TInt StringToTime(TInt64 &aTime, char *aString);
       
   156 
       
   157 void ByteSwap(TUint &aVal);
       
   158 void ByteSwap(TUint16 &aVal);
       
   159 void ByteSwap(TUint *aPtr, TInt aSize);
       
   160 
       
   161 extern TBool gLittleEndian;
       
   162 
       
   163 
       
   164 /**
       
   165  Convert string to number.
       
   166 */
       
   167 template <class T>
       
   168 TInt Val(T& aVal, char* aStr)
       
   169 	{
       
   170 
       
   171 	T x;
       
   172 	#ifdef __TOOLS2__
       
   173 	istringstream val(aStr);
       
   174 	#else
       
   175 	istrstream val(aStr,strlen(aStr));
       
   176 	#endif
       
   177 	#if defined(__MSVCDOTNET__) || defined (__TOOLS2__) 
       
   178 		val >> setbase(0);
       
   179 	#endif //__MSVCDOTNET__                             
       
   180 	val >> x;
       
   181 	if (!val.eof() || val.fail())
       
   182 		return KErrGeneral;
       
   183 	aVal=x;
       
   184 	return KErrNone;
       
   185 	}
       
   186 
       
   187 // Filename decompose routines
       
   188 enum TDecomposeFlag
       
   189 	{
       
   190 	EUidPresent=1,
       
   191 	EVerPresent=2
       
   192 	};
       
   193 
       
   194 class TFileNameInfo
       
   195 	{
       
   196 public:
       
   197 	TFileNameInfo(const char* aFileName, TBool aLookForUid);
       
   198 public:
       
   199 	const char* iFileName;
       
   200 	TInt iTotalLength;
       
   201 	TInt iBaseLength;
       
   202 	TInt iExtPos;
       
   203 	TUint32 iUid3;
       
   204 	TUint32 iModuleVersion;
       
   205 	TUint32 iFlags;
       
   206 	};
       
   207 
       
   208 extern char* NormaliseFileName(const char* aName, bool aConvertPathPunct = true);
       
   209 extern char* SplitFileName(const char* aName, TUint32& aUid, TUint32& aModuleVersion, TUint32& aFlags);
       
   210 extern char* SplitFileName(const char* aName, TUint32& aModuleVersion, TUint32& aFlags);
       
   211 extern TInt ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText);
       
   212 extern TInt ParseBoolArg(TBool& aValue, const char *aText);
       
   213 
       
   214 #endif
       
   215