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