memana/analyzetoolclient/commandlineengine/internal/src/CATBase.cpp
changeset 2 6a82cd05fb1e
parent 1 3ff3fecb12fe
equal deleted inserted replaced
1:3ff3fecb12fe 2:6a82cd05fb1e
     1 /*
       
     2 * Copyright (c) 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 "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:  Definitions for the class CATBase.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "../inc/CATBase.h"
       
    20 #include "../inc/CATParseXML.h"
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // CATBase::CATBase
       
    24 // Constructor.
       
    25 // -----------------------------------------------------------------------------
       
    26 CATBase::CATBase(void)
       
    27 {
       
    28 	LOG_FUNC_ENTRY("CATBase::CATBase");
       
    29 }
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CATBase::~CATBase
       
    33 // Destructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 CATBase::~CATBase(void)
       
    36 {
       
    37 	LOG_FUNC_ENTRY("CATBase::~CATBase");
       
    38 }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CATBase::ChangeToLower
       
    42 // Converts any uppercase letter to lowercase.
       
    43 // -----------------------------------------------------------------------------
       
    44 void CATBase::ChangeToLower( string& sInput )
       
    45 {
       
    46 	LOG_LOW_FUNC_ENTRY("CATBase::ChangeToLower");
       
    47 	int iLength = (int)sInput.size();
       
    48 	for( int i = 0 ; i < iLength ; i++ )
       
    49 	{
       
    50 		sInput[i] = (char)tolower( sInput[i] );
       
    51 	}
       
    52 }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CATBase::ChangeToUpper
       
    56 // Converts any uppercase letter to lowercase.
       
    57 // -----------------------------------------------------------------------------
       
    58 void CATBase::ChangeToUpper( string& sInput )
       
    59 {
       
    60 	LOG_LOW_FUNC_ENTRY("CATBase::ChangeToUpper");
       
    61 	int iLength = (int)sInput.size();
       
    62 	for( int i = 0 ; i < iLength ; i++ )
       
    63 	{
       
    64 		sInput[i] = (char)toupper( sInput[i] );
       
    65 	}
       
    66 }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CATBase::TrimString
       
    70 // Remove spaces and tabulatures from beginning and
       
    71 // end of given string.
       
    72 // -----------------------------------------------------------------------------
       
    73 void CATBase::TrimString( string& sInput )
       
    74 {
       
    75 	LOG_LOW_FUNC_ENTRY("CATBase::TrimString");
       
    76 	if( sInput.empty() )
       
    77 		return;
       
    78 	//Remove spaces and tabulatures from beginning of string
       
    79 	while( !sInput.empty() && ( sInput[0] == SPACE_CHAR_VALUE || sInput[0] == TAB_CHAR_VALUE ) )
       
    80 	{
       
    81 		sInput.erase( 0, 1 );
       
    82 	}
       
    83 	//Remove spaces and tabulatures from end of string
       
    84 	while( !sInput.empty() && ( sInput[sInput.size()-1] == SPACE_CHAR_VALUE || sInput[sInput.size()-1] == TAB_CHAR_VALUE ) )
       
    85 	{
       
    86 		sInput.erase( sInput.size()-1, 1 );
       
    87 	}
       
    88 }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CATBase::SearchFileWithExtension
       
    92 // Searches files with given extension from path.
       
    93 // -----------------------------------------------------------------------------
       
    94 bool CATBase::SearchFileWithExtension( const char* pPathAndExt, bool bPrintErrors, string& sErrorLog )
       
    95 {
       
    96 	LOG_FUNC_ENTRY("CATBase::SearchFileWithExtension");
       
    97 	WIN32_FIND_DATA FindFileData;
       
    98 	HANDLE hFind;
       
    99 	string sTemp( pPathAndExt );
       
   100 
       
   101 	//Find file
       
   102 	hFind = FindFirstFile( sTemp.c_str(), &FindFileData );
       
   103 	if (hFind == INVALID_HANDLE_VALUE)
       
   104 	{
       
   105 		string sErrorString( "No " );
       
   106 		//Get extension
       
   107 		string sExt( pPathAndExt );
       
   108 		sExt.erase( 0, sExt.find_last_of( "." ) );
       
   109 
       
   110 		sErrorString.append( sExt );
       
   111 		sErrorString.append( " files in directory: " );
       
   112 
       
   113 		string sWithoutExt( pPathAndExt );
       
   114 		sWithoutExt.erase( sWithoutExt.find_last_of( "." )-1, string::npos );
       
   115 		sErrorString.append( sWithoutExt );
       
   116 
       
   117 		if( bPrintErrors )
       
   118 		{
       
   119 			//string sTemp( pPathAndExt );
       
   120 			//printf( "Can not find: %s.\n", pPathAndExt );
       
   121 			printf( sErrorString.c_str() );
       
   122 		}
       
   123 		else
       
   124 		{
       
   125 			//Add line change if sErrorString not empty
       
   126 			if( !sErrorLog.empty() )
       
   127 				sErrorString.insert( 0, "\n" );
       
   128 			sErrorLog.append( sErrorString );
       
   129 		}
       
   130 		return false;
       
   131 	} 
       
   132 	else 
       
   133 	{
       
   134 		FindClose(hFind);
       
   135 		return true;
       
   136 	}
       
   137 }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CATBase::GetPathOrFileName
       
   141 // Returns path to file or file name.
       
   142 // -----------------------------------------------------------------------------
       
   143 string CATBase::GetPathOrFileName( bool bFileName, string sInput )
       
   144 {
       
   145 	LOG_LOW_FUNC_ENTRY("CATBase::GetPathOrFileName");
       
   146 	string sRet;
       
   147 	size_t iPos = sInput.size();
       
   148 
       
   149 	sInput = ChangeSlashToBackSlash( sInput );
       
   150 
       
   151 	//Find character '\' starting from end of string
       
   152 	while( iPos > 0 && sInput[iPos] != '\\' )
       
   153 	{
       
   154 		iPos--;
       
   155 	}
       
   156 	if( iPos > 0 )
       
   157 	{
       
   158 		//Return file name
       
   159 		if( bFileName )
       
   160 		{
       
   161 			sInput.erase( 0, iPos+1 );
       
   162 			sRet = sInput;
       
   163 		}
       
   164 		else //Return file path
       
   165 		{
       
   166 			sInput.erase( iPos+1, string::npos );
       
   167 			sRet = sInput;
       
   168 		}
       
   169 	}
       
   170 	else
       
   171 	{
       
   172 		if( !bFileName )
       
   173 			return sRet;
       
   174 		sRet = sInput;
       
   175 	}
       
   176 	return sRet;
       
   177 }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CATBase::GetFileNameUsingExt
       
   181 // Searches files with given extension from path.
       
   182 // -----------------------------------------------------------------------------
       
   183 string CATBase::GetFileNameUsingExt( const char* pPathAndExt )
       
   184 {
       
   185 	LOG_FUNC_ENTRY("CATBase::GetFileNameUsingExt");
       
   186 	WIN32_FIND_DATA FindFileData;
       
   187 	HANDLE hFind;
       
   188 	string sRet;
       
   189 
       
   190 	//Find file
       
   191 	hFind = FindFirstFile( pPathAndExt, &FindFileData );
       
   192 	if (hFind == INVALID_HANDLE_VALUE)
       
   193 	{
       
   194 		//if( bPrintErrors )
       
   195 		printf( "Can not find: %s.\n", pPathAndExt );
       
   196 		return sRet;
       
   197 	} 
       
   198 	else 
       
   199 	{
       
   200 		sRet.append( FindFileData.cFileName );
       
   201 		FindClose(hFind);
       
   202 		return sRet;
       
   203 	}
       
   204 }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CATBase::GetStringUntilNextSpace
       
   208 // Function returns string from begin of given string until next space,
       
   209 // characters until next space are removed from sInput string.
       
   210 // -----------------------------------------------------------------------------
       
   211 string CATBase::GetStringUntilNextSpace( string& sInput, bool bEraseFromInput )
       
   212 {
       
   213 	LOG_LOW_FUNC_ENTRY("CATBase::GetStringUntilNextSpace");
       
   214 	string sTemp( sInput );
       
   215 	size_t iSize = sTemp.find_first_of(' ');
       
   216 	if( iSize != string::npos )
       
   217 	{
       
   218 		sTemp.resize( iSize );
       
   219 		if( bEraseFromInput )
       
   220 			sInput.erase( 0, (iSize+1) );
       
   221 	}
       
   222 	else
       
   223 	{
       
   224 		if ( bEraseFromInput )
       
   225 			sInput.clear();
       
   226 	}
       
   227 	return sTemp;
       
   228 }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CATBase::ChangeSlashToBackSlash
       
   232 // Function changes all BackSlash characters to Slash character from
       
   233 // given string.
       
   234 // -----------------------------------------------------------------------------
       
   235 string CATBase::ChangeSlashToBackSlash( string sInput )
       
   236 {
       
   237 	LOG_LOW_FUNC_ENTRY("CATBase::ChangeSlashToBackSlash");
       
   238 	for( unsigned int i = 0 ; i < sInput.length() ; i++ )
       
   239 	{
       
   240 		if( sInput[i] == '/' )
       
   241 		{
       
   242 			sInput[i] = '\\';
       
   243 		}
       
   244 	}
       
   245 	return sInput;
       
   246 }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CATBase::FileExists
       
   250 // Check if given file exists.
       
   251 // -----------------------------------------------------------------------------
       
   252 bool CATBase::FileExists( const char * pFilename )
       
   253 {
       
   254 	LOG_FUNC_ENTRY("CATBase::FileExists");
       
   255 	DWORD dwRet = GetFileAttributes( pFilename );
       
   256 	if( dwRet == INVALID_FILE_ATTRIBUTES )
       
   257 	{
       
   258 		return false;
       
   259 	}
       
   260 	else
       
   261 	{
       
   262 		//Is file directory?
       
   263 		if( dwRet & FILE_ATTRIBUTE_DIRECTORY )
       
   264 		{
       
   265 			return false;
       
   266 		}
       
   267 	}
       
   268 	return true;
       
   269 }
       
   270 
       
   271 bool CATBase::IsFileReadOnly( const char* pFilename )
       
   272 {
       
   273 	LOG_FUNC_ENTRY("CATBase::IsFileReadOnly");
       
   274 	DWORD dwRet = GetFileAttributes( pFilename );
       
   275 	if( dwRet == INVALID_FILE_ATTRIBUTES )
       
   276 		return false;
       
   277 	if( dwRet & FILE_ATTRIBUTE_READONLY )
       
   278 		return true;
       
   279 	return false;
       
   280 }
       
   281 
       
   282 bool CATBase::SetFileReadOnly( const char* pFileName )
       
   283 {
       
   284 	LOG_FUNC_ENTRY("CATBase::SetFileReadOnly");
       
   285 	DWORD dw = GetFileAttributes( pFileName );
       
   286 	if( dw == INVALID_FILE_ATTRIBUTES )
       
   287 		return false;
       
   288 	if( dw & FILE_ATTRIBUTE_READONLY )
       
   289 		return true;
       
   290 	dw = dw | FILE_ATTRIBUTE_READONLY ;
       
   291 	if ( SetFileAttributes( pFileName, dw ) )
       
   292 		return true;
       
   293 	return false;
       
   294 }
       
   295 bool CATBase::SetFileWritable( const char* pFileName )
       
   296 {
       
   297 	LOG_FUNC_ENTRY("CATBase::SetFileWritable");
       
   298 	DWORD dw = GetFileAttributes( pFileName );
       
   299 	if( dw == INVALID_FILE_ATTRIBUTES )
       
   300 		return false;
       
   301 	if( ! dw & FILE_ATTRIBUTE_READONLY )
       
   302 		return true;
       
   303 	dw = dw ^ FILE_ATTRIBUTE_READONLY ;
       
   304 	if ( SetFileAttributes( pFileName, dw ) )
       
   305 		return true;
       
   306 	return false;
       
   307 }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CATBase::FileCopyToPath
       
   311 // Copies file to given path
       
   312 // -----------------------------------------------------------------------------
       
   313 bool CATBase::FileCopyToPath(const string& sFile, const string& sToPath)
       
   314 {
       
   315 	LOG_FUNC_ENTRY("CATBase::FileCopyToPath");
       
   316 	// Display message
       
   317 	cout << AT_MSG << "Copy " << sFile << AT_FILE_TO << sToPath << endl;
       
   318 	if ( sFile.empty() || sToPath.empty() )
       
   319 	{
       
   320 		LOG_FUNC_EXIT("CATBase::FileCopyToPath Error, empty parameter");
       
   321 		return false;
       
   322 	}
       
   323 	// Copy using windows api (seems not to work when relavite path ..
       
   324 	/*
       
   325 	// Full path where to copy
       
   326 	string sDestination = sToPath;
       
   327 	// Append '\' to string if not exists
       
   328 	if ( sDestination.length() > 1 )
       
   329 	{
       
   330 		const char cLastChar = sDestination[ sDestination.length() -1 ];
       
   331 		if ( cLastChar != DASH )
       
   332 			sDestination.append("\\");
       
   333 	}
       
   334 	int iRet = 0;
       
   335 	iRet = CopyFile( sFile.c_str(), sDestination.c_str(), false );
       
   336 	if ( iRet != 0 )
       
   337 	{
       
   338 		return false;
       
   339 	}
       
   340 	*/
       
   341 	string sCommand;
       
   342 	sCommand.append( "copy /Y \"");
       
   343 	sCommand.append( sFile );
       
   344 	sCommand.append( "\" \"" );
       
   345 	sCommand.append( sToPath );
       
   346 	sCommand.append( "\" > nul 2>&1" );
       
   347 	LOG_STRING( sCommand );
       
   348 	int iRet = 0;
       
   349 	iRet = (int)system( sCommand.c_str() );
       
   350 	if ( iRet != 0 )
       
   351 		return false;
       
   352 	return true;
       
   353 }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CATBase::FileMoveToPath
       
   357 // Copies file to given path
       
   358 // -----------------------------------------------------------------------------
       
   359 bool CATBase::FileMoveToPath(const string& sFile, const string& sToPath)
       
   360 {
       
   361 	LOG_FUNC_ENTRY("CATBase::FileMoveToPath");
       
   362 	// Display message
       
   363 	cout << AT_MSG << "Move " << sFile << AT_FILE_TO << sToPath << endl;
       
   364 	if ( sFile.empty() || sToPath.empty() )
       
   365 	{
       
   366 		LOG_FUNC_EXIT("CATBase::FileMoveToPath Error, empty parameter");
       
   367 		return false;
       
   368 	}
       
   369 	// Move (again windows api function does not support relative path .. in it
       
   370 	/*
       
   371 	// Get filename from sFile
       
   372 	string sFileName = GetPathOrFileName( true, sFile );
       
   373 	// Full path where to copy
       
   374 	string sDestination = sToPath;
       
   375 	// Append '\' to string if not exists
       
   376 	if ( sDestination.length() > 1 )
       
   377 	{
       
   378 		const char cLastChar = sDestination[ sDestination.length() -1 ];
       
   379 		if ( cLastChar != DASH )
       
   380 			sDestination.append("\\");
       
   381 	}
       
   382 	int iRet = 0;
       
   383 	iRet = MoveFile( sFile.c_str(), sDestination.c_str());
       
   384 	if ( iRet != 0 )
       
   385 	{
       
   386 		return false;
       
   387 	}
       
   388 	*/
       
   389 	string sCommand;
       
   390 	sCommand.append( "move /Y \"");
       
   391 	sCommand.append( sFile );
       
   392 	sCommand.append( "\" \"" );
       
   393 	sCommand.append( sToPath );
       
   394 	sCommand.append( "\" > nul 2>&1" );
       
   395 	LOG_STRING( sCommand );
       
   396 	int iRet = 0;
       
   397 	iRet = (int)system( sCommand.c_str() );
       
   398 	if ( iRet != 0 )
       
   399 		return false;
       
   400 	return true;
       
   401 }
       
   402 // -----------------------------------------------------------------------------
       
   403 // CATBase::CreateTempPath
       
   404 // Creates temporary directory path for given mmp file
       
   405 // -----------------------------------------------------------------------------
       
   406 string CATBase::CreateTempPath(const string& sMmpFileWithPath)
       
   407 {
       
   408 	LOG_FUNC_ENTRY("CATBase::CreateTempPath");
       
   409 	string sTempPath = GetPathOrFileName( false, sMmpFileWithPath );
       
   410 	sTempPath.append( AT_TEMP_DIR );
       
   411 	sTempPath.append( "\\" );
       
   412 	return sTempPath;
       
   413 }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CATBase::RemovePathAndExt
       
   417 // Removes extension from file name and returns file name without extension.
       
   418 // -----------------------------------------------------------------------------
       
   419 string CATBase::RemovePathAndExt( string sFileName, bool bReverseFindExt)
       
   420 {
       
   421 	LOG_LOW_FUNC_ENTRY("CATBase::RemovePathAndExt");
       
   422 	string sRet;
       
   423 	sFileName = GetPathOrFileName( true, sFileName );
       
   424 	if ( bReverseFindExt )
       
   425 	{
       
   426 		// Remove extension from reverse
       
   427 		size_t iPos = sFileName.find_last_of('.');
       
   428 		if( iPos != string::npos )
       
   429 		{
       
   430 			sFileName.resize( sFileName.find_last_of('.') );
       
   431 			sRet = sFileName;
       
   432 		}
       
   433 	}
       
   434 	else
       
   435 	{
       
   436 		// Remove extension finding first .
       
   437 		size_t iPos = sFileName.find_first_of('.');
       
   438 		if( iPos != string::npos )
       
   439 		{
       
   440 			sFileName.resize( sFileName.find_first_of('.') );
       
   441 			sRet = sFileName;
       
   442 		}
       
   443 	}
       
   444 	return sRet;
       
   445 }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CATBase::IsTargetTypeSupported
       
   449 // Checks from constant array is this target unsupported
       
   450 // -----------------------------------------------------------------------------
       
   451 bool CATBase::IsTargetTypeSupported(string sTargetType)
       
   452 {
       
   453 	LOG_FUNC_ENTRY("CATBase::IsTargetTypeSupported");
       
   454 	// compare to list
       
   455 	int iArraySize = sizeof( UNSUPPORTED_TARGET_TYPES ) / sizeof( string );
       
   456 	for ( int i=0 ; i < iArraySize ; i++ )
       
   457 	{
       
   458 		string sUnsupported = UNSUPPORTED_TARGET_TYPES[i];
       
   459 		// lowercase both
       
   460 		ChangeToLower(sTargetType);
       
   461 		ChangeToLower(sUnsupported);
       
   462 		// compare
       
   463 		if ( sUnsupported.compare( sTargetType ) == 0 )
       
   464 		{
       
   465 			return false;
       
   466 		}
       
   467 	}
       
   468 	return true;
       
   469 }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // CATBase::IsTargetTypeKernelSide
       
   473 // Checks from constant array is this target type kernel side
       
   474 // -----------------------------------------------------------------------------
       
   475 bool CATBase::IsTargetTypeKernelSide(string sTargetType)
       
   476 {
       
   477 	LOG_FUNC_ENTRY("CATBase::IsTargetTypeKernelSide");
       
   478 	// compare to list
       
   479 	int iArraySize = sizeof( KERNEL_SIDE_TARGET_TYPES ) / sizeof( string );
       
   480 	for ( int i=0 ; i < iArraySize ; i++ )
       
   481 	{
       
   482 		string sUnsupported = KERNEL_SIDE_TARGET_TYPES[i];
       
   483 		// lowercase both
       
   484 		ChangeToLower(sTargetType);
       
   485 		ChangeToLower(sUnsupported);
       
   486 		// compare
       
   487 		if ( sUnsupported.compare( sTargetType ) == 0 )
       
   488 		{
       
   489 			return true;
       
   490 		}
       
   491 	}
       
   492 	return false;
       
   493 }
       
   494 
       
   495 bool CATBase::CheckVariant( const string& sEpocRoot, const string& sVariant )
       
   496 {
       
   497 	LOG_FUNC_ENTRY("CATBase::CheckVariant");
       
   498 	string sFileToCheck;
       
   499 	// Add epoc root
       
   500 	if( sEpocRoot.size() > 1 )
       
   501 		sFileToCheck.append( sEpocRoot );
       
   502 	// Add path
       
   503 	sFileToCheck.append( VARIANT_DIR ) ;
       
   504 	// Add variant
       
   505 	sFileToCheck.append( sVariant );
       
   506 	// Add extension
       
   507 	sFileToCheck.append( VARIANT_FILE_EXTENSION );
       
   508 	// check does FileExists
       
   509 	return FileExists( sFileToCheck.c_str() );
       
   510 }
       
   511 bool CATBase::IsDefaultVariant( const string& sEpocRoot )
       
   512 {
       
   513 	LOG_FUNC_ENTRY("CATBase::IsDefaultVariant");
       
   514 	string sFileToCheck;
       
   515 	// Add epoc root
       
   516 	if( sEpocRoot.size() > 1 )
       
   517 		sFileToCheck.append( sEpocRoot );
       
   518 	// Add path
       
   519 	sFileToCheck.append( VARIANT_DIR ) ;
       
   520 	// Add variant
       
   521 	sFileToCheck.append( "DEFAULT" );
       
   522 	// Add extension
       
   523 	sFileToCheck.append( VARIANT_FILE_EXTENSION );
       
   524 	// check does FileExists
       
   525 	return FileExists( sFileToCheck.c_str() );
       
   526 }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CATBase::FileDelete
       
   530 // FileDelete
       
   531 // -----------------------------------------------------------------------------
       
   532 bool CATBase::FileDelete(const string& sFile, bool bPrint )
       
   533 {
       
   534 	LOG_FUNC_ENTRY("CATBase::FileDelete");
       
   535 	// does file even exists
       
   536 	if ( !FileExists( sFile.c_str() ) )
       
   537 		return false;
       
   538 	// delete file
       
   539 	int iRet = _unlink( sFile.c_str() );
       
   540 	// if print on display error
       
   541 	if ( iRet  && bPrint )
       
   542 	{
       
   543 		cout << AT_MSG << "Error, deleting file " << sFile
       
   544 			<< endl;
       
   545 	}
       
   546 	// if print on display message
       
   547 	else if ( !iRet && bPrint )
       
   548 	{
       
   549 		cout << AT_MSG << "Delete " << sFile << endl;
       
   550 	}
       
   551 	// return
       
   552 	if ( iRet )
       
   553 		return false;
       
   554 	return true;
       
   555 }
       
   556 // -----------------------------------------------------------------------------
       
   557 // CATBase::DirDelete
       
   558 // Delelete directory
       
   559 // -----------------------------------------------------------------------------
       
   560 bool CATBase::DirDelete(const string& sDir, bool bPrint )
       
   561 {
       
   562 	LOG_FUNC_ENTRY("CATBase::DirDelete");
       
   563 	if ( sDir.find( AT_TEMP_DIR) == string::npos )
       
   564 		return false;
       
   565 	
       
   566 	if ( sDir.length() < 2 )
       
   567 		return false;
       
   568 
       
   569 	string sDir2;
       
   570 	if ( sDir.at(1) != ':' )
       
   571 	{
       
   572 		char cDir[MAX_LINE_LENGTH];
       
   573 		GetCurrentDirectory( MAX_LINE_LENGTH , cDir );
       
   574 		sDir2.append( cDir );
       
   575 		sDir2.append( "\\" );
       
   576 		sDir2.append( sDir );
       
   577 	}
       
   578 	else
       
   579 		sDir2.append( sDir );
       
   580 
       
   581 	// does directory exists
       
   582 	DWORD dwRet = GetFileAttributes( sDir2.c_str() );
       
   583 	if ( dwRet == INVALID_FILE_ATTRIBUTES )
       
   584 		return false;
       
   585 	else if ( ! (dwRet & FILE_ATTRIBUTE_DIRECTORY) )
       
   586 	{
       
   587 		return false;
       
   588 	}
       
   589 	// Delete dir
       
   590 	string sCmd( "rmdir /S /Q " );
       
   591 	sCmd.append( sDir2 );
       
   592 	sCmd.append( " > nul 2>&1" );
       
   593 	int iRet = (int)system( sCmd.c_str() );
       
   594 	if ( iRet && bPrint)
       
   595 	{
       
   596 		cout << AT_MSG << "Error, deleting directory " << sDir2 << endl;
       
   597 	}
       
   598 	else if ( !iRet && bPrint )
       
   599 	{
       
   600 		cout << AT_MSG << "Delete directory " << sDir2 << endl;
       
   601 	}
       
   602 	if ( iRet )
       
   603 		return false;
       
   604 	return true;
       
   605 }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CATBase::DirCreate
       
   609 // Create directory
       
   610 // -----------------------------------------------------------------------------
       
   611 bool CATBase::DirCreate(const string& sDir, bool bPrint )
       
   612 {
       
   613 	LOG_FUNC_ENTRY("CATBase::DirCreate");
       
   614 
       
   615 	if ( sDir.length() < 2 )
       
   616 		return false;
       
   617 
       
   618 	string sDir2;
       
   619 	if ( sDir.at(1) != ':' )
       
   620 	{
       
   621 		char cDir[MAX_LINE_LENGTH];
       
   622 		GetCurrentDirectory( MAX_LINE_LENGTH , cDir );
       
   623 		sDir2.append( cDir );
       
   624 		sDir2.append( "\\" );
       
   625 		sDir2.append( sDir );
       
   626 	}
       
   627 	else
       
   628 		sDir2.append( sDir );
       
   629 
       
   630 	// does directory exists
       
   631 	DWORD dwRet = GetFileAttributes( sDir2.c_str() );
       
   632 	if ( dwRet != INVALID_FILE_ATTRIBUTES )
       
   633 	{
       
   634 		if( dwRet & FILE_ATTRIBUTE_DIRECTORY )
       
   635 			return false;
       
   636 	}
       
   637 	// Create dir
       
   638 	string sCmd( "mkdir " );
       
   639 	sCmd.append( sDir2 );
       
   640 	sCmd.append( " > nul 2>&1" );
       
   641 	int iRet = (int)system( sCmd.c_str() );
       
   642 	if ( iRet && bPrint)
       
   643 	{
       
   644 		cout << AT_MSG << "Error, creating directory " << sDir2 << endl;
       
   645 	}
       
   646 	else if ( !iRet && bPrint )
       
   647 	{
       
   648 		cout << AT_MSG << "Directory " << sDir2 << " created" << endl;
       
   649 	}
       
   650 	if ( iRet )
       
   651 		return false;
       
   652 	return true;
       
   653 }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CATBase::ConvertTCHARtoString
       
   657 // Convert TCHAR* to std::string
       
   658 // -----------------------------------------------------------------------------
       
   659 string CATBase::ConvertTCHARtoString(TCHAR* charArray)
       
   660 {
       
   661 	LOG_LOW_FUNC_ENTRY("CATBase::ConvertTCHARtoString");
       
   662 	// Loop char array
       
   663 	stringstream ss;
       
   664 	int iIndex = 0;
       
   665 	char c = (char) charArray[iIndex];
       
   666 	// until null termination
       
   667 	while ( c != '\0' )
       
   668 	{
       
   669 		ss << c;
       
   670 		iIndex++;
       
   671 		c = (char) charArray[iIndex];
       
   672 	}
       
   673 	// return string
       
   674 	return ss.str();
       
   675 }
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // CATBase::ConvertTCHARtoString
       
   679 // Get list of files in directory
       
   680 // -----------------------------------------------------------------------------
       
   681 vector<string> CATBase::DirList(const string& sDirectory
       
   682 								, bool bListDirs, bool bAddPathToFile)
       
   683 {
       
   684 	LOG_FUNC_ENTRY("CATBase::DirList");
       
   685 	// Create string to modify it
       
   686 	string sDir = sDirectory;
       
   687 	// Add if missing '\' & '*' to the sDirectory
       
   688 	if ( sDir.at( sDir.size()-1 ) != '\\' )
       
   689 		sDir.append( "\\" );
       
   690 	// Path to add to file string if specified
       
   691 	string sPath = sDir;
       
   692 	// Add * to for windows api to find all files
       
   693 	sDir.append( "*" );
       
   694 	// convert directory string to LPCSTR
       
   695 	LPCSTR dir( sDir.c_str() );
       
   696 	// vector to store file list
       
   697 	vector<string> vFileList;
       
   698 	// Using win32 api to find list of files in directory
       
   699 	// file data "container"
       
   700 	WIN32_FIND_DATA fileData;
       
   701 	// handle to directory
       
   702 	HANDLE hFinder = FindFirstFile( dir, &fileData );
       
   703 	if ( hFinder == INVALID_HANDLE_VALUE )
       
   704 	{
       
   705 		// no files found
       
   706 		return vFileList;
       
   707 	}
       
   708 	// loop files add to vector and return
       
   709 	while( FindNextFile(hFinder, &fileData ) )
       
   710 	{
       
   711 		DWORD dw = fileData.dwFileAttributes;
       
   712 		// skip if its directory and bListDirs not specified
       
   713 		if ( dw & FILE_ATTRIBUTE_DIRECTORY && ! bListDirs)
       
   714 			continue;
       
   715 		// add files to vector
       
   716 		string sFile = ConvertTCHARtoString( fileData.cFileName );
       
   717 		// Add given path to file string if specified
       
   718 		if ( bAddPathToFile )
       
   719 			sFile.insert( 0, sPath );
       
   720 		vFileList.push_back( sFile );
       
   721 	}
       
   722 	// Close file find handler
       
   723 	FindClose( hFinder );
       
   724 	return vFileList;
       
   725 }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CATBase::ParseRelativePathToString
       
   729 // ParseRelative
       
   730 // -----------------------------------------------------------------------------
       
   731 void CATBase::ParseRelativePathString(string& sPathString)
       
   732 {
       
   733 	LOG_LOW_FUNC_ENTRY("CATBase::ParseRelativePathString");
       
   734 	string sParsed;
       
   735 	// find ..
       
   736 	size_t iDots = sPathString.find( ".." );
       
   737 	while ( iDots != string::npos )
       
   738 	{
       
   739 		RemoveRelativePath( sPathString, iDots );
       
   740 		iDots = sPathString.find( ".." );
       
   741 	}
       
   742 }
       
   743 
       
   744 // -----------------------------------------------------------------------------
       
   745 // CATBase::RemoveRelativePath
       
   746 // Remove relative path from string (using given index)
       
   747 // -----------------------------------------------------------------------------
       
   748 void CATBase::RemoveRelativePath(string& sString, size_t iDots)
       
   749 {
       
   750 	LOG_LOW_FUNC_ENTRY("CATBase::RemoveRelativePath");
       
   751 	// Chck if accidentally given wrong parameter
       
   752 	if ( iDots == string::npos 
       
   753 		|| iDots < 1 )
       
   754 		return;
       
   755 	// Parsed string
       
   756 	string sParsed;
       
   757 	// Find position of last backslash before dots
       
   758 	size_t i = sString.rfind("\\", iDots-2 );
       
   759 	// Pickup start part (depending is the backslash at last parts first char)
       
   760 	if ( sString.at(iDots+2) != '\\' )
       
   761 		sParsed = sString.substr( 0, i+1 ) ;
       
   762 	else
       
   763 		sParsed = sString.substr( 0, i );
       
   764 	// Pick up last part
       
   765 	sParsed.append( sString.substr( iDots+2, sString.size() ) );
       
   766 	sString = sParsed;
       
   767 }
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // Get extension from given string
       
   771 // -----------------------------------------------------------------------------
       
   772 string CATBase::GetExtension(const string& sString)
       
   773 {
       
   774 	LOG_LOW_FUNC_ENTRY("CATBase::GetExtension");
       
   775 	// find last .
       
   776 	size_t iDot = sString.find_last_of( "." );
       
   777 	// return string after . if found
       
   778 	if ( iDot != string::npos )
       
   779 		return sString.substr(iDot+1, sString.length()-(iDot+1) );
       
   780 	// otherwise return given string
       
   781 	return sString;
       
   782 }
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 // CATBase::DirectoryExists
       
   786 // Check if given directory exists.
       
   787 // -----------------------------------------------------------------------------
       
   788 bool CATBase::DirectoryExists( const char* pDirname )
       
   789 {
       
   790 	LOG_FUNC_ENTRY("CATBase::DirectoryExists");
       
   791 	size_t iLenght = strlen( pDirname );
       
   792 	
       
   793 	if ( iLenght < 2 )
       
   794 		return false;
       
   795 
       
   796 	string sDir;
       
   797 	if ( pDirname[1] != ':' )
       
   798 	{
       
   799 		char cDir[MAX_LINE_LENGTH];
       
   800 		GetCurrentDirectory( MAX_LINE_LENGTH , cDir );
       
   801 		sDir.append( cDir );
       
   802 		sDir.append( "\\" );
       
   803 		sDir.append( pDirname );
       
   804 	}
       
   805 	else
       
   806 		sDir.append( pDirname );
       
   807 
       
   808 	DWORD dwRet = GetFileAttributes( sDir.c_str() );
       
   809 	if( dwRet == INVALID_FILE_ATTRIBUTES )
       
   810 	{
       
   811 		return false;
       
   812 	}
       
   813 	else
       
   814 	{
       
   815 		//Is file directory?
       
   816 		if( dwRet & FILE_ATTRIBUTE_DIRECTORY )
       
   817 		{
       
   818 			return true;
       
   819 		}
       
   820 		else
       
   821 		{
       
   822 			return false;
       
   823 		}
       
   824 	}
       
   825 }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CATBase::ConvertUnixPathToWin
       
   829 // -----------------------------------------------------------------------------
       
   830 void CATBase::ConvertUnixPathToWin( string& sPath )
       
   831 {
       
   832 	LOG_LOW_FUNC_ENTRY("CATBase::ConvertUnixPathToWin");
       
   833 	size_t iSpot = 0;
       
   834 	// convert '/' to '\'
       
   835 	iSpot = sPath.find( "/" );
       
   836 	while( iSpot != string::npos )
       
   837 	{
       
   838 		sPath.replace(iSpot,1, "\\");
       
   839 		iSpot = sPath.find( "/", iSpot+1 );
       
   840 	}
       
   841 	// convert '\\' to '\'
       
   842 	iSpot = sPath.find( "\\\\" );
       
   843 	while( iSpot != string::npos )
       
   844 	{
       
   845 		sPath.replace(iSpot,2,"\\");
       
   846 		iSpot = sPath.find( "\\\\" );
       
   847 	}
       
   848 }
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CATBase::RemoveAllAfterDotIfTwoDots
       
   852 // Removes all after first '.'
       
   853 // if given string contains 2 '.' or more
       
   854 // -----------------------------------------------------------------------------
       
   855 void CATBase::RemoveAllAfterDotIfTwoDots(string& sModName)
       
   856 {
       
   857 	LOG_LOW_FUNC_ENTRY("CATBase::RemoveAllAfterDotIfTwoDots");
       
   858 	// did we find variable?
       
   859 	size_t found;
       
   860 	// Find first '.'
       
   861 	found = sModName.find(".");
       
   862 	if ( found != string::npos )
       
   863 	{
       
   864 		// Try find second '.'
       
   865 		found = sModName.find(".", found+1);
       
   866 		if ( found != string::npos )
       
   867 		{
       
   868 			// Remove all after first '.'
       
   869 			sModName = sModName.substr(0, sModName.find(".")+1 );
       
   870 		}
       
   871 	}
       
   872 }
       
   873 // -----------------------------------------------------------------------------
       
   874 // CATBase::CreateTemporaryCpp
       
   875 // -----------------------------------------------------------------------------
       
   876 bool CATBase::CreateTemporaryCpp( const string& sId,
       
   877 								 const string& sPath
       
   878 								 ,const string& sS60FileName
       
   879 								 ,int iLogOption
       
   880 								 ,int iIsDebug
       
   881 								 ,int iAllocCallStackSize
       
   882 								 ,int iFreeCallStackSize )
       
   883 {
       
   884 	LOG_FUNC_ENTRY("CATBase::CreateTemporaryCpp");
       
   885 	// Add slash to path if missing
       
   886 	string sTempCpp = sPath;
       
   887 	if( sTempCpp.at( sTempCpp.length() - 1 ) != '\\' )
       
   888 		sTempCpp.append("\\");
       
   889 
       
   890 	// append temporary cpp name with id in middle
       
   891 	sTempCpp.append( AT_TEMP_CPP_LOWER_START );
       
   892 	sTempCpp.append( sId );
       
   893 	sTempCpp.append( AT_TEMP_CPP_LOWER_END );
       
   894 
       
   895 	//Open and truncate temporary cpp
       
   896 	ofstream out( sTempCpp.c_str() , ios::trunc );
       
   897 	if ( ! out.good() )
       
   898 	{
       
   899 		out.close();
       
   900 		return false;
       
   901 	}
       
   902 	out << "#include <e32base.h>";
       
   903 	out << "\n\n// CONSTANTS\n";
       
   904 	out << "\n/* The filename for log file */";
       
   905 	out << "\n_LIT( KFileName, \"";
       
   906 	//Set data file name
       
   907 	out << sS60FileName;
       
   908 	out << "\" );\n";
       
   909 	// Version number
       
   910 	out << "\n/* The AnalyzeTool version number used. */";
       
   911 	out << "\n_LIT( KAtoolVersion, \"";
       
   912 	out << ATOOL_COMPATIBILITY_STRING;
       
   913 	out << "\" );\n";
       
   914 	
       
   915 	out << "\n// -----------------------------------------------------------------------------";
       
   916 	out << "\n// LogFileName()";
       
   917 	out << "\n// Returns the log filename.";
       
   918 	out << "\n// -----------------------------------------------------------------------------";
       
   919 	out << "\n//";
       
   920 	out << "\nconst TFileName LogFileName()";
       
   921 	out << "\n    {";
       
   922 	out << "\n    return TFileName( KFileName() );";
       
   923 	out << "\n    }";
       
   924 
       
   925 	out << "\n// -----------------------------------------------------------------------------";
       
   926 	out << "\n// AllocCallStackSize()";
       
   927 	out << "\n// Returns the call stack size gathered in alloc.";
       
   928 	out << "\n// -----------------------------------------------------------------------------";
       
   929 	out << "\n//";
       
   930 	out << "\nTUint32 AllocCallStackSize()";
       
   931 	out << "\n    {";
       
   932 	out << "\n    return TUint32( ";
       
   933 	out << iAllocCallStackSize;
       
   934 	out << " );\n";
       
   935 	out << "\n    }";
       
   936 	
       
   937 	out << "\n// -----------------------------------------------------------------------------";
       
   938 	out << "\n// FreeCallStackSize()";
       
   939 	out << "\n// Returns the call stack size gathered in free.";
       
   940 	out << "\n// -----------------------------------------------------------------------------";
       
   941 	out << "\n//";
       
   942 	out << "\nTUint32 FreeCallStackSize()";
       
   943 	out << "\n    {";
       
   944 	out << "\n    return TUint32( ";
       
   945 	out << iFreeCallStackSize;
       
   946 	out << " );\n";
       
   947 	out << "\n    }";
       
   948 
       
   949 	out << "\n// -----------------------------------------------------------------------------";
       
   950 	out << "\n// AtoolVersion()";
       
   951 	out << "\n// Returns the version number of AnalyzeTool used.";
       
   952 	out << "\n// -----------------------------------------------------------------------------";
       
   953 	out << "\n//";
       
   954 	out << "\nconst TFileName AtoolVersion()";
       
   955 	out << "\n    {";
       
   956 	out << "\n    return TFileName( KAtoolVersion() );";
       
   957 	out << "\n    }";
       
   958 
       
   959 	out << "\n// -----------------------------------------------------------------------------";
       
   960 	out << "\n// LogOption()";
       
   961 	out << "\n// Returns the log option.";
       
   962 	out << "\n// -----------------------------------------------------------------------------";
       
   963 	out << "\n//    ";
       
   964 	out << "\nTUint32 LogOption()";
       
   965 	out << "\n    {";
       
   966 	out << "\n    return TUint32( ";
       
   967 	//Set logging target
       
   968 	out << iLogOption;
       
   969 	out << " );";
       
   970 	out << "\n    }";
       
   971 	
       
   972 	//Write build mode function
       
   973 	out << "\n// -----------------------------------------------------------------------------";
       
   974 	out << "\n// IsDebug()";
       
   975 	out << "\n// Return build mode";
       
   976 	out << "\n// -----------------------------------------------------------------------------";
       
   977 	out << "\n//";
       
   978 	out << "\nTUint32 IsDebug()";
       
   979 	out << "\n    {";
       
   980 	out << "\n    return TUint32( ";
       
   981 	//Set logging target
       
   982 	out << iIsDebug;
       
   983 	out << " );";
       
   984 	out << "\n    }";
       
   985 	out << "\n\n// End of File\n";
       
   986 	out.close();
       
   987 	cout << AT_MSG << "Created " << sTempCpp << endl;
       
   988 	return true;
       
   989 }
       
   990 
       
   991 // -----------------------------------------------------------------------------
       
   992 // CATBase::IsDataFile
       
   993 // -----------------------------------------------------------------------------
       
   994 bool CATBase::IsDataFile( string sFile )
       
   995 {
       
   996 	LOG_FUNC_ENTRY("CATBase::IsDataFile");
       
   997 	// Check that sFile not empty
       
   998 	if ( sFile.empty() || sFile.length() < 1 )
       
   999 		return false;
       
  1000 
       
  1001 	// Temporary line char array.
       
  1002 	char cLineFromFile[MAX_LINE_LENGTH];
       
  1003 	//Open file
       
  1004 	ifstream in( sFile.c_str() );
       
  1005 
       
  1006 	//File open ok?
       
  1007 	if( !in.good() )
       
  1008 		return false;
       
  1009 
       
  1010 	//Read all lines
       
  1011 	in.getline( cLineFromFile, MAX_LINE_LENGTH );
       
  1012 
       
  1013 	string sLineFromFile( cLineFromFile );
       
  1014 	in.close();
       
  1015 	if( sLineFromFile.find( "DATA_FILE_VERSION" ) != string::npos )
       
  1016 		return true;
       
  1017 	else
       
  1018 		return false;
       
  1019 }
       
  1020 
       
  1021 // -----------------------------------------------------------------------------
       
  1022 // CATBase::FilterString
       
  1023 // Filter string out of unwanted characters. The list of allowed
       
  1024 // characters is defined in CFILTERSTRING.
       
  1025 // -----------------------------------------------------------------------------
       
  1026 string CATBase::FilterString( const string& sString )
       
  1027 {
       
  1028 	LOG_LOW_FUNC_ENTRY("CATBase::FilterString");
       
  1029 	string sFiltered;
       
  1030 	for( size_t i = 0 ; i < sString.length() ; i++ )
       
  1031 	{
       
  1032 		const char p = sString.at( i );
       
  1033 		if ( strchr( CFILTERSTRING, p ) !=  0 )
       
  1034 			sFiltered.push_back( p );
       
  1035 	}
       
  1036 	return sFiltered;
       
  1037 }
       
  1038 
       
  1039 // -----------------------------------------------------------------------------
       
  1040 // CATBase::FilterExtraSpaces
       
  1041 // Replaces multiple continuous spaces with single. Won't leave
       
  1042 // spaces in start or end of string.
       
  1043 // -----------------------------------------------------------------------------
       
  1044 void CATBase::FilterExtraSpaces( string& sString )
       
  1045 {
       
  1046 	LOG_LOW_FUNC_ENTRY("CATBase::FilterExtraSpaces");
       
  1047 	string sFiltered;
       
  1048 	// Loop thru char array.
       
  1049 	for( size_t i = 0 ; i < sString.length(); i++ )
       
  1050 	{
       
  1051 		// Is char space?
       
  1052 		if ( sString.at( i ) == ' ' )
       
  1053 		{
       
  1054 			// Pick up space if filtered does not contain char as last.
       
  1055 			if ( sFiltered.rbegin() == sFiltered.rend() )
       
  1056 				sFiltered.push_back( sString.at( i ) );
       
  1057 			else if ( * ( sFiltered.rbegin() ) != ' ' )
       
  1058 				sFiltered.push_back( sString.at( i ) );
       
  1059 		}
       
  1060 		else
       
  1061 			sFiltered.push_back( sString.at( i ) );
       
  1062 	}
       
  1063 
       
  1064 	// Remove first and/or last character if it is space.
       
  1065 	if ( sFiltered.begin() != sFiltered.end() )
       
  1066 	{
       
  1067 		if( * ( sFiltered.begin() ) == ' ' )
       
  1068 			sFiltered.erase( 0, 1 );
       
  1069 	}
       
  1070 	if ( sFiltered.rbegin() != sFiltered.rend() )
       
  1071 	{
       
  1072 		if( * ( sFiltered.rbegin() ) == ' ' )
       
  1073 			sFiltered.resize( sFiltered.length()-1 );
       
  1074 	}
       
  1075 	sString = sFiltered;
       
  1076 }
       
  1077 
       
  1078 
       
  1079 bool CATBase::hexToDec( string& sHex, unsigned int& iDec )
       
  1080 {
       
  1081 	LOG_LOW_FUNC_ENTRY("CATBase::hexToDec");
       
  1082 	istringstream ss( sHex );
       
  1083 	ss.setf( ios::hex, ios::basefield );
       
  1084 	if( ( ss >> iDec ) )
       
  1085 		return true;
       
  1086 	return false;
       
  1087 }
       
  1088 
       
  1089 bool CATBase::hexToDec( string& sHex, int& iDec )
       
  1090 {
       
  1091 	LOG_LOW_FUNC_ENTRY("CATBase::hexToDec");
       
  1092 	istringstream ss( sHex );
       
  1093 	ss.setf( ios::hex, ios::basefield );
       
  1094 	if( ( ss >> iDec ) )
       
  1095 		return true;
       
  1096 	return false;
       
  1097 }
       
  1098 
       
  1099 bool CATBase::hexToDec( string& sHex, unsigned long& ulDec )
       
  1100 {
       
  1101 	LOG_LOW_FUNC_ENTRY("CATBase::hexToDec");
       
  1102 	istringstream ss( sHex );
       
  1103 	ss.setf( ios::hex, ios::basefield );
       
  1104 	if( ( ss >> ulDec ) )
       
  1105 		return true;
       
  1106 	return false;
       
  1107 }
       
  1108 
       
  1109 bool CATBase::hexToDec( string& sHex, unsigned long long& ullDec )
       
  1110 {
       
  1111 	LOG_LOW_FUNC_ENTRY("CATBase::hexToDec");
       
  1112 	istringstream ss( sHex );
       
  1113 	ss.setf( ios::hex, ios::basefield );
       
  1114 	if( ( ss >> ullDec ) )
       
  1115 		return true;
       
  1116 	return false;
       
  1117 }
       
  1118 
       
  1119 // -----------------------------------------------------------------------------
       
  1120 // CATBase::_httoi
       
  1121 // -----------------------------------------------------------------------------
       
  1122 struct CHexMap
       
  1123 {
       
  1124 	char chr;
       
  1125 	int value;
       
  1126 };
       
  1127 unsigned long CATBase::_httoi(const char *value)
       
  1128 {
       
  1129 	LOG_LOW_FUNC_ENTRY("CATBase::_httoi");
       
  1130 	unsigned long l;
       
  1131 	string s( value );
       
  1132 	if ( CATBase::hexToDec( s, l ) )
       
  1133 		return l;
       
  1134 	return 0;
       
  1135 }
       
  1136 
       
  1137 
       
  1138 // -----------------------------------------------------------------------------
       
  1139 // CATBase::NumberToHexString(int)
       
  1140 // -----------------------------------------------------------------------------
       
  1141 string CATBase::NumberToHexString( unsigned int i )
       
  1142 {
       
  1143 	LOG_LOW_FUNC_ENTRY("CATBase::IntToHexString");
       
  1144 	stringstream ss;
       
  1145 	ss << "0x" << hex << i;
       
  1146 	string retval; retval = ss.str().c_str();
       
  1147 	return retval;
       
  1148 }
       
  1149 // -----------------------------------------------------------------------------
       
  1150 // CATBase::NumberToHexString(long)
       
  1151 // -----------------------------------------------------------------------------
       
  1152 string CATBase::NumberToHexString( unsigned long i )
       
  1153 {
       
  1154 	LOG_LOW_FUNC_ENTRY("CATBase::IntToHexString");
       
  1155 	stringstream ss;
       
  1156 	ss << "0x" << hex << i;
       
  1157 	string retval; retval = ss.str().c_str();
       
  1158 	return retval;
       
  1159 }
       
  1160 
       
  1161 // -----------------------------------------------------------------------------
       
  1162 // CATBase::IsHexCharacter
       
  1163 // -----------------------------------------------------------------------------
       
  1164 bool CATBase::IsHexCharacter(const TCHAR *value)
       
  1165 {
       
  1166 	LOG_LOW_FUNC_ENTRY("CATBase::IsHexCharacter");
       
  1167 	const int HexMapL = 22;
       
  1168 	CHexMap HexMap[HexMapL] =
       
  1169 	{
       
  1170 	    {'0', 0}, {'1', 1},
       
  1171 		{'2', 2}, {'3', 3},
       
  1172 		{'4', 4}, {'5', 5},
       
  1173 		{'6', 6}, {'7', 7},
       
  1174 		{'8', 8}, {'9', 9},
       
  1175 		{'A', 10}, {'B', 11},
       
  1176 		{'C', 12}, {'D', 13},
       
  1177 		{'E', 14}, {'F', 15},
       
  1178 		{'a', 10}, {'b', 11},
       
  1179 		{'c', 12}, {'d', 13},
       
  1180 		{'e', 14}, {'f', 15}
       
  1181 	};
       
  1182 	bool found = false;
       
  1183 	for (int i = 0; i < HexMapL; i++)
       
  1184 	{
       
  1185 		if(HexMap[i].chr == *value)
       
  1186 		{
       
  1187 			found = true;
       
  1188 			break;
       
  1189 		}
       
  1190 	}
       
  1191 	return found;
       
  1192 }
       
  1193 
       
  1194 // -----------------------------------------------------------------------------
       
  1195 // CATBase::IsAscii(const char*,const unsigned int)
       
  1196 // -----------------------------------------------------------------------------
       
  1197 bool CATBase::IsAscii( const char* pInput, const unsigned int iLength )
       
  1198 {
       
  1199 	LOG_LOW_FUNC_ENTRY("CATBase::IsAscii");
       
  1200 	bool bRet = true;
       
  1201 	const char* pPoint = pInput;
       
  1202 	for( unsigned int i = 0 ; i < iLength ; i++)
       
  1203 	{
       
  1204 		if(	!__isascii(*pPoint) )
       
  1205 		{
       
  1206 			bRet = false;
       
  1207 			break;
       
  1208 		}
       
  1209 		pPoint++;
       
  1210 	}
       
  1211 	return bRet;
       
  1212 }
       
  1213 
       
  1214 // -----------------------------------------------------------------------------
       
  1215 // CATBase::GetEpocRoot( string& sEpocRoot )
       
  1216 // -----------------------------------------------------------------------------
       
  1217 bool CATBase::GetEpocRoot( string& sEpocRoot )
       
  1218 {
       
  1219 	LOG_FUNC_ENTRY( "CATBase::GetEpocRoot" );
       
  1220 	bool bRet = true;
       
  1221 	//Find EPOCROOT from environment variable
       
  1222 	char* pEpocRoot = getenv ("EPOCROOT");
       
  1223 	if( pEpocRoot == NULL )
       
  1224 	{
       
  1225 		const char pDevicesPath[] = "C:\\Program Files\\Common Files\\Symbian\\devices.xml";
       
  1226 		CATParseXML parser;
       
  1227 		//Find EPOCROOT from devices
       
  1228 		sEpocRoot = parser.GetEpocRootPathFromXML(pDevicesPath);
       
  1229 		if( sEpocRoot.empty() )
       
  1230 		{
       
  1231 			printf("EPOCROOT not set to environment variables.\n");
       
  1232 			bRet = false;
       
  1233 		}
       
  1234 	}
       
  1235 	else
       
  1236 	{
       
  1237 		sEpocRoot.append( pEpocRoot );
       
  1238 		LOG_STRING( "EpocRoot :" << sEpocRoot );
       
  1239 	}
       
  1240 	//Remove trailing slash
       
  1241 	if ( sEpocRoot.size() > 1 && sEpocRoot[ sEpocRoot.length()-1 ] == '\\' )
       
  1242 		sEpocRoot.resize( sEpocRoot.length()-1 );
       
  1243 	return bRet;
       
  1244 }
       
  1245 //End of file