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