imgtools/romtools/rofsbuild/r_obey.h
changeset 606 30b30f9da0b7
parent 0 044383f39525
child 607 378360dbbdba
equal deleted inserted replaced
605:122d2b873fd1 606:30b30f9da0b7
    21 #ifndef __R_OBEY_H__
    21 #ifndef __R_OBEY_H__
    22 #define __R_OBEY_H__
    22 #define __R_OBEY_H__
    23 
    23 
    24 #define __REFERENCE_CAPABILITY_NAMES__
    24 #define __REFERENCE_CAPABILITY_NAMES__
    25 
    25 
    26 #ifdef _MSC_VER
       
    27 #pragma warning(disable:4503)
       
    28 #endif
       
    29 
       
    30 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
    31 #include <fstream>
       
    32 #else
       
    33 #include <fstream.h>
       
    34 #endif
       
    35 
       
    36 #include <stdio.h>
    26 #include <stdio.h>
    37 #include <e32capability.h>
    27 #include <e32capability.h>
    38 
    28 #include <kernel/kernboot.h>
    39 #ifdef _L
    29 #include "fatdefines.h"
    40 #undef _L
       
    41 #endif
       
    42 
    30 
    43 #include <vector>
    31 #include <vector>
    44 #include <map>
    32 #include <map>
    45 #include <kernel/kernboot.h>
    33 #include <fstream>
    46 
    34 
       
    35 using namespace std;
    47 //
    36 //
    48 const TUint32 KNumWords=16;
    37 const TUint32 KNumWords=16;
    49 //
    38 //
    50 const TInt KDefaultRomSize=0x400000;
    39 const TInt KDefaultRomSize=0x400000;
    51 const TInt KDefaultRomAlign=0x10;
    40 const TInt KDefaultRomAlign=0x10;
    52 //
    41 //
    53 
    42 typedef vector<string> StringVector ;
    54 typedef std::string String;
    43 typedef map<string, StringVector> KeywordMap;
    55 typedef std::vector<String> StringVector;
       
    56 typedef std::map<String, StringVector> KeywordMap;
       
    57 
    44 
    58 enum EKeyword
    45 enum EKeyword
    59 {
    46 {
    60 	EKeywordNone=0,	// backwards compatibility, but now ignored
    47 	EKeywordNone=0,	// backwards compatibility, but now ignored
    61 	EKeywordFile,
    48 	EKeywordFile,
    62 	EKeywordData,
    49 	EKeywordData,
       
    50 	EKeywordDir,
    63 	EKeywordRofsName,
    51 	EKeywordRofsName,
    64 	EKeywordExtensionRofs, 
    52 	EKeywordExtensionRofs, 
    65 	EKeywordCoreRofsName,
    53 	EKeywordCoreRofsName,
    66 	EKeywordRomSize,
    54 	EKeywordRomSize,
    67 	EKeywordAlias,
    55 	EKeywordAlias,
   120 
   108 
   121 #include "r_romnode.h"
   109 #include "r_romnode.h"
   122 #include "r_rofs.h"
   110 #include "r_rofs.h"
   123 
   111 
   124 class MRofsImage;
   112 class MRofsImage;
   125 
   113  
   126 struct ObeyFileKeyword
   114 struct ObeyFileKeyword
   127 	{
   115 	{
   128 	const char* iKeyword;
   116 	const char* iKeyword;
   129 	size_t iKeywordLength;
   117 	size_t iKeywordLength;
   130 	TInt iPass;
   118 	TInt iPass;
   144 	};
   132 	};
   145 
   133 
   146 class ObeyFileReader
   134 class ObeyFileReader
   147 	{
   135 	{
   148 public:
   136 public:
   149 	ObeyFileReader(TText *aFileName);
   137 	ObeyFileReader(const char *aFileName);
   150 	~ObeyFileReader();
   138 	~ObeyFileReader();
   151 
   139 
   152 	static void KeywordHelp();
   140 	static void KeywordHelp();
   153 
   141 
   154 	TBool Open();
   142 	TBool Open();
   155 	void Mark();
   143 	void Mark();
   156 	void MarkNext();
   144 	void MarkNext();
   157 	void Rewind();
   145 	void Rewind();
   158 
   146 
   159 	TInt NextLine(TInt aPass, enum EKeyword& aKeyword);
   147 	TInt NextLine(TInt aPass, enum EKeyword& aKeyword);
   160 	TInt NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, TText*& aArg);
   148 	TInt NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, char*& aArg);
   161 
   149 
   162 	void CopyWord(TInt aIndex, TText*& aString);				// allocate copy of nth word
   150 	char* DupWord(TInt aIndex) const;				// allocate copy of nth word
   163 	TInt Count() { return iNumWords;}				// number of words on current line
   151 	TInt Count() const { return iNumWords;}				// number of words on current line
   164 	char* Word(TInt aIndex) { return (char*)iWord[aIndex]; }	// return nth word as char*
   152 	const char* Word(TInt aIndex) const { return iWord[aIndex]; }	// return nth word as char* 
   165 	TText* Text(TInt aIndex) { return iWord[aIndex]; }			// return nth word as TText*
   153 	const char* Suffix() const { return iSuffix; } 			// return unmatched suffix of word[0]
   166 	char* Suffix() { return (char*)iSuffix; }			// return unmatched suffix of word[0]
   154 	TInt CurrentLine() const { return iCurrentLine;}				// number of words on current line
   167 	TInt CurrentLine() { return iCurrentLine;}				// number of words on current line
   155 	const char* GetCurrentObeyStatement() const {return iCurrentObeyStatement;}						// return current obey statement
   168 	TText* GetCurrentObeyStatement() const;						// return current obey statement
       
   169 
   156 
   170 	void ProcessTime(TInt64& aTime);
   157 	void ProcessTime(TInt64& aTime);
   171 
       
   172 	static void TimeNow(TInt64& aTime);
   158 	static void TimeNow(TInt64& aTime);
   173 private:
   159 private:
   174 	TInt ReadAndParseLine();
   160 	TInt ReadAndParseLine(); 
   175 	TInt SetLineLengthBuffer();
       
   176 	TInt Parse();
   161 	TInt Parse();
   177 	inline TBool IsGap(char ch);
   162 	inline static TBool IsGap(char ch) {
       
   163 		return (ch==' ' || ch=='=' || ch=='\t');
       
   164 	}
   178 
   165 
   179 	static const ObeyFileKeyword iKeywords[];
   166 	static const ObeyFileKeyword iKeywords[];
   180 	static const FileAttributeKeyword iAttributeKeywords[];
   167 	static const FileAttributeKeyword iAttributeKeywords[];
   181 	static TInt64 iTimeNow;
   168 	static TInt64 iTimeNow;
   182 
   169 
   183 private:
   170 private:
   184 	FILE* iObeyFile;
   171 	TInt iCurrentLine; 
   185 	long iMark;
   172 	StringVector iLines ;
   186 	TInt iMarkLine;
   173 	string iFileName;
   187 	long iCurrentMark;
   174 	TInt iNumWords;	
   188 	TInt iCurrentLine;
   175 	char* iLine;
   189 	TInt imaxLength;
   176 	TInt iMarkLine ;
   190 	TText* iFileName;
   177 	char* iCurrentObeyStatement;
   191 	TInt iNumWords;
   178 	char iSuffix[80];
   192 	TText* iWord[KNumWords];
   179 	char* iWord[KNumWords];
   193 	TText* iSuffix;
       
   194 	TText* iLine;
       
   195 	TText* iCurrentObeyStatement;
       
   196 	};
   180 	};
   197 
   181 
   198 class CPatchDataProcessor;
   182 class CPatchDataProcessor;
   199 struct ConfigurableFatAttributes;
   183 // Configurable FAT attributes
       
   184 
   200 
   185 
   201 class CObeyFile
   186 class CObeyFile
   202 	{
   187 	{
   203 public:
   188 public:
   204 	TText *iRomFileName;
   189 	char* iRomFileName;
   205 	TText *iExtensionRofsName;
   190 	char* iExtensionRofsName;
   206 	TText *iKernelRofsName;
   191 	char* iKernelRofsName;
   207 	TInt iRomSize;
   192 	TInt iRomSize;
   208 	TVersion iVersion;
   193 	TVersion iVersion;
   209 	TUint32 iCheckSum;
   194 	TUint32 iCheckSum;
   210 	TInt iNumberOfFiles;
   195 	TInt iNumberOfFiles;
   211 	TInt64 iTime;
   196 	TInt64 iTime;
   212 	TRomNode* iRootDirectory;
   197 	TRomNode* iRootDirectory;
   213 	TInt iNumberOfDataFiles;
   198 	TInt iNumberOfDataFiles;
   214 	// Added to support Data Drive Images.
   199 	// Added to support Data Drive Images.
   215 	TText* iDriveFileName;
   200 	char* iDriveFileName; 
   216 	TInt64 iDataSize;
   201 	char* iDriveFileFormat;
   217 	TText* iDriveFileFormat;
   202 	ConfigurableFatAttributes iConfigurableFatAttributes;
   218 	ConfigurableFatAttributes* iConfigurableFatAttributes;
       
   219 
   203 
   220 private:
   204 private:
   221 	ObeyFileReader& iReader;
   205 	ObeyFileReader& iReader;
   222 	TInt iMissingFiles;
   206 	TInt iMissingFiles;
   223 	TRomNode* iLastExecutable;
   207 	TRomNode* iLastExecutable;
   234 	TInt ProcessRofs();
   218 	TInt ProcessRofs();
   235 	TInt ProcessExtensionRofs(MRofsImage* info);
   219 	TInt ProcessExtensionRofs(MRofsImage* info);
   236 	TInt ProcessDataDrive();		//	Process the data drive obey file.
   220 	TInt ProcessDataDrive();		//	Process the data drive obey file.
   237 	TRomBuilderEntry *FirstFile();
   221 	TRomBuilderEntry *FirstFile();
   238 	TRomBuilderEntry *NextFile();
   222 	TRomBuilderEntry *NextFile();
   239 	TText* ProcessCoreImage();
   223 	char* ProcessCoreImage() const;
   240 	void SkipToExtension();
   224 	void SkipToExtension();
   241 	TBool AutoSize();
   225 	TBool AutoSize() const {return iAutoSize ;}
   242 	TUint32 AutoPageSize();
   226 	TUint32 AutoPageSize() const {return iAutoPageSize;} 
   243 	TBool Process();
   227 	TBool Process();
   244 	StringVector getValues(const String& aKey);
   228  
       
   229 	StringVector getValues(const string& aKey);
   245 
   230 
   246 private:
   231 private:
   247 	TBool ProcessFile(TInt aAlign, enum EKeyword aKeyword);
   232 	TBool ProcessFile(TInt aAlign, enum EKeyword aKeyword);
   248 	TBool ProcessDriveFile(enum EKeyword aKeyword);               
   233 	TBool ProcessDriveFile(enum EKeyword aKeyword);               
   249 	TBool ProcessRenaming(enum EKeyword aKeyword);
   234 	TBool ProcessRenaming(enum EKeyword aKeyword);
   254 	TInt ParseSection();
   239 	TInt ParseSection();
   255 	TBool ParsePatchDllData();
   240 	TBool ParsePatchDllData();
   256 	TBool GotKeyVariables();
   241 	TBool GotKeyVariables();
   257 	TBool GotKeyDriveVariables();			// To check the data drive mandatory variables. 
   242 	TBool GotKeyDriveVariables();			// To check the data drive mandatory variables. 
   258 	TBool GotExtensionVariables(MRofsImage* aRom);
   243 	TBool GotExtensionVariables(MRofsImage* aRom);
   259 	TBool GetNextBitOfFileName(TText **epocEndPtr);
       
   260 	TText *IsValidFilePath(TText *aPath);
       
   261 	void AddFile(TRomBuilderEntry* aFile);
   244 	void AddFile(TRomBuilderEntry* aFile);
   262 
   245 
   263 	TInt SetStackSize(TRomNode* aNode, TText *aStr);
   246 	TInt SetStackSize(TRomNode* aNode, const char *aStr);
   264 	TInt SetHeapSizeMin(TRomNode* aNode, TText *aStr);
   247 	TInt SetHeapSizeMin(TRomNode* aNode, const char *aStr);
   265 	TInt SetHeapSizeMax(TRomNode* aNode, TText *aStr);
   248 	TInt SetHeapSizeMax(TRomNode* aNode, const char *aStr);
   266 	TInt SetCapability(TRomNode* aNode, TText *aStr);
   249 	TInt SetCapability(TRomNode* aNode, const char *aStr);
   267 	TInt SetUid1(TRomNode* aNode, TText *aStr);
   250 	TInt SetUid1(TRomNode* aNode, const char *aStr);
   268 	TInt SetUid2(TRomNode* aNode, TText *aStr);
   251 	TInt SetUid2(TRomNode* aNode, const char *aStr);
   269 	TInt SetUid3(TRomNode* aNode, TText *aStr);
   252 	TInt SetUid3(TRomNode* aNode, const char *aStr);
   270 	TInt SetPriority(TRomNode* aNode, TText *aStr);
   253 	TInt SetPriority(TRomNode* aNode, const char *aStr);
       
   254 	
       
   255 	static TBool GetNextBitOfFileName(char*& epocEndPtr);
       
   256 	static const char *IsValidFilePath(const char *aPath);
       
   257 	static const char* IsValidDirPath(const char* aPath);
   271 
   258 
   272 	TBool iAutoSize;
   259 	TBool iAutoSize;
   273 	TUint32 iAutoPageSize;
   260 	TUint32 iAutoPageSize;
   274 	TBool iPagingOverrideParsed;
   261 	TBool iPagingOverrideParsed;
   275 	TBool iCodePagingOverrideParsed;
   262 	TBool iCodePagingOverrideParsed;
   276 	TBool iDataPagingOverrideParsed;
   263 	TBool iDataPagingOverrideParsed;
   277 
       
   278 public:
   264 public:
   279 	CPatchDataProcessor* iPatchData;	
   265 	CPatchDataProcessor* iPatchData;	
   280 	void SplitPatchDataStatement(StringVector& aPatchDataTokens);	
   266 	void SplitPatchDataStatement(StringVector& aPatchDataTokens);	
   281 	};
   267 	};
   282 
   268