toolsandutils/e32tools/host/h_utl.cpp
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     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 
       
    17 #define __INCLUDE_CAPABILITY_NAMES__
       
    18 
       
    19 #if defined(_MSVCDOTNET__) || defined(__TOOLS2__)
       
    20 #include <string>
       
    21 #else //!__MSVCDOTNET__
       
    22 #include <string.h>
       
    23 #endif //__MSVCDOTNET__
       
    24 
       
    25 #include <stdarg.h>
       
    26 #include <stdlib.h>
       
    27 
       
    28 #include <e32std.h>
       
    29 
       
    30 #include "h_utl.h"
       
    31 
       
    32 #ifdef __LINUX__
       
    33  
       
    34  // Convert the supplied string to uppercase, in-place 
       
    35  char* strupr(char *a)
       
    36     {
       
    37      char *ret = a;
       
    38  
       
    39     while (*a)
       
    40         {
       
    41         *a = toupper(*a);
       
    42         a++;
       
    43          }
       
    44  
       
    45      return ret;
       
    46      }
       
    47  
       
    48  off_t filelength(int filedes)
       
    49      {
       
    50      struct stat buf;
       
    51      if(!fstat(filedes, &buf))
       
    52          {
       
    53         return buf.st_size;
       
    54          }
       
    55     perror("fstat failed");
       
    56    return 0;
       
    57     }
       
    58  
       
    59 #endif
       
    60 
       
    61 TBool PVerbose=ETrue;
       
    62 
       
    63 HPrint H;
       
    64 
       
    65 HPrint::~HPrint()
       
    66 	{
       
    67 	iLogFile.close();
       
    68 	}
       
    69 
       
    70 void HPrint::SetLogFile(TText *aFileName)
       
    71 	{
       
    72 	iLogFile.open((const char *)aFileName);
       
    73 	}
       
    74 
       
    75 
       
    76 /**
       
    77 Closing the logfile.(since 'n' number of drive images can be created)
       
    78 
       
    79 @internalComponent
       
    80 @released
       
    81 
       
    82 */
       
    83 void HPrint::CloseLogFile()
       
    84 	{
       
    85 	if(iLogFile.is_open())
       
    86 		iLogFile.close();
       
    87 	}
       
    88 
       
    89 TInt HPrint::PrintString(TPrintType aType,const char *aFmt,...)
       
    90 //
       
    91 // Print text, noting where to send it.
       
    92 //
       
    93 	{
       
    94 
       
    95 	TInt r=KErrNone;
       
    96 	va_list list;
       
    97 	va_start(list,aFmt);
       
    98 	_vsnprintf((char *)iText,KMaxStringLength,aFmt,list);
       
    99 	va_end(list);
       
   100 	switch (aType)
       
   101 		{
       
   102 	case EAlways:
       
   103 		cout << iText;
       
   104 		iLogFile << iText;
       
   105 		break;
       
   106 	case EScreen:
       
   107 		cout << iText;
       
   108 		break;
       
   109 	case ELog:
       
   110 		if (iVerbose)
       
   111 			cout << iText;
       
   112 		iLogFile << iText;
       
   113 		break;
       
   114 	case EWarning:
       
   115 		cerr << "WARNING: " << iText;
       
   116 		iLogFile << "WARNING: "<<iText;
       
   117 		break;
       
   118 	case EError:
       
   119 		cerr << "ERROR: " << iText;
       
   120 		iLogFile << "ERROR: " << iText;
       
   121 		r=KErrGeneral;
       
   122 		break;
       
   123 	case EPeError:
       
   124 		if (PVerbose)
       
   125 			{
       
   126 			cerr << "ERROR: " << iText;
       
   127 			iLogFile << "ERROR: " << iText;
       
   128 			}
       
   129 		r=KErrGeneral;
       
   130 		break;
       
   131 	case ESevereError:
       
   132 		cerr << "ERROR: " << iText;
       
   133 		iLogFile << "ERROR: " << iText;
       
   134 		r=KErrGeneral;
       
   135 		break;
       
   136 	case EDiagnostic:
       
   137 		cerr << "DIAGNOSTIC MESSAGE: " << iText;
       
   138 		iLogFile << "DIAGNOSTIC MESSAGE: "<<iText;
       
   139 		break;
       
   140 	default:
       
   141 		cerr << "ERROR: Invalid print type" << endl;
       
   142 		r=KErrGeneral;
       
   143 		}
       
   144 	cout.flush();
       
   145 	iLogFile.flush();
       
   146 	return r;
       
   147     }
       
   148 
       
   149 TVersion::TVersion()
       
   150 	{}
       
   151 TVersion::TVersion(TInt aMajor, TInt aMinor, TInt aBuild)
       
   152 	: iMajor((TInt8)aMajor), iMinor((TInt8)aMinor), iBuild((TInt16)aBuild)
       
   153 	{}
       
   154 #ifdef __TOOLS2__
       
   155 istringstream &operator>>(istringstream &is, TVersion &aVersion)
       
   156 #else
       
   157 istrstream &operator>>(istrstream &is, TVersion &aVersion)
       
   158 #endif
       
   159 //
       
   160 // Input a TVersion with syntax: major[.minor][(build)]
       
   161 //	
       
   162 	{
       
   163 #ifdef __TOOLS2__
       
   164 string tmp = is.str();
       
   165 const char *str=tmp.c_str();
       
   166 #else
       
   167 #ifdef __LINUX__
       
   168     char *str = is.rdbuf()->str();
       
   169 #else
       
   170     char *str=is.str();
       
   171 #endif
       
   172 #endif
       
   173 
       
   174 
       
   175 	TInt build=0;
       
   176 	memset(&aVersion, sizeof(TVersion), 0);	
       
   177 	TInt i;
       
   178 	TInt len=strlen(str);
       
   179 	for (i=0; i<len; i++)
       
   180 		if (str[i]=='(')
       
   181 			break;
       
   182 	if (i<len)
       
   183 		build=atoi(str+i+1);
       
   184 	aVersion.iMajor = (TInt8)Min(KMaxTInt8, atoi(str));
       
   185 	int majorV = atoi(str);
       
   186 	// iMajor is defined as TInt8 so it should not be bigger than 127
       
   187 	if (majorV > 127)
       
   188 		{ 
       
   189 		cout << "\n Warning: major version must be in range 0 - 127 \n";
       
   190 		}
       
   191 	char* pMinor = strchr(str, '.');
       
   192 	if (pMinor)
       
   193 		{
       
   194 		pMinor++; 
       
   195 		aVersion.iMinor = (TInt8)Min(KMaxTInt8, atoi(pMinor));
       
   196 		int minorV = atoi(pMinor);
       
   197 		// iMinor is defined as TInt8 so it should not be bigger than 127
       
   198 		if (minorV > 127)
       
   199 			{ 
       
   200 			cout << "\n Warning: minor version must be in range 0 - 127 \n";
       
   201 			}
       
   202 		}	
       
   203 	aVersion.iBuild=(TInt16)build;
       
   204 	return is;
       
   205 	}
       
   206 
       
   207 TInt Locate(const char *aString, char aChar)
       
   208 //
       
   209 // Locate aChar in aString
       
   210 //
       
   211 	{
       
   212 
       
   213 	if (aString==NULL)
       
   214 		return KErrNotFound;
       
   215 	TInt i=0;
       
   216 	while (*aString!=0)
       
   217 		{
       
   218 		if (*aString==aChar)
       
   219 			return i;
       
   220 		aString++;
       
   221 		i++;
       
   222 		}
       
   223 	return KErrNotFound;
       
   224 	}
       
   225 
       
   226 
       
   227 #define KHoursToMicroSeconds	Int64(3600000000UL) 
       
   228 #define KDaysToMicroSeconds		(Int64(24)*KHoursToMicroSeconds)
       
   229 const TInt KMinutesToMicroSeconds = 60000000;
       
   230 const TInt KSecondsToMicroSeconds =  1000000;
       
   231 
       
   232 const TInt8 mTab[2][12]=
       
   233     {
       
   234     {31,28,31,30,31,30,31,31,30,31,30,31}, // 28 days in Feb
       
   235     {31,29,31,30,31,30,31,31,30,31,30,31}  // 29 days in Feb
       
   236     };
       
   237 
       
   238 TInt Time::LeapYearsUpTo(TInt aYear)
       
   239 //
       
   240 // from 0AD to present year according to the rule above
       
   241 //
       
   242 	{
       
   243 
       
   244 	if (aYear<=0)
       
   245 		return(aYear/4);
       
   246 	if (aYear<=1600)
       
   247 		return(1+((aYear-1)/4));
       
   248 	TInt num=401; // 1600/4+1
       
   249 	aYear-=1601;
       
   250 	num+=(aYear/4-aYear/100+aYear/400);
       
   251 	return(num);
       
   252 	}
       
   253 
       
   254 TBool Time::IsLeapYear(TInt aYear)
       
   255 //
       
   256 // up to and including 1600 leap years were every 4 years,since then leap years are every 4 years unless
       
   257 // the year falls on a century which is not divisible by 4 (ie 1900 wasnt,2000 will be)
       
   258 // for simplicity define year 0 as a leap year
       
   259 //
       
   260 	{
       
   261 
       
   262 	if (aYear>1600)
       
   263     	return(!(aYear%4) && (aYear%100 || !(aYear%400)));
       
   264 	return(!(aYear%4));
       
   265 	}
       
   266 
       
   267 
       
   268 Int64 ConvertTime(TInt aDay, TInt aMonth, TInt aYear, TInt aHour, TInt aMinute, TInt aSecond, TInt aMilliSeconds)
       
   269 //
       
   270 // converts TDateTime into a TTime, doesnt check for overflows
       
   271 //
       
   272 	{
       
   273 	
       
   274 	TInt days=365*aYear+Time::LeapYearsUpTo(aYear);
       
   275 	TBool isleap=Time::IsLeapYear(aYear);
       
   276 	for (TInt ii=0; ii<aMonth; ii++)
       
   277 	    days+=(mTab[isleap][ii]);	
       
   278 	days+=aDay;
       
   279 	TInt sum=aMilliSeconds+aSecond*KSecondsToMicroSeconds;
       
   280 	return((Int64(days)*KDaysToMicroSeconds+Int64(aHour)*KHoursToMicroSeconds) 
       
   281 			+(Int64(KMinutesToMicroSeconds)*Int64(aMinute)+Int64(sum))); 
       
   282 	}
       
   283 	
       
   284 TInt StringToTime(Int64 &aTime, char *aString)
       
   285 //
       
   286 // Convert string to time. String is in the format:
       
   287 //
       
   288 // dd/mm/yyyy hh:mm:ss.mmmmmmm
       
   289 //
       
   290 	{
       
   291 	TInt day=1;
       
   292 	TInt month=1;
       
   293 	TInt year=1997;
       
   294 	TInt hour=10;
       
   295 	TInt minute=10;
       
   296 	TInt sec=0;
       
   297 	TInt mill=0;
       
   298 	char ch;
       
   299 	#ifdef __TOOLS2__
       
   300 	istringstream val(aString);
       
   301 	#else
       
   302 	istrstream val(aString,strlen(aString));
       
   303 	#endif
       
   304 	val >> dec >> day; // locks istrstream in decimal mode for further extractions
       
   305 	val >> ch;
       
   306 	if (ch!='/')
       
   307 		return KErrGeneral;
       
   308 	val >> month;
       
   309 	val >> ch;
       
   310 	if (ch!='/')
       
   311 		return KErrGeneral;
       
   312 	val >> year;
       
   313 	val >> ch;
       
   314 
       
   315 	if (ch=='_')
       
   316 		{
       
   317 		// time too.
       
   318 		val >> hour;
       
   319 		val >> ch;
       
   320 		if (ch!=':')
       
   321 			return KErrGeneral;
       
   322 		val >> minute;
       
   323 		val >> ch;
       
   324 		if (ch!=':')
       
   325 			return KErrGeneral;
       
   326 		val >> sec;
       
   327 		val >> ch;
       
   328 		if (ch=='.')
       
   329 			{
       
   330 			val >> mill;
       
   331 			}
       
   332 		}
       
   333 
       
   334 	if (day<1 || day>31)
       
   335 		return KErrArgument;
       
   336 	if (month<1 || month>12)
       
   337 		return KErrArgument;
       
   338 	if (year<1970 || year>2060)
       
   339 		return KErrArgument;
       
   340 	if (hour<0 || hour>23)
       
   341 		return KErrArgument;
       
   342 	if (minute<0 || minute>59)
       
   343 		return KErrArgument;
       
   344 	if (sec<0 || sec>59)
       
   345 		return KErrArgument;
       
   346 	if (mill<0 || mill>999999)
       
   347 		return KErrArgument;
       
   348 
       
   349 	aTime=ConvertTime(day-1, month-1, year, hour, minute, sec, mill);
       
   350 	return KErrNone;
       
   351 	}
       
   352 
       
   353 void ByteSwap(TUint &aVal)
       
   354 	{
       
   355 	TUint t0=aVal & 0xff;
       
   356 	TUint t1=(aVal>>8)  & 0xff;
       
   357 	TUint t2=(aVal>>16) & 0xff;
       
   358 	TUint t3=aVal>>24;
       
   359 	aVal=(t0 << 24) | (t1 << 16) | (t2 << 8) | (t3);
       
   360 	}
       
   361 
       
   362 void ByteSwap(TUint16 &aVal)
       
   363 	{
       
   364 	TUint16 t0=(TUint16)((aVal >> 8) & 0xff);
       
   365 	TUint16 t1=(TUint16)(aVal & 0xff);
       
   366 	aVal=(TUint16)((t1 << 8) | t0);
       
   367 	}
       
   368 
       
   369 void ByteSwap(TUint *aPtr, TInt aSize)
       
   370 	{
       
   371 
       
   372 	while ((aSize-=4)>=0)
       
   373 		ByteSwap(*aPtr++);
       
   374 	}
       
   375 
       
   376 TBool IsBracketedHex(const char* s, const char* brackets, TInt digits, TUint32& aValue)
       
   377 	{
       
   378 	if (s[0]!=brackets[0] || s[1+digits]!=brackets[1])
       
   379 		return EFalse;
       
   380 	TInt i;
       
   381 	TUint32 x = 0;
       
   382 	for (i=1; i<=digits; ++i)
       
   383 		{
       
   384 		TInt c = s[i];
       
   385 		if (c>='a' && c<='z') c-=32;
       
   386 		if (c<'0' || (c>'9' && c<'A') || c>'F')
       
   387 			return EFalse;
       
   388 		c-='0';
       
   389 		if (c>9) c-=7;
       
   390 		x = (x<<4) | (TUint32)c;
       
   391 		}
       
   392 	aValue = x;
       
   393 	return ETrue;
       
   394 	}
       
   395 
       
   396 TInt CheckForDecimalVersion(const char* begin, const char* s, TUint32& aValue)
       
   397 	{
       
   398 	aValue = 0;
       
   399 	if (s <= begin || *s != '}')
       
   400 		return 0;
       
   401 	TUint32 v[2] = {0,0};
       
   402 	TUint32 m = 1;
       
   403 	TInt pos = 0;
       
   404 	const char* s0 = s + 1;
       
   405 	for (--s; s >= begin; --s)
       
   406 		{
       
   407 		int c = *s;
       
   408 		if (c >= '0' && c <= '9')
       
   409 			{
       
   410 			v[pos] += m * (c - '0');
       
   411 			if (v[pos] >= 65536u)
       
   412 				return 0;
       
   413 			m *= 10;
       
   414 			}
       
   415 		else if (c == '.')
       
   416 			{
       
   417 			m = 1;
       
   418 			if (++pos >= 2)
       
   419 				return 0;
       
   420 			}
       
   421 		else if (c == '{')
       
   422 			break;
       
   423 		else
       
   424 			return 0;
       
   425 		}
       
   426 	if (s < begin)
       
   427 		return 0;
       
   428 	aValue = (v[1] << 16) | v[0];
       
   429 	return s0 - s;
       
   430 	}
       
   431 
       
   432 // Decompose a name of the form NAME{MMMMmmmm}[UUUUUUUU].EXT where the bracketed
       
   433 // sections and extension are both optional.
       
   434 // Return a newly malloc-ed string containing NAME.EXT
       
   435 // Set aUid = 0xUUUUUUUU if present, 0 if not
       
   436 // Set aModuleVersion = 0xMMMMmmmm if present, 0 if not
       
   437 // Set aFlags according to which of these are present
       
   438 char* SplitFileName(const char* aName, TUint32& aUid, TUint32& aModuleVersion, TUint32& aFlags)
       
   439 	{
       
   440 	TFileNameInfo f(aName, ETrue);
       
   441 	aUid = f.iUid3;
       
   442 	aModuleVersion = f.iModuleVersion;
       
   443 	aFlags = f.iFlags;
       
   444 	TInt nl = f.iBaseLength;
       
   445 	TInt el = f.iTotalLength - f.iExtPos;
       
   446 	TInt tl = nl + el;
       
   447 	char* t = (char*)malloc(tl + 1);
       
   448 	if (t)
       
   449 		{
       
   450 		memcpy(t, aName, nl);
       
   451 		if (el)
       
   452 			memcpy(t + nl, aName + f.iExtPos, el);
       
   453 		t[tl] = 0;
       
   454 		}
       
   455 	return t;
       
   456 	}
       
   457 
       
   458 
       
   459 // Decompose a name of the form NAME{MMMMmmmm}.EXT where the bracketed
       
   460 // sections and extension are both optional.
       
   461 // Return a newly malloc-ed string containing NAME.EXT
       
   462 // Set aModuleVersion = 0xMMMMmmmm if present, 0 if not
       
   463 // Set aFlags according to whether version present
       
   464 char* SplitFileName(const char* aName, TUint32& aModuleVersion, TUint32& aFlags)
       
   465 	{
       
   466 	TFileNameInfo f(aName, EFalse);
       
   467 	aModuleVersion = f.iModuleVersion;
       
   468 	aFlags = f.iFlags;
       
   469 	TInt nl = f.iBaseLength;
       
   470 	TInt el = f.iTotalLength - f.iExtPos;
       
   471 	TInt tl = nl + el;
       
   472 	char* t = (char*)malloc(tl + 1);
       
   473 	if (t)
       
   474 		{
       
   475 		memcpy(t, aName, nl);
       
   476 		if (el)
       
   477 			memcpy(t + nl, aName + f.iExtPos, el);
       
   478 		t[tl] = 0;
       
   479 		}
       
   480 	return t;
       
   481 	}
       
   482 
       
   483 
       
   484 // Parse a filename and convert decimal version number to hex
       
   485 char* NormaliseFileName(const char* aName)
       
   486 {
       
   487 	//convert forward slashes into back slashes.
       
   488 	char* filename = strdup(aName);  //prevent violated access from stack.
       
   489 	char* fwdslashfinder = filename;
       
   490 	fwdslashfinder=strstr(fwdslashfinder, "/");
       
   491 	while(fwdslashfinder)
       
   492 	  {
       
   493 		*fwdslashfinder++ = '\\';
       
   494 		fwdslashfinder=strstr(fwdslashfinder, "/");
       
   495 	  }
       
   496 
       
   497 	//normalize filename.
       
   498 	TFileNameInfo f(filename, EFalse);
       
   499 	TInt nl = f.iBaseLength;
       
   500 	TInt el = f.iTotalLength - f.iExtPos;
       
   501 	TInt tl = nl + el;
       
   502 	if (f.iFlags & EVerPresent)
       
   503 		tl += 10;
       
   504 	char* t = (char*)malloc(tl + 1);
       
   505 	if (t)
       
   506 		{
       
   507 		memcpy(t, filename, nl);
       
   508 		if (f.iFlags & EVerPresent)
       
   509 			sprintf(t + nl, "{%08lx}%s", f.iModuleVersion, filename + f.iExtPos);
       
   510 		else if (el)
       
   511 			memcpy(t + nl, filename + f.iExtPos, el);
       
   512 		t[tl] = 0;
       
   513 		}
       
   514 	free(filename);
       
   515 
       
   516 	return t;
       
   517 }
       
   518 
       
   519 TFileNameInfo::TFileNameInfo(const char* aFileName, TBool aLookForUid)
       
   520 	{
       
   521 	iFileName = aFileName;
       
   522 	TInt l = strlen(aFileName);
       
   523 	iTotalLength = l;
       
   524 	TInt remain = l;
       
   525 	iFlags = 0;
       
   526 	iUid3 = 0;
       
   527 	iModuleVersion = 0;
       
   528 	iBaseLength = l;
       
   529 	iExtPos = l;
       
   530 	const char* s = iFileName + l;
       
   531 	for (; s>=iFileName && *s!='.' && *s!='}' && (!aLookForUid || *s!=']'); --s) {}
       
   532 	if (s<iFileName)
       
   533 		return;
       
   534 	if (*s == '.')
       
   535 		{
       
   536 		iExtPos = s - iFileName;
       
   537 		if (iExtPos == 0)
       
   538 			{
       
   539 			iBaseLength = 0;
       
   540 			return;
       
   541 			}
       
   542 		remain = iExtPos;
       
   543 		--s;
       
   544 		}
       
   545 	else if (s != iFileName + l)
       
   546 		return;
       
   547 	if (aLookForUid && remain>=10 && IsBracketedHex(s-9, "[]", 8, iUid3))
       
   548 		{
       
   549 		iFlags |= EUidPresent;
       
   550 		remain -= 10;
       
   551 		s -= 10;
       
   552 		}
       
   553 	if (remain>=10 && IsBracketedHex(s-9, "{}", 8, iModuleVersion))
       
   554 		{
       
   555 		iFlags |= EVerPresent;
       
   556 		remain -= 10;
       
   557 		s -= 10;
       
   558 		}
       
   559 	else
       
   560 		{
       
   561 		TInt n = CheckForDecimalVersion(iFileName, s, iModuleVersion);
       
   562 		if (n>0)
       
   563 			{
       
   564 			iFlags |= EVerPresent;
       
   565 			remain -= n;
       
   566 			s -= n;
       
   567 			}
       
   568 		}
       
   569 	iBaseLength = remain;
       
   570 	}
       
   571 
       
   572 
       
   573 #define PARSE_CAPABILITIES_ERROR(aMessage) Print(EError, "%s\n",aMessage)
       
   574 #define PARSE_CAPABILITIES_ERROR2(aMessage1,aMessage2) Print(EError, "%s%s\n",aMessage1,aMessage2)
       
   575 
       
   576 TInt ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText)
       
   577 //
       
   578 // This is a cun'n'paste copy of the function in BASE\WINS\SPECIFIC\PROPERTY.CPP
       
   579 // Keep both of these versions up to date with each other
       
   580 //
       
   581 	{
       
   582 	memset(&aCapabilities,0,sizeof(aCapabilities));
       
   583 	char c;
       
   584 	while((c=*aText)!=0)
       
   585 		{
       
   586 		if(c<=' ')
       
   587 			{
       
   588 			++aText;
       
   589 			continue;
       
   590 			}
       
   591 		int invert=0;
       
   592 		if(c=='+')
       
   593 			{
       
   594 			++aText;
       
   595 			c=*aText;
       
   596 			}
       
   597 		if(c=='-')
       
   598 			{
       
   599 			invert=1;
       
   600 			++aText;
       
   601 			}
       
   602 		const char* name = aText;
       
   603 		while((c=*aText)>' ')
       
   604 			{
       
   605 			if(c=='-' || c=='+')
       
   606 				break;
       
   607 			++aText;
       
   608 			}
       
   609 		TUint n = aText-name; 
       
   610 		TInt i; 
       
   611 
       
   612 		if(n==3 && strnicmp("all",name,n)==0)
       
   613 			{
       
   614 			if(invert)
       
   615 				{
       
   616 				PARSE_CAPABILITIES_ERROR("Capability '-ALL' not allowed");
       
   617 				return KErrArgument;
       
   618 				}
       
   619 			for(i=0; i<ECapability_Limit; i++)
       
   620 				{
       
   621 				if(CapabilityNames[i])
       
   622 					aCapabilities[i>>5] |= (1<<(i&31));
       
   623 				}
       
   624 			continue;
       
   625 			}
       
   626 
       
   627 		if(n==4 && strnicmp("none",name,n)==0)
       
   628 			{
       
   629 			if(invert)
       
   630 				{
       
   631 				PARSE_CAPABILITIES_ERROR("Capability '-NONE' not allowed");
       
   632 				return KErrArgument;
       
   633 				}
       
   634 			memset(&aCapabilities,0,sizeof(aCapabilities));
       
   635 			continue;
       
   636 			}
       
   637 
       
   638 		for(i=0; i<ECapability_Limit; i++)
       
   639 			{
       
   640 			const char* cap = CapabilityNames[i];
       
   641 			if(!cap)
       
   642 				continue;
       
   643 			if((TUint)strlen(cap)!=n) 
       
   644 				continue;
       
   645 			if(strnicmp(cap,name,n)!=0)
       
   646 				continue;
       
   647 			break;
       
   648 			}
       
   649 		if(i>=ECapability_Limit)
       
   650 			{
       
   651 			char badName[32];
       
   652 			if(n>=sizeof(badName)) n=sizeof(badName)-1;
       
   653 			memcpy(badName,name,n);
       
   654 			badName[n]=0;
       
   655 			PARSE_CAPABILITIES_ERROR2("Unrecognised capability name: ",badName);
       
   656 			return KErrArgument;
       
   657 			}
       
   658 		if(invert)
       
   659 			aCapabilities[i>>5] &= ~(1<<(i&31));
       
   660 		else
       
   661 			aCapabilities[i>>5] |= (1<<(i&31));
       
   662 		}
       
   663 	return KErrNone;
       
   664 	}
       
   665 
       
   666 TInt ParseBoolArg(TBool& aValue, const char *aText)
       
   667 	{
       
   668 	if (_stricmp(aText, "on")==0 || _stricmp(aText, "yes")==0 || _stricmp(aText, "1")==0 || strlen(aText)==0)
       
   669 		{
       
   670 		aValue = ETrue;
       
   671 		return KErrNone;
       
   672 		}
       
   673 	if (_stricmp(aText, "off")==0 || _stricmp(aText, "no")==0 || _stricmp(aText, "0")==0 )
       
   674 		{
       
   675 		aValue = EFalse;
       
   676 		return KErrNone;
       
   677 		}
       
   678 	Print(EError, "Expected a boolean on/off value but found %s\n",aText);
       
   679 	return KErrArgument;
       
   680 	}