imgtools/sisutils/inc/pkgfileparser.h
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 #ifndef __PKGFILEPARSER_H__
       
    20 #define __PKGFILEPARSER_H__
       
    21 
       
    22 #ifdef WIN32
       
    23 #include <windows.h>
       
    24 #endif
       
    25 
       
    26 #include <iostream>
       
    27 
       
    28 #include <sstream>
       
    29 #include <string>
       
    30 #include <list>
       
    31 #include <map>
       
    32 #undef _L
       
    33 
       
    34 #include "pkglanguage.h"
       
    35 
       
    36 typedef class PkgParser PKGPARSER, *PPKGPARSER;
       
    37 
       
    38 //Data structures for pkg file parsing
       
    39 #define EOF_TOKEN			0
       
    40 #define NUMERIC_TOKEN		1
       
    41 #define ALPHA_TOKEN			2
       
    42 #define QUOTED_STRING_TOKEN	3
       
    43 #define AND_TOKEN			4
       
    44 #define OR_TOKEN			5
       
    45 #define NOT_TOKEN			6
       
    46 #define EXISTS_TOKEN		7
       
    47 #define DEVCAP_TOKEN		8
       
    48 #define APPCAP_TOKEN		9
       
    49 #define GE_TOKEN			10
       
    50 #define LE_TOKEN			11
       
    51 #define NE_TOKEN			12
       
    52 #define IF_TOKEN			13
       
    53 #define ELSEIF_TOKEN		14
       
    54 #define ELSE_TOKEN			15
       
    55 #define ENDIF_TOKEN			16
       
    56 #define TYPE_TOKEN			17
       
    57 #define KEY_TOKEN			18
       
    58 #define LAST_TOKEN			18
       
    59 
       
    60 #define MAX_STRING 255
       
    61 
       
    62 typedef union _tag_VARIANTVAL
       
    63 {
       
    64 	long dwNumber;					// numeric value, e.g. 100
       
    65 	wchar_t pszString[MAX_STRING];	// string value, e.g. "crystal"
       
    66 }VARIANTVAL;
       
    67 
       
    68 //Data structures to store the pkg file contents
       
    69 /**
       
    70 Supported package body statements
       
    71 */
       
    72 typedef enum cmd_type {IF, ELSEIF, ELSE, ENDIF, INSTALLFILE, PACKAGE} CMD_TYPE;
       
    73 
       
    74 /**
       
    75 Structure to store the language details
       
    76 */
       
    77 typedef struct _tag_LangList
       
    78 {
       
    79 	String langName;  // Language Name
       
    80 	unsigned long langCode; // Language code
       
    81 	unsigned long dialectCode; // Dialect code
       
    82 }LANG_LIST, *PLANG_LIST;
       
    83 
       
    84 /**
       
    85 Structure to store the package file header details
       
    86 */
       
    87 typedef struct _tag_Pkgheader
       
    88 {
       
    89 	std::list<String> pkgNameList;
       
    90 	unsigned long pkgUid;
       
    91 	int vMajor;
       
    92 	int vMinor;
       
    93 	int vBuild;
       
    94 	String pkgType;
       
    95 }PKG_HEADER, *PPKG_HEADER;
       
    96 
       
    97 /**
       
    98 Structure to store the installable file list
       
    99 */
       
   100 typedef struct _tag_InstallFileList
       
   101 {
       
   102 	int langDepFlg;
       
   103 	int pkgFlg;
       
   104 	std::list<String> srcFiles;
       
   105 	String destFile;
       
   106 }INSTALLFILE_LIST, *PINSTALLFILE_LIST;
       
   107 
       
   108 /**
       
   109 Structure to store the package body details
       
   110 */
       
   111 typedef struct _tag_CmdBlock
       
   112 {
       
   113 	CMD_TYPE cmdType; // Command type
       
   114 	String cmdExpression; // Expression
       
   115 	PINSTALLFILE_LIST iInstallFileList; // Installable file details
       
   116 }CMD_BLOCK, *PCMD_BLOCK;
       
   117 
       
   118 typedef std::list<PLANG_LIST> LANGUAGE_LIST;
       
   119 typedef std::list<String> SISFILE_LIST, FILE_LIST;
       
   120 typedef std::list<PCMD_BLOCK> CMDBLOCK_LIST;
       
   121 
       
   122 /** 
       
   123 class PkgParser
       
   124 	Parses the package file generated by DUMPSIS tool
       
   125 
       
   126 @internalComponent
       
   127 @released
       
   128 */
       
   129 class PkgParser
       
   130 {
       
   131 public:
       
   132 	PkgParser(String aFile);
       
   133 	~PkgParser();
       
   134 
       
   135 	void ParsePkgFile();
       
   136 	void GetEmbeddedSisList(SISFILE_LIST& embedSisList);
       
   137 	void GetInstallOptions(FILE_LIST& aOptions);
       
   138 	void GetLanguageList(LANGUAGE_LIST& langList);
       
   139 	void GetHeader(PKG_HEADER& pkgHeader);
       
   140 	void GetCommandList(CMDBLOCK_LIST& cmdList);
       
   141 	String GetPkgFileName()
       
   142 	{
       
   143 		return iPkgFile;
       
   144 	}
       
   145 
       
   146 private:
       
   147 	int OpenFile();
       
   148 	void DeleteAll();
       
   149 
       
   150 	HANDLE iPkgHandle;
       
   151 
       
   152 	LANGUAGE_LIST iLangList;
       
   153 	PKG_HEADER iPkgHeader;
       
   154 	SISFILE_LIST iEmbedSisFiles;
       
   155 	FILE_LIST iInstallOptions;
       
   156 	CMDBLOCK_LIST iPkgBlock;
       
   157 
       
   158 	String iPkgFile;
       
   159 
       
   160 	//Parser Methods
       
   161 	void AddLanguage(String aLang, unsigned long aCode, unsigned long aDialect);
       
   162 	void GetNextChar();
       
   163 	void GetNextToken();
       
   164 	bool GetStringToken();
       
   165 	WORD ParseEscapeChars();
       
   166 	void GetAlphaNumericToken();
       
   167 	bool IsNumericToken();
       
   168 	void GetNumericToken();
       
   169 	void ParseEmbeddedBlockL ();
       
   170 	void ParseCommentL();
       
   171 	void ExpectToken(int aToken);
       
   172 	void ParseHeaderL();
       
   173 	void ParseLanguagesL();
       
   174 	void ParseFileL();
       
   175 	void ParsePackageL();
       
   176 	void ParseIfBlockL();
       
   177 	void ParseLogicalOp(String& aExpression);
       
   178 	void ParseRelation(String& aExpression);
       
   179 	void ParseUnary(String& aExpression);
       
   180 	void ParseFactor(String& aExpression);
       
   181 	void ParseOptionsBlockL();
       
   182 	void ParsePropertyL();
       
   183 	void ParseVendorNameL();
       
   184 	void ParseLogoL();
       
   185 	void ParseDependencyL();
       
   186 	void ParseVersion();
       
   187 	void ParseVendorUniqueNameL();
       
   188 	void ParseTargetDeviceL();
       
   189 
       
   190 	//Parser Attributes
       
   191 	wchar_t m_pkgChar;
       
   192 	int m_token;
       
   193 	VARIANTVAL m_tokenValue;
       
   194 	int m_nLineNo;
       
   195 
       
   196 	void ParserError(char* msg);
       
   197 
       
   198 	friend String wstring2string (const std::wstring& aWide);
       
   199 	friend std::wstring string2wstring (const String& aNarrow);
       
   200 	friend int CompareTwoString(wchar_t* string ,wchar_t* option);
       
   201 	friend int CompareNString(wchar_t* string ,wchar_t* option, int len);
       
   202 };
       
   203 
       
   204 #endif //__PKGFILEPARSER_H__