imgtools/imglib/host/h_utl.cpp
changeset 620 ad8ffc8e1982
parent 590 360bd6b35136
child 626 ac03b93ca9c4
equal deleted inserted replaced
585:238f4cb8391f 620:ad8ffc8e1982
    18 
    18 
    19 
    19 
    20 #define __INCLUDE_CAPABILITY_NAMES__
    20 #define __INCLUDE_CAPABILITY_NAMES__
    21 
    21 
    22 #if defined(_MSVCDOTNET__) || defined(__TOOLS2__)
    22 #if defined(_MSVCDOTNET__) || defined(__TOOLS2__)
    23 #include <string>
    23 
    24 #else //!__MSVCDOTNET__
    24 #else //!__MSVCDOTNET__
    25 #include <string.h>
    25 #include <string.h>
    26 #endif //__MSVCDOTNET__
    26 #endif //__MSVCDOTNET__
    27 
    27 
    28 #include <stdarg.h>
    28 #include <stdarg.h>
    69 HPrint::~HPrint()
    69 HPrint::~HPrint()
    70 	{
    70 	{
    71 	iLogFile.close();
    71 	iLogFile.close();
    72 	}
    72 	}
    73 
    73 
    74 void HPrint::SetLogFile(TText *aFileName)
    74 void HPrint::SetLogFile(const char* aFileName)
    75 	{
    75 	{
    76 	iLogFile.open((const char *)aFileName);
    76 	iLogFile.open(aFileName);
    77 	}
    77 	}
    78 
    78 
    79 
    79 
    80 /**
    80 /**
    81 Closing the logfile.(since 'n' number of drive images can be created)
    81 Closing the logfile.(since 'n' number of drive images can be created)
   484 	return t;
   484 	return t;
   485 	}
   485 	}
   486 
   486 
   487 
   487 
   488 // Parse a filename and convert decimal version number to hex
   488 // Parse a filename and convert decimal version number to hex
   489 char* NormaliseFileName(const char* aName)
   489 char* NormaliseFileName(const char* aName) {
   490 {
       
   491 	//convert forward slashes into back slashes.
   490 	//convert forward slashes into back slashes.
   492 	char* filename = strdup(aName);  //prevent violated access from stack.
   491 	char* filename = strdup(aName);  //prevent violated access from stack.	
       
   492 #ifdef WIN32
       
   493 #define SPLIT_CHAR1	'/'
       
   494 #define SPLIT_CHAR2	'\\'
       
   495 #else
       
   496 #define SPLIT_CHAR1	'\\'
       
   497 #define SPLIT_CHAR2	'/'
       
   498 #endif
   493 	char* fwdslashfinder = filename;
   499 	char* fwdslashfinder = filename;
   494 	fwdslashfinder=strstr(fwdslashfinder, "/");
   500 	fwdslashfinder=strchr(fwdslashfinder, SPLIT_CHAR1);
   495 	while(fwdslashfinder)
   501 	while(fwdslashfinder){
   496 	  {
   502 		*fwdslashfinder++ = SPLIT_CHAR2;
   497 		*fwdslashfinder++ = '\\';
   503 		fwdslashfinder=strchr(fwdslashfinder, SPLIT_CHAR1);
   498 		fwdslashfinder=strstr(fwdslashfinder, "/");
   504 	}
   499 	  }
       
   500 
   505 
   501 	//normalize filename.
   506 	//normalize filename.
   502 	TFileNameInfo f(filename, EFalse);
   507 	TFileNameInfo f(filename, EFalse);
   503 	TInt nl = f.iBaseLength;
   508 	TInt nl = f.iBaseLength;
   504 	TInt el = f.iTotalLength - f.iExtPos;
   509 	TInt el = f.iTotalLength - f.iExtPos;
   505 	TInt tl = nl + el;
   510 	TInt tl = nl + el;
   506 	if (f.iFlags & EVerPresent)
   511 	if (f.iFlags & EVerPresent)
   507 		tl += 10;
   512 		tl += 10;
   508 	char* t = (char*)malloc(tl + 1);
   513 	char* t = new char[tl + 1];
   509 	if (t)
   514 	if (t) {
   510 		{
       
   511 		memcpy(t, filename, nl);
   515 		memcpy(t, filename, nl);
   512 		if (f.iFlags & EVerPresent)
   516 		if (f.iFlags & EVerPresent)
   513 			sprintf(t + nl, "{%08lx}%s", f.iModuleVersion, filename + f.iExtPos);
   517 			sprintf(t + nl, "{%08lx}%s", f.iModuleVersion, filename + f.iExtPos);
   514 		else if (el)
   518 		else if (el)
   515 			memcpy(t + nl, filename + f.iExtPos, el);
   519 			memcpy(t + nl,  filename + f.iExtPos, el);
   516 		t[tl] = 0;
   520 		t[tl] = 0;
   517 		}
   521 	} 
   518 	free(filename);
   522 	free(filename);
   519 
       
   520 	return t;
   523 	return t;
   521 }
   524 }
   522 
   525 
   523 TFileNameInfo::TFileNameInfo(const char* aFileName, TBool aLookForUid)
   526 TFileNameInfo::TFileNameInfo(const char* aFileName, TBool aLookForUid)
   524 	{
   527 	{
   679 		aValue = EFalse;
   682 		aValue = EFalse;
   680 		return KErrNone;
   683 		return KErrNone;
   681 		}
   684 		}
   682 	Print(EError, "Expected a boolean on/off value but found %s\n",aText);
   685 	Print(EError, "Expected a boolean on/off value but found %s\n",aText);
   683 	return KErrArgument;
   686 	return KErrArgument;
   684 	}
   687 }
       
   688  
       
   689 TBool IsValidNumber(const char* aStr){
       
   690 	if(0 == aStr || 0 == *aStr) 
       
   691 		return EFalse ;
       
   692 	if(*aStr == '+' || *aStr == '-') 
       
   693 			aStr ++ ; 
       
   694 	if(aStr[0] == '0' && (aStr[1] | 0x20) == 'x'){
       
   695 		aStr += 2 ;
       
   696 		while(*aStr){
       
   697 			if((*aStr >= '0' && *aStr <= '9') ||
       
   698 				(*aStr >= 'a' && *aStr <= 'f') ||
       
   699 				(*aStr >= 'A' && *aStr <= 'F'))
       
   700 				aStr++ ;
       
   701 			else
       
   702 				return EFalse ;
       
   703 		}
       
   704 	}
       
   705 	else {		
       
   706 		while(*aStr){
       
   707 			if(*aStr >= '0' && *aStr <= '9')
       
   708 				aStr++ ;
       
   709 			else
       
   710 				return EFalse ;
       
   711 		}
       
   712 	}
       
   713 	return ETrue ;
       
   714 }