imgtools/sisutils/src/pkgfileparser.cpp
changeset 2 39c28ec933dd
child 6 787612182dd0
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 /*
       
     2 * Copyright (c) 2008-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 #include "sisutils.h"
       
    20 #include "pkgfileparser.h"
       
    21 #include <vector>
       
    22 #include <wchar.h>
       
    23 
       
    24 // Parse options lookups
       
    25 #define MAXTOKENLEN	30
       
    26 struct SParseToken
       
    27 {
       
    28 	wchar_t pszOpt[MAXTOKENLEN];
       
    29 	unsigned dwOpt;
       
    30 };
       
    31 
       
    32 const SParseToken KTokens[] =
       
    33 {
       
    34 	{L"if",		IF_TOKEN},
       
    35 	{L"elseif",	ELSEIF_TOKEN},
       
    36 	{L"else",	ELSE_TOKEN},
       
    37 	{L"endif",	ENDIF_TOKEN},
       
    38 	{L"exists",	EXISTS_TOKEN},
       
    39 	{L"devprop",DEVCAP_TOKEN},
       
    40 	{L"appcap",	APPCAP_TOKEN},
       
    41 	{L"package",DEVCAP_TOKEN},
       
    42 	{L"appprop",APPCAP_TOKEN},
       
    43 	{L"not",	NOT_TOKEN},
       
    44 	{L"and",	AND_TOKEN},
       
    45 	{L"or",		OR_TOKEN},
       
    46 	{L"type",	TYPE_TOKEN},
       
    47 	{L"key",	KEY_TOKEN},
       
    48 };
       
    49 #define NUMPARSETOKENS (sizeof(KTokens)/sizeof(SParseToken))
       
    50 
       
    51 std::wstring string2wstring (const String& aNarrow);
       
    52 String wstring2string (const std::wstring& aWide);
       
    53 
       
    54 
       
    55 /**
       
    56 Constructor: PkgParser class
       
    57 Initilize the parameters to data members.
       
    58 
       
    59 @internalComponent
       
    60 @released
       
    61 
       
    62 @param aFile	- Name of the package script file
       
    63 */
       
    64 PkgParser::PkgParser(String aFile) : iPkgFile(aFile), m_nLineNo(0)
       
    65 {
       
    66 }
       
    67 
       
    68 /**
       
    69 Destructor: PkgParser class
       
    70 Deallocates the memory for data members
       
    71 
       
    72 @internalComponent
       
    73 @released
       
    74 */
       
    75 PkgParser::~PkgParser()
       
    76 {
       
    77 	if(iPkgHandle)
       
    78 	{
       
    79 		std::fclose(iPkgHandle);
       
    80 	}
       
    81 
       
    82 	DeleteAll();
       
    83 }
       
    84 
       
    85 /**
       
    86 OpenFile: Opens the package script file
       
    87 
       
    88 @internalComponent
       
    89 @released
       
    90 */
       
    91 int PkgParser::OpenFile()
       
    92 {
       
    93 #ifdef WIN32
       
    94 	iPkgHandle = _wfopen(string2wstring(iPkgFile).c_str(),L"r");
       
    95 #else
       
    96 	// *nix fopen doesn't care about the filename encoding, as long as its NULL-terminated.
       
    97 	iPkgHandle = std::fopen(iPkgFile.c_str(),"r");
       
    98 #endif
       
    99 	return iPkgHandle ? 1 : 0;
       
   100 
       
   101 }
       
   102 
       
   103 /**
       
   104 GetEmbeddedSisList: Returns the embedded sis file list
       
   105 
       
   106 @internalComponent
       
   107 @released
       
   108 
       
   109 @param embedSisList	- reference to sis file list structure
       
   110 */
       
   111 void PkgParser::GetEmbeddedSisList(SISFILE_LIST& embedSisList)
       
   112 {
       
   113 	embedSisList = iEmbedSisFiles;
       
   114 }
       
   115 
       
   116 /**
       
   117 GetInstallOptions: Returns the install options read from the package file
       
   118 
       
   119 @internalComponent
       
   120 @released
       
   121 
       
   122 @param aOptions	- reference to the string list structure
       
   123 */
       
   124 void PkgParser::GetInstallOptions(FILE_LIST& aOptions)
       
   125 {
       
   126 	aOptions = iInstallOptions;
       
   127 }
       
   128 
       
   129 /**
       
   130 GetLanguageList: Returns the language list read from the package file
       
   131 
       
   132 @internalComponent
       
   133 @released
       
   134 
       
   135 @param langList	- reference to the language list structure
       
   136 */
       
   137 void PkgParser::GetLanguageList(LANGUAGE_LIST& langList)
       
   138 {
       
   139 	langList = iLangList;
       
   140 }
       
   141 
       
   142 /**
       
   143 GetHeader: Returns the header details read from the package file
       
   144 
       
   145 @internalComponent
       
   146 @released
       
   147 
       
   148 @param pkgHeader	- reference to the package header structure
       
   149 */
       
   150 void PkgParser::GetHeader(PKG_HEADER& pkgHeader)
       
   151 {
       
   152 	pkgHeader = iPkgHeader;
       
   153 }
       
   154 
       
   155 /**
       
   156 GetCommandList: Returns the package body details read from the package file
       
   157 
       
   158 @internalComponent
       
   159 @released
       
   160 
       
   161 @param cmdList	- reference to the command list structure
       
   162 */
       
   163 void PkgParser::GetCommandList(CMDBLOCK_LIST& cmdList)
       
   164 {
       
   165 	cmdList = iPkgBlock;
       
   166 }
       
   167 
       
   168 /**
       
   169 ParsePkgFile: Parses the package file
       
   170 
       
   171 @internalComponent
       
   172 @released
       
   173 */
       
   174 void PkgParser::ParsePkgFile()
       
   175 {
       
   176 	if(!OpenFile())
       
   177 	{
       
   178 		throw SisUtilsException((char*)iPkgFile.data(), const_cast<char *>("Could not open file"));
       
   179 	}
       
   180 
       
   181 	GetNextChar();
       
   182 
       
   183 	// skip unicode marker if present
       
   184 	if(m_pkgChar==0xFEFF) GetNextChar();
       
   185 
       
   186 	GetNextToken ();
       
   187 	while(m_token!=EOF_TOKEN)
       
   188 	{
       
   189 		ParseEmbeddedBlockL();
       
   190 		switch (m_token)
       
   191 		{
       
   192 		case '&':
       
   193 			GetNextToken ();
       
   194 			ParseLanguagesL();
       
   195 			break;
       
   196 		case '#':
       
   197 			GetNextToken ();
       
   198 			ParseHeaderL();
       
   199 			break;
       
   200 		case '%':
       
   201 			GetNextToken ();
       
   202 			ParseVendorNameL();
       
   203 			break;
       
   204 		case '=':
       
   205 			GetNextToken ();
       
   206 			ParseLogoL();
       
   207 			break;
       
   208 		case '(':
       
   209 			GetNextToken ();
       
   210 			ParseDependencyL();
       
   211 			break;
       
   212 		case ':':
       
   213 			GetNextToken ();
       
   214 			ParseVendorUniqueNameL();
       
   215 			break;
       
   216 		case '[':
       
   217 			GetNextToken ();
       
   218 			ParseTargetDeviceL();
       
   219 			break;
       
   220 		case EOF_TOKEN:
       
   221 			break;
       
   222 		default:
       
   223 			ParserError(const_cast<char *>("Unexpected token"));
       
   224 			break;
       
   225 		}
       
   226 	}
       
   227 }
       
   228 
       
   229 /**
       
   230 ParseLanguagesL: Parses the language section
       
   231 
       
   232 @internalComponent
       
   233 @released
       
   234 */
       
   235 void PkgParser::ParseLanguagesL()
       
   236 {
       
   237 	unsigned long langCode = 0;
       
   238 	unsigned long dialect = 0;
       
   239 	
       
   240 	while (true)
       
   241 	{
       
   242 		if (m_token==ALPHA_TOKEN)
       
   243 		{
       
   244 			langCode = PkgLanguage::GetLanguageCode(m_tokenValue.pszString);
       
   245 		}
       
   246 		else if (m_token==NUMERIC_TOKEN && m_tokenValue.dwNumber>=0 && m_tokenValue.dwNumber<=1000)
       
   247 		{
       
   248 			langCode = (m_tokenValue.dwNumber);
       
   249 		}
       
   250 
       
   251 		GetNextToken ();
       
   252 
       
   253 		// Check if a dialect is defined
       
   254 		if (m_token == '(')
       
   255 		{
       
   256 			GetNumericToken();
       
   257 			// Modify the last added language code, combining it with dialect code
       
   258 			dialect = (m_tokenValue.dwNumber);
       
   259 			GetNextToken ();
       
   260 			GetNextToken ();
       
   261 		}
       
   262 		AddLanguage(wstring2string(PkgLanguage::GetLanguageName(langCode)), langCode, dialect);
       
   263 
       
   264 		if (m_token!=',')
       
   265 			return;
       
   266 		GetNextToken ();
       
   267 	}
       
   268 }
       
   269 
       
   270 
       
   271 /**
       
   272 ParseHeaderL: Parses the package header section
       
   273 
       
   274 @internalComponent
       
   275 @released
       
   276 */
       
   277 void PkgParser::ParseHeaderL()
       
   278 {
       
   279 	if (!iLangList.size())
       
   280 	{
       
   281 		//No languages defined, assuming English."
       
   282 		AddLanguage("EN", PkgLanguage::ELangEnglish, 0);
       
   283 	}
       
   284 	
       
   285 	// process application names
       
   286 	ExpectToken('{');
       
   287 	for (unsigned short wNumLangs = 0; wNumLangs < iLangList.size(); wNumLangs++)
       
   288 	{
       
   289 		GetNextToken ();
       
   290 		ExpectToken(QUOTED_STRING_TOKEN);
       
   291 		iPkgHeader.pkgNameList.push_back(wstring2string(m_tokenValue.pszString));
       
   292 		GetNextToken ();
       
   293 		if (wNumLangs < (iLangList.size()-1) )
       
   294 		{
       
   295 			ExpectToken(',');
       
   296 		}
       
   297 	}
       
   298 	ExpectToken('}');
       
   299 	GetNextToken (); 
       
   300 	
       
   301 	ExpectToken(',');
       
   302 	GetNextToken ();
       
   303 	ExpectToken('(');
       
   304 	GetNextToken ();
       
   305 	
       
   306 	ExpectToken(NUMERIC_TOKEN);
       
   307 	iPkgHeader.pkgUid = m_tokenValue.dwNumber;
       
   308 	GetNextToken ();
       
   309 	
       
   310 	ExpectToken(')');
       
   311 	GetNextToken ();
       
   312 	ExpectToken(',');
       
   313 	GetNextToken ();
       
   314 	
       
   315 	ExpectToken(NUMERIC_TOKEN);
       
   316 	iPkgHeader.vMajor = m_tokenValue.dwNumber;
       
   317 	GetNextToken ();
       
   318 	ExpectToken(',');
       
   319 	GetNextToken ();
       
   320 	
       
   321 	ExpectToken(NUMERIC_TOKEN);
       
   322 	iPkgHeader.vMinor = m_tokenValue.dwNumber;
       
   323 	GetNextToken ();
       
   324 	ExpectToken(',');
       
   325 	GetNextToken ();
       
   326 	
       
   327 	ExpectToken(NUMERIC_TOKEN);
       
   328 	iPkgHeader.vBuild = m_tokenValue.dwNumber;
       
   329 	GetNextToken ();
       
   330 	
       
   331 	// Parse any options
       
   332 	while (m_token==',')
       
   333 	{
       
   334 		GetNextToken ();
       
   335 		if (m_token==TYPE_TOKEN)
       
   336 		{
       
   337 			GetNextToken ();
       
   338 			ExpectToken('=');
       
   339 			GetNextToken ();
       
   340 			iPkgHeader.pkgType = wstring2string(m_tokenValue.pszString);
       
   341 			GetNextToken ();
       
   342 		}
       
   343 		else
       
   344 			GetNextToken ();
       
   345 	}
       
   346 }
       
   347 
       
   348 /**
       
   349 ParseEmbeddedBlockL: Parses the package body block
       
   350 
       
   351 @internalComponent
       
   352 @released
       
   353 */
       
   354 void PkgParser::ParseEmbeddedBlockL ()
       
   355 {
       
   356 	while(m_token!=EOF_TOKEN)
       
   357 	{
       
   358 		switch (m_token)
       
   359 		{
       
   360 		case QUOTED_STRING_TOKEN:
       
   361 			ParseFileL ();
       
   362 			break;
       
   363 		case '@':
       
   364 			GetNextToken ();
       
   365 			ParsePackageL ();
       
   366 			break;
       
   367 		case '!':
       
   368 			GetNextToken ();
       
   369 			ParseOptionsBlockL();
       
   370 			break;
       
   371 		case '+':
       
   372 			GetNextToken ();
       
   373 			ParsePropertyL ();
       
   374 			break;
       
   375 		case IF_TOKEN:
       
   376 			GetNextToken ();
       
   377 			ParseIfBlockL ();
       
   378 			break;
       
   379 		case ';' :
       
   380 			ParseCommentL ();
       
   381 			break;
       
   382 		default :
       
   383 			return;
       
   384 		}
       
   385 	}
       
   386 }
       
   387 
       
   388 /**
       
   389 ParseFileL: Parses the file list section
       
   390 
       
   391 @internalComponent
       
   392 @released
       
   393 */
       
   394 void PkgParser::ParseFileL()
       
   395 {
       
   396 	PCMD_BLOCK pCmdBlock = 0;
       
   397 	PINSTALLFILE_LIST pFileList = 0;
       
   398 	
       
   399 	std::wstring sourceFile (m_tokenValue.pszString);
       
   400 	
       
   401 	// Linux and windows both support forward slashes so if source path is given '\' need to convert
       
   402 	// in forward slash for compatibility.
       
   403 	wchar_t *pBuffer = (wchar_t*)sourceFile.c_str();
       
   404 	wchar_t *pCurrent = pBuffer;
       
   405 	while (pBuffer && *pBuffer && (pCurrent = wcschr(pBuffer,L'\\')) != NULL)
       
   406 	{
       
   407 		*pCurrent = L'/';
       
   408 		pBuffer = pCurrent + 1;
       
   409 	}
       
   410 	
       
   411 	GetNextToken ();
       
   412 	
       
   413 	ExpectToken('-');
       
   414 	GetNextToken ();
       
   415 	
       
   416 	ExpectToken(QUOTED_STRING_TOKEN);
       
   417 	
       
   418 	std::wstring destinationFile (m_tokenValue.pszString);
       
   419 	
       
   420 	// SWI only supports backward slashesh so need to convert destination path in backward slash if
       
   421 	// user gives '/' in Linux.
       
   422 	pBuffer = (wchar_t*)destinationFile.c_str();
       
   423 	pCurrent = pBuffer;
       
   424 	while (pBuffer && *pBuffer && (pCurrent = wcschr(pBuffer,L'/')) != NULL)
       
   425 	{
       
   426 		*pCurrent = L'\\';
       
   427 		pBuffer = pCurrent + 1;
       
   428 	}
       
   429 	
       
   430 	GetNextToken ();
       
   431 	
       
   432 	// Test for options
       
   433 	if (m_token!=',')
       
   434 	{
       
   435 		pCmdBlock = new CMD_BLOCK;
       
   436 		pFileList = new INSTALLFILE_LIST;
       
   437 
       
   438 		pCmdBlock->cmdType = INSTALLFILE;
       
   439 		pCmdBlock->iInstallFileList = pFileList;
       
   440 
       
   441 		pFileList->langDepFlg = 0;
       
   442 		pFileList->srcFiles.push_back(wstring2string(sourceFile));
       
   443 		pFileList->destFile = wstring2string(destinationFile);
       
   444 
       
   445 		iPkgBlock.push_back(pCmdBlock);
       
   446 	}
       
   447 	else
       
   448 	{	
       
   449 		bool needAdd = false;
       
   450 		while(m_token==',')
       
   451 		{
       
   452 			GetNextToken ();
       
   453 			std::wstring installOption = m_tokenValue.pszString;
       
   454 			if((installOption == L"FF") || (installOption == L"FILE"))
       
   455 			{
       
   456 				needAdd = true;
       
   457 			}
       
   458 			GetNextToken ();
       
   459 		}
       
   460 		if (needAdd)
       
   461 		{
       
   462 			pCmdBlock = new CMD_BLOCK;
       
   463 			pFileList = new INSTALLFILE_LIST;
       
   464 
       
   465 			pCmdBlock->cmdType = INSTALLFILE;
       
   466 			pCmdBlock->iInstallFileList = pFileList;
       
   467 
       
   468 			pFileList->langDepFlg = 0;
       
   469 			pFileList->srcFiles.push_back(wstring2string(sourceFile));
       
   470 			pFileList->destFile = wstring2string(destinationFile);
       
   471 		
       
   472 			iPkgBlock.push_back(pCmdBlock);
       
   473 		}
       
   474 	}
       
   475 }
       
   476 
       
   477 /**
       
   478 ParseIfBlockL: Parses the conditional installation body
       
   479 
       
   480 @internalComponent
       
   481 @released
       
   482 */
       
   483 void PkgParser::ParseIfBlockL()
       
   484 {
       
   485 	PCMD_BLOCK pCmdBlock = 0; 
       
   486 
       
   487 	//IF
       
   488 	pCmdBlock = new CMD_BLOCK;
       
   489 	pCmdBlock->cmdType = IF;
       
   490 	ParseLogicalOp(pCmdBlock->cmdExpression);
       
   491 	iPkgBlock.push_back(pCmdBlock);
       
   492 
       
   493 	ParseEmbeddedBlockL ();
       
   494 	
       
   495 	while (m_token==ELSEIF_TOKEN)
       
   496 	{
       
   497 		GetNextToken ();
       
   498 		//ELSEIF
       
   499 		pCmdBlock = new CMD_BLOCK;
       
   500 		pCmdBlock->cmdType = ELSEIF;
       
   501 		ParseLogicalOp(pCmdBlock->cmdExpression);
       
   502 		iPkgBlock.push_back(pCmdBlock);
       
   503 
       
   504 		ParseEmbeddedBlockL ();
       
   505 	}
       
   506 	
       
   507 	if (m_token==ELSE_TOKEN)
       
   508 	{
       
   509 		GetNextToken ();
       
   510 		//ELSEIF
       
   511 		pCmdBlock = new CMD_BLOCK;
       
   512 		pCmdBlock->cmdType = ELSE;
       
   513 		iPkgBlock.push_back(pCmdBlock);
       
   514 
       
   515 		ParseEmbeddedBlockL ();
       
   516 	}
       
   517 	
       
   518 	ExpectToken(ENDIF_TOKEN);
       
   519 	//ENDIF
       
   520 	pCmdBlock = new CMD_BLOCK;
       
   521 	pCmdBlock->cmdType = ENDIF;
       
   522 	iPkgBlock.push_back(pCmdBlock);
       
   523 
       
   524 	GetNextToken ();
       
   525 }
       
   526 
       
   527 /**
       
   528 ParseLogicalOp: Parses the logical expression
       
   529 
       
   530 @internalComponent
       
   531 @released
       
   532 */
       
   533 void PkgParser::ParseLogicalOp (String& aExpression)
       
   534 {
       
   535     ParseRelation (aExpression);
       
   536 	switch (m_token)
       
   537 	{
       
   538 	case AND_TOKEN:
       
   539 	case OR_TOKEN:
       
   540 		{
       
   541 			if (m_token==AND_TOKEN)
       
   542 				aExpression.append(" && ");
       
   543 			else
       
   544 				aExpression.append(" || ");
       
   545 			GetNextToken ();
       
   546 			ParseLogicalOp (aExpression);
       
   547 		}
       
   548 		break;
       
   549 	}
       
   550 }
       
   551 
       
   552 /**
       
   553 ParseRelation: Parses the relational expression
       
   554 
       
   555 @internalComponent
       
   556 @released
       
   557 */
       
   558 void PkgParser::ParseRelation(String& aExpression)
       
   559 {
       
   560     ParseUnary (aExpression);
       
   561 	switch (m_token)
       
   562 	{
       
   563 	case '=':
       
   564 	case '>':
       
   565 	case '<':
       
   566 	case GE_TOKEN:
       
   567 	case LE_TOKEN:
       
   568 	case NE_TOKEN:
       
   569 	case APPCAP_TOKEN:
       
   570 		{
       
   571 			switch (m_token)
       
   572 			{
       
   573 			case '=':
       
   574 				aExpression.append(" == ");
       
   575 				break;
       
   576 			case '>':
       
   577 				aExpression.append(" > ");
       
   578 				break;
       
   579 			case '<':
       
   580 				aExpression.append(" < ");
       
   581 				break;
       
   582 			case GE_TOKEN:
       
   583 				aExpression.append(" >= ");
       
   584 				break;
       
   585 			case LE_TOKEN:
       
   586 				aExpression.append(" <= ");
       
   587 				break;
       
   588 			case NE_TOKEN:
       
   589 				aExpression.append(" != ");
       
   590 				break;
       
   591 			case APPCAP_TOKEN:
       
   592 				aExpression.append(" APPPROP ");
       
   593 				break;
       
   594 			}
       
   595 			GetNextToken ();
       
   596 			ParseUnary (aExpression);
       
   597 			break;
       
   598 		}
       
   599 	}
       
   600 }
       
   601 
       
   602 /**
       
   603 ParseUnary: Parses the unary expression
       
   604 
       
   605 @internalComponent
       
   606 @released
       
   607 */
       
   608 void PkgParser::ParseUnary(String& aExpression)
       
   609 {
       
   610     switch (m_token)
       
   611 	{
       
   612 	case NOT_TOKEN:
       
   613 		aExpression.append(" !");
       
   614 		GetNextToken ();
       
   615 		ParseUnary (aExpression);
       
   616 		break;
       
   617 	case EXISTS_TOKEN:
       
   618 	case DEVCAP_TOKEN:
       
   619 		{	// 1 arg function
       
   620 			int token=m_token;
       
   621 			GetNextToken ();
       
   622 			ExpectToken('(');
       
   623 			GetNextToken ();
       
   624 			if (token==EXISTS_TOKEN)
       
   625 			{
       
   626 				aExpression.append("EXISTS(\"");
       
   627 				ExpectToken(QUOTED_STRING_TOKEN);
       
   628 				GetNextToken ();
       
   629 				aExpression.append(wstring2string(m_tokenValue.pszString));
       
   630 				aExpression.append("\")");
       
   631 			}
       
   632 			else
       
   633 			{
       
   634 				aExpression.append("DEVCAP(");
       
   635 				ParseUnary (aExpression);
       
   636 				aExpression.append(")");
       
   637 			}
       
   638 			ExpectToken(')');
       
   639 			GetNextToken ();
       
   640 			break;
       
   641 		}
       
   642 	default:
       
   643 		ParseFactor (aExpression);
       
   644 		break;
       
   645 	}
       
   646 }
       
   647 
       
   648 /**
       
   649 ParseFactor: Parses the expression factor
       
   650 
       
   651 @internalComponent
       
   652 @released
       
   653 */
       
   654 void PkgParser::ParseFactor(String& aExpression)
       
   655 {
       
   656     switch (m_token) {
       
   657 	case '(':
       
   658 		{
       
   659 			aExpression.append("(");
       
   660 			GetNextToken ();
       
   661 			ParseLogicalOp (aExpression);
       
   662 			ExpectToken(')');
       
   663 			aExpression.append(")");
       
   664 		}
       
   665 		break;
       
   666 	case QUOTED_STRING_TOKEN:
       
   667 	case ALPHA_TOKEN:
       
   668 	case NUMERIC_TOKEN:
       
   669 		{
       
   670 			switch (m_token)
       
   671 			{
       
   672 			case QUOTED_STRING_TOKEN:
       
   673 				aExpression.append("\"");
       
   674 				aExpression.append(wstring2string(m_tokenValue.pszString));
       
   675 				aExpression.append("\"");
       
   676 				break;
       
   677 			case ALPHA_TOKEN:
       
   678                 if(!CompareNString(m_tokenValue.pszString,const_cast<wchar_t *>(L"option"),6))
       
   679 				{
       
   680 					aExpression.append(" defined(");
       
   681 					aExpression.append(wstring2string(m_tokenValue.pszString));
       
   682 					aExpression.append(") ");
       
   683 				}
       
   684 				else
       
   685 				{
       
   686 					aExpression.append(wstring2string(m_tokenValue.pszString));
       
   687 				}
       
   688 				break;
       
   689 			case NUMERIC_TOKEN:
       
   690 				{
       
   691 					std::ostringstream str;
       
   692 
       
   693 					str << "(0x" << std::setbase(16) << m_tokenValue.dwNumber << ")";
       
   694 					aExpression.append(str.str());
       
   695 				}
       
   696 				break;
       
   697 			}
       
   698 		}
       
   699 		break;
       
   700 	default:
       
   701 		ParserError(const_cast<char *>("ErrBadCondFormat"));
       
   702 	}
       
   703 	GetNextToken ();
       
   704 }
       
   705 
       
   706 
       
   707 /**
       
   708 ParsePackageL: Parses the embedded package section
       
   709 
       
   710 @internalComponent
       
   711 @released
       
   712 */
       
   713 void PkgParser::ParsePackageL()
       
   714 {
       
   715 	PCMD_BLOCK pCmdBlock = 0;
       
   716 	int found = 0;
       
   717 
       
   718 	ExpectToken(QUOTED_STRING_TOKEN);
       
   719 
       
   720 	//if the sis file already exists then skip it
       
   721 	SISFILE_LIST::iterator begin = iEmbedSisFiles.begin();
       
   722 	SISFILE_LIST::iterator end = iEmbedSisFiles.end();
       
   723 
       
   724 	while(begin != end)
       
   725 	{
       
   726 		if((*begin).compare(wstring2string(m_tokenValue.pszString)) == 0)
       
   727 		{
       
   728 			found = 1;
       
   729 			break;
       
   730 		}
       
   731 		++begin;
       
   732 	}
       
   733 
       
   734 	if(!found)
       
   735 	{
       
   736 		iEmbedSisFiles.push_back(wstring2string(m_tokenValue.pszString));
       
   737 	}
       
   738 	
       
   739 	//add as a command block as well
       
   740 	{
       
   741 		pCmdBlock = new CMD_BLOCK;
       
   742 
       
   743 		pCmdBlock->cmdType = PACKAGE;
       
   744 		pCmdBlock->iInstallFileList = 0;
       
   745 		pCmdBlock->cmdExpression = wstring2string(m_tokenValue.pszString);
       
   746 
       
   747 		iPkgBlock.push_back(pCmdBlock);
       
   748 	}
       
   749 
       
   750 
       
   751 	GetNextToken ();
       
   752 
       
   753 	ExpectToken(',');
       
   754 	GetNextToken ();
       
   755 	ExpectToken('(');
       
   756 	GetNextToken ();
       
   757 	ExpectToken(NUMERIC_TOKEN);
       
   758 	GetNextToken ();
       
   759 	ExpectToken(')');
       
   760 	GetNextToken ();
       
   761 }
       
   762 
       
   763 /**
       
   764 ParseCommentL: Parses the comment section
       
   765   Parses a comment line (Does nothing, just throws the line away)
       
   766 
       
   767 @internalComponent
       
   768 @released
       
   769 */
       
   770 void PkgParser::ParseCommentL()
       
   771 {
       
   772 	// parse to end of line
       
   773 	while (m_pkgChar && (m_pkgChar!='\n')) GetNextChar();
       
   774 	GetNextToken ();
       
   775 }
       
   776 
       
   777 /**
       
   778 ParseOptionsBlockL: Parses the install options section
       
   779 
       
   780 @internalComponent
       
   781 @released
       
   782 */
       
   783 void PkgParser::ParseOptionsBlockL()
       
   784 {
       
   785 	unsigned short wNumLangs;
       
   786 	
       
   787 	ExpectToken('(');
       
   788 	GetNextToken ();
       
   789 	
       
   790 	for (;;)
       
   791 	{
       
   792 		ExpectToken('{');
       
   793 		GetNextToken ();
       
   794 		
       
   795 		wNumLangs = 0;
       
   796 		while (wNumLangs < iLangList.size())
       
   797 		{
       
   798 			ExpectToken(QUOTED_STRING_TOKEN);
       
   799 			iInstallOptions.push_back(wstring2string(m_tokenValue.pszString));
       
   800 			GetNextToken ();
       
   801 			if (wNumLangs < iLangList.size() - 1)
       
   802 			{
       
   803 				ExpectToken(',');
       
   804 				GetNextToken ();
       
   805 			}
       
   806 			wNumLangs++;
       
   807 		}
       
   808 		
       
   809 		ExpectToken('}');
       
   810 		GetNextToken ();
       
   811 		if (m_token!=',') break;
       
   812 		GetNextToken ();
       
   813 	}
       
   814 	
       
   815 	ExpectToken(')');
       
   816 	GetNextToken ();	
       
   817 }
       
   818 
       
   819 /**
       
   820 ParsePropertyL: Parses the capability options section
       
   821 
       
   822 @internalComponent
       
   823 @released
       
   824 */
       
   825 void PkgParser::ParsePropertyL()
       
   826 {
       
   827 	ExpectToken('(');
       
   828 	do
       
   829 	{
       
   830 		GetNextToken ();
       
   831 		
       
   832 		ExpectToken(NUMERIC_TOKEN);
       
   833 		GetNextToken ();
       
   834 		ExpectToken('=');
       
   835 		GetNextToken ();
       
   836 		ExpectToken(NUMERIC_TOKEN);
       
   837 		GetNextToken ();
       
   838 	} while (m_token==',');
       
   839 	ExpectToken(')');
       
   840 	GetNextToken ();
       
   841 }
       
   842 
       
   843 /**
       
   844 ParseVendorNameL: Parses the vendor options section
       
   845 
       
   846 @internalComponent
       
   847 @released
       
   848 */
       
   849 void PkgParser::ParseVendorNameL()
       
   850 {
       
   851 	ExpectToken('{');
       
   852 	for (unsigned short wNumLangs = 0; wNumLangs < iLangList.size(); wNumLangs++)
       
   853 	{
       
   854 		GetNextToken ();
       
   855 		ExpectToken(QUOTED_STRING_TOKEN);
       
   856 		GetNextToken ();
       
   857 		if (wNumLangs < iLangList.size() -1 )
       
   858 		{
       
   859 			ExpectToken(',');
       
   860 		}
       
   861 	}
       
   862 	ExpectToken('}');
       
   863 	GetNextToken ();
       
   864 }
       
   865 
       
   866 /**
       
   867 ParseLogoL: Parses the logo options section
       
   868 
       
   869 @internalComponent
       
   870 @released
       
   871 */
       
   872 void PkgParser::ParseLogoL()
       
   873 {
       
   874 	ExpectToken (QUOTED_STRING_TOKEN);
       
   875 	GetNextToken ();
       
   876 	ExpectToken(',');
       
   877 	GetNextToken ();
       
   878 	ExpectToken (QUOTED_STRING_TOKEN);
       
   879 	GetNextToken ();
       
   880 	if (m_token==',')
       
   881 	{
       
   882 		GetNextToken ();
       
   883 		ExpectToken (QUOTED_STRING_TOKEN);
       
   884 		GetNextToken ();
       
   885 	}
       
   886 }
       
   887 
       
   888 /**
       
   889 ParseVersion: Parses the version details
       
   890 
       
   891 @internalComponent
       
   892 @released
       
   893 */
       
   894 void PkgParser::ParseVersion()
       
   895 {
       
   896 	GetNextToken();
       
   897 	ExpectToken(NUMERIC_TOKEN);
       
   898 
       
   899 	GetNextToken();
       
   900 	ExpectToken(',');
       
   901 	GetNextToken();
       
   902 	ExpectToken(NUMERIC_TOKEN);
       
   903 
       
   904 	GetNextToken();
       
   905 	ExpectToken(',');
       
   906 	GetNextToken();
       
   907 	ExpectToken(NUMERIC_TOKEN);
       
   908 
       
   909 	GetNextToken();
       
   910 }
       
   911 
       
   912 /**
       
   913 ParseDependencyL: Parses the dependency package section
       
   914 
       
   915 @internalComponent
       
   916 @released
       
   917 */
       
   918 void PkgParser::ParseDependencyL()
       
   919 {
       
   920 	ExpectToken(NUMERIC_TOKEN);
       
   921 	GetNextToken ();
       
   922 	ExpectToken(')');
       
   923 	GetNextToken ();
       
   924 	ExpectToken(',');
       
   925 
       
   926 	ParseVersion();
       
   927 	if (m_token == '~')
       
   928 	{
       
   929 		ParseVersion();
       
   930 		ExpectToken(',');
       
   931 	}
       
   932 	
       
   933 	GetNextToken ();
       
   934 	ExpectToken('{');
       
   935 	for (TUint numLangs = 0; numLangs < iLangList.size(); ++numLangs)
       
   936 	{
       
   937 		GetNextToken ();
       
   938 		ExpectToken(QUOTED_STRING_TOKEN);
       
   939 		GetNextToken ();
       
   940 		if (numLangs < (iLangList.size() - 1))
       
   941 			ExpectToken(',');
       
   942 	}
       
   943 	ExpectToken('}');
       
   944 	GetNextToken ();
       
   945 }
       
   946 
       
   947 /**
       
   948 ParseVendorUniqueNameL: Parses the vendor unique name section
       
   949 
       
   950 @internalComponent
       
   951 @released
       
   952 */
       
   953 void PkgParser::ParseVendorUniqueNameL()
       
   954 {
       
   955 	ExpectToken(QUOTED_STRING_TOKEN);
       
   956 	GetNextToken ();
       
   957 }
       
   958 
       
   959 /**
       
   960 ParseTargetDeviceL: Parses the target device name section
       
   961 
       
   962 @internalComponent
       
   963 @released
       
   964 */
       
   965 void PkgParser::ParseTargetDeviceL()
       
   966 {
       
   967 	ExpectToken(NUMERIC_TOKEN);
       
   968 	GetNextToken ();
       
   969 	ExpectToken(']');
       
   970 	GetNextToken ();
       
   971 	ExpectToken(',');
       
   972 	
       
   973 	ParseVersion();
       
   974 	if (m_token == '~')
       
   975 	{
       
   976 		ParseVersion();
       
   977 		ExpectToken(',');
       
   978 	}
       
   979 	GetNextToken ();
       
   980 	ExpectToken('{');
       
   981 	
       
   982 	// must do this before adding language strings	
       
   983 	for (TUint numLangs = 0; numLangs < iLangList.size(); ++numLangs)
       
   984 	{
       
   985 		GetNextToken ();
       
   986 		ExpectToken(QUOTED_STRING_TOKEN);
       
   987 		GetNextToken ();
       
   988 		if (numLangs < (iLangList.size() - 1))
       
   989 			ExpectToken(',');
       
   990 	}
       
   991 	ExpectToken('}');
       
   992 	GetNextToken ();
       
   993 }
       
   994 
       
   995 
       
   996 /**
       
   997 GetNextChar: Reads the next character from the package file
       
   998 
       
   999 @internalComponent
       
  1000 @released
       
  1001 */
       
  1002 void PkgParser::GetNextChar()
       
  1003 {
       
  1004 	wint_t wch = std::fgetwc(iPkgHandle);
       
  1005 	m_pkgChar = (wch == WEOF) ? 0 : wch;
       
  1006 }
       
  1007 
       
  1008 /**
       
  1009 ExpectToken: Tests the current token value
       
  1010 
       
  1011 @internalComponent
       
  1012 @released
       
  1013 
       
  1014 @param aToken - expected token value
       
  1015 */
       
  1016 void PkgParser::ExpectToken(int aToken)
       
  1017 {
       
  1018 	if (m_token!=aToken)
       
  1019 	{
       
  1020 		ParserError(const_cast<char *>("Unexpected Token"));
       
  1021 	}
       
  1022 }
       
  1023 
       
  1024 /**
       
  1025 GetNextToken: Reads the next valid token from the package file
       
  1026 
       
  1027 @internalComponent
       
  1028 @released
       
  1029 */
       
  1030 void PkgParser::GetNextToken ()
       
  1031 {
       
  1032 	// skip any white space & newLine's
       
  1033 	while (m_pkgChar == '\n' || isspace(m_pkgChar) || m_pkgChar == 0xA0)
       
  1034 	{
       
  1035 		if (m_pkgChar == '\n') ++m_nLineNo;
       
  1036 		GetNextChar();
       
  1037 	}
       
  1038 	
       
  1039 	if (m_pkgChar == '\0')
       
  1040 		m_token=EOF_TOKEN;
       
  1041 	else if (IsNumericToken())
       
  1042 	{
       
  1043 		GetNumericToken();
       
  1044 		m_token=NUMERIC_TOKEN;
       
  1045 	}
       
  1046 	else if (isalpha(m_pkgChar))
       
  1047 	{ // have some alphanumeric text
       
  1048 		GetAlphaNumericToken();
       
  1049 		m_token=ALPHA_TOKEN;
       
  1050 		// check if it is a keyword
       
  1051 		for(unsigned short wLoop = 0; wLoop < NUMPARSETOKENS; wLoop++)
       
  1052 		{
       
  1053 			if(CompareTwoString(m_tokenValue.pszString,(wchar_t*)KTokens[wLoop].pszOpt) == 0)
       
  1054 			{
       
  1055 				m_token=KTokens[wLoop].dwOpt;
       
  1056 				break;
       
  1057 			}
       
  1058 		}
       
  1059 	}
       
  1060 	else if (m_pkgChar == '\"')
       
  1061 	{ // have a quoted string
       
  1062 		GetStringToken();
       
  1063 		m_token=QUOTED_STRING_TOKEN;
       
  1064 	}
       
  1065 	else if (m_pkgChar == '>')
       
  1066 	{
       
  1067 		GetNextChar();
       
  1068 		if (m_pkgChar == '=')
       
  1069 		{
       
  1070 			m_token=GE_TOKEN;
       
  1071 			GetNextChar();
       
  1072 		}
       
  1073 		else
       
  1074 			m_token='>';
       
  1075 	}
       
  1076 	else if (m_pkgChar == '<')
       
  1077 	{
       
  1078 		// check if start of an escaped string, e.g. <123>"abc"
       
  1079 		if (GetStringToken())
       
  1080 			m_token=QUOTED_STRING_TOKEN;
       
  1081 		else
       
  1082 		{
       
  1083 			GetNextChar();
       
  1084 			if (m_pkgChar == '=')
       
  1085 			{
       
  1086 				m_token=LE_TOKEN;
       
  1087 				GetNextChar();
       
  1088 			}
       
  1089 			else if (m_pkgChar == '>')
       
  1090 			{
       
  1091 				m_token=NE_TOKEN;
       
  1092 				GetNextChar();
       
  1093 			}
       
  1094 			else
       
  1095 				m_token='<';
       
  1096 		}
       
  1097 	}
       
  1098 	else
       
  1099 	{
       
  1100 		m_token=m_pkgChar;
       
  1101 		GetNextChar();
       
  1102 	}
       
  1103 }
       
  1104 
       
  1105 /**
       
  1106 GetStringToken: Reads the string token from the package file
       
  1107 
       
  1108 @internalComponent
       
  1109 @released
       
  1110 */
       
  1111 bool PkgParser::GetStringToken()
       
  1112 {
       
  1113 	unsigned wCount = 0;
       
  1114 	bool done=false;
       
  1115 	bool finished=false;
       
  1116 	unsigned escapeChars = 0;
       
  1117 	
       
  1118 	while (!finished)
       
  1119 	{
       
  1120 		if (m_pkgChar == '\"')
       
  1121 		{
       
  1122 			GetNextChar();
       
  1123 			while(m_pkgChar && m_pkgChar != '\"')
       
  1124 			{
       
  1125 				if(wCount < (MAX_STRING - 1))
       
  1126 					m_tokenValue.pszString[wCount++] = m_pkgChar;
       
  1127 				else //We dont want the string with length greater than MAX_STRING to be cut off silently
       
  1128 					ParserError(const_cast<char *>("Bad String"));
       
  1129 				GetNextChar();
       
  1130 			}
       
  1131 			if(m_pkgChar == '\0')
       
  1132 				ParserError(const_cast<char *>("Bad String"));
       
  1133 			GetNextChar();
       
  1134 			done=true;
       
  1135 		}
       
  1136 		if (m_pkgChar == '<')
       
  1137 		{
       
  1138 			m_tokenValue.pszString[wCount] = L'\0';
       
  1139 			escapeChars=ParseEscapeChars();
       
  1140 			if (escapeChars>0)
       
  1141 			{
       
  1142 				done=true;
       
  1143 				wCount+=escapeChars;
       
  1144 				if (wCount>=MAX_STRING) wCount=MAX_STRING-1;
       
  1145 			}
       
  1146 		}
       
  1147 		if (escapeChars==0 || m_pkgChar != '\"')
       
  1148 			finished=true;
       
  1149 	}
       
  1150 	
       
  1151 	m_tokenValue.pszString[wCount] = L'\0';
       
  1152 	return done;
       
  1153 }
       
  1154 
       
  1155 /**
       
  1156 ParseEscapeChars: Parses the escape sequence characters
       
  1157 
       
  1158 @internalComponent
       
  1159 @released
       
  1160 */
       
  1161 unsigned short PkgParser::ParseEscapeChars()
       
  1162 {
       
  1163 	unsigned short found=0;
       
  1164 	wchar_t temp[MAX_STRING];
       
  1165 
       
  1166 	while (m_pkgChar == '<')
       
  1167 	{
       
  1168 		wcscpy(temp,m_tokenValue.pszString);
       
  1169 		std::fpos_t foff;
       
  1170 		std::fgetpos(iPkgHandle,&foff);
       
  1171 		try
       
  1172 		{
       
  1173 			GetNextChar();
       
  1174 			GetNumericToken();
       
  1175 			if (m_pkgChar=='>')
       
  1176 				found++;
       
  1177 			else
       
  1178 			{
       
  1179 				std::fsetpos(iPkgHandle,&foff);
       
  1180 				break;
       
  1181 			}
       
  1182 		}
       
  1183 		catch (...)
       
  1184 		{
       
  1185 			wcscpy(m_tokenValue.pszString,temp);
       
  1186 			std::fsetpos(iPkgHandle,&foff);
       
  1187 			break;
       
  1188 		}
       
  1189 		unsigned num=m_tokenValue.dwNumber;
       
  1190 		// watch for CP1252 escapes which aren't appropriate for UNICODE
       
  1191 		if (num>=0x80 && num<=0x9F) ParserError(const_cast<char *>("Invalid Escape"));
       
  1192 		unsigned len=wcslen(temp);
       
  1193 		wcscpy(m_tokenValue.pszString,temp);
       
  1194 		if (len+2<=MAX_STRING)
       
  1195 		{
       
  1196 			m_tokenValue.pszString[len]=(wchar_t)num;
       
  1197 			len++;
       
  1198 			m_tokenValue.pszString[len]='\0';
       
  1199 		}
       
  1200 		GetNextChar();
       
  1201 	}
       
  1202 	return found;
       
  1203 }
       
  1204 
       
  1205 /**
       
  1206 GetAlphaNumericToken: Parse an alphanumeric string from the input line
       
  1207 
       
  1208 @internalComponent
       
  1209 @released
       
  1210 */
       
  1211 void PkgParser::GetAlphaNumericToken()
       
  1212 {
       
  1213 	unsigned short wCount = 0;
       
  1214 	while(m_pkgChar && (isalnum(m_pkgChar) || ((m_pkgChar) == '_')))
       
  1215 	{
       
  1216 		if(wCount < (MAX_STRING - 1))
       
  1217 			m_tokenValue.pszString[wCount++] = m_pkgChar;
       
  1218 		GetNextChar();
       
  1219 	}
       
  1220 	m_tokenValue.pszString[wCount] = L'\0';
       
  1221 }
       
  1222 
       
  1223 /**
       
  1224 IsNumericToken: Determines if the next lexeme is a numeric token
       
  1225 
       
  1226 @internalComponent
       
  1227 @released
       
  1228 */
       
  1229 bool PkgParser::IsNumericToken()
       
  1230 {
       
  1231 	bool lexemeIsNumber = false;
       
  1232 	if (iswdigit(m_pkgChar))
       
  1233 		lexemeIsNumber = true;
       
  1234 	else if (m_pkgChar == '+' || m_pkgChar == '-')
       
  1235 	{
       
  1236 		// we may have a number but we must look ahead one char to be certain
       
  1237 		
       
  1238 		wchar_t oldChar = m_pkgChar;
       
  1239 		std::fpos_t foff;
       
  1240 		std::fgetpos(iPkgHandle,&foff);
       
  1241 		GetNextChar();
       
  1242 		lexemeIsNumber = iswdigit(m_pkgChar) != FALSE;
       
  1243 		m_pkgChar = oldChar;
       
  1244 		std::fsetpos(iPkgHandle,&foff);
       
  1245 	}
       
  1246 	
       
  1247 	return lexemeIsNumber;
       
  1248 }
       
  1249 
       
  1250 /**
       
  1251 GetNumericToken: Parse a number from the input line
       
  1252 
       
  1253 @internalComponent
       
  1254 @released
       
  1255 */
       
  1256 void PkgParser::GetNumericToken()
       
  1257 {
       
  1258 	wchar_t temp[MAX_STRING];
       
  1259 	wchar_t * end;
       
  1260 	bool hexString = false;
       
  1261 	std::fpos_t foff;
       
  1262 	std::fgetpos(iPkgHandle,&foff);
       
  1263 	
       
  1264 	temp[0]=m_pkgChar;
       
  1265 	unsigned wchRead = fread(&temp[1],sizeof(wchar_t),MAX_STRING - 2,iPkgHandle);
       
  1266 	if (!wchRead)
       
  1267 	{ 
       
  1268 		ParserError(const_cast<char *>("Read failed"));
       
  1269 	}
       
  1270 	temp[1+wchRead] = 0;
       
  1271 	hexString = (!CompareNString(temp, const_cast<wchar_t *>(L"0x"), 2) ||
       
  1272 		!CompareNString(&temp[1], const_cast<wchar_t *>(L"0x"), 2));
       
  1273 	
       
  1274 	m_tokenValue.dwNumber = wcstoul(temp, &end, (hexString) ? 16 : 10);
       
  1275 	
       
  1276 	if (end==temp)
       
  1277 	{
       
  1278 		ParserError(const_cast<char *>("Read failed"));
       
  1279 	}
       
  1280 	std::fsetpos(iPkgHandle,&foff);
       
  1281 	std::fseek(iPkgHandle,(end-temp-1) * sizeof(wchar_t),SEEK_CUR);		
       
  1282 	GetNextChar();
       
  1283 }
       
  1284 
       
  1285 /**
       
  1286 AddLanguage: Updates the language list structure
       
  1287 
       
  1288 @internalComponent
       
  1289 @released
       
  1290 
       
  1291 @param aLang - Name of the language
       
  1292 @param aCode - Language code
       
  1293 @param aDialect - Language dialect code
       
  1294 */
       
  1295 void PkgParser::AddLanguage(String aLang, unsigned long aCode, unsigned long aDialect)
       
  1296 {
       
  1297 	PLANG_LIST lc = new LANG_LIST;
       
  1298 	
       
  1299 	lc->langName = aLang;
       
  1300 	lc->langCode = aCode;
       
  1301 	lc->dialectCode = aDialect;
       
  1302 
       
  1303 	iLangList.push_back(lc);
       
  1304 }
       
  1305 
       
  1306 /**
       
  1307 DeleteAll: Deallocates memory for the data members
       
  1308 
       
  1309 @internalComponent
       
  1310 @released
       
  1311 */
       
  1312 void PkgParser::DeleteAll()
       
  1313 {
       
  1314 	while(iPkgBlock.size() > 0)
       
  1315 	{
       
  1316 		PCMD_BLOCK ptemp = 0;
       
  1317 
       
  1318 		ptemp = iPkgBlock.front();
       
  1319 		iPkgBlock.pop_front();
       
  1320 
       
  1321 		if(ptemp->cmdType == INSTALLFILE)
       
  1322 		{
       
  1323 			delete ptemp->iInstallFileList;
       
  1324 		}
       
  1325 		delete ptemp;
       
  1326 	}
       
  1327 
       
  1328 	{
       
  1329 		LANGUAGE_LIST::iterator begin = iLangList.begin();
       
  1330 		LANGUAGE_LIST::iterator end = iLangList.end();
       
  1331 		while(begin != end)
       
  1332 		{
       
  1333 			PLANG_LIST ptemp = 0;
       
  1334 			ptemp = (*begin);
       
  1335 
       
  1336 			if(ptemp)
       
  1337 				delete ptemp;
       
  1338 			++begin;
       
  1339 		}
       
  1340 		iLangList.clear();
       
  1341 	}
       
  1342 }
       
  1343 
       
  1344 /**
       
  1345 ParserError: Throws exception with the given error message
       
  1346 
       
  1347 @internalComponent
       
  1348 @released
       
  1349 
       
  1350 @param msg - error message to be thrown
       
  1351 */
       
  1352 void PkgParser::ParserError(char* msg)
       
  1353 {
       
  1354 	std::ostringstream str;
       
  1355 
       
  1356 	str << (char*)iPkgFile.data() << "(" << m_nLineNo << "): " << msg;
       
  1357 
       
  1358 	throw SisUtilsException(const_cast<char *>("PackageFile-Parser Error"), (char*)(str.str()).data());
       
  1359 }
       
  1360 
       
  1361 /**
       
  1362 wstring2string: Converts wide string to string
       
  1363 
       
  1364 @internalComponent
       
  1365 @released
       
  1366 
       
  1367 @param aWide - input wide string
       
  1368 */
       
  1369 String wstring2string (const std::wstring& aWide)
       
  1370 {
       
  1371 	std::vector<char> buffer((aWide.length() * sizeof(wchar_t)) + 1, '\0');
       
  1372 	size_t nchars = wcstombs(&buffer[0],aWide.c_str(),buffer.size());
       
  1373 	if (nchars == (size_t)-1)
       
  1374 	{
       
  1375 		throw SisUtilsException(const_cast<char *>("ParserError"),
       
  1376 			const_cast<char *>("wstring to string conversion failed"));
       
  1377 	}
       
  1378 	String reply(&buffer[0]);
       
  1379 	return reply;
       
  1380 }
       
  1381 
       
  1382 /**
       
  1383 string2wstring: Converts string to wide string
       
  1384 
       
  1385 @internalComponent
       
  1386 @released
       
  1387 
       
  1388 @param aNarrow - input string
       
  1389 */
       
  1390 std::wstring string2wstring (const String& aNarrow)
       
  1391 {
       
  1392 	std::vector<char> buffer(mblen(aNarrow.c_str(),aNarrow.length()) + 2, '\0');
       
  1393 	size_t nchars = mbstowcs((wchar_t *)&buffer[0],aNarrow.c_str(),buffer.size());
       
  1394 	if (nchars == (size_t)-1)
       
  1395 	{
       
  1396 		throw SisUtilsException(const_cast<char *>("ParserError"),
       
  1397 			const_cast<char *>("string to wstring conversion failed"));
       
  1398 	}
       
  1399 	std::wstring reply((wchar_t *)&buffer[0]);
       
  1400 	return reply;
       
  1401 }
       
  1402 
       
  1403 /**
       
  1404 CompareTwoString: Compares two wide string
       
  1405 
       
  1406 @internalComponent
       
  1407 @released
       
  1408 
       
  1409 @param string - first string
       
  1410 @param option - second string
       
  1411 */
       
  1412 int CompareTwoString(wchar_t const * string ,wchar_t const * option)
       
  1413 {
       
  1414 #if defined(WIN32)
       
  1415 	return wcsicmp(string,option);
       
  1416 #elif defined(__LINUX__)
       
  1417 	return wcscasecmp(string,option);
       
  1418 #endif
       
  1419 }
       
  1420 
       
  1421 /**
       
  1422 CompareNString: Compares two wide string for n characters
       
  1423 
       
  1424 @internalComponent
       
  1425 @released
       
  1426 
       
  1427 @param string - first string
       
  1428 @param option - second string
       
  1429 @param len - no of wide characters to be compared
       
  1430 */
       
  1431 int CompareNString(wchar_t const * string ,wchar_t const * option, int len)
       
  1432 {
       
  1433 	return wmemcmp(string,option,len);
       
  1434 }