imgtools/romtools/rofsbuild/r_obey.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
child 607 378360dbbdba
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    14 * Description: 
    14 * Description: 
    15 * @internalComponent * @released
    15 * @internalComponent * @released
    16 * Rofsbuild Obey file class and its reader class.
    16 * Rofsbuild Obey file class and its reader class.
    17 *
    17 *
    18 */
    18 */
    19 
    19  
    20 
    20 #include <strstream>
       
    21 #include <iomanip>
       
    22  
    21 #include <string.h>
    23 #include <string.h>
    22 
       
    23 #ifdef __VC32__
       
    24  #ifdef __MSVCDOTNET__
       
    25   #include <strstream>
       
    26   #include <iomanip>
       
    27  #else //__MSVCDOTNET__
       
    28   #include <strstrea.h>
       
    29   #include <iomanip.h>
       
    30  #endif  //__MSVCDOTNET__
       
    31 #else // !__VC32__
       
    32 #ifdef __TOOLS2__
       
    33 	#include <sstream>
       
    34 	#include <iomanip>
       
    35 	#include <sys/stat.h>
       
    36 	using namespace std;
       
    37 #else
       
    38 	#include <strstrea.h>
       
    39 	#include <iomanip.h>
       
    40 #endif
       
    41  
       
    42 #endif //__VC32__
       
    43 
       
    44 
       
    45 #include <stdlib.h>
    24 #include <stdlib.h>
    46 #include <stdio.h>
    25 #include <stdio.h>
    47 #include <time.h>
    26 #include <time.h>
    48 #include <assert.h>
    27 #include <assert.h>
    49 #include <errno.h>
    28 #include <errno.h>
    63 
    42 
    64 extern TInt gCodePagingOverride;
    43 extern TInt gCodePagingOverride;
    65 extern TInt gDataPagingOverride;
    44 extern TInt gDataPagingOverride;
    66 extern ECompression gCompress;
    45 extern ECompression gCompress;
    67 extern TBool gEnableStdPathWarning; // Default to not warn if destination path provided for a file is not in standard path.
    46 extern TBool gEnableStdPathWarning; // Default to not warn if destination path provided for a file is not in standard path.
    68 
    47 extern TBool gKeepGoing;
    69 
    48 
    70 
    49 
    71 #define _P(word)	word, sizeof(word)-1	// match prefix, optionally followed by [HWVD]
    50 #define _P(word)	word, sizeof(word)-1	// match prefix, optionally followed by [HWVD]
    72 #define _K(word)	word, 0					// match whole word
    51 #define _K(word)	word, 0					// match whole word
    73 
    52 static char* const NullString = "" ;
    74 const ObeyFileKeyword ObeyFileReader::iKeywords[] =
    53 const ObeyFileKeyword ObeyFileReader::iKeywords[] =
    75 {
    54 {
    76 	{_K("file"),		2,-2, EKeywordFile, "File to be copied into ROFS"},
    55 	{_K("file"),		2,-2, EKeywordFile, "File to be copied into ROFS"},
    77 	{_K("data"),		2,-2, EKeywordData, "same as file"},
    56 	{_K("data"),		2,-2, EKeywordData, "same as file"},
    78 
    57 
   112 	{_K("payloadflags"), 1, 1, EKeywordSmrFlags, "payload flags for the HCR SMR image"},
    91 	{_K("payloadflags"), 1, 1, EKeywordSmrFlags, "payload flags for the HCR SMR image"},
   113 	{_K("payloaduid"), 1, 1, EKeywordSmrUID, "payload UID for the HCR SMR image"},
    92 	{_K("payloaduid"), 1, 1, EKeywordSmrUID, "payload UID for the HCR SMR image"},
   114 	{0,0,0,0,EKeywordNone,""}
    93 	{0,0,0,0,EKeywordNone,""}
   115 };
    94 };
   116 
    95 
   117 extern TInt isNumber(TText *aString);
    96 void ObeyFileReader::KeywordHelp() { // static
   118 extern TInt getNumber(TText *aStr);
    97 
   119 
       
   120 void ObeyFileReader::KeywordHelp() // static
       
   121 	{
       
   122 	cout << "Obey file keywords:\n";
    98 	cout << "Obey file keywords:\n";
   123 
    99 
   124 	const ObeyFileKeyword* k=0;
   100 	const ObeyFileKeyword* k=0;
   125 	for (k=iKeywords; k->iKeyword!=0; k++)
   101 	for (k=iKeywords; k->iKeyword!=0; k++)
   126 		{
   102 	{
   127 		if (k->iHelpText==0)
   103 		if (k->iHelpText == 0)
   128 			continue;
   104 			continue;
   129 		if (k->iHelpText[0]=='(' && !H.iVerbose)
   105 		if (k->iHelpText[0]=='(' && !H.iVerbose)
   130 			continue;	// don't normally report things in (parentheses)
   106 			continue;	// don't normally report things in (parentheses)
   131 
   107 
   132 		char buf[32];
   108 		char buf[32];
   134 		if (k->iKeywordLength)
   110 		if (k->iKeywordLength)
   135 			memcpy(buf+k->iKeywordLength,"[HWVD]",6);
   111 			memcpy(buf+k->iKeywordLength,"[HWVD]",6);
   136 		if (H.iVerbose)
   112 		if (H.iVerbose)
   137 			sprintf(buf+20,"%2d",k->iNumArgs);
   113 			sprintf(buf+20,"%2d",k->iNumArgs);
   138 		cout << "    " << buf << " " << k->iHelpText << endl;
   114 		cout << "    " << buf << " " << k->iHelpText << endl;
   139 		}
   115 	}
   140 	cout << endl;
   116 	cout << endl;
   141 
   117 
   142 	cout << "File attributes:\n";
   118 	cout << "File attributes:\n";
   143 
   119 
   144 	const FileAttributeKeyword* f=0;
   120 	const FileAttributeKeyword* f=0;
   145 	for (f=iAttributeKeywords; f->iKeyword!=0; f++)
   121 	for (f=iAttributeKeywords; f->iKeyword!=0; f++)
   146 		{
   122 	{
   147 		if (f->iHelpText==0)
   123 		if (f->iHelpText == 0)
   148 			continue;
   124 			continue;
   149 		if (f->iHelpText[0]=='(' && !H.iVerbose)
   125 		if (f->iHelpText[0]=='(' && !H.iVerbose)
   150 			continue;	// don't normally report things in (parentheses)
   126 			continue;	// don't normally report things in (parentheses)
   151 
   127 
   152 		char buf[32];
   128 		char buf[32];
   153 		sprintf(buf, "%-20s", f->iKeyword);
   129 		sprintf(buf, "%-20s", f->iKeyword);
   154 		if (H.iVerbose)
   130 		if (H.iVerbose)
   155 			sprintf(buf+20,"%2d",k->iNumArgs);
   131 			sprintf(buf+20,"%2d",k->iNumArgs);
   156 		cout << "    " << buf << " " << f->iHelpText << endl;
   132 		cout << "    " << buf << " " << f->iHelpText << endl;
   157 		}
   133 	}
   158 	cout << endl;
   134 	cout << endl;
   159 	}
   135 }
   160 
   136 
   161 ObeyFileReader::ObeyFileReader(TText* aFileName):
   137 ObeyFileReader::ObeyFileReader(const char* aFileName):iCurrentLine(0),
   162 iObeyFile(0),iMark(0), iMarkLine(0), iCurrentMark(0), iCurrentLine(0), imaxLength(0)
   138 iFileName(aFileName),iNumWords(0),iLine(0),iMarkLine(0),iCurrentObeyStatement(0)	{  
   163 	{
   139 	for(TUint i = 0 ; i < KNumWords ; i++)
   164 
   140 		iWord[i] = NullString;
   165 	iFileName = new TText[strlen((const char *)aFileName)+1];
   141 	*iSuffix = 0 ; 
   166 	strcpy((char *)iFileName,(const char *)aFileName);
   142 }
   167 	iNumWords = 0 ;
   143 
   168 	for(unsigned int i = 0 ; i < KNumWords ; i++)
   144 ObeyFileReader::~ObeyFileReader() {	  
   169 		iWord[i] = 0 ;
   145 	if(iCurrentObeyStatement) {
   170 	iSuffix = new TText();
   146 		delete []iCurrentObeyStatement;
   171 	iLine = 0 ;
   147 		iCurrentObeyStatement = 0 ;
   172 	iCurrentObeyStatement = 0 ;
   148 	}
   173 	 }
   149 	if(iLine) {
   174 
   150 		delete []iLine; 
   175 
   151 		iLine = 0 ;
   176 ObeyFileReader::~ObeyFileReader()
   152 	}
   177 	{
   153 }
   178 	if (iObeyFile)
   154 
   179 		fclose(iObeyFile);
       
   180 	iObeyFile=0;
       
   181 	delete [] iFileName;
       
   182 	delete [] iLine;
       
   183 	delete [] iCurrentObeyStatement;
       
   184 	}
       
   185 
       
   186 TBool ObeyFileReader::Open()
       
   187 //
   155 //
   188 // Open the file & return a status
   156 // Open the file & return a status
   189 //
   157 //
   190 {
   158 TBool ObeyFileReader::Open() {     
   191     if (!iFileName)
   159 	ifstream ifs(iFileName.c_str(),ios_base::in + ios_base::binary);
   192     {
   160 	if (!ifs.is_open()) {
   193         return EFalse;
   161 		Print(EError,"Cannot open obey file %s\n",iFileName.c_str());
   194     }
   162 		return EFalse;
   195 
   163 	}
   196     iObeyFile = fopen((const char *)iFileName,"r");
   164 	iLines.clear();
   197     if (!iObeyFile)
   165 	if(iLine){
   198     {
   166 		delete []iLine;
   199         Print(EError,"Cannot open obey file %s\n",iFileName);
   167 		iLine = 0 ;
   200         return EFalse;
   168 	}		
   201     }
   169 	ifs.seekg(0,ios_base::end);
   202     if (SetLineLengthBuffer() != KErrNone)
   170 	size_t length = ifs.tellg();
   203     {
   171 	char* buffer = new char[length + 2];
   204         Print(EError,"Insufficent Memory to Continue.");	
   172 	if (0 == buffer) {
   205         return EFalse;
   173 		Print(EError,"Insufficent Memory to Continue.");	
   206     }
   174 		ifs.close();
   207     return ETrue;
   175 		return EFalse;
   208 }
   176 	}
   209    
   177 	ifs.seekg(0,ios_base::beg);
   210  TInt ObeyFileReader::SetLineLengthBuffer()
   178 	ifs.read(buffer,length);
   211  // Get the Max Line length for the given obey file and allocate the buffer.
   179 	size_t readcout = ifs.gcount() ;
   212  	{
   180 	if(readcout != length){ 	
   213 	char ch = '\0';
   181 		Print(EError,"Cannot Read All of File.");	
   214  	TInt length = 0;
   182 		delete []buffer ;
   215 		
   183 		ifs.close();
   216 	Rewind();
   184 		return EFalse;
   217  	while ((ch = (char)fgetc(iObeyFile)) != EOF)
   185 	}
   218  		{
   186 	buffer[length] = '\n';
   219  		length++;
   187 	buffer[length + 1] = 0 ;
   220 		if (ch == '\n')
   188 	ifs.close();
   221 			{
   189 	char* lineStart = buffer ;
   222  			if (length > imaxLength)
   190 	char* end = buffer + length ;
   223  				imaxLength = length;
   191 	string line ;
   224  			length = 0;				
   192 	size_t maxLengthOfLine = 0 ;
   225  			}
   193 	while(lineStart < end){
   226  		}
   194 		while(*lineStart == ' ' || *lineStart == '\t') //trimleft 
   227 	
   195 			lineStart ++ ;		
   228 	if (length > imaxLength)
   196 		char* lineEnd = lineStart ;	 
   229  		imaxLength = length;
   197 		while(*lineEnd != '\r' && *lineEnd != '\n')
   230 		
   198 			lineEnd ++ ;
   231 	if (0 == imaxLength)
   199 		if(strnicmp(lineStart,"REM",3) == 0){
   232 		{
   200 			line = "" ; // REMOVE "REM ... "
   233 		Print(EError,"Empty obey file passed as input.");
   201 		}
   234 		exit(-1);
   202 		else {
   235 		}			
   203 			TInt lastIndex = lineEnd - lineStart - 1;
   236 	else if (imaxLength < 2)
   204 			while(lastIndex >= 0 &&  // trimright
   237 		{
   205 				(lineStart[lastIndex] == ' ' || lineStart[lastIndex] == '\t'))
   238 		Print(EError,"Invalid obey file passed as input.");
   206 				lastIndex -- ;			
   239 		exit(-1);
   207 			if(lastIndex >= 0)
   240 		}
   208 				line.assign(lineStart,lastIndex + 1);
   241 		
   209 			else
   242 	Rewind();
   210 				line = "";
   243  	iLine = new TText[imaxLength+1];
   211 		}
   244  	
   212 		if(line.length() > maxLengthOfLine)
   245  	if(!iLine)
   213 			maxLengthOfLine = line.length();
   246  		return KErrNoMemory;
   214 		iLines.push_back(line);
   247  
   215 		if(*lineEnd == '\r') {
   248  	return KErrNone;
   216 			if(lineEnd[1] == '\n')
   249  	}
   217 				lineStart = lineEnd + 2 ;
   250 
   218 			else
   251 void ObeyFileReader::Mark()
   219 				lineStart = lineEnd + 1 ;
   252 	{
   220 		}
   253 
   221 		else // '\n'
   254 	iMark = iCurrentMark;
   222 			lineStart = lineEnd + 1 ;
   255 	iMarkLine = iCurrentLine-1;
   223 	}	
   256 	}
   224 	delete []buffer ;
   257 
   225 	iLine = new char[maxLengthOfLine + 1];
   258 void ObeyFileReader::MarkNext()
   226 	iCurrentObeyStatement = new char[maxLengthOfLine + 1];
   259 	{
   227 	*iCurrentObeyStatement = 0 ;
   260 
   228 	*iLine = 0 ;
   261 	iMark = ftell(iObeyFile);
   229 	iCurrentLine = 0 ;
       
   230 	iMarkLine = 0 ;
       
   231 	return ETrue;
       
   232 }
       
   233 
       
   234 void ObeyFileReader::Mark()	{ 
       
   235 	iMarkLine = iCurrentLine - 1;
       
   236 }
       
   237 
       
   238 void ObeyFileReader::MarkNext() { 
   262 	iMarkLine = iCurrentLine;
   239 	iMarkLine = iCurrentLine;
   263 	}
   240 }
   264 
   241 
   265 void ObeyFileReader::Rewind()
   242 void ObeyFileReader::Rewind() {
   266 	{
       
   267 	
       
   268 	fseek(iObeyFile,iMark,SEEK_SET);
       
   269 	iCurrentMark = iMark;
       
   270 	iCurrentLine = iMarkLine;
   243 	iCurrentLine = iMarkLine;
   271 	}
   244 }
   272 
   245 
   273 void ObeyFileReader::CopyWord(TInt aIndex, TText*& aString)
   246 char* ObeyFileReader::DupWord(TInt aIndex) const {
   274 	{
   247 	char* retVal = 0 ;
   275 	aString = new TText[strlen((const char *)iWord[aIndex])+1];
   248 	if(aIndex >= 0 && aIndex < (TInt)KNumWords){
   276 	strcpy((char *)aString, (const char *)iWord[aIndex]);
   249 		size_t len = strlen(iWord[aIndex]) + 1;
   277 	}
   250 		retVal = new char[len];
   278 
   251 		if(retVal)
   279 TInt ObeyFileReader::ReadAndParseLine()
   252 			memcpy(retVal,iWord[aIndex],len);
   280 	{
   253 	} 
   281 	if (feof(iObeyFile))
   254 	return retVal ;
       
   255 }
       
   256 
       
   257 TInt ObeyFileReader::ReadAndParseLine() {
       
   258 	if (iCurrentLine >= (TInt)iLines.size())
   282 		return KErrEof;
   259 		return KErrEof;
   283 	iCurrentLine++;
   260 	iCurrentLine++; 	
   284 	iCurrentMark = ftell(iObeyFile);
       
   285 	iLine[0]='\0';
       
   286 	fgets((char*)iLine,imaxLength+1,iObeyFile);
       
   287 	iCurrentObeyStatement = new TText[imaxLength+1];
       
   288 	strcpy((char*)iCurrentObeyStatement,(char*)iLine);
       
   289 	iNumWords = Parse();
   261 	iNumWords = Parse();
   290 	return KErrNone;
   262 	return KErrNone;
   291 	}
   263 }
   292 
   264 
   293 TInt ObeyFileReader::NextLine(TInt aPass, enum EKeyword& aKeyword)
   265 TInt ObeyFileReader::NextLine(TInt aPass, enum EKeyword& aKeyword) {
   294 	{
       
   295 
   266 
   296 NextLine:
   267 NextLine:
   297 	TInt err = ReadAndParseLine();
   268 	TInt err = ReadAndParseLine();
   298 	if (err == KErrEof)
   269 	if (err == KErrEof)
   299 		return KErrEof;
   270 		return KErrEof;
   300 	if (iNumWords == 0 || stricmp((const char*)iWord[0], "rem")==0)
   271 	if(iNumWords == 0)
   301 		goto NextLine;
   272 		goto NextLine;
   302 	if (stricmp((const char*)iWord[0], "stop")==0)
   273 	if (stricmp(iWord[0], "stop")==0)
   303 		return KErrEof;
   274 		return KErrEof;
   304 
   275 
   305 	const ObeyFileKeyword* k=0;
   276 	const ObeyFileKeyword* k=0;
   306 	for (k=iKeywords; k->iKeyword!=0; k++)
   277 	for (k=iKeywords; k->iKeyword!=0; k++) {
   307 		{
   278 		if (k->iKeywordLength == 0) {
   308 		if (k->iKeywordLength == 0)
       
   309 			{
       
   310 			// Exact case-insensitive match on keyword
   279 			// Exact case-insensitive match on keyword
   311 			if (stricmp((const char*)iWord[0], k->iKeyword) != 0)
   280 			if (stricmp(iWord[0], k->iKeyword) != 0)
   312 				continue;
   281 				continue;
   313 			iSuffix = 0;
   282 			*iSuffix = 0;
   314 			}
   283 		}
   315 		else
   284 		else {
   316 			{
       
   317 			// Prefix match
   285 			// Prefix match
   318 			if (strnicmp((const char*)iWord[0], k->iKeyword, k->iKeywordLength) != 0)
   286 			if (strnicmp(iWord[0], k->iKeyword, k->iKeywordLength) != 0)
   319 				continue;
   287 				continue;
   320 			// Suffix must be empty, or a variant number in []
   288 			// Suffix must be empty, or a variant number in []
   321 			iSuffix = iWord[0]+k->iKeywordLength;
   289 			strncpy(iSuffix,iWord[0] + k->iKeywordLength,80);
   322 			if (*iSuffix != '\0' && *iSuffix != '[')
   290 			if (*iSuffix != '\0' && *iSuffix != '[')
   323 				continue;
   291 				continue;
   324 			}
   292 		}
   325 		// found a match
   293 		// found a match
   326 		if ((k->iPass & aPass) == 0)
   294 		if ((k->iPass & aPass) == 0)
   327 			goto NextLine;
   295 			goto NextLine;
   328 		if (k->iNumArgs>=0 && (1+k->iNumArgs != iNumWords))
   296 		if (k->iNumArgs>=0 && (1+k->iNumArgs != iNumWords)) {
   329 			{
       
   330 			Print(EError, "Incorrect number of arguments for keyword %s on line %d.\n",
   297 			Print(EError, "Incorrect number of arguments for keyword %s on line %d.\n",
   331 				iWord[0], iCurrentLine);
   298 				iWord[0], iCurrentLine);
   332 			goto NextLine;
   299 			goto NextLine;
   333 			}
   300 		}
   334 		if (k->iNumArgs<0 && (1-k->iNumArgs > iNumWords))
   301 		if (k->iNumArgs<0 && (1-k->iNumArgs > iNumWords)) {
   335 			{
       
   336 			Print(EError, "Too few arguments for keyword %s on line %d.\n",
   302 			Print(EError, "Too few arguments for keyword %s on line %d.\n",
   337 				iWord[0], iCurrentLine);
   303 				iWord[0], iCurrentLine);
   338 			goto NextLine;
   304 			goto NextLine;
   339 			}
   305 		}
   340 		
   306 
   341 		aKeyword = k->iKeywordEnum;
   307 		aKeyword = k->iKeywordEnum;
   342 		return KErrNone;
   308 		return KErrNone;
   343 		}
   309 	}
   344 	if (aPass == 1)
   310 	if (aPass == 1)
   345 		Print(EWarning, "Unknown keyword '%s'.  Line %d ignored\n", iWord[0], iCurrentLine);
   311 		Print(EWarning, "Unknown keyword '%s'.  Line %d ignored\n", iWord[0], iCurrentLine);
   346 	goto NextLine;
   312 	goto NextLine;
   347 	}
   313 }
   348 
   314 
   349 inline TBool ObeyFileReader::IsGap(char ch)
       
   350 	{
       
   351 	return (ch==' ' || ch=='=' || ch=='\t');
       
   352 	}
       
   353 
       
   354 TInt ObeyFileReader::Parse()
       
   355 //
   315 //
   356 // splits a line into words, and returns the number of words found
   316 // splits a line into words, and returns the number of words found
   357 //
   317 // 
   358 	{
   318 TInt ObeyFileReader::Parse() {
   359 
   319 
   360 	TInt i;
   320 	for (TUint i = 0; i < KNumWords; i++)
   361 	TText *letter=iLine;
   321 		iWord[i] = NullString;
   362 	TText *end=iLine+strlen((char *)iLine);
       
   363 	for (i=0; (TUint)i<KNumWords; i++)
       
   364 		iWord[i]=end;
       
   365 
   322 
   366 	enum TState {EInWord, EInQuotedWord, EInGap};
   323 	enum TState {EInWord, EInQuotedWord, EInGap};
   367 	TState state=EInGap;
   324 	TState state = EInGap;
   368 
   325 	const string& line = iLines[iCurrentLine - 1]; 	
   369 	i=0;
   326 	size_t len = line.length();	
   370 	while ((TUint)i<KNumWords && letter<end)
   327 	memcpy(iLine,line.c_str(),len);
       
   328 	memcpy(iCurrentObeyStatement,iLine,len);
       
   329 	iLine[len] = 0 ; 
       
   330 	iCurrentObeyStatement[len] = 0 ;
       
   331 	TUint i = 0;
       
   332 	char* linestr = iLine;
       
   333 	while (i < KNumWords && *linestr != 0) {	 
       
   334 		switch (state)
   371 		{
   335 		{
   372 		char ch=*letter;
       
   373 		if (ch==0)
       
   374 			break;
       
   375 		if (ch=='\n')
       
   376 			{
       
   377 			*letter='\0';	// remove trailing newline left by fgets
       
   378 			break;
       
   379 			}
       
   380 		switch (state)
       
   381 			{
       
   382 		case EInGap:
   336 		case EInGap:
   383 			if (ch=='\"')
   337 			if (*linestr =='\"') {
   384 				{
   338 				if (linestr[1] != 0 && linestr[1]!='\"')
   385 				if (letter[1]!=0 && letter[1]!='\"')
   339 					iWord[i++] = linestr + 1;
   386 					iWord[i++]=letter+1;
   340 				state = EInQuotedWord;
       
   341 			}
       
   342 			else if (!IsGap(*linestr)) {
       
   343 				iWord[i++] = linestr;
       
   344 				state=EInWord;
       
   345 			}
       
   346 			else
       
   347 				*linestr=0;
       
   348 			break;
       
   349 		case EInWord:
       
   350 			if (*linestr == '\"') {
       
   351 				*linestr = 0;
       
   352 				if (linestr[1] != 0 && linestr[1] != '\"')
       
   353 					iWord[i++] = linestr+1;
   387 				state=EInQuotedWord;
   354 				state=EInQuotedWord;
   388 				}
   355 			}
   389 			else if (!IsGap(ch))
   356 			else if (IsGap(*linestr)) {
   390 				{
   357 				*linestr=0;
   391 				iWord[i++]=letter;
       
   392 				state=EInWord;
       
   393 				}
       
   394 			else
       
   395 				*letter=0;
       
   396 			break;
       
   397 		case EInWord:
       
   398 			if (ch=='\"')
       
   399 				{
       
   400 				*letter=0;
       
   401 				if (letter[1]!=0 && letter[1]!='\"')
       
   402 					iWord[i++]=letter+1;
       
   403 				state=EInQuotedWord;
       
   404 				}
       
   405 			else if (IsGap(ch))
       
   406 				{
       
   407 				*letter=0;
       
   408 				state=EInGap;
   358 				state=EInGap;
   409 				}
   359 			}
   410 			break;
   360 			break;
   411 		case EInQuotedWord:
   361 		case EInQuotedWord:
   412 			if (ch=='\"')
   362 			if (*linestr == '\"'){
   413 				{
   363 				*linestr = 0;
   414 				*letter=0;
   364 				state = EInGap;
   415 				state=EInGap;
   365 			}
   416 				}
   366 			break;
   417 			break;
   367 		}
   418 			}
   368 		linestr++;
   419 		letter++;
   369 	}
   420 		}
       
   421 	return i;
   370 	return i;
   422 	}
   371 }
   423 
   372 
   424 
       
   425 void ObeyFileReader::ProcessTime(TInt64& aTime)
       
   426 //
   373 //
   427 // Process the timestamp
   374 // Process the timestamp
   428 //
   375 //
   429 	{
   376 void ObeyFileReader::ProcessTime(TInt64& aTime) {
   430 	char timebuf[256];
   377 	char timebuf[256];
   431 	if (iNumWords>2)
   378 	if (iNumWords>2)
   432 		sprintf(timebuf, "%s_%s", iWord[1], iWord[2]);
   379 		sprintf(timebuf, "%s_%s", iWord[1], iWord[2]);
   433 	else
   380 	else
   434 		strcpy(timebuf, (char*)iWord[1]);
   381 		strncpy(timebuf, iWord[1],256);
   435 
   382 
   436 	TInt r=StringToTime(aTime, timebuf);
   383 	TInt r = StringToTime(aTime, timebuf);
   437 	if (r==KErrGeneral)
   384 	if (r==KErrGeneral) {
   438 		{
       
   439 		Print(EError, "incorrect format for time keyword on line %d\n", iCurrentLine);
   385 		Print(EError, "incorrect format for time keyword on line %d\n", iCurrentLine);
   440 		exit(0x670);
   386 		exit(0x670);
   441 		}
   387 	}
   442 	if (r==KErrArgument)
   388 	if (r==KErrArgument){
   443 		{
       
   444 		Print(EError, "Time out of range on line %d\n", iCurrentLine);
   389 		Print(EError, "Time out of range on line %d\n", iCurrentLine);
   445 		exit(0x670);
   390 		exit(0x670);
   446 		}
   391 	}
   447 	}
   392 }
   448 
   393 
   449 TInt64 ObeyFileReader::iTimeNow=0;
   394 TInt64 ObeyFileReader::iTimeNow = 0;
   450 void ObeyFileReader::TimeNow(TInt64& aTime)
   395 void ObeyFileReader::TimeNow(TInt64& aTime) {
   451 	{
   396 	if (iTimeNow==0) {
   452 	if (iTimeNow==0)
   397 		TInt sysTime = time(0);					// seconds since midnight Jan 1st, 1970
   453 		{
   398 		sysTime -= (30*365*24*60*60+7*24*60*60);	// seconds since midnight Jan 1st, 2000
   454 		TInt sysTime=time(0);					// seconds since midnight Jan 1st, 1970
       
   455 		sysTime-=(30*365*24*60*60+7*24*60*60);	// seconds since midnight Jan 1st, 2000
       
   456 		TInt64 daysTo2000AD=730497;
   399 		TInt64 daysTo2000AD=730497;
   457 		TInt64 t=daysTo2000AD*24*3600+sysTime;	// seconds since 0000
   400 		TInt64 t=daysTo2000AD*24*3600+sysTime;	// seconds since 0000
   458 		t=t+3600;								// BST (?)
   401 		t = t+3600;								// BST (?)
   459 		iTimeNow=t*1000000;						// milliseconds
   402 		iTimeNow=t*1000000;						// milliseconds
   460 		}
   403 	}
   461 	aTime=iTimeNow;
   404 	aTime=iTimeNow;
   462 	}
   405 }
   463 
   406 
   464 /**
   407  
   465 Funtion to get the current oby file line
       
   466 */
       
   467 TText* ObeyFileReader::GetCurrentObeyStatement() const
       
   468 { 
       
   469 	return iCurrentObeyStatement;
       
   470 }
       
   471 
   408 
   472 // File attributes.
   409 // File attributes.
   473 
   410 
   474 
   411 
   475 const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] =
   412 const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] =
   476 {
   413 {
   477 	{"attrib",3			,0,1,EAttributeAtt, "File attributes in ROM file system"},
   414 	{"attrib",3			,0,1,EAttributeAtt, "File attributes in ROM file system"},
   478 	{"exattrib",3		,0,1,EAttributeAttExtra, "File extra attributes in ROM file system"},
   415 	{"exattrib",3		,0,1,EAttributeAttExtra, "File extra attributes in ROM file system"},
   479 //	{_K("compress")		,1,1,EAttributeCompress, "Compress file"},
   416 	//	{_K("compress")		,1,1,EAttributeCompress, "Compress file"},
   480 	{"stack",3			,1,1,EAttributeStack, "?"},
   417 	{"stack",3			,1,1,EAttributeStack, "?"},
   481 	{"fixed",3			,1,0,EAttributeFixed, "Relocate to a fixed address space"},
   418 	{"fixed",3			,1,0,EAttributeFixed, "Relocate to a fixed address space"},
   482 	{"priority",3		,1,1,EAttributePriority, "Override process priority"},
   419 	{"priority",3		,1,1,EAttributePriority, "Override process priority"},
   483 	{_K("uid1")			,1,1,EAttributeUid1, "Override first UID"},
   420 	{_K("uid1")			,1,1,EAttributeUid1, "Override first UID"},
   484 	{_K("uid2")			,1,1,EAttributeUid2, "Override second UID"},
   421 	{_K("uid2")			,1,1,EAttributeUid2, "Override second UID"},
   493 	{_K("unpageddata")	,1,0,EAttributeUnpagedData, "Don't page data for this file"},
   430 	{_K("unpageddata")	,1,0,EAttributeUnpagedData, "Don't page data for this file"},
   494 	{_K("pageddata")	,1,0,EAttributePagedData, "Page data for this file"},
   431 	{_K("pageddata")	,1,0,EAttributePagedData, "Page data for this file"},
   495 	{0,0,0,0,EAttributeAtt,0}
   432 	{0,0,0,0,EAttributeAtt,0}
   496 };
   433 };
   497 
   434 
   498 TInt ObeyFileReader::NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, TText*& aArg)
   435 TInt ObeyFileReader::NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, char*& aArg)
   499 	{
   436 {
   500 NextAttribute:
   437 NextAttribute:
   501 	if (aIndex >= iNumWords)
   438 	if (aIndex >= iNumWords)
   502 		return KErrEof;
   439 		return KErrEof;
   503 	TText* word=iWord[aIndex++];
   440 	char* word=iWord[aIndex++];
   504 	const FileAttributeKeyword* k;
   441 	const FileAttributeKeyword* k;
   505 	for (k=iAttributeKeywords; k->iKeyword!=0; k++)
   442 	for (k=iAttributeKeywords; k->iKeyword!=0; k++)
       
   443 	{
       
   444 		if (k->iKeywordLength == 0)
   506 		{
   445 		{
   507 		if (k->iKeywordLength == 0)
       
   508 			{
       
   509 			// Exact match on keyword
   446 			// Exact match on keyword
   510 			if (stricmp((const char*)word, k->iKeyword) != 0)
   447 			if (stricmp(word, k->iKeyword) != 0)
   511 				continue;
   448 				continue;
   512 			}
   449 		}
   513 		else
   450 		else
   514 			{
   451 		{
   515 			// Prefix match
   452 			// Prefix match
   516 			if (strnicmp((const char*)word, k->iKeyword, k->iKeywordLength) != 0)
   453 			if (strnicmp(word, k->iKeyword, k->iKeywordLength) != 0)
   517 				continue;
   454 				continue;
   518 			}
   455 		}
   519 		// found a match
   456 		// found a match
   520 		if (k->iNumArgs>0)
   457 		if (k->iNumArgs>0)
   521 			{
   458 		{
   522 			TInt argIndex = aIndex;
   459 			TInt argIndex = aIndex;
   523 			aIndex += k->iNumArgs;		// interface only really supports 1 argument
   460 			aIndex += k->iNumArgs;		// interface only really supports 1 argument
   524 			if (aIndex>iNumWords)
   461 			if (aIndex>iNumWords)
   525 				{
   462 			{
   526 				Print(EError, "Missing argument for attribute %s on line %d\n", word, iCurrentLine);
   463 				Print(EError, "Missing argument for attribute %s on line %d\n", word, iCurrentLine);
   527 				return KErrArgument;
   464 				return KErrArgument;
   528 				}
   465 			}
   529 			aArg=iWord[argIndex];
   466 			aArg=iWord[argIndex];
   530 			}
   467 		}
   531 		if (k->iIsFileAttribute && !aHasFile)
   468 		if (k->iIsFileAttribute && !aHasFile)
   532 			{
   469 		{
   533 			Print(EError, "File attribute %s applied to non-file on line %d\n", word, iCurrentLine);
   470 			Print(EError, "File attribute %s applied to non-file on line %d\n", word, iCurrentLine);
   534 			return KErrNotSupported;
   471 			return KErrNotSupported;
   535 			}
   472 		}
   536 		aKeyword=k->iAttributeEnum;
   473 		aKeyword=k->iAttributeEnum;
   537 		return KErrNone;
   474 		return KErrNone;
   538 		}
   475 	}
   539 	Print(EWarning, "Unknown attribute '%s' skipped on line %d\n", word, iCurrentLine);
   476 	Print(EWarning, "Unknown attribute '%s' skipped on line %d\n", word, iCurrentLine);
   540 	goto NextAttribute;
   477 	goto NextAttribute;
   541 	}
   478 }
   542 
   479 
   543 
   480 
   544 
   481 
   545 /**
   482 /**
   546 Constructor:
   483 Constructor:
   548 2.used by both rofs and datadrive image.
   485 2.used by both rofs and datadrive image.
   549 
   486 
   550 @param aReader - obey file reader object.
   487 @param aReader - obey file reader object.
   551 */
   488 */
   552 CObeyFile::CObeyFile(ObeyFileReader& aReader):
   489 CObeyFile::CObeyFile(ObeyFileReader& aReader):
   553 	iRomFileName(NULL),
   490 iRomFileName(NULL),
   554 	iExtensionRofsName(0),
   491 iExtensionRofsName(0),
   555 	iKernelRofsName(0),
   492 iKernelRofsName(0),
   556 	iRomSize(0),
   493 iRomSize(0),
   557 	iVersion(0,0,0),
   494 iVersion(0,0,0),
   558 	iCheckSum(0),
   495 iCheckSum(0),
   559 	iNumberOfFiles(0),
   496 iNumberOfFiles(0),
   560 	iTime(0),
   497 iTime(0),
   561 	iRootDirectory(0),
   498 iRootDirectory(0),
   562 	iNumberOfDataFiles(0),
   499 iNumberOfDataFiles(0),
   563 	iDriveFileName(0),
   500 iDriveFileName(0),
   564 	iDataSize(0),
   501 iDataSize(0),
   565 	iDriveFileFormat(0),
   502 iDriveFileFormat(0),
   566 	iConfigurableFatAttributes(new ConfigurableFatAttributes),
   503 iConfigurableFatAttributes(new ConfigurableFatAttributes),
   567 	iReader(aReader), 
   504 iReader(aReader), 
   568 	iMissingFiles(0), 
   505 iMissingFiles(0), 
   569 	iLastExecutable(0),
   506 iLastExecutable(0),
   570 	iFirstFile(0), 	
   507 iFirstFile(0), 	
   571 	iCurrentFile(0),
   508 iCurrentFile(0),
   572 	iAutoSize(EFalse),
   509 iAutoSize(EFalse),
   573 	iAutoPageSize(4096),
   510 iAutoPageSize(4096),
   574 	iPagingOverrideParsed(0),
   511 iPagingOverrideParsed(0),
   575 	iCodePagingOverrideParsed(0),
   512 iCodePagingOverrideParsed(0),
   576 	iDataPagingOverrideParsed(0),
   513 iDataPagingOverrideParsed(0),
   577 	iPatchData(new CPatchDataProcessor)
   514 iPatchData(new CPatchDataProcessor)
   578 	{
   515 {
   579 		iNextFilePtrPtr = &iFirstFile ;
   516 	iNextFilePtrPtr = &iFirstFile ;
   580 	}
   517 }
   581 
   518 
   582 /**
   519 /**
   583 Obey file Destructor.
   520 Obey file Destructor.
   584 1.Release the tree memory.
   521 1.Release the tree memory.
   585 2.Release all allocated memory if any.
   522 2.Release all allocated memory if any.
   586 */
   523 */
   587 CObeyFile::~CObeyFile()
   524 CObeyFile::~CObeyFile() {
   588 //
   525 	if(iDriveFileName){
   589 // Destructor
       
   590 //
       
   591 	{
       
   592 	if(iDriveFileName)
       
   593 		delete[] iDriveFileName;					
   526 		delete[] iDriveFileName;					
   594 	if(iDriveFileFormat)
   527 		iDriveFileName = 0 ;
       
   528 	}
       
   529 	if(iDriveFileFormat) {
   595 		delete[] iDriveFileFormat;
   530 		delete[] iDriveFileFormat;
       
   531 		iDriveFileFormat = 0 ;
       
   532 	}
   596 	iRootDirectory->deleteTheFirstNode();                
   533 	iRootDirectory->deleteTheFirstNode();                
   597 	iRootDirectory->InitializeCount();
   534 	iRootDirectory->InitializeCount();
   598 
   535 
   599 	Release();
   536 	Release();
   600 	delete [] iRomFileName;
   537 	if(iRomFileName){ 
       
   538 		delete [] iRomFileName;
       
   539 		iRomFileName = 0 ;
       
   540 	}
   601 	if (iRootDirectory)
   541 	if (iRootDirectory)
   602 		iRootDirectory->Destroy();
   542 		iRootDirectory->Destroy();
   603 
   543 	if(iConfigurableFatAttributes)
   604 	delete iConfigurableFatAttributes;
   544 		delete iConfigurableFatAttributes;
   605 	delete iPatchData;
   545 	if(iPatchData)
   606 	}
   546 		delete iPatchData;
   607 
   547 }
   608 TBool CObeyFile::AutoSize()
   548 
   609 {
       
   610 	return iAutoSize;
       
   611 }
       
   612 
       
   613 TUint32 CObeyFile::AutoPageSize()
       
   614 {
       
   615 	return iAutoPageSize;
       
   616 }
       
   617 
       
   618 void CObeyFile::Release()
       
   619 //
   549 //
   620 // Free resources not needed after building a ROM
   550 // Free resources not needed after building a ROM
   621 //
   551 //
   622 	{
   552 void CObeyFile::Release() {
   623 	iFirstFile = 0;
   553 	iFirstFile = 0;
   624 	iNextFilePtrPtr = &iFirstFile;
   554 	iNextFilePtrPtr = &iFirstFile;
   625 	}
   555 }
   626 
   556 
   627 TRomBuilderEntry *CObeyFile::FirstFile()
   557 TRomBuilderEntry *CObeyFile::FirstFile() {
   628 	{
       
   629 	iCurrentFile = iFirstFile;
   558 	iCurrentFile = iFirstFile;
   630 	return iCurrentFile;
   559 	return iCurrentFile;
   631 	}
   560 }
   632 
   561 
   633 TRomBuilderEntry *CObeyFile::NextFile()
   562 TRomBuilderEntry *CObeyFile::NextFile() {
   634 	{
       
   635 	iCurrentFile = iCurrentFile ? iCurrentFile->iNext : 0;
   563 	iCurrentFile = iCurrentFile ? iCurrentFile->iNext : 0;
   636 	return iCurrentFile;
   564 	return iCurrentFile;
   637 	}
   565 }
   638 
   566 
   639 TText* CObeyFile::ProcessCoreImage()
   567 char* CObeyFile::ProcessCoreImage() const {
   640 	{
   568 	// check for coreimage keyword and return filename	 
   641 	// check for coreimage keyword and return filename
   569 	enum EKeyword keyword;
       
   570 	char* coreImageFileName = 0;
       
   571 	iReader.Rewind();
       
   572 	while (iReader.NextLine(1,keyword) != KErrEof) {
       
   573 		if (keyword == EKeywordCoreImage) {  			  
       
   574 			coreImageFileName = iReader.DupWord(1);	
       
   575 			iReader.MarkNext();
       
   576 			break;
       
   577 		}
       
   578 	}
       
   579 	return coreImageFileName;
       
   580 }
       
   581 
       
   582 void CObeyFile::SkipToExtension() {
   642 	iReader.Rewind();
   583 	iReader.Rewind();
   643 	enum EKeyword keyword;
   584 	enum EKeyword keyword;
   644 	TText* coreImageFileName = 0;
   585 	while (iReader.NextLine(1,keyword) != KErrEof) {
   645 	while (iReader.NextLine(1,keyword) != KErrEof)
   586 		if (keyword == EKeywordExtensionRofs) {
   646 		{
   587 			iReader.Mark(); // ready for processing extension
   647 		  if (keyword == EKeywordCoreImage)
   588 			break;
   648 			  {
   589 		}
   649   			  #if defined(__TOOLS2__) && defined (_STLP_THREADS)
   590 	}
   650   			  istringstream val(iReader.Word(1),(ios_base::in+ios_base::out));	  
   591 }
   651   			  #elif __TOOLS2__
   592 
   652   			  istringstream val(iReader.Word(1),(std::_Ios_Openmode)(ios_base::in+ios_base::out));
   593 TInt CObeyFile::ProcessRofs() {
   653 			  #else
   594 	
   654 			  istrstream val(iReader.Word(1),strlen(iReader.Word(1)));
       
   655 			  #endif
       
   656 			  iReader.CopyWord(1, coreImageFileName);
       
   657 			  iReader.MarkNext(); // ready for processing extension
       
   658 			  break;
       
   659 			  }
       
   660 		}
       
   661 	return coreImageFileName;
       
   662 	}
       
   663 
       
   664 void CObeyFile::SkipToExtension()
       
   665 	{
       
   666 	iReader.Rewind();
       
   667 	enum EKeyword keyword;
       
   668 	while (iReader.NextLine(1,keyword) != KErrEof)
       
   669 		{
       
   670 		  if (keyword == EKeywordExtensionRofs)
       
   671 			  {
       
   672 			  iReader.Mark(); // ready for processing extension
       
   673 			  break;
       
   674 			  }
       
   675 		}
       
   676 	}
       
   677 TInt CObeyFile::ProcessRofs()
       
   678 	{
       
   679 	//
   595 	//
   680 	// First pass through the obey file to set up key variables
   596 	// First pass through the obey file to set up key variables
   681 	//
   597 	//
   682 
   598 
   683 	iReader.Rewind();
   599 	iReader.Rewind();
   684 
   600 
   685 	TInt count=0;
   601 	TInt count=0;
   686 	enum EKeyword keyword;
   602 	enum EKeyword keyword;
   687 	while (iReader.NextLine(1,keyword) != KErrEof)
   603 	while (iReader.NextLine(1,keyword) != KErrEof) {
   688 		{
   604 		if (keyword == EKeywordExtensionRofs){
   689 		  if (keyword == EKeywordExtensionRofs)
   605 			if (count==0)
   690 		    {
   606 				return KErrNotFound;		// no core ROFS, just extension ROFSs.
   691 		      if (count==0)
   607 			break;
   692 			return KErrNotFound;		// no core ROFS, just extension ROFSs.
   608 		}
   693 		      break;
       
   694 		    }
       
   695 
   609 
   696 		count++;
   610 		count++;
   697 		if (! ProcessKeyword(keyword))
   611 		if (! ProcessKeyword(keyword))
   698 			return KErrGeneral;
   612 			return KErrGeneral;
   699 		}
   613 	}
   700 
   614 
   701 	if (!GotKeyVariables())
   615 	if (!GotKeyVariables())
   702 		return KErrGeneral;
   616 		return KErrGeneral;
   703 
   617 
   704 	//
   618 	//
   705 	// second pass to process the file specifications in the obey file building
   619 	// second pass to process the file specifications in the obey file building
   706 	// up the TRomNode directory structure and the TRomBuilderEntry list
   620 	// up the TRomNode directory structure and the TRomBuilderEntry list
   707 	//
   621 	//
   708 	iReader.Rewind();
   622 	iReader.Rewind();
   709 
   623 
   710 	iRootDirectory = new TRomNode((TText*)"");
   624 	iRootDirectory = new TRomNode("");
   711 	iLastExecutable = iRootDirectory;
   625 	iLastExecutable = iRootDirectory;
   712 
   626 
   713 	TInt align=0;
   627 	TInt align=0;
   714 	while (iReader.NextLine(2,keyword)!=KErrEof)
   628 	while (iReader.NextLine(2,keyword)!=KErrEof) {
   715 		{
       
   716 		if (keyword == EKeywordExtensionRofs)
   629 		if (keyword == EKeywordExtensionRofs)
   717 			break;
   630 			break;
   718 
   631 
   719 		if (keyword == EKeywordHide)
   632 		if (keyword == EKeywordHide)
   720 			keyword = EKeywordHideV2;
   633 			keyword = EKeywordHideV2;
   721 
   634 
   722 		switch (keyword)
   635 		switch (keyword) 
   723 			{
   636 		{
   724 			  
       
   725 		case EKeywordHide:
   637 		case EKeywordHide:
   726 		case EKeywordAlias:
   638 		case EKeywordAlias:
   727 		case EKeywordRename:
   639 		case EKeywordRename:
   728 			if (!ProcessRenaming(keyword))
   640 			if (!ProcessRenaming(keyword))
   729 				return KErrGeneral;
   641 				return KErrGeneral;
   730 			break;
   642 			break;
   731 		case EKeywordPatchDllData:
   643 		case EKeywordPatchDllData:
   732 		{
   644 			{
   733 			// Collect patchdata statements to process at the end
   645 				// Collect patchdata statements to process at the end
   734 			StringVector patchDataTokens;
   646 				StringVector patchDataTokens;
   735 			SplitPatchDataStatement(patchDataTokens); 
   647 				SplitPatchDataStatement(patchDataTokens); 
   736 			iPatchData->AddPatchDataStatement(patchDataTokens);									
   648 				iPatchData->AddPatchDataStatement(patchDataTokens);									
   737 			break;
   649 				break;
   738 		}
   650 			}
   739 		default:
   651 		default:
   740 		        if (!ProcessFile(align, keyword))
   652 			if (!ProcessFile(align, keyword))
   741 		        return KErrGeneral;
   653 				return KErrGeneral;
   742 		        align=0;
   654 			align=0;
   743 		        break;
   655 			break;
   744 			}
   656 		}
   745 		}
   657 	}
   746 
   658 
   747 	if(!ParsePatchDllData())
   659 	if(!ParsePatchDllData())
   748 		return KErrGeneral;
   660 		return KErrGeneral;
   749 	iReader.Mark();			// ready for processing the extension rom(s)
   661 	iReader.Mark();			// ready for processing the extension rom(s)
   750 
   662 
   751 	if (iMissingFiles!=0)
   663 	if (iMissingFiles!=0) {
   752 		{
       
   753 		return KErrGeneral;
   664 		return KErrGeneral;
   754 		}
   665 	}
   755 	if ( 0 == iNumberOfFiles )
   666 	if ( 0 == iNumberOfFiles ){
   756 		{
       
   757 		Print(EError, "No files specified.\n");
   667 		Print(EError, "No files specified.\n");
   758 		return KErrGeneral;
   668 		return KErrGeneral;
   759 		}
   669 	}
   760 
   670 
   761 	return KErrNone;
   671 	return KErrNone;
   762 	}
   672 }
   763 
   673 
   764 TBool CObeyFile::Process()
   674 TBool CObeyFile::Process() {
   765 {
       
   766 	TBool result = ETrue;
   675 	TBool result = ETrue;
   767 	iReader.Rewind();
   676 	iReader.Rewind();
   768 	enum EKeyword keyword;
   677 	enum EKeyword keyword;
   769 	while(iReader.NextLine(1, keyword) != KErrEof)
   678 	while(iReader.NextLine(1, keyword) != KErrEof){
   770 	{
   679 		string key = iReader.Word(0);
   771 		String key = iReader.Word(0);
   680 		string value = iReader.Word(1);
   772 		String value = iReader.Word(1);
   681 		if(iKeyValues.find(key) != iKeyValues.end()){
   773 		if(iKeyValues.find(key) != iKeyValues.end())
       
   774 		{
       
   775 			iKeyValues[key].push_back(value);
   682 			iKeyValues[key].push_back(value);
   776 		}
   683 		}
   777 		else
   684 		else {
   778 		{
       
   779 			StringVector values;
   685 			StringVector values;
   780 			values.push_back(value);
   686 			values.push_back(value);
   781 			iKeyValues[key]=values;
   687 			iKeyValues[key]=values;
   782 		}
   688 		}
   783 
   689 
   784 
   690 
   785 	}
   691 	}
   786 	return result;
   692 	return result;
   787 }
   693 }
   788 StringVector CObeyFile::getValues(const String& aKey)
   694 StringVector CObeyFile::getValues(const string& aKey) {
   789 {
       
   790 	StringVector values;
   695 	StringVector values;
   791 	if(iKeyValues.find(aKey) != iKeyValues.end())
   696 	if(iKeyValues.find(aKey) != iKeyValues.end()){
   792 	{
       
   793 		values = iKeyValues[aKey];
   697 		values = iKeyValues[aKey];
   794 	}
   698 	}
   795 	return values;
   699 	return values;
   796 }
   700 }
   797 
   701 
   798 /**
   702 /**
   799 Process drive obey file and construct the tree.
   703 Process drive obey file and construct the tree.
   800 
   704 
   801 @return - Return the status,
   705 @return - Return the status,
   802           'KErrnone' for Success,
   706 'KErrnone' for Success,
   803           'KErrGeneral' for failure (required keywords not there in obey file or failed
   707 'KErrGeneral' for failure (required keywords not there in obey file or failed
   804 									 to construct the tree).
   708 to construct the tree).
   805 */
   709 */
   806 TInt CObeyFile::ProcessDataDrive()
   710 TInt CObeyFile::ProcessDataDrive() {
   807 	{
       
   808 
       
   809 	iReader.Rewind();
   711 	iReader.Rewind();
   810 	enum EKeyword keyword;
   712 	enum EKeyword keyword;
   811 
   713 
   812 	// First pass through the obey file to set up key variables
   714 	// First pass through the obey file to set up key variables
   813 	while (iReader.NextLine(1,keyword) != KErrEof)	
   715 	while (iReader.NextLine(1,keyword) != KErrEof) {
   814 		{
       
   815 		if (!ProcessDriveKeyword(keyword))			
   716 		if (!ProcessDriveKeyword(keyword))			
   816 			return KErrGeneral;
   717 			return KErrGeneral;
   817 		}
   718 	}
   818 
   719 
   819 	if (!GotKeyDriveVariables())
   720 	if (!GotKeyDriveVariables())
   820 		return KErrGeneral;
   721 		return KErrGeneral;
   821 
   722 
   822 	// Second pass to process the file specifications in the obey file.
   723 	// Second pass to process the file specifications in the obey file.
   823 	// Build the TRomNode directory structure and the TRomBuilderEntry list
   724 	// Build the TRomNode directory structure and the TRomBuilderEntry list
   824 	iReader.Rewind();
   725 	iReader.Rewind();
   825 	iRootDirectory = new TRomNode((TText*)"//");					
   726 	iRootDirectory = new TRomNode("//");					
   826 	iLastExecutable = iRootDirectory;
   727 	iLastExecutable = iRootDirectory;
   827 
   728 
   828 	while(iReader.NextLine(2,keyword)!=KErrEof)
   729 	while(iReader.NextLine(2,keyword)!=KErrEof) {
       
   730 		switch (keyword) 
   829 		{
   731 		{
   830 		switch (keyword)
   732 		case EKeywordPatchDllData:
   831 			{
       
   832 			case EKeywordPatchDllData:
       
   833 			{	// Collect patchdata statements to process at the end
   733 			{	// Collect patchdata statements to process at the end
   834 				StringVector patchDataTokens;
   734 				StringVector patchDataTokens;
   835 				SplitPatchDataStatement(patchDataTokens); 				
   735 				SplitPatchDataStatement(patchDataTokens); 				
   836 				iPatchData->AddPatchDataStatement(patchDataTokens);									
   736 				iPatchData->AddPatchDataStatement(patchDataTokens);									
   837 				break;
   737 				break;
   838 			}
   738 			}
   839 	
   739 
   840 			case EKeywordHide:						
   740 		case EKeywordHide:						
   841 			case EKeywordFile:
   741 		case EKeywordFile:
   842 			case EKeywordData:
   742 		case EKeywordData:
   843 			case EKeywordFileCompress:
   743 		case EKeywordFileCompress:
   844 			case EKeywordFileUncompress:
   744 		case EKeywordFileUncompress:
   845 		        if (!ProcessDriveFile(keyword))
   745 			if (!ProcessDriveFile(keyword))
   846 				  return KErrGeneral;
   746 				return KErrGeneral;
   847 		        break;
   747 			break;
   848 	
   748 
   849 			default:							
   749 		default:							
   850 		        break;
   750 			break;
   851 			}
   751 		}
   852 		}
   752 	}
   853 
   753 
   854 	if(!ParsePatchDllData())
   754 	if(!ParsePatchDllData())
   855 		return KErrGeneral;
   755 		return KErrGeneral;
   856     if (iMissingFiles)   
   756 	if (iMissingFiles) {
   857 		{
       
   858 		Print(EError, "Source Files Missing.\n");
   757 		Print(EError, "Source Files Missing.\n");
   859 		return KErrGeneral;
   758 		return KErrGeneral;
   860 		}
   759 	}
   861 	if (!iNumberOfFiles)
   760 	if (!iNumberOfFiles)
   862 		Print(EWarning,"No files specified.\n");
   761 		Print(EWarning,"No files specified.\n");
   863 	
   762 
   864 	return KErrNone;
   763 	return KErrNone;
   865 	}
   764 }
   866 
   765 
   867 
   766 
   868 /**
   767 /**
   869 Process and stores the keyword information.
   768 Process and stores the keyword information.
   870 
   769 
   871 @param aKeyword - keyword to update its value to variables.
   770 @param aKeyword - keyword to update its value to variables.
   872 @return - Return the status i.e Success,
   771 @return - Return the status i.e Success,
   873 */
   772 */
   874 TBool CObeyFile::ProcessDriveKeyword(enum EKeyword aKeyword)
   773 TBool CObeyFile::ProcessDriveKeyword(enum EKeyword aKeyword) {
   875 	{
       
   876 
   774 
   877 	TBool success = ETrue;
   775 	TBool success = ETrue;
   878 	switch (aKeyword)
   776 	switch (aKeyword)
       
   777 	{
       
   778 	case EKeywordDataImageName:
       
   779 		iDriveFileName = iReader.DupWord(1);
       
   780 		break;
       
   781 	case EKeywordDataImageFileSystem:
       
   782 		iDriveFileFormat = iReader.DupWord(1);
       
   783 		break;
       
   784 	case EKeywordDataImageSize:
   879 		{
   785 		{
   880 		case EKeywordDataImageName:
   786 			const char* bigString = iReader.Word(1);
   881 			iReader.CopyWord(1, iDriveFileName);
   787 			if(*bigString == '\0')
   882 			break;
       
   883 		case EKeywordDataImageFileSystem:
       
   884 			iReader.CopyWord(1, iDriveFileFormat);
       
   885 			break;
       
   886 		case EKeywordDataImageSize:
       
   887 			{
   788 			{
   888 			char* bigString = iReader.Word(1);
       
   889 			if(*bigString == '\0')
       
   890 				{
       
   891 				Print(EWarning,"Not a valid Image Size. Default size is considered\n");		
   789 				Print(EWarning,"Not a valid Image Size. Default size is considered\n");		
   892 				break;
   790 				break;
   893 				}
   791 			}
   894 #ifdef __LINUX__
   792 #ifdef __LINUX__
   895 			errno = 0;
   793 			errno = 0;
   896 			iDataSize = strtoll(bigString,NULL,10);
   794 			iDataSize = strtoll(bigString,NULL,10);
   897 			if((iDataSize == LONG_MAX) || (iDataSize == LONG_MIN) ||(errno == ERANGE))
   795 			if((iDataSize == LONG_MAX) || (iDataSize == LONG_MIN) ||(errno == ERANGE))
   898 				{
   796 			{
   899 				Print(EWarning,"Invalid Range. Default size is considered\n");		
   797 				Print(EWarning,"Invalid Range. Default size is considered\n");		
   900 				}
   798 			}
   901 #else
   799 #else
   902 			iDataSize = _atoi64(bigString);
   800 			iDataSize = _atoi64(bigString);
   903 #endif
   801 #endif
   904 			}
   802 		}
   905 			break;
   803 		break;
   906 		case EKeywordDataImageVolume:
   804 	case EKeywordDataImageVolume:
   907 			{				
   805 		{				
   908 				// Get the volume label provided by using "volume" keyword.
   806 			// Get the volume label provided by using "volume" keyword.
   909 				// e.g. vlolume = NO NAME
   807 			// e.g. vlolume = NO NAME
   910 				String volumeLabel = (char*)iReader.GetCurrentObeyStatement();
   808 			string volumeLabel = iReader.GetCurrentObeyStatement();
   911 				String volumeLabelKeyword = "volume";
   809 			string volumeLabelKeyword = "volume";
   912 
   810 
   913 				TUint position = volumeLabel.find(volumeLabelKeyword.c_str(),0,volumeLabelKeyword.size());
   811 			TUint position = volumeLabel.find(volumeLabelKeyword.c_str(),0,volumeLabelKeyword.size());
   914 				position += volumeLabelKeyword.size();
   812 			position += volumeLabelKeyword.size();
   915 				if (volumeLabel.find('=',position) != std::string::npos)
   813 			if (volumeLabel.find('=',position) != string::npos) {
   916 				{
   814 				position=volumeLabel.find('=',position);
   917 					position=volumeLabel.find('=',position);
   815 				++position;
   918 					++position;
   816 			}								
   919 				}								
   817 
   920 
   818 			position = volumeLabel.find_first_not_of(' ',position);
   921 				position = volumeLabel.find_first_not_of(' ',position);
   819 			if (position != string::npos) {
   922 				if (position != std::string::npos)
   820 				volumeLabel = volumeLabel.substr(position);
   923 				{
   821 
   924 					volumeLabel = volumeLabel.substr(position);
   822 				// Remove the new line character from the end
   925 
   823 				position = volumeLabel.find_first_of("\r\n");
   926 					// Remove the new line character from the end
   824 				if (position != string::npos)
   927 					position = volumeLabel.find_first_of("\r\n");
   825 					volumeLabel = volumeLabel.substr(0,position);
   928 					if (position != std::string::npos)
   826 
   929 						volumeLabel = volumeLabel.substr(0,position);
   827 				iConfigurableFatAttributes->iDriveVolumeLabel = volumeLabel.data() ;
   930 
   828 			}
   931 					iConfigurableFatAttributes->iDriveVolumeLabel = volumeLabel.data(); 								
   829 			else {
   932 				}
   830 				Print(EWarning,"Value for Volume Label is not provided. Default value is considered.\n");
   933 				else
   831 			}
   934 				{
   832 			break;
   935 					Print(EWarning,"Value for Volume Label is not provided. Default value is considered.\n");
   833 		}
   936 				}
   834 	case EKeywordDataImageSectorSize:
   937 				break;
   835 		{
   938 			}
   836 			const char* bigString = iReader.Word(1);
   939 		case EKeywordDataImageSectorSize:
   837 			TInt sectorSize = atoi(bigString);
   940 			{
   838 			if(sectorSize <= 0)	{
   941 				char* bigString = iReader.Word(1);
   839 				Print(EWarning,"Invalid Sector Size value. Default value is considered.\n");
   942 				TInt sectorSize = atoi(bigString);
   840 			}
   943 				if(sectorSize <= 0)
   841 			else {
   944 				{
   842 				iConfigurableFatAttributes->iDriveSectorSize = atoi(bigString);
   945 					Print(EWarning,"Invalid Sector Size value. Default value is considered.\n");
   843 			}
   946 				}
   844 		}			
   947 				else
   845 		break;
   948 				{
   846 	case EKeywordDataImageNoOfFats:
   949 					iConfigurableFatAttributes->iDriveSectorSize = atoi(bigString);
   847 		{
   950 				}
   848 			const char* bigString = iReader.Word(1);
   951 			}			
   849 			TInt noOfFats = atoi(bigString);
   952 			break;
   850 			if (noOfFats <=0)
   953 		case EKeywordDataImageNoOfFats:
   851 				Print(EWarning,"Invalid No of FATs specified. Default value is considered.\n");
   954 			{
   852 			else
   955 				char* bigString = iReader.Word(1);
   853 				iConfigurableFatAttributes->iDriveNoOfFATs = atoi(bigString);			
   956 				TInt noOfFats = atoi(bigString);
   854 		}			
   957 				if (noOfFats <=0)
   855 		break;			
   958 				{
   856 	default:
   959 					Print(EWarning,"Invalid No of FATs specified. Default value is considered.\n");
   857 		// unexpected keyword iReader.Word(0), keep going.
   960 				}
   858 		break;
   961 				else
   859 	}
   962 				{
       
   963 					iConfigurableFatAttributes->iDriveNoOfFATs = atoi(bigString);			
       
   964 				}
       
   965 			}			
       
   966 			break;			
       
   967 		default:
       
   968 			// unexpected keyword iReader.Word(0), keep going.
       
   969 			break;
       
   970 		}
       
   971 	return success;
   860 	return success;
   972 	}
   861 }
   973 
   862 
   974 
   863 
   975 /**
   864 /**
   976 Checks whether obeyfile has supplied enough variables to continue.
   865 Checks whether obeyfile has supplied enough variables to continue.
   977 
   866 
   978 @return - Return the status 
   867 @return - Return the status 
   979 		  ETrue - Supplied valid values,
   868 ETrue - Supplied valid values,
   980 		  EFalse- Not valied values.
   869 EFalse- Not valied values.
   981 */
   870 */
   982 TBool CObeyFile::GotKeyDriveVariables()
   871 TBool CObeyFile::GotKeyDriveVariables() {
   983    	{
       
   984 
   872 
   985 	TBool retVal=ETrue;
   873 	TBool retVal=ETrue;
   986 
   874 
   987 	// Mandatory keywords
   875 	// Mandatory keywords
   988 	if (iDriveFileName==0)                             
   876 	if (iDriveFileName==0) {                                                  
   989 		{                                                  
       
   990 		Print(EError,"The name of the image file has not been supplied.\n");
   877 		Print(EError,"The name of the image file has not been supplied.\n");
   991 		Print(EError,"Use the keyword \"dataimagename\".\n");
   878 		Print(EError,"Use the keyword \"dataimagename\".\n");
   992 		retVal = EFalse;
   879 		retVal = EFalse;
   993 		}
   880 	}
   994 		
       
   995 	// Check for '-'ve entered value.
   881 	// Check for '-'ve entered value.
   996 	if(iDataSize <= 0)
   882 	if(iDataSize <= 0){
   997 		{
       
   998 		Print(EWarning,"Image Size should be positive. Default size is Considered.\n");
   883 		Print(EWarning,"Image Size should be positive. Default size is Considered.\n");
   999 		}
   884 	}
  1000 
   885 
  1001 	// File system format.
   886 	// File system format.
  1002 	if(iDriveFileFormat==0)
   887 	if(iDriveFileFormat==0) {
  1003 		{
       
  1004 		Print(EError,"The name of the file system not been supplied.\n");
   888 		Print(EError,"The name of the file system not been supplied.\n");
  1005 		Print(EError,"Use the keyword \"dataimagefilesystem\".\n");
   889 		Print(EError,"Use the keyword \"dataimagefilesystem\".\n");
  1006 		retVal = EFalse;
   890 		retVal = EFalse;
  1007 		}
   891 	}
  1008 
   892 
  1009 	// Checking the validity of file system format.
   893 	// Checking the validity of file system format.
  1010 	if(iDriveFileFormat)
   894 	if(iDriveFileFormat){
  1011 		{
       
  1012 		strupr((char *)iDriveFileFormat);
   895 		strupr((char *)iDriveFileFormat);
  1013 		enum TFileSystem check = (TFileSystem)0;
   896 		enum TFileSystem check = (TFileSystem)0;
  1014 		if(!(CDriveImage::FormatTranslation(iDriveFileFormat,check)))
   897 		if(!(CDriveImage::FormatTranslation(iDriveFileFormat,check))) {
  1015 			{
       
  1016 			Print(EError,"The name of the file system not supported : %s\n",iDriveFileFormat);
   898 			Print(EError,"The name of the file system not supported : %s\n",iDriveFileFormat);
  1017 			retVal = EFalse;
   899 			retVal = EFalse;
  1018 			}
   900 		}
  1019 		}
   901 	}
  1020 	
       
  1021 	if(retVal)
   902 	if(retVal)
  1022 		Print(ELog,"\nCreating Data Drive image : %s\n", iDriveFileName);
   903 		Print(ELog,"\nCreating Data Drive image : %s\n", iDriveFileName);
  1023 
   904 
  1024   	return retVal;
   905 	return retVal;
  1025 	}
   906 }
  1026 
   907 
  1027 /**
   908 /**
  1028 Process a parsed line to set up one or more new TRomBuilder entry objects.
   909 Process a parsed line to set up one or more new TRomBuilder entry objects.
  1029 
   910 
  1030 @param  - obey file keyword.
   911 @param  - obey file keyword.
  1032 // iWord[1] = the PC pathname
   913 // iWord[1] = the PC pathname
  1033 // iWord[2] = the EPOC pathname
   914 // iWord[2] = the EPOC pathname
  1034 // iWord[3] = start of the file attributes
   915 // iWord[3] = start of the file attributes
  1035 
   916 
  1036 @return - Return the status 
   917 @return - Return the status 
  1037 		  ETrue - Successful generation of tree.
   918 ETrue - Successful generation of tree.
  1038 		  EFalse- Fail to generate the tree.
   919 EFalse- Fail to generate the tree.
  1039 */
   920 */
  1040 TBool CObeyFile::ProcessDriveFile(enum EKeyword aKeyword)               
   921 TBool CObeyFile::ProcessDriveFile(enum EKeyword aKeyword) {
  1041 	{
       
  1042 
   922 
  1043 	TBool isPeFile = ETrue;
   923 	TBool isPeFile = ETrue;
  1044 	TBool aFileCompressOption, aFileUncompressOption;
   924 	TBool aFileCompressOption, aFileUncompressOption;
  1045 
   925 
  1046 	TInt epocPathStart=2;
   926 	TInt epocPathStart=2;
  1047 	aFileCompressOption = aFileUncompressOption = EFalse;
   927 	aFileCompressOption = aFileUncompressOption = EFalse;
  1048 	// do some validation of the keyword
   928 	// do some validation of the keyword
  1049 	TInt currentLine = iReader.CurrentLine();
   929 	TInt currentLine = iReader.CurrentLine();
  1050 
   930 
  1051 	switch (aKeyword)
   931 	switch (aKeyword)
  1052 		{
   932 	{
  1053 		case EKeywordData:
   933 	case EKeywordData:
  1054 		case EKeywordHide:
   934 	case EKeywordHide:
  1055 			isPeFile = EFalse;
   935 		isPeFile = EFalse;
  1056 			break;
   936 		break;
  1057 
   937 
  1058 		case EKeywordFile:
   938 	case EKeywordFile:
  1059 			break;
   939 		break;
  1060 
   940 
  1061 		case EKeywordFileCompress:
   941 	case EKeywordFileCompress:
  1062 			aFileCompressOption = ETrue;
   942 		aFileCompressOption = ETrue;
  1063 			break;
   943 		break;
  1064 
   944 
  1065 		case EKeywordFileUncompress:
   945 	case EKeywordFileUncompress:
  1066 			aFileUncompressOption = ETrue;
   946 		aFileUncompressOption = ETrue;
  1067 			break;
   947 		break;
  1068 
   948 
  1069 		default:
   949 	default:
  1070 			return EFalse;
   950 		return EFalse;
  1071 		}
   951 	}
  1072 
   952 
  1073 	if (aKeyword!=EKeywordHide)
   953 	if (aKeyword!=EKeywordHide) {
  1074 		{
       
  1075 		// check the PC file exists
   954 		// check the PC file exists
  1076 		char* nname = NormaliseFileName(iReader.Word(1));                 
   955 		char* nname = NormaliseFileName(iReader.Word(1));		  
  1077 
       
  1078 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)																		  
       
  1079 		ifstream test(nname);
   956 		ifstream test(nname);
  1080 #else //!__MSVCDOTNET__
   957 		if(!test.is_open()){
  1081 		ifstream test(nname, ios::nocreate);
       
  1082 #endif //__MSVCDOTNET__
       
  1083 
       
  1084 		if (!test)
       
  1085 			{
       
  1086 			Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
   958 			Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
  1087 			iMissingFiles++;
   959 			iMissingFiles++;
  1088 			}
   960 		}
  1089 
       
  1090 		test.close();
   961 		test.close();
  1091 		if(nname)
   962 		delete []nname ;												
  1092 			free(nname);												
   963 		 
  1093 		nname = 0;
   964 	}
  1094 		}
       
  1095 	else
   965 	else
  1096 		epocPathStart=1;   
   966 		epocPathStart=1;   
  1097 
   967 
  1098 	iNumberOfFiles++;
   968 	iNumberOfFiles++;
  1099 
   969 
  1100 	TBool endOfName=EFalse;
   970 	TBool endOfName=EFalse;
  1101 	TText *epocStartPtr=IsValidFilePath(iReader.Text(epocPathStart));
   971 	const char *epocStartPtr= IsValidFilePath(iReader.Word(epocPathStart));
  1102 	TText *epocEndPtr=epocStartPtr;
   972 	char *epocEndPtr = const_cast<char*>(epocStartPtr);
  1103 
   973 
  1104 	if (epocStartPtr==NULL)
   974 	if (epocStartPtr == NULL) {
  1105 		{
       
  1106 		Print(EError, "Invalid destination path on line %d\n",currentLine);
   975 		Print(EError, "Invalid destination path on line %d\n",currentLine);
  1107 		return EFalse;
   976 		return EFalse;
  1108 		}
   977 	}
  1109 
   978 
  1110 	TRomNode* dir=iRootDirectory;
   979 	TRomNode* dir=iRootDirectory;
  1111 	TRomNode* subDir=0;
   980 	TRomNode* subDir=0;
  1112 	TRomBuilderEntry *file=0;      
   981 	TRomBuilderEntry *file=0;      
  1113 
   982 
  1114 	while (!endOfName)
   983 	while (!endOfName) {
  1115 		{
   984 		endOfName = GetNextBitOfFileName(epocEndPtr);      
  1116 		endOfName = GetNextBitOfFileName(&epocEndPtr);      
   985 		if (endOfName) { // file		
  1117 		if (endOfName) // file
       
  1118 			{
       
  1119 			TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
   986 			TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
  1120 
   987 			if ((aKeyword != EKeywordHide) && alreadyExists) { // duplicate file		
  1121 			if ((aKeyword != EKeywordHide) && alreadyExists) // duplicate file
   988 				if (gKeepGoing) {
  1122 				{
   989 					Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine());
  1123 				Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
   990 					iNumberOfFiles--;
  1124 				return EFalse;
   991 					return ETrue;
  1125 				}
   992 				}
  1126 			else if((aKeyword == EKeywordHide) && (alreadyExists))
   993 				else {	
  1127 				{ 
   994 					Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
       
   995 					return EFalse;
       
   996 				}
       
   997 			}
       
   998 			else if((aKeyword == EKeywordHide) && (alreadyExists)) { 
  1128 				alreadyExists->iEntry->iHidden = ETrue;
   999 				alreadyExists->iEntry->iHidden = ETrue;
  1129 				alreadyExists->iHidden = ETrue;
  1000 				alreadyExists->iHidden = ETrue;
  1130 				return ETrue;
  1001 				return ETrue;
  1131 				}
  1002 			}
  1132 			else if((aKeyword == EKeywordHide) && (!alreadyExists))
  1003 			else if((aKeyword == EKeywordHide) && (!alreadyExists)) {
  1133 				{
       
  1134 				Print(EWarning, "Hiding non-existent file %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
  1004 				Print(EWarning, "Hiding non-existent file %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
  1135 				return ETrue;
  1005 				return ETrue;
  1136 				}
  1006 			}
  1137 				
  1007 
  1138 			file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr);                   
  1008 			file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr);                   
  1139 			file->iExecutable=isPeFile;
  1009 			file->iExecutable=isPeFile;
  1140 			if( aFileCompressOption )
  1010 			if( aFileCompressOption ) {
  1141 			{
  1011 				file->iCompressEnabled = ECompressionCompress;
  1142 			file->iCompressEnabled = ECompressionCompress;
  1012 			}
  1143 			}
  1013 			else if(aFileUncompressOption )	{
  1144 			else if(aFileUncompressOption )
  1014 				file->iCompressEnabled = ECompressionUncompress;
  1145 			{
  1015 			}
  1146 			file->iCompressEnabled = ECompressionUncompress;
  1016 
  1147 			}
       
  1148 			
       
  1149 			TRomNode* node=new TRomNode(epocStartPtr, file);
  1017 			TRomNode* node=new TRomNode(epocStartPtr, file);
  1150 			if (node==0)
  1018 			if (node==0)
  1151 				return EFalse;
  1019 				return EFalse;
  1152 
  1020 
  1153 			TInt r=ParseFileAttributes(node, file, aKeyword);         
  1021 			TInt r=ParseFileAttributes(node, file, aKeyword);         
  1154 			if (r!=KErrNone)
  1022 			if (r!=KErrNone)
  1155 				return EFalse;
  1023 				return EFalse;
  1156 
  1024 
  1157 			if(gCompress != ECompressionUnknown)
  1025 			if(gCompress != ECompressionUnknown) {
  1158 			{
  1026 				node->iFileUpdate = ETrue;
  1159 			node->iFileUpdate = ETrue;
  1027 			}
  1160 			}
  1028 
  1161 
  1029 			if((node->iOverride) || (aFileCompressOption) || (aFileUncompressOption)) {
  1162 			if((node->iOverride) || (aFileCompressOption) || (aFileUncompressOption))
  1030 				node->iFileUpdate = ETrue;
  1163 			{
       
  1164 			node->iFileUpdate = ETrue;
       
  1165 			}
  1031 			}
  1166 
  1032 
  1167 			dir->AddFile(node);	// to drive directory structure.
  1033 			dir->AddFile(node);	// to drive directory structure.
  1168 			}		 
  1034 		}		 
  1169 		else	
  1035 		else {
  1170 		{
  1036 			// directory
  1171 		// directory
  1037 			subDir = dir->FindInDirectory(epocStartPtr);      
  1172 		subDir = dir->FindInDirectory(epocStartPtr);      
  1038 			if (!subDir){ // sub directory does not exist			
  1173 		if (!subDir) // sub directory does not exist
  1039 				if(aKeyword==EKeywordHide) {
  1174 			{
  1040 					Print(EWarning, "Hiding non-existent file %s on line %d\n",
  1175 			if(aKeyword==EKeywordHide)
  1041 						iReader.Word(1),iReader.CurrentLine());
  1176 			{
  1042 					return ETrue;
  1177 			Print(EWarning, "Hiding non-existent file %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
  1043 				}
  1178 			return ETrue;
  1044 				subDir = dir->NewSubDir(epocStartPtr);
  1179 			}
  1045 				if (!subDir)
  1180 			subDir = dir->NewSubDir(epocStartPtr);
  1046 					return EFalse;
  1181 			if (!subDir)
       
  1182 				return EFalse;
       
  1183 			}
  1047 			}
  1184 			dir=subDir;
  1048 			dir=subDir;
  1185 
       
  1186 			epocStartPtr = epocEndPtr;
  1049 			epocStartPtr = epocEndPtr;
  1187 			}  // end of else.
  1050 		}  // end of else.
  1188 		}
  1051 	}
  1189 	return ETrue;
  1052 	return ETrue;
  1190 	}
  1053 }
  1191 
  1054 
  1192 
  1055 
  1193 TInt CObeyFile::SetStackSize(TRomNode *aNode, TText *aStr)
  1056 TInt CObeyFile::SetStackSize(TRomNode *aNode, const char* aStr) {
  1194 	{
  1057 	if (EFalse == IsValidNumber(aStr))
  1195 	if (isNumber(aStr)==0)
  1058 		return Print(EError, "Number required as argument for keyword 'stack'.\n"); 
  1196 		return Print(EError, "Number required as argument for keyword 'stack'.\n");
  1059 	TInt size ;
  1197 	aNode->SetStackSize( getNumber(aStr) );
  1060 	TInt err = Val(size,aStr);
  1198 	return KErrNone;
  1061 	if(KErrNone == err){
  1199 	}
  1062 		aNode->SetStackSize(size );
  1200 
  1063 	}
  1201 TInt CObeyFile::SetHeapSizeMin(TRomNode *aNode, TText *aStr)
  1064 	return err;
  1202 	{
  1065 }
  1203 	if (isNumber(aStr)==0)
  1066 
       
  1067 TInt CObeyFile::SetHeapSizeMin(TRomNode *aNode, const char* aStr) {
       
  1068 	if (EFalse == IsValidNumber(aStr))
  1204 		return Print(EError, "Number required as argument for keyword 'heapmin'.\n");
  1069 		return Print(EError, "Number required as argument for keyword 'heapmin'.\n");
  1205 	aNode->SetHeapSizeMin( getNumber(aStr) );
  1070 	TInt size ;
  1206 	return KErrNone;
  1071 	TInt err = Val(size,aStr);
  1207 	}
  1072 	if(KErrNone == err){
  1208 
  1073 		aNode->SetHeapSizeMin(size );
  1209 TInt CObeyFile::SetHeapSizeMax(TRomNode *aNode, TText *aStr)
  1074 	}
  1210 	{
  1075 	return err;	 
  1211 	if (isNumber(aStr)==0)
  1076 }
       
  1077 
       
  1078 TInt CObeyFile::SetHeapSizeMax(TRomNode *aNode, const char* aStr) {
       
  1079 	if (EFalse == IsValidNumber(aStr))
  1212 		return Print(EError, "Number required as argument for keyword 'heapmax'.\n");
  1080 		return Print(EError, "Number required as argument for keyword 'heapmax'.\n");
  1213 	aNode->SetHeapSizeMax( getNumber(aStr) );
  1081 	TInt size ;
  1214 	return KErrNone;
  1082 	TInt err = Val(size,aStr);
  1215 	}
  1083 	if(KErrNone == err){
  1216 
  1084 		aNode->SetHeapSizeMax(size );
  1217 TInt CObeyFile::SetCapability(TRomNode *aNode, TText *aStr)
  1085 	}
  1218 	{
  1086 	return err;	
  1219 	if (isNumber(aStr))
  1087 	 
  1220 		{
  1088 }
       
  1089 
       
  1090 TInt CObeyFile::SetCapability(TRomNode *aNode, const char* aStr) {
       
  1091 	if ( IsValidNumber(aStr)){
  1221 		Print(EDiagnostic,"Old style numeric CAPABILTY specification ignored.\n");
  1092 		Print(EDiagnostic,"Old style numeric CAPABILTY specification ignored.\n");
  1222 		return KErrNone;
  1093 		return KErrNone;
  1223 		}
  1094 	}
  1224 	SCapabilitySet cap;
  1095 	SCapabilitySet cap;
  1225 	TInt r = ParseCapabilitiesArg(cap, (char*)aStr);
  1096 	TInt r = ParseCapabilitiesArg(cap, (char*)aStr);
  1226 	if( KErrNone == r )
  1097 	if( KErrNone == r ) {
  1227 		{
       
  1228 		aNode->SetCapability( cap );
  1098 		aNode->SetCapability( cap );
  1229 		}
  1099 	}
  1230 	return r;
  1100 	return r;
  1231 	}
  1101 }
  1232 
  1102 
  1233 TInt CObeyFile::SetPriority(TRomNode *aNode, TText *aStr)
  1103 TInt CObeyFile::SetPriority(TRomNode *aNode, const char* aStr) {
  1234 	{
  1104 	TProcessPriority priority;	
  1235 	TProcessPriority priority;
  1105 	
  1236 	if (isNumber(aStr))
  1106 	if ( IsValidNumber(aStr)) {
  1237 		{
  1107 		TUint32 temp = 0;
  1238 		priority = (TProcessPriority)getNumber(aStr);
  1108 		Val(temp,aStr) ;
  1239 		}
  1109 		priority = (TProcessPriority)temp ; 
  1240 	else
  1110 	}
  1241 		{
  1111 	else {	 
  1242 		char *str=(char *)aStr;
  1112 		if (stricmp(aStr, "low")==0)
  1243 		if (stricmp(str, "low")==0)
       
  1244 			priority=EPriorityLow;
  1113 			priority=EPriorityLow;
  1245 		else if (strnicmp(str, "background", 4)==0)
  1114 		else if (strnicmp(aStr, "background", 4)==0)
  1246 			priority=EPriorityBackground;
  1115 			priority=EPriorityBackground;
  1247 		else if (strnicmp(str, "foreground", 4)==0)
  1116 		else if (strnicmp(aStr, "foreground", 4)==0)
  1248 			priority=EPriorityForeground;
  1117 			priority=EPriorityForeground;
  1249 		else if (stricmp(str, "high")==0)
  1118 		else if (stricmp(aStr, "high")==0)
  1250 			priority=EPriorityHigh;
  1119 			priority=EPriorityHigh;
  1251 		else if (strnicmp(str, "windowserver",3)==0)
  1120 		else if (strnicmp(aStr, "windowserver",3)==0)
  1252 			priority=EPriorityWindowServer;
  1121 			priority=EPriorityWindowServer;
  1253 		else if (strnicmp(str, "fileserver",4)==0)
  1122 		else if (strnicmp(aStr, "fileserver",4)==0)
  1254 			priority=EPriorityFileServer;
  1123 			priority=EPriorityFileServer;
  1255 		else if (strnicmp(str, "realtimeserver",4)==0)
  1124 		else if (strnicmp(aStr, "realtimeserver",4)==0)
  1256 			priority=EPriorityRealTimeServer;
  1125 			priority=EPriorityRealTimeServer;
  1257 		else if (strnicmp(str, "supervisor",3)==0)
  1126 		else if (strnicmp(aStr, "supervisor",3)==0)
  1258 			priority=EPrioritySupervisor;
  1127 			priority=EPrioritySupervisor;
  1259 		else
  1128 		else
  1260 			return Print(EError, "Unrecognised priority keyword.\n");
  1129 			return Print(EError, "Unrecognised priority keyword.\n");
  1261 		}
  1130 	}
  1262 	if (priority<EPriorityLow || priority>EPrioritySupervisor)
  1131 	if (priority<EPriorityLow || priority>EPrioritySupervisor)
  1263 		return Print(EError, "Priority out of range.\n");
  1132 		return Print(EError, "Priority out of range.\n");
  1264 
  1133 
  1265 	aNode->SetPriority( priority );
  1134 	aNode->SetPriority( priority );
  1266 	return KErrNone;
  1135 	return KErrNone;
  1267 	}
  1136 }
  1268 
  1137 
  1269 TInt CObeyFile::SetUid1(TRomNode *aNode, TText *aStr)
  1138 TInt CObeyFile::SetUid1(TRomNode *aNode, const char* aStr){
  1270 	{
  1139 	if (EFalse == IsValidNumber(aStr))
  1271 	if (isNumber(aStr)==0)
       
  1272 		return Print(EError, "Number required as argument for keyword 'uid1'.\n");
  1140 		return Print(EError, "Number required as argument for keyword 'uid1'.\n");
  1273 	aNode->SetUid1( getNumber(aStr) );
  1141 	TInt size ;
  1274 	return KErrNone;
  1142 	TInt err = Val(size,aStr);
  1275 	}
  1143 	if(KErrNone == err){
  1276 TInt CObeyFile::SetUid2(TRomNode *aNode, TText *aStr)
  1144 		aNode->SetUid1(size );
  1277 	{
  1145 	}
  1278 	if (isNumber(aStr)==0)
  1146 	return err;		 
       
  1147 }
       
  1148 TInt CObeyFile::SetUid2(TRomNode *aNode, const char* aStr) {
       
  1149 	if (EFalse == IsValidNumber(aStr))
  1279 		return Print(EError, "Number required as argument for keyword 'uid2'.\n");
  1150 		return Print(EError, "Number required as argument for keyword 'uid2'.\n");
  1280 	aNode->SetUid2( getNumber(aStr) );
  1151 	TInt size ;
  1281 	return KErrNone;
  1152 	TInt err = Val(size,aStr);
  1282 	}
  1153 	if(KErrNone == err){
  1283 TInt CObeyFile::SetUid3(TRomNode *aNode, TText *aStr)
  1154 		aNode->SetUid2(size );
  1284 	{
  1155 	}
  1285 	if (isNumber(aStr)==0)
  1156 	return err;	
       
  1157 }
       
  1158 TInt CObeyFile::SetUid3(TRomNode *aNode, const char* aStr) {
       
  1159 	if (EFalse == IsValidNumber(aStr))
  1286 		return Print(EError, "Number required as argument for keyword 'uid3'.\n");
  1160 		return Print(EError, "Number required as argument for keyword 'uid3'.\n");
  1287 	aNode->SetUid3( getNumber(aStr) );
  1161 	TInt size ;
  1288 	return KErrNone;
  1162 	TInt err = Val(size,aStr);
  1289 	}
  1163 	if(KErrNone == err){
  1290 
  1164 		aNode->SetUid3(size );
  1291 
  1165 	}
  1292 TInt CObeyFile::ParseFileAttributes(TRomNode *aNode, TRomBuilderEntry* aFile, enum EKeyword aKeyword)
  1166 	return err;	
       
  1167 }
       
  1168 
  1293 //
  1169 //
  1294 // Process any inline keywords
  1170 // Process any inline keywords
  1295 //
  1171 //
  1296 	{
  1172 TInt CObeyFile::ParseFileAttributes(TRomNode *aNode, TRomBuilderEntry* aFile, enum EKeyword aKeyword) {
  1297 	TInt currentLine = iReader.CurrentLine();
  1173 	TInt currentLine = iReader.CurrentLine();
  1298 	enum EFileAttribute attribute;
  1174 	enum EFileAttribute attribute;
  1299 	TInt r=KErrNone;
  1175 	TInt r=KErrNone;
  1300 	TInt index=3;
  1176 	TInt index=3;
  1301 	TText* arg=0;
  1177 	char* arg=0;
  1302 
  1178 
  1303 	while(r==KErrNone)
  1179 	while(r==KErrNone) {
  1304 		{
       
  1305 		r=iReader.NextAttribute(index,(aFile!=0),attribute,arg);
  1180 		r=iReader.NextAttribute(index,(aFile!=0),attribute,arg);
  1306 		if (r!=KErrNone)
  1181 		if (r!=KErrNone)
  1307 			break;
  1182 			break;
  1308 		switch(attribute)
  1183 		switch(attribute)
  1309 			{
  1184 		{
  1310 		case EAttributeAtt:
  1185 		case EAttributeAtt:
  1311 			r=aNode->SetAtt(arg);
  1186 			r=aNode->SetAtt(arg);
  1312 			break;
  1187 			break;
  1313 		case EAttributeAttExtra:
  1188 		case EAttributeAttExtra:
  1314 			r=aNode->SetAttExtra(arg, aFile, aKeyword);
  1189 			r=aNode->SetAttExtra(arg, aFile, aKeyword);
  1344 		case EAttributeUnpaged:
  1219 		case EAttributeUnpaged:
  1345 			aNode->iOverride |= KOverrideCodeUnpaged|KOverrideDataUnpaged;
  1220 			aNode->iOverride |= KOverrideCodeUnpaged|KOverrideDataUnpaged;
  1346 			aNode->iOverride &= ~(KOverrideCodePaged|KOverrideDataPaged);
  1221 			aNode->iOverride &= ~(KOverrideCodePaged|KOverrideDataPaged);
  1347 			break;
  1222 			break;
  1348 		case EAttributePaged:
  1223 		case EAttributePaged:
  1349 			aNode->iOverride |= KOverrideCodePaged|KOverrideDataPaged;
  1224 			aNode->iOverride |= KOverrideCodePaged;
  1350 			aNode->iOverride &= ~(KOverrideCodeUnpaged|KOverrideDataUnpaged);
  1225 			aNode->iOverride &= ~(KOverrideCodeUnpaged);
  1351 			break;
  1226 			break;
  1352 		case EAttributeUnpagedCode:
  1227 		case EAttributeUnpagedCode:
  1353 			aNode->iOverride |= KOverrideCodeUnpaged;
  1228 			aNode->iOverride |= KOverrideCodeUnpaged;
  1354 			aNode->iOverride &= ~KOverrideCodePaged;
  1229 			aNode->iOverride &= ~KOverrideCodePaged;
  1355 			break;
  1230 			break;
  1363 			break;
  1238 			break;
  1364 		case EAttributePagedData:
  1239 		case EAttributePagedData:
  1365 			aNode->iOverride |= KOverrideDataPaged;
  1240 			aNode->iOverride |= KOverrideDataPaged;
  1366 			aNode->iOverride &= ~KOverrideDataUnpaged;
  1241 			aNode->iOverride &= ~KOverrideDataUnpaged;
  1367 			break;
  1242 			break;
  1368 
       
  1369 		default:
  1243 		default:
  1370 			return Print(EError, "Unrecognised keyword in file attributes on line %d.\n",currentLine);
  1244 			return Print(EError, "Unrecognised keyword in file attributes on line %d.\n",currentLine);
  1371 			}
  1245 		}
  1372 		}
  1246 	}
  1373 
  1247 
  1374 	if (r==KErrEof)
  1248 	if (r==KErrEof)
  1375 		return KErrNone;
  1249 		return KErrNone;
  1376 	return r;
  1250 	return r;
  1377 	}
  1251 }
  1378 
  1252 
  1379 
       
  1380 TBool CObeyFile::ProcessFile(TInt /*aAlign*/, enum EKeyword aKeyword)
       
  1381 //
  1253 //
  1382 // Process a parsed line to set up one or more new TRomBuilder entry objects.
  1254 // Process a parsed line to set up one or more new TRomBuilder entry objects.
  1383 // iWord[0] = the keyword (file, primary or secondary)
  1255 // iWord[0] = the keyword (file, primary or secondary)
  1384 // iWord[1] = the PC pathname
  1256 // iWord[1] = the PC pathname
  1385 // iWord[2] = the EPOC pathname
  1257 // iWord[2] = the EPOC pathname
  1386 // iWord[3] = start of the file attributes
  1258 // iWord[3] = start of the file attributes
  1387 //
  1259 //
  1388 	{
  1260 TBool CObeyFile::ProcessFile(TInt /*aAlign*/, enum EKeyword aKeyword){
       
  1261 
  1389 	TBool isPeFile = ETrue;
  1262 	TBool isPeFile = ETrue;
  1390 	TBool aFileCompressOption, aFileUncompressOption;
  1263 	TBool aFileCompressOption, aFileUncompressOption;
  1391 	TInt epocPathStart=2;
  1264 	TInt epocPathStart=2;
  1392 	aFileCompressOption = aFileUncompressOption = EFalse;
  1265 	aFileCompressOption = aFileUncompressOption = EFalse;
  1393  	TBool warnFlag = EFalse;
  1266 	TBool warnFlag = EFalse;
  1394  	static const char aStdPath[] = "SYS\\BIN\\";
  1267 	static const char aStdPath[] = "SYS\\BIN\\";
  1395  	static const int sysBinLength = sizeof(aStdPath)-1;
  1268 	static const int sysBinLength = sizeof(aStdPath)-1;
  1396 
  1269 
  1397 	// do some validation of the keyword
  1270 	// do some validation of the keyword
  1398 	TInt currentLine = iReader.CurrentLine();
  1271 	TInt currentLine = iReader.CurrentLine();
  1399 
       
  1400 	switch (aKeyword)
  1272 	switch (aKeyword)
  1401 		{
  1273 	{
  1402 	case EKeywordData:
  1274 	case EKeywordData:
  1403 	case EKeywordHideV2:
  1275 	case EKeywordHideV2:
  1404 		iNumberOfDataFiles++;
  1276 		iNumberOfDataFiles++;
  1405 		isPeFile = EFalse;
  1277 		isPeFile = EFalse;
  1406 		break;
  1278 		break;
  1418 		break;
  1290 		break;
  1419 
  1291 
  1420 	default:
  1292 	default:
  1421 		Print(EError,"Unexpected keyword '%s' on line %d.\n",iReader.Word(0),currentLine);
  1293 		Print(EError,"Unexpected keyword '%s' on line %d.\n",iReader.Word(0),currentLine);
  1422 		return EFalse;
  1294 		return EFalse;
  1423 		}
  1295 	}
  1424 
  1296 
  1425 	if (aKeyword!=EKeywordHideV2)
  1297 	if (aKeyword!=EKeywordHideV2) {
  1426 		{
       
  1427 
  1298 
  1428 		// check the PC file exists
  1299 		// check the PC file exists
  1429 		char* nname = NormaliseFileName(iReader.Word(1));
  1300 		char* nname = NormaliseFileName(iReader.Word(1)); 
  1430 
       
  1431 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
  1432 		ifstream test(nname);
  1301 		ifstream test(nname);
  1433 #else //!__MSVCDOTNET__
  1302 		if (!test) {
  1434 		ifstream test(nname, ios::nocreate);
       
  1435 #endif //__MSVCDOTNET__
       
  1436 
       
  1437 		if (!test)
       
  1438 			{
       
  1439 			Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
  1303 			Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
  1440 			iMissingFiles++;
  1304 			iMissingFiles++;
  1441 			}
  1305 		}
  1442 		test.close();
  1306 		test.close();
  1443 		free(nname);
  1307 		delete []nname;
  1444 		}
  1308 	}
  1445 	else
  1309 	else
  1446 		epocPathStart=1;
  1310 		epocPathStart=1;
  1447 
  1311 
  1448 	iNumberOfFiles++;
  1312 	iNumberOfFiles++;
  1449 
  1313 
  1450 
  1314 
  1451  	TBool endOfName=EFalse;
  1315 	TBool endOfName=EFalse;
  1452 	TText *epocStartPtr=IsValidFilePath(iReader.Text(epocPathStart));
  1316 	const char *epocStartPtr=IsValidFilePath(iReader.Word(epocPathStart));
  1453 	TText *epocEndPtr=epocStartPtr;
  1317 	char *epocEndPtr=const_cast<char*>(epocStartPtr);
  1454 	if (epocStartPtr==NULL)
  1318 	if (epocStartPtr==NULL) {
  1455 		{
       
  1456 		Print(EError, "Invalid destination path on line %d\n",currentLine);
  1319 		Print(EError, "Invalid destination path on line %d\n",currentLine);
  1457 		return EFalse;
  1320 		return EFalse;
  1458 		}
  1321 	}
  1459  	if(warnFlag)	// Check for the std destination path(for executables) as per platsec.
  1322 	if(warnFlag){	// Check for the std destination path(for executables) as per platsec.	
  1460  		{
  1323 		if(strnicmp(aStdPath,epocStartPtr,sysBinLength) != 0) {
  1461  		if(strnicmp(aStdPath,(const char*)epocStartPtr,sysBinLength) != 0)
  1324 			Print(EWarning,"Invalid destination path on line %d. \"%s\" \n",currentLine,epocStartPtr);
  1462  			{
  1325 		}
  1463  			Print(EWarning,"Invalid destination path on line %d. \"%s\" \n",currentLine,epocStartPtr);
  1326 	}
  1464  			}
  1327 
  1465 		}
       
  1466 	
       
  1467 	TRomNode* dir=iRootDirectory;
  1328 	TRomNode* dir=iRootDirectory;
  1468 	TRomNode* subDir=0;
  1329 	TRomNode* subDir=0;
  1469 	TRomBuilderEntry *file=0;
  1330 	TRomBuilderEntry *file=0;
  1470 	while (!endOfName)
  1331 	while (!endOfName) {
  1471 		{
  1332 		endOfName = GetNextBitOfFileName(epocEndPtr);
  1472 		endOfName = GetNextBitOfFileName(&epocEndPtr);
  1333 		if (endOfName) {// file		
  1473 		if (endOfName) // file
       
  1474 			{
       
  1475 			TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
  1334 			TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
  1476 			/*
  1335 			/*
  1477 			 * The EKeywordHideV2 keyword is used to indicate that:
  1336 			* The EKeywordHideV2 keyword is used to indicate that:
  1478 			 *	1. if the file exists in the same image and then hidden, mark it hidden
  1337 			*	1. if the file exists in the same image and then hidden, mark it hidden
  1479 			 *	2. if the file exists in another image, but in this (ROFS) image, it is
  1338 			*	2. if the file exists in another image, but in this (ROFS) image, it is
  1480 			 *		required to hide that file, create a 0 length file entry setting the 'hide'
  1339 			*		required to hide that file, create a 0 length file entry setting the 'hide'
  1481 			 *		flag so that at runtime, file gets hidden in the composite filesystem.
  1340 			*		flag so that at runtime, file gets hidden in the composite filesystem.
  1482 			 */
  1341 			*/
  1483 			if ((aKeyword != EKeywordHideV2) && alreadyExists) // duplicate file
  1342 			if ((aKeyword != EKeywordHideV2) && alreadyExists){ // duplicate file		
  1484 				{
  1343 				if(gKeepGoing){	
  1485 				Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
  1344 					Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine());
  1486 				return EFalse;
  1345 					switch (aKeyword)
       
  1346 					{
       
  1347 					case EKeywordData:
       
  1348 					case EKeywordHideV2:
       
  1349 						iNumberOfDataFiles--;
       
  1350 					default:
       
  1351 						break;
       
  1352 					}
       
  1353 					iNumberOfFiles--;	 	
       
  1354 					return ETrue;
  1487 				}
  1355 				}
       
  1356 				else {					
       
  1357 					Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
       
  1358 					return EFalse;
       
  1359 				}
       
  1360 			}
  1488 
  1361 
  1489 			TBool aHidden = aKeyword==EKeywordHideV2;
  1362 			TBool aHidden = aKeyword==EKeywordHideV2;
  1490 			/* The file is only marked hidden and hence the source file name isn't known 
  1363 			/* The file is only marked hidden and hence the source file name isn't known 
  1491 			 * here as hide statement says :
  1364 			* here as hide statement says :
  1492 			 *	hide <filename as in ROM>
  1365 			*	hide <filename as in ROM>
  1493 			 * Therefore, create TRomBuilderEntry with iFileName as 0 for hidden file when
  1366 			* Therefore, create TRomBuilderEntry with iFileName as 0 for hidden file when
  1494 			 * the file doesn't exist in the same ROM image. Otherwise, the src file name
  1367 			* the file doesn't exist in the same ROM image. Otherwise, the src file name
  1495 			 * is known because of alreadyExists (which comes from the 'file'/'data' statement).
  1368 			* is known because of alreadyExists (which comes from the 'file'/'data' statement).
  1496 			 */
  1369 			*/
  1497 			if(aHidden)
  1370 			if(aHidden)
  1498 				file = new TRomBuilderEntry(0, epocStartPtr);
  1371 				file = new TRomBuilderEntry(0, epocStartPtr);
  1499 			else
  1372 			else
  1500 				file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr);
  1373 				file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr);
  1501 			file->iExecutable=isPeFile;
  1374 			file->iExecutable=isPeFile;
  1502 			file->iHidden= aHidden;
  1375 			file->iHidden= aHidden;
  1503 			if( aFileCompressOption )
  1376 			if( aFileCompressOption ){
  1504 			{
       
  1505 				file->iCompressEnabled = ECompressionCompress;
  1377 				file->iCompressEnabled = ECompressionCompress;
  1506 			}
  1378 			}
  1507 			else if(aFileUncompressOption )
  1379 			else if(aFileUncompressOption )	{
  1508 			{
       
  1509 				file->iCompressEnabled = ECompressionUncompress;
  1380 				file->iCompressEnabled = ECompressionUncompress;
  1510 			}
  1381 			}
  1511 			TRomNode* node=new TRomNode(epocStartPtr, file);
  1382 			TRomNode* node=new TRomNode(epocStartPtr, file);
  1512 			if (node==0)
  1383 			if (node==0)
  1513 				return EFalse;
  1384 				return EFalse;
  1515 			if (r!=KErrNone)
  1386 			if (r!=KErrNone)
  1516 				return EFalse;
  1387 				return EFalse;
  1517 
  1388 
  1518 			dir->AddFile(node);	// to ROFS directory structure
  1389 			dir->AddFile(node);	// to ROFS directory structure
  1519 			AddFile(file);		// to our list of files
  1390 			AddFile(file);		// to our list of files
  1520 			}		 
  1391 		}		 
  1521 		else // directory
  1392 		else { // directory		
  1522 			{
       
  1523 			subDir = dir->FindInDirectory(epocStartPtr);
  1393 			subDir = dir->FindInDirectory(epocStartPtr);
  1524 			if (!subDir) // sub directory does not exist
  1394 			if (!subDir) { // sub directory does not exist			
  1525 				{
       
  1526 				subDir = dir->NewSubDir(epocStartPtr);
  1395 				subDir = dir->NewSubDir(epocStartPtr);
  1527 				if (!subDir)
  1396 				if (!subDir)
  1528 					return EFalse;
  1397 					return EFalse;
  1529 				}
  1398 			}
  1530 			dir=subDir;
  1399 			dir=subDir;
  1531 			epocStartPtr = epocEndPtr;
  1400 			epocStartPtr = epocEndPtr;
  1532 			}
  1401 		}
  1533 		}
  1402 	}
  1534 	return ETrue;
  1403 	return ETrue;
  1535 	}
  1404 }
  1536 
  1405 
  1537 
  1406 
  1538 TBool CObeyFile::ProcessRenaming(enum EKeyword aKeyword)
  1407 TBool CObeyFile::ProcessRenaming(enum EKeyword aKeyword) {
  1539 	{
       
  1540 
  1408 
  1541 	// find existing file
  1409 	// find existing file
  1542 	TBool endOfName=EFalse;
  1410 	TBool endOfName=EFalse;
  1543 	TText *epocStartPtr=IsValidFilePath(iReader.Text(1));
  1411 	const char *epocStartPtr=IsValidFilePath(iReader.Word(1));
  1544 	
  1412 
  1545 	// Store the current name and new name to maintain renamed file map
  1413 	// Store the current name and new name to maintain renamed file map
  1546 	String currentName=iReader.Word(1);
  1414 	string currentName=iReader.Word(1);
  1547 	String newName=iReader.Word(2);
  1415 	string newName=iReader.Word(2);
  1548 
  1416 
  1549 	TText *epocEndPtr=epocStartPtr;
  1417 	char *epocEndPtr= const_cast<char*>(epocStartPtr);
  1550 	if (epocStartPtr==NULL)
  1418 	if (epocStartPtr == NULL) {
  1551 		{
       
  1552 		Print(EError, "Invalid source path on line %d\n",iReader.CurrentLine());
  1419 		Print(EError, "Invalid source path on line %d\n",iReader.CurrentLine());
  1553 		return EFalse;
  1420 		return EFalse;
  1554 		}
  1421 	}
  1555 
  1422 
  1556 	char saved_srcname[257];
  1423 	char saved_srcname[257];
  1557 	strcpy(saved_srcname, iReader.Word(1));
  1424 	strncpy(saved_srcname, iReader.Word(1),257);
  1558 
  1425 
  1559 	TRomNode* dir=iRootDirectory;
  1426 	TRomNode* dir=iRootDirectory;
  1560 	TRomNode* existingFile=0;
  1427 	TRomNode* existingFile=0;
  1561 	while (!endOfName)
  1428 	while (!endOfName){
  1562 		{
  1429 		endOfName = GetNextBitOfFileName(epocEndPtr);
  1563 		endOfName = GetNextBitOfFileName(&epocEndPtr);
  1430 		if (endOfName) { // file
  1564 		if (endOfName) // file
       
  1565 			{
       
  1566 			existingFile=dir->FindInDirectory(epocStartPtr);
  1431 			existingFile=dir->FindInDirectory(epocStartPtr);
  1567 			if (existingFile)
  1432 			if (existingFile) {
  1568 				{
       
  1569 				TInt fileCount=0;
  1433 				TInt fileCount=0;
  1570 				TInt dirCount=0;
  1434 				TInt dirCount=0;
  1571 				existingFile->CountDirectory(fileCount, dirCount);
  1435 				existingFile->CountDirectory(fileCount, dirCount);
  1572 				if (dirCount != 0 || fileCount != 0)
  1436 				if (dirCount != 0 || fileCount != 0) {
  1573 					{
  1437 					Print(EError, "Keyword %s not applicable to directories - line %d\n",
  1574 					Print(EError, "Keyword %s not applicable to directories - line %d\n",iReader.Word(0),iReader.CurrentLine());
  1438 						iReader.Word(0),iReader.CurrentLine());
  1575 					return EFalse;
  1439 					return EFalse;
  1576 					}
       
  1577 				}
  1440 				}
  1578 			}
  1441 			}
  1579 		else // directory
  1442 		}
  1580 			{
  1443 		else { // directory		
  1581 			TRomNode* subDir = dir->FindInDirectory(epocStartPtr);
  1444 			TRomNode* subDir = dir->FindInDirectory(epocStartPtr);
  1582 			if (!subDir) // sub directory does not exist
  1445 			if (!subDir) // sub directory does not exist
  1583 				break;
  1446 				break;
  1584 			dir=subDir;
  1447 			dir=subDir;
  1585 			epocStartPtr = epocEndPtr;
  1448 			epocStartPtr = epocEndPtr;
  1586 			}
  1449 		}
  1587 		}
  1450 	}
  1588 	if (aKeyword == EKeywordHide)
  1451 	if (aKeyword == EKeywordHide) {
  1589 		{
  1452 		/*
  1590 			/*
  1453 		* The EKeywordHide keyword is used to indicate that if the file exists in 
  1591 			 * The EKeywordHide keyword is used to indicate that if the file exists in 
  1454 		* the primary ROFS image and then hidden in extension ROFS, mark it hidden.
  1592 			 * the primary ROFS image and then hidden in extension ROFS, mark it hidden.
  1455 		*/
  1593 			 */
  1456 		if (!existingFile) {
  1594 		if (!existingFile)
       
  1595 			{
       
  1596 			Print(EWarning, "Hiding non-existent file %s on line %d\n", 
  1457 			Print(EWarning, "Hiding non-existent file %s on line %d\n", 
  1597 				saved_srcname, iReader.CurrentLine());
  1458 				saved_srcname, iReader.CurrentLine());
  1598 			// Just a warning, as we've achieved the right overall effect.
  1459 			// Just a warning, as we've achieved the right overall effect.
  1599 			}
  1460 		}
  1600 		else if (existingFile->iFileStartOffset==(TUint)KFileHidden)
  1461 		else if (existingFile->iFileStartOffset==(TUint)KFileHidden){
  1601 			{
       
  1602 			Print(EWarning, "Hiding already hidden file %s on line %d\n", 
  1462 			Print(EWarning, "Hiding already hidden file %s on line %d\n", 
  1603 				saved_srcname, iReader.CurrentLine());
  1463 				saved_srcname, iReader.CurrentLine());
  1604 			// We will igrore this request, otherwise it will "undelete" it.
  1464 			// We will igrore this request, otherwise it will "undelete" it.
  1605 			}
  1465 		}
  1606 		else
  1466 		else {
  1607 			{
  1467 			//hidden files will not be placed to the image
  1608 			  //hidden files will not be placed to the image
  1468 			existingFile->iHidden = ETrue;
  1609 			  existingFile->iHidden = ETrue;
  1469 		}
  1610 			}
       
  1611 		return ETrue;
  1470 		return ETrue;
  1612 		}
  1471 	}
  1613 
  1472 
  1614 	if (!existingFile)
  1473 	if (!existingFile) {
  1615 		{
       
  1616 		Print(EError, "Can't %s non-existent source file %s on line %d\n",
  1474 		Print(EError, "Can't %s non-existent source file %s on line %d\n",
  1617 			iReader.Word(0), saved_srcname, iReader.CurrentLine());
  1475 			iReader.Word(0), saved_srcname, iReader.CurrentLine());
  1618 		return EFalse;
  1476 		return EFalse;
  1619 		}
  1477 	}
  1620 
  1478 
  1621 	epocStartPtr=IsValidFilePath(iReader.Text(2));
  1479 	epocStartPtr = IsValidFilePath(iReader.Word(2));
  1622 	epocEndPtr=epocStartPtr;
  1480 	epocEndPtr = const_cast<char*>(epocStartPtr);
  1623 	endOfName=EFalse;
  1481 	endOfName = EFalse;
  1624 	if (epocStartPtr==NULL)
  1482 	if (epocStartPtr == NULL) {
  1625 		{
       
  1626 		Print(EError, "Invalid destination path on line %d\n",iReader.CurrentLine());
  1483 		Print(EError, "Invalid destination path on line %d\n",iReader.CurrentLine());
  1627 		return EFalse;
  1484 		return EFalse;
  1628 		}
  1485 	}
  1629 
  1486 
  1630 	TRomNode* newdir=iRootDirectory;
  1487 	TRomNode* newdir=iRootDirectory;
  1631 	while (!endOfName)
  1488 	while (!endOfName) {
  1632 		{
  1489 		endOfName = GetNextBitOfFileName(epocEndPtr);
  1633 		endOfName = GetNextBitOfFileName(&epocEndPtr);
  1490 		if (endOfName) {// file		
  1634 		if (endOfName) // file
       
  1635 			{
       
  1636 			TRomNode* alreadyExists=newdir->FindInDirectory(epocStartPtr);
  1491 			TRomNode* alreadyExists=newdir->FindInDirectory(epocStartPtr);
  1637 			if (alreadyExists && !(alreadyExists->iHidden)) // duplicate file
  1492 			if (alreadyExists && !(alreadyExists->iHidden)) {// duplicate file	
  1638 				{
  1493 				if(gKeepGoing){
  1639 				Print(EError, "Duplicate file for %s on line %d\n",saved_srcname,iReader.CurrentLine());
  1494 					Print(EWarning, "Duplicate file for %s on line %d, renaming will be skipped\n",saved_srcname,iReader.CurrentLine());
  1640 				return EFalse;
  1495 					return ETrue;
  1641 				}
  1496 				}
  1642 			}
  1497 				else {							
  1643 		else // directory
  1498 					Print(EError, "Duplicate file for %s on line %d\n",saved_srcname,iReader.CurrentLine());
  1644 			{
  1499 					return EFalse;
       
  1500 				}
       
  1501 			}
       
  1502 		}
       
  1503 		else { // directory		
  1645 			TRomNode* subDir = newdir->FindInDirectory(epocStartPtr);
  1504 			TRomNode* subDir = newdir->FindInDirectory(epocStartPtr);
  1646 			if (!subDir) // sub directory does not exist
  1505 			if (!subDir) {// sub directory does not exist			
  1647 				{
       
  1648 				subDir = newdir->NewSubDir(epocStartPtr);
  1506 				subDir = newdir->NewSubDir(epocStartPtr);
  1649 				if (!subDir)
  1507 				if (!subDir)
  1650 					return EFalse;
  1508 					return EFalse;
  1651 				}
  1509 			}
  1652 			newdir=subDir;
  1510 			newdir=subDir;
  1653 			epocStartPtr = epocEndPtr;
  1511 			epocStartPtr = epocEndPtr;
  1654 			}
  1512 		}
  1655 		}
  1513 	}
  1656 
  1514 
  1657 	if (aKeyword == EKeywordRename)
  1515 	if (aKeyword == EKeywordRename) {
  1658 		{
       
  1659 		// rename => remove existingFile and insert into tree at new place
  1516 		// rename => remove existingFile and insert into tree at new place
  1660 		// has no effect on the iNextExecutable or iNextNodeForSameFile links
  1517 		// has no effect on the iNextExecutable or iNextNodeForSameFile links
  1661 
       
  1662 		TInt r=ParseFileAttributes(existingFile, existingFile->iEntry, aKeyword);
  1518 		TInt r=ParseFileAttributes(existingFile, existingFile->iEntry, aKeyword);
  1663 		if (r!=KErrNone)
  1519 		if (r!=KErrNone)
  1664 			return EFalse;
  1520 			return EFalse;
  1665 		existingFile->Rename(dir, newdir, epocStartPtr);
  1521 		existingFile->Rename(dir, newdir, epocStartPtr);
  1666 		// Store the current and new name of file in the renamed file map.
  1522 		// Store the current and new name of file in the renamed file map.
  1667 		iPatchData->AddToRenamedFileMap(currentName, newName);
  1523 		iPatchData->AddToRenamedFileMap(currentName, newName);
  1668 		return ETrue;
  1524 		return ETrue;
  1669 		}
  1525 	}
  1670 	
  1526 
  1671 	// alias => create new TRomNode entry and insert into tree
  1527 	// alias => create new TRomNode entry and insert into tree
  1672 
       
  1673 	TRomNode* node = new TRomNode(epocStartPtr, 0);
  1528 	TRomNode* node = new TRomNode(epocStartPtr, 0);
  1674 	if (node == 0)
  1529 	if (node == 0) {
  1675 		{
       
  1676 		Print(EError, "Out of memory\n");
  1530 		Print(EError, "Out of memory\n");
  1677 		return EFalse;
  1531 		return EFalse;
  1678 		}
  1532 	}
  1679 	node->Alias(existingFile);
  1533 	node->Alias(existingFile);
  1680 	TInt r=ParseFileAttributes(node, 0, aKeyword);
  1534 	TInt r=ParseFileAttributes(node, 0, aKeyword);
  1681 	if (r!=KErrNone)
  1535 	if (r!=KErrNone)
  1682 		return EFalse;
  1536 		return EFalse;
  1683 
       
  1684 	newdir->AddFile(node);	// to ROFS directory structure, though possibly hidden
  1537 	newdir->AddFile(node);	// to ROFS directory structure, though possibly hidden
  1685 
       
  1686 	return ETrue;
  1538 	return ETrue;
  1687 	}
  1539 }
  1688 
  1540 
  1689 TInt ParsePagingPolicy(const char* policy)
  1541 TInt ParsePagingPolicy(const char* policy){
  1690 	{
  1542 	if(stricmp(policy,"NOPAGING") == 0)
  1691 	if(stricmp(policy,"NOPAGING")==0)
       
  1692 		return EKernelConfigPagingPolicyNoPaging;
  1543 		return EKernelConfigPagingPolicyNoPaging;
  1693 	else if (stricmp(policy,"ALWAYSPAGE")==0)
  1544 	else if (stricmp(policy,"ALWAYSPAGE") == 0)
  1694 		return EKernelConfigPagingPolicyAlwaysPage;
  1545 		return EKernelConfigPagingPolicyAlwaysPage;
  1695 	else if(stricmp(policy,"DEFAULTUNPAGED")==0)
  1546 	else if(stricmp(policy,"DEFAULTUNPAGED") == 0)
  1696 		return EKernelConfigPagingPolicyDefaultUnpaged;
  1547 		return EKernelConfigPagingPolicyDefaultUnpaged;
  1697 	else if(stricmp(policy,"DEFAULTPAGED")==0)
  1548 	else if(stricmp(policy,"DEFAULTPAGED") == 0)
  1698 		return EKernelConfigPagingPolicyDefaultPaged;
  1549 		return EKernelConfigPagingPolicyDefaultPaged;
  1699 	return KErrArgument;
  1550 	return KErrArgument;
  1700 	}
  1551 }
  1701 
  1552 
  1702 TBool CObeyFile::ProcessKeyword(enum EKeyword aKeyword)
  1553 TBool CObeyFile::ProcessKeyword(enum EKeyword aKeyword) { 
       
  1554 
       
  1555 	TBool success = ETrue;
       
  1556 	switch (aKeyword)
  1703 	{
  1557 	{
  1704 	#ifdef __TOOLS2__
  1558 	case EKeywordRofsName:
  1705 	istringstream val(iReader.Word(1));
  1559 		iRomFileName = iReader.DupWord(1);
  1706 	#else
  1560 		break;
  1707 	istrstream val(iReader.Word(1),strlen(iReader.Word(1)));
  1561 	case EKeywordRofsSize:
  1708 	#endif
  1562 		Val(iRomSize,iReader.Word(1));
  1709 
  1563 		break;
  1710 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
  1564 	case EKeywordVersion:
  1711 	val >> setbase(0);
       
  1712 #endif //__MSVCDOTNET__
       
  1713 
       
  1714 	TBool success = ETrue;
       
  1715 
       
  1716 	switch (aKeyword)
       
  1717 		{
  1565 		{
  1718 	case EKeywordRofsName:
  1566 			istringstream val(iReader.Word(1)); 
  1719 		iReader.CopyWord(1, iRomFileName);
  1567 			val >> iVersion;
  1720 		break;
  1568 		}
  1721 	case EKeywordRofsSize:
       
  1722 		val >> iRomSize;
       
  1723 		break;
       
  1724 	case EKeywordVersion:
       
  1725 		val >> iVersion;
       
  1726 		break;
  1569 		break;
  1727 	case EKeywordRofsChecksum:
  1570 	case EKeywordRofsChecksum:
  1728 		val >> iCheckSum;
  1571 		Val(iCheckSum,iReader.Word(1));
  1729 		break;
  1572 		break;
  1730 	case EKeywordTime:
  1573 	case EKeywordTime:
  1731 		iReader.ProcessTime(iTime);
  1574 		iReader.ProcessTime(iTime);
  1732 		break;
  1575 		break;
  1733 	case EKeywordPagingOverride:
  1576 	case EKeywordPagingOverride:
  1734 		{
  1577 		{
  1735 		if(iPagingOverrideParsed)
  1578 			if(iPagingOverrideParsed)
  1736 			Print(EWarning, "PagingOverride redefined - previous PagingOverride values lost\n");
  1579 				Print(EWarning, "PagingOverride redefined - previous PagingOverride values lost\n");
  1737 		if(iCodePagingOverrideParsed)
  1580 			if(iCodePagingOverrideParsed)
  1738 			Print(EWarning, "PagingOverride defined - previous CodePagingOverride values lost\n");
  1581 				Print(EWarning, "PagingOverride defined - previous CodePagingOverride values lost\n");
  1739 		if(iDataPagingOverrideParsed)
  1582 			iPagingOverrideParsed = true;
  1740 			Print(EWarning, "PagingOverride defined - previous DataPagingOverride values lost\n");
  1583 			TInt policy = ParsePagingPolicy(iReader.Word(1));
  1741 		iPagingOverrideParsed = true;
  1584 			if(policy < 0) {
  1742 		TInt policy = ParsePagingPolicy(iReader.Word(1));
  1585 				Print(EError,"Unrecognized option for PAGINGOVERRIDE keyword\n");
  1743 		if(policy<0)
  1586 				success = false;
  1744 			{
  1587 			}
  1745 			Print(EError,"Unrecognised option for PAGINGOVERRIDE keyword\n");
  1588 			else {
  1746 			success = false;
  1589 				gCodePagingOverride = policy;
  1747 			}
  1590 				if((policy == EKernelConfigPagingPolicyNoPaging) || (policy == EKernelConfigPagingPolicyDefaultUnpaged))
  1748 		else
  1591 					gDataPagingOverride = policy;
  1749 			{
       
  1750 			gCodePagingOverride = policy;
       
  1751 			gDataPagingOverride = policy;
       
  1752 			}
  1592 			}
  1753 		}
  1593 		}
  1754 		break;
  1594 		break;
  1755 	case EKeywordCodePagingOverride:
  1595 	case EKeywordCodePagingOverride:
  1756 		{
  1596 		{
  1757 		if(iCodePagingOverrideParsed)
  1597 			if(iCodePagingOverrideParsed)
  1758 			Print(EWarning, "CodePagingOverride redefined - previous CodePagingOverride values lost\n");
  1598 				Print(EWarning, "CodePagingOverride redefined - previous CodePagingOverride values lost\n");
  1759 		if(iPagingOverrideParsed)
  1599 			if(iPagingOverrideParsed)
  1760 			Print(EWarning, "CodePagingOverride defined - previous PagingOverride values lost\n");
  1600 				Print(EWarning, "CodePagingOverride defined - previous PagingOverride values lost\n");
  1761 		iCodePagingOverrideParsed = true;
  1601 			iCodePagingOverrideParsed = true;
  1762 		TInt policy = ParsePagingPolicy(iReader.Word(1));
  1602 			TInt policy = ParsePagingPolicy(iReader.Word(1));
  1763 		if(policy<0)
  1603 			if(policy<0)
  1764 			{
  1604 			{
  1765 			Print(EError,"Unrecognised option for CODEPAGINGOVERRIDE keyword\n");
  1605 				Print(EError,"Unrecognized option for CODEPAGINGOVERRIDE keyword\n");
  1766 			success = false;
  1606 				success = false;
  1767 			}
  1607 			}
  1768 		else
  1608 			else
  1769 			gCodePagingOverride = policy;
  1609 				gCodePagingOverride = policy;
  1770 		}
  1610 		}
  1771 		break;
  1611 		break;
  1772 	case EKeywordDataPagingOverride:
  1612 	case EKeywordDataPagingOverride:
  1773 		{
  1613 		{
  1774 		if(iDataPagingOverrideParsed)
  1614 			if(iDataPagingOverrideParsed)
  1775 			Print(EWarning, "DataPagingOverride redefined - previous DataPagingOverride values lost\n");
  1615 				Print(EWarning, "DataPagingOverride redefined - previous DataPagingOverride values lost\n");
  1776 		if(iPagingOverrideParsed)
  1616 /*			if(iPagingOverrideParsed){
  1777 			{
  1617 				Print(EError, "DataPagingOverride defined - previous PagingOverride values lost\n");
  1778 			Print(EError, "DataPagingOverride defined - previous PagingOverride values lost\n");
  1618 				success = false;
  1779 			success = false;
  1619 				break;
  1780 			break;
  1620 			}
  1781 			}
  1621 */
  1782 		iDataPagingOverrideParsed = true;
  1622 			iDataPagingOverrideParsed = true;
  1783 		TInt policy = ParsePagingPolicy(iReader.Word(1));
  1623 			TInt policy = ParsePagingPolicy(iReader.Word(1));
  1784 		if(policy<0)
  1624 			if(policy < 0) {
  1785 			{
  1625 				Print(EError,"Unrecognized option for DATAPAGINGOVERRIDE keyword\n");
  1786 			Print(EError,"Unrecognised option for DATAPAGINGOVERRIDE keyword\n");
  1626 				success = false;
  1787 			success = false;
  1627 			}
  1788 			}
  1628 			else
  1789 		else
  1629 				gDataPagingOverride = policy;
  1790 			gDataPagingOverride = policy;
       
  1791 		}
  1630 		}
  1792 		break;
  1631 		break;
  1793 	case EKeywordRofsAutoSize:
  1632 	case EKeywordRofsAutoSize:
  1794 		iAutoSize = ETrue;
  1633 		iAutoSize = ETrue;
  1795 		val >> iAutoPageSize;
  1634 		Val(iAutoPageSize,iReader.Word(1));
  1796 		break;
  1635 		break;
  1797 	default:
  1636 	default:
  1798 		// unexpected keyword iReader.Word(0)
  1637 		// unexpected keyword iReader.Word(0)
  1799 		break;
  1638 		break;
  1800 		}
  1639 	}
  1801 
  1640 
  1802 	return success;
  1641 	return success;
  1803 	}
  1642 }
  1804 
       
  1805 TBool CObeyFile::GotKeyVariables()
       
  1806 //
  1643 //
  1807 // Checks that the obeyfile has supplied enough variables to continue
  1644 // Checks that the obeyfile has supplied enough variables to continue
  1808 //
  1645 //
  1809    	{
  1646 TBool CObeyFile::GotKeyVariables() {
  1810 
  1647 
  1811 	TBool retVal=ETrue;
  1648 	TBool retVal=ETrue;
  1812 
       
  1813 	// Mandatory keywords
  1649 	// Mandatory keywords
  1814 
  1650 	if (iRomFileName == 0) {
  1815 	if (iRomFileName==0)
       
  1816 		{
       
  1817 		Print(EAlways,"The name of the image file has not been supplied.\n");
  1651 		Print(EAlways,"The name of the image file has not been supplied.\n");
  1818 		Print(EAlways,"Use the keyword \"rofsname\".\n");
  1652 		Print(EAlways,"Use the keyword \"rofsname\".\n");
  1819 		retVal = EFalse;
  1653 		retVal = EFalse;
  1820 		}
  1654 	}
  1821 	if (iRomSize==0)
  1655 	if (iRomSize == 0) {
  1822 		{
       
  1823 		Print(EAlways,"The size of the image has not been supplied.\n");
  1656 		Print(EAlways,"The size of the image has not been supplied.\n");
  1824 		Print(EAlways,"Use the keyword \"rofssize\".\n");
  1657 		Print(EAlways,"Use the keyword \"rofssize\".\n");
  1825 		retVal = EFalse;
  1658 		retVal = EFalse;
  1826 		}
  1659 	}
  1827 
       
  1828 	// Apply defaults as necessary
  1660 	// Apply defaults as necessary
  1829 	if (iTime==0)
  1661 	if (iTime == 0)	{
  1830 		{
       
  1831 		Print(ELog, "No timestamp specified. Using current time...\n");
  1662 		Print(ELog, "No timestamp specified. Using current time...\n");
  1832 		ObeyFileReader::TimeNow(iTime);
  1663 		ObeyFileReader::TimeNow(iTime);
  1833 		}
  1664 	}
  1834 
       
  1835 	Print(ELog, "\nCreating Rofs image %s\n", iRomFileName);
  1665 	Print(ELog, "\nCreating Rofs image %s\n", iRomFileName);
  1836 	return retVal;
  1666 	return retVal;
  1837 	}
  1667 }
  1838 
  1668 
  1839 
       
  1840 TText *CObeyFile::IsValidFilePath(TText *aPath)
       
  1841 //
  1669 //
  1842 // Check the path is valid
  1670 // Check the path is valid
  1843 //
  1671 //
  1844 	{
  1672 const char* CObeyFile::IsValidFilePath(const char* aPath) {
  1845 	// skip leading "\"
  1673 	// skip leading "\"
  1846 	if (*aPath=='\\')
  1674 	if (*aPath == '/' || *aPath == '\\')
  1847 		aPath++;
  1675 		aPath++;
  1848 	if (*aPath==0)
  1676 	if (*aPath == 0)
  1849 		return NULL; // file ends in a backslash
  1677 		return NULL; // file ends in a backslash
  1850 
  1678 
  1851 	TText *p=aPath;
  1679 	const char *p = aPath;
  1852 	TInt len=0;
  1680 	TInt len=0;
  1853 	FOREVER
  1681 	while(*p) {			
  1854 		{
  1682 		if (*p == '/' || *p == '\\') {
  1855 		if (*p==0)
  1683 			if (len == 0)
  1856 			return (len ? aPath : NULL);
       
  1857 		if (*p=='\\')
       
  1858 			{
       
  1859 			if (len==0)
       
  1860 				return NULL;
  1684 				return NULL;
  1861 			len=0;
  1685 			len=0;
  1862 			}
  1686 		}
  1863 		len++;
  1687 		len++;
  1864 		p++;
  1688 		p++;
  1865 		}
  1689 	}
  1866 	}
  1690 	return (len ? aPath : NULL);
  1867 
  1691 }
  1868 TBool CObeyFile::GetNextBitOfFileName(TText **epocEndPtr)
  1692 
  1869 //
  1693 //
  1870 // Move the end pointer past the next directory separator, replacing it with 0
  1694 // Move the end pointer past the next directory separator, replacing it with 0
  1871 //
  1695 //
  1872 	{
  1696 TBool CObeyFile::GetNextBitOfFileName(char*& epocEndPtr) {
  1873 	while (**epocEndPtr != '\\') // until reach the directory separator
  1697 	while (*epocEndPtr != '/' && *epocEndPtr != '\\'){ // until reach the directory separator		
  1874 		{
  1698 		if (*epocEndPtr == 0) // if reach end of string, return TRUE, it's the filename
  1875 		if (**epocEndPtr==0) // if reach end of string, return TRUE, it's the filename
       
  1876 			return ETrue;
  1699 			return ETrue;
  1877 		(*epocEndPtr)++;
  1700 		epocEndPtr++;
  1878 		}
  1701 	}
  1879 	**epocEndPtr=0; // overwrite the directory separator with a 0
  1702 	*epocEndPtr = 0; // overwrite the directory separator with a 0
  1880 	(*epocEndPtr)++; // point past the 0 ready for the next one
  1703 	epocEndPtr++; // point past the 0 ready for the next one
  1881 	return EFalse;
  1704 	return EFalse;
  1882 	}
  1705 }
  1883 
  1706 
  1884 
  1707 void CObeyFile::AddFile(TRomBuilderEntry* aFile) {
  1885 void CObeyFile::AddFile(TRomBuilderEntry* aFile)
       
  1886 	{
       
  1887 	*iNextFilePtrPtr = aFile;
  1708 	*iNextFilePtrPtr = aFile;
  1888 	iNextFilePtrPtr = &(aFile->iNext);
  1709 	iNextFilePtrPtr = &(aFile->iNext);
  1889 	}
  1710 }
  1890 
  1711 
  1891 
  1712 //
  1892 
  1713 // First pass through the obey file to set up key variables
  1893 TInt CObeyFile::ProcessExtensionRofs(MRofsImage* aKernelRom)
  1714 //
  1894 	{
  1715 TInt CObeyFile::ProcessExtensionRofs(MRofsImage* aKernelRom) { 
  1895 	//
  1716 	
  1896 	// First pass through the obey file to set up key variables
  1717 	iReader.Rewind();
  1897 	//
       
  1898 
       
  1899 
       
  1900         iReader.Rewind();
       
  1901 
       
  1902 	enum EKeyword keyword;
  1718 	enum EKeyword keyword;
  1903 
  1719 
  1904 	// Deal with the "extensionrofs" keyword, which should be first
  1720 	// Deal with the "extensionrofs" keyword, which should be first
  1905 		
  1721 	// however, you may've found "time" before it.
  1906 	if (iReader.NextLine(1,keyword) != KErrNone)
  1722 	while(iReader.NextLine(1,keyword) != KErrEof) {
  1907 		return KErrEof;
  1723 		if(EKeywordExtensionRofs == keyword)
  1908 	if (keyword != EKeywordExtensionRofs)
  1724 			break ;		
  1909 		return Print(EError, "Unexpected keyword '%s' at start of extension rom - line %d\n",
  1725 	}
  1910 			iReader.Word(0), iReader.CurrentLine());
  1726 	if(EKeywordExtensionRofs != keyword) return KErrEof;
  1911 	
  1727 	iRomFileName = iReader.DupWord(1);
  1912 	iReader.CopyWord(1, iRomFileName);
       
  1913 	Print(ELog, "\n========================================================\n");
  1728 	Print(ELog, "\n========================================================\n");
  1914 	Print(ELog, "Extension ROFS %s starting at line %d\n\n", iRomFileName, iReader.CurrentLine());
  1729 	Print(ELog, "Extension ROFS %s starting at line %d\n\n", iRomFileName, iReader.CurrentLine());
  1915 
  1730 
  1916 
       
  1917 	iReader.MarkNext();		// so that we rewind to the line after the extensionrom keyword
  1731 	iReader.MarkNext();		// so that we rewind to the line after the extensionrom keyword
  1918 
  1732 
  1919 	while (iReader.NextLine(1,keyword) != KErrEof)
  1733 	while (iReader.NextLine(1,keyword) != KErrEof) {
  1920 		{
       
  1921 		if (keyword == EKeywordExtensionRofs)
  1734 		if (keyword == EKeywordExtensionRofs)
  1922 			break;
  1735 			break;
  1923 			ProcessExtensionKeyword(keyword);
  1736 		ProcessExtensionKeyword(keyword);
  1924 		}
  1737 	}
  1925 
  1738 
  1926 	if (!GotExtensionVariables(aKernelRom))
  1739 	if (!GotExtensionVariables(aKernelRom))
  1927 		return KErrGeneral;
  1740 		return KErrGeneral;
  1928 
  1741 
  1929 	// second pass to process the file specifications in the obey file building
  1742 	// second pass to process the file specifications in the obey file building
  1930 	// up the TRomNode directory structure and the TRomBuilderEntry list
  1743 	// up the TRomNode directory structure and the TRomBuilderEntry list
  1931 	//
  1744 	//
  1932 	iReader.Rewind();
  1745 	iReader.Rewind();
  1933 
  1746 
  1934 	//
  1747 	//
  1935 	if (aKernelRom==0)
  1748 	if (aKernelRom == 0)
  1936 		return Print(EError, "Option to extend a kernel ROFS image not yet implemented\n");
  1749 		return Print(EError, "Option to extend a kernel ROFS image not yet implemented\n");
  1937 
  1750 
  1938 
  1751 	iRootDirectory = new TRomNode("");
  1939 	
  1752 
  1940 	iRootDirectory = new TRomNode((TText*)"");
       
  1941 	
       
  1942 	iLastExecutable = 0;
  1753 	iLastExecutable = 0;
  1943 
  1754 
  1944 	(aKernelRom->RootDirectory())->deleteTheFirstNode();
  1755 	(aKernelRom->RootDirectory())->deleteTheFirstNode();
  1945 
  1756 
  1946 
  1757 
  1947 	iRootDirectory = aKernelRom->CopyDirectory(iLastExecutable);
  1758 	iRootDirectory = aKernelRom->CopyDirectory(iLastExecutable);
  1948 	aKernelRom->SetRootDirectory(iRootDirectory);
  1759 	aKernelRom->SetRootDirectory(iRootDirectory);
  1949 
  1760 
  1950 
  1761 
  1951 	TInt align=0;
  1762 	TInt align=0;
  1952 	while (iReader.NextLine(2,keyword)!=KErrEof)
  1763 	while (iReader.NextLine(2,keyword)!=KErrEof) {
       
  1764 		if (keyword == EKeywordExtensionRofs)
       
  1765 			break;
       
  1766 
       
  1767 		switch (keyword)
  1953 		{
  1768 		{
  1954 		if (keyword == EKeywordExtensionRofs)
       
  1955 			break;
       
  1956 
       
  1957 		switch (keyword)
       
  1958 			{
       
  1959 		case EKeywordHide:
  1769 		case EKeywordHide:
  1960 		case EKeywordAlias:
  1770 		case EKeywordAlias:
  1961 		case EKeywordRename:
  1771 		case EKeywordRename:
  1962 			if (!ProcessRenaming(keyword))
  1772 			if (!ProcessRenaming(keyword))
  1963 				return KErrGeneral;
  1773 				return KErrGeneral;
  1964 			break;
  1774 			break;
  1965 
  1775 
  1966 		case EKeywordPatchDllData:
  1776 		case EKeywordPatchDllData:
  1967 		{	
  1777 			{	
  1968 			// Collect patchdata statements to process at the end
  1778 				// Collect patchdata statements to process at the end
  1969 			StringVector patchDataTokens;
  1779 				StringVector patchDataTokens;
  1970 			SplitPatchDataStatement(patchDataTokens); 
  1780 				SplitPatchDataStatement(patchDataTokens); 
  1971 			iPatchData->AddPatchDataStatement(patchDataTokens);									
  1781 				iPatchData->AddPatchDataStatement(patchDataTokens);									
  1972 			break;
  1782 				break;
  1973 		}
  1783 			}
  1974 		default:
  1784 		default:
  1975 			if (!ProcessFile(align, keyword))
  1785 			if (!ProcessFile(align, keyword))
  1976 				return KErrGeneral;
  1786 				return KErrGeneral;			
  1977 			align=0;
  1787 			align=0;
  1978 			break;
  1788 			break;
  1979 			}
  1789 		}
  1980 		}
  1790 	}
  1981 
  1791 	
  1982 	if(!ParsePatchDllData() )
  1792 	if(!ParsePatchDllData() )
  1983 		return KErrGeneral;
  1793 		return KErrGeneral;
  1984 	
  1794 
  1985 	iReader.Mark();			// ready for processing the next extension rom(s)
  1795 	iReader.MarkNext();			// ready for processing the next extension rom(s)
  1986 
  1796 
  1987 	if (iMissingFiles!=0)
  1797 	if (iMissingFiles!=0)
  1988 		return KErrGeneral;
  1798 		return KErrGeneral;
  1989 	if (iNumberOfFiles==0)
  1799 	if (iNumberOfFiles == 0) {
  1990 		{
       
  1991 		Print(EError, "No files specified.\n");
  1800 		Print(EError, "No files specified.\n");
  1992 		return KErrGeneral;
  1801 		return KErrGeneral;
  1993 		}
  1802 	}
  1994 	return KErrNone;
  1803 	return KErrNone;
  1995 	}
  1804 }
  1996 
  1805 void CObeyFile::ProcessExtensionKeyword(enum EKeyword aKeyword)	{ 
  1997 
  1806 
  1998 
  1807 	switch (aKeyword)
  1999 
       
  2000 void CObeyFile::ProcessExtensionKeyword(enum EKeyword aKeyword)
       
  2001 	{
  1808 	{
  2002 	#ifdef __TOOLS2__
       
  2003 	istringstream val(iReader.Word(1));
       
  2004 	#else
       
  2005 	istrstream val(iReader.Word(1),strlen(iReader.Word(1)));
       
  2006 	#endif
       
  2007 
       
  2008 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
  2009 	val >> setbase(0);
       
  2010 #endif //__MSVCDOTNET__
       
  2011 
       
  2012 	switch (aKeyword)
       
  2013 		{
       
  2014 	case EKeywordCoreRofsName:
  1809 	case EKeywordCoreRofsName:
  2015  		iReader.CopyWord(1, iKernelRofsName);
  1810 		iKernelRofsName = iReader.DupWord(1);
  2016 		return;
  1811 		return;
  2017 	case EKeywordRofsSize:
  1812 	case EKeywordRofsSize:
  2018 		val >> iRomSize;
  1813 		Val(iRomSize,iReader.Word(1));
  2019 		return;
  1814 		return;
  2020 	case EKeywordVersion:
  1815 	case EKeywordVersion:
  2021 		val >> iVersion;
  1816 		{
       
  1817 			istringstream val(iReader.Word(1)); 
       
  1818 			val >> iVersion;
       
  1819 		}
  2022 		return;
  1820 		return;
  2023 	case EKeywordRomChecksum:
  1821 	case EKeywordRomChecksum:
  2024 		val >> iCheckSum;
  1822 		Val(iCheckSum,iReader.Word(1)); //--
  2025 		return;
  1823 		return;
  2026 	case EKeywordTime:
  1824 	case EKeywordTime:
  2027 		iReader.ProcessTime(iTime);
  1825 		iReader.ProcessTime(iTime);
  2028 		return;
  1826 		return;
  2029 	case EKeywordRofsAutoSize:
  1827 	case EKeywordRofsAutoSize:
  2030 		iAutoSize = ETrue;
  1828 		iAutoSize = ETrue;
  2031 		val >> iAutoPageSize;
  1829 		Val(iAutoPageSize , iReader.Word(1)); 
  2032 		return;
  1830 		return;
  2033 	default:
  1831 	default:
  2034 		Print(EError,"Keyword '%s' not valid in extension ROFS - line %d\n", iReader.Word(0), iReader.CurrentLine());
  1832 		Print(EError,"Keyword '%s' not valid in extension ROFS - line %d\n", iReader.Word(0), iReader.CurrentLine());
  2035 		break;
  1833 		break;
  2036 		}
  1834 	}
  2037 	return;
  1835 	return;
  2038 	}
  1836 }
  2039 
       
  2040 TBool CObeyFile::GotExtensionVariables(MRofsImage* aRom)
       
  2041 //
  1837 //
  2042 // Checks that the obeyfile has supplied enough variables to continue
  1838 // Checks that the obeyfile has supplied enough variables to continue
  2043 //
  1839 //
  2044    	{
  1840 TBool CObeyFile::GotExtensionVariables(MRofsImage* aRom) {
  2045 
  1841 
  2046 	TBool retVal=ETrue;
  1842 	TBool retVal=ETrue;
  2047   	TText* kernelRofsName = iKernelRofsName;
  1843 	const char* kernelRofsName = iKernelRofsName;
  2048 
  1844 
  2049 	// Mandatory keywords
  1845 	// Mandatory keywords
  2050 
  1846 
  2051 	if (iRomSize==0)
  1847 	if (iRomSize == 0){
  2052 		{
       
  2053 		Print(EAlways,"The size of the extension ROFS has not been supplied.\n");
  1848 		Print(EAlways,"The size of the extension ROFS has not been supplied.\n");
  2054 		Print(EAlways,"Use the keyword \"rofssize\".\n");
  1849 		Print(EAlways,"Use the keyword \"rofssize\".\n");
  2055 		retVal = EFalse;
  1850 		retVal = EFalse;
  2056 		}
  1851 	}
  2057 
  1852 
  2058 	// keywords we need if we don't already have a ROFS image to work from
  1853 	// keywords we need if we don't already have a ROFS image to work from
  2059 
  1854 	if (aRom == 0) {
  2060 	if (aRom==0)
  1855 		if (iKernelRofsName == 0) {
  2061 		{
       
  2062   		if (iKernelRofsName==0)
       
  2063 			{
       
  2064 			Print(EAlways,"The name of the core ROFS has not been supplied.\n");
  1856 			Print(EAlways,"The name of the core ROFS has not been supplied.\n");
  2065 			Print(EAlways,"Use the keyword \"rofsname\".\n");
  1857 			Print(EAlways,"Use the keyword \"rofsname\".\n");
  2066 			retVal = EFalse;
  1858 			retVal = EFalse;
  2067 			}
  1859 		}
  2068 		}
  1860 	}
  2069 	else
  1861 	else {
  2070 		{
  1862 		if (iKernelRofsName != 0){
  2071 		if (iKernelRofsName != 0)
       
  2072 			{
       
  2073 			Print(EWarning,"Keyword \"rofsname\" ignored.\n");
  1863 			Print(EWarning,"Keyword \"rofsname\" ignored.\n");
  2074 			}
  1864 		}
  2075 		kernelRofsName = aRom->RomFileName();
  1865 		kernelRofsName = aRom->RomFileName();
  2076 		}
  1866 	}
  2077 
  1867 
  2078 	// validation
  1868 	// validation
  2079 
       
  2080 	// Apply defaults as necessary
  1869 	// Apply defaults as necessary
  2081 	if (iTime==0)
  1870 	if (iTime == 0)	{
  2082 		{
       
  2083 		Print(ELog, "No timestamp specified. Using current time...\n");
  1871 		Print(ELog, "No timestamp specified. Using current time...\n");
  2084 		ObeyFileReader::TimeNow(iTime);
  1872 		ObeyFileReader::TimeNow(iTime);
  2085 		}
  1873 	}
  2086 
  1874 
  2087 	// fix up "*" in rofsname
  1875 	// fix up "*" in rofsname
  2088 	TText newname[256];
  1876 	char newname[256];
  2089 	TText* p=newname;
  1877 	char* p=newname;
  2090 	TText* q=iRomFileName;
  1878 	char* q=iRomFileName;
  2091 	TText c;
  1879 	char c;
  2092 
  1880 
  2093 	while ((c=*q++)!='\0')
  1881 	while ((c=*q++)!='\0'){
  2094 		{
  1882 		if (c!='*') {
  2095 		if (c!='*')
       
  2096 			{
       
  2097 			*p++=c;
  1883 			*p++=c;
  2098 			continue;
  1884 			continue;
  2099 			}
  1885 		}
  2100 		TText *r=kernelRofsName;
  1886 		const char *r = kernelRofsName;
  2101 		while ((c=*r++)!='\0')
  1887 		while ((c=*r++)!='\0')
  2102 			*p++=c;
  1888 			*p++=c;
  2103 		}
  1889 	}
  2104 	*p = '\0';
  1890 	*p++ = '\0';
  2105 	free(iRomFileName);
  1891 	delete []iRomFileName;
  2106   	iRomFileName = (TText*)strdup((char*)newname);
  1892 	size_t len = p - newname ;
  2107 
  1893 	iRomFileName = new char[len];
       
  1894 	memcpy(iRomFileName,newname,len);
  2108 	Print(ELog, "\nCreating ROFS image %s\n", iRomFileName);
  1895 	Print(ELog, "\nCreating ROFS image %s\n", iRomFileName);
  2109 
       
  2110 	return retVal;
  1896 	return retVal;
  2111 	}
  1897 }
  2112 
  1898 
  2113 // Fuction to split patchdata statement 
  1899 // Fuction to split patchdata statement 
  2114 void CObeyFile::SplitPatchDataStatement(StringVector& aPatchDataTokens)
  1900 void CObeyFile::SplitPatchDataStatement(StringVector& aPatchDataTokens) {
  2115 {
       
  2116 	// Get the value of symbol size, address/ordinal and new value 
  1901 	// Get the value of symbol size, address/ordinal and new value 
  2117 	// to be patched from the patchdata statement.
  1902 	// to be patched from the patchdata statement.
  2118 	// Syntax of patchdata statements is as follows:
  1903 	// Syntax of patchdata statements is as follows:
  2119 	// 1)	patchdata dll_name  ordinal OrdinalNumber size_in_bytes   new_value 
  1904 	// 1)	patchdata dll_name  ordinal OrdinalNumber size_in_bytes   new_value 
  2120 	// 2)   patchdata dll_name  addr    Address       size_in_bytes   new_value
  1905 	// 2)   patchdata dll_name  addr    Address       size_in_bytes   new_value
  2121 	for(TInt count=1; count<=5; count++)
  1906 	for(TInt count=1; count<=5; count++) {
  2122 	{
       
  2123 		aPatchDataTokens.push_back(iReader.Word(count));
  1907 		aPatchDataTokens.push_back(iReader.Word(count));
  2124 	}
  1908 	}
  2125 
  1909 
  2126 	// Store the the value of current line which will be used
  1910 	// Store the the value of current line which will be used
  2127 	// when displaying error messages.
  1911 	// when displaying error messages.
  2128 	OutputStringStream outStrStream;
  1912 	ostringstream outStrStream;
  2129 	outStrStream<<iReader.CurrentLine();
  1913 	outStrStream<<iReader.CurrentLine();
  2130     aPatchDataTokens.push_back(outStrStream.str());
  1914 	aPatchDataTokens.push_back(outStrStream.str());
  2131 }
  1915 }
  2132 
  1916 
  2133 TBool CObeyFile::ParsePatchDllData()
  1917 TBool CObeyFile::ParsePatchDllData() {
  2134 {
       
  2135 	// Get the list of patchdata statements
  1918 	// Get the list of patchdata statements
  2136 	VectorOfStringVector patchDataStatements=iPatchData->GetPatchDataStatements();
  1919 	VectorOfStringVector patchDataStatements=iPatchData->GetPatchDataStatements();
  2137 	// Get the list of renamed file map
  1920 	// Get the list of renamed file map
  2138 	MapOfString RenamedFileMap=iPatchData->GetRenamedFileMap();
  1921 	MapOfString RenamedFileMap=iPatchData->GetRenamedFileMap();
  2139 
  1922 
  2140 	for(TUint count=0; count<patchDataStatements.size(); count++)
  1923 	for(TUint count=0; count < patchDataStatements.size(); count++) {
  2141 	{
  1924 		
  2142 		StringVector strVector = patchDataStatements.at(count);
  1925 		StringVector strVector = patchDataStatements.at(count);
  2143 		String filename=strVector.at(0);
  1926 		string filename=strVector.at(0);
  2144 		String lineNoStr = strVector.at(5);
  1927 		string lineNoStr = strVector.at(5);
  2145 		TUint lineNo=getNumber(((TText*)lineNoStr.c_str()));
  1928 		TUint lineNo = 0 ;
       
  1929 		Val(lineNo,lineNoStr.c_str());
  2146 		TRomNode* existingFile = NULL;
  1930 		TRomNode* existingFile = NULL;
  2147 		
  1931 
  2148 		do
  1932 		do {
  2149 		{
       
  2150 			TRomNode* dir=iRootDirectory;			
  1933 			TRomNode* dir=iRootDirectory;			
  2151 			TBool endOfName=EFalse;
  1934 			TBool endOfName=EFalse; 
  2152 
  1935 			
  2153 			TText *epocStartPtr=IsValidFilePath((TText*)filename.c_str());
  1936 			if (!IsValidFilePath(filename.c_str())) {
  2154 			if (epocStartPtr==NULL)
       
  2155 			{
       
  2156 				Print(EError, "Invalid source path on line %d\n",lineNo);
  1937 				Print(EError, "Invalid source path on line %d\n",lineNo);
  2157 				return EFalse;
  1938 				return EFalse;
  2158 			}
  1939 			}
  2159 			epocStartPtr = (TText*)NormaliseFileName((const char*)epocStartPtr);
  1940 			char* epocStartPtr =NormaliseFileName(filename.c_str());
  2160 			TText *epocEndPtr=epocStartPtr;
  1941 			char* savedPtr = epocStartPtr;
  2161 
  1942 			if(*epocStartPtr == '/' ||*epocStartPtr == '\\')
  2162 			while (!endOfName)
  1943 				epocStartPtr++ ;
  2163 			{
  1944 			char* epocEndPtr = epocStartPtr;
  2164 				endOfName = GetNextBitOfFileName(&epocEndPtr);
  1945 
  2165 				if (endOfName) // file
  1946 			while (!endOfName) {
  2166 				{
  1947 				endOfName = GetNextBitOfFileName(epocEndPtr);
       
  1948 				if (endOfName) {// file				
  2167 					existingFile=dir->FindInDirectory(epocStartPtr);
  1949 					existingFile=dir->FindInDirectory(epocStartPtr);
  2168 					if (existingFile)
  1950 					if (existingFile) {
  2169 					{
       
  2170 						TInt fileCount=0;
  1951 						TInt fileCount=0;
  2171 						TInt dirCount=0;
  1952 						TInt dirCount=0;
  2172 						existingFile->CountDirectory(fileCount, dirCount);
  1953 						existingFile->CountDirectory(fileCount, dirCount);
  2173 						if (dirCount != 0 || fileCount != 0)
  1954 						if (dirCount != 0 || fileCount != 0) {
  2174 						{
       
  2175 							Print(EError, "Keyword %s not applicable to directories - line %d\n","patchdata",lineNo);
  1955 							Print(EError, "Keyword %s not applicable to directories - line %d\n","patchdata",lineNo);
  2176 							return EFalse;
  1956 							return EFalse;
  2177 						}
  1957 						}
  2178 					}
  1958 					}
  2179 				}
  1959 				}
  2180 				else // directory
  1960 				else {// directory				
  2181 				{
       
  2182 					TRomNode* subDir = dir->FindInDirectory(epocStartPtr);
  1961 					TRomNode* subDir = dir->FindInDirectory(epocStartPtr);
  2183 					if (!subDir) // sub directory does not exist
  1962 					if (!subDir) // sub directory does not exist
  2184 						break;
  1963 						break;
  2185 					dir=subDir;
  1964 					dir=subDir;
  2186 					epocStartPtr = epocEndPtr;
  1965 					epocStartPtr = epocEndPtr;
  2187 				}
  1966 				}
  2188 			}
  1967 			}
  2189 
  1968 			delete []savedPtr;
  2190 			if(!existingFile)
  1969 
  2191 			{
  1970 			if(!existingFile) {
  2192 				// If the E32Image file to be patched is not included then check if the
  1971 				// If the E32Image file to be patched is not included then check if the
  2193 				// file was renamed.
  1972 				// file was renamed.
  2194 				MapOfStringIterator RenamedFileMapIterator;
  1973 				MapOfStringIterator RenamedFileMapIterator;
  2195 				if ((RenamedFileMapIterator=RenamedFileMap.find(filename)) != RenamedFileMap.end())
  1974 				if ((RenamedFileMapIterator=RenamedFileMap.find(filename)) != RenamedFileMap.end())
  2196 					filename = (*RenamedFileMapIterator).second; 				
  1975 					filename = (*RenamedFileMapIterator).second; 				
  2197 				else
  1976 				else {
  2198 				{
       
  2199 					Print(EError, "File %s not found - line %d\n", filename.c_str(), lineNo);
  1977 					Print(EError, "File %s not found - line %d\n", filename.c_str(), lineNo);
  2200 					return EFalse;
  1978 					return EFalse;
  2201 				}
  1979 				}
  2202 			}
  1980 			}
  2203 		}while(!existingFile);
  1981 		}while(!existingFile);
  2207 
  1985 
  2208 		aOrdinal = (TUint32)-1;
  1986 		aOrdinal = (TUint32)-1;
  2209 		aDataAddr = (TUint32)-1;
  1987 		aDataAddr = (TUint32)-1;
  2210 		aOffset = 0;
  1988 		aOffset = 0;
  2211 
  1989 
  2212 		String symbolSize=strVector.at(3);
  1990 		string symbolSize=strVector.at(3);
  2213 		aSize = getNumber((TText*)symbolSize.c_str());
  1991 		Val(aSize,symbolSize.c_str());
  2214 		String aValue=strVector.at(4);
  1992 		string aValue=strVector.at(4);
  2215 		aNewValue = getNumber((TText*)aValue.c_str());		
  1993 		Val(aNewValue,aValue.c_str());		
  2216 
  1994 
  2217 		DllDataEntry *dataEntry = new DllDataEntry(aSize, aNewValue);
  1995 		DllDataEntry *dataEntry = new DllDataEntry(aSize, aNewValue);
  2218 
  1996 
  2219 		// Set the address of the data or the ordinal number specified in OBY statement.
  1997 		// Set the address of the data or the ordinal number specified in OBY statement.
  2220 		String keyword=strVector.at(1);
  1998 		string keyword=strVector.at(1);
  2221 		String keywordValue=strVector.at(2);
  1999 		string keywordValue=strVector.at(2);
  2222 		
  2000 
  2223 		/* Check for +OFFSET at the end of the ordinal number or address */
  2001 		/* Check for +OFFSET at the end of the ordinal number or address */
  2224 		TUint plus = keywordValue.find("+",0);
  2002 		TUint plus = keywordValue.find("+",0);
  2225 		if (plus != std::string::npos)
  2003 		if (plus != string::npos) {
  2226 		{
       
  2227 			/* Get the offset that we found after the + sign */
  2004 			/* Get the offset that we found after the + sign */
  2228 			String offset = keywordValue.substr(plus+1);
  2005 			string offset = keywordValue.substr(plus+1);
  2229 			aOffset = getNumber((TText*)offset.c_str());
  2006 			Val(aOffset,offset.c_str());
  2230 
  2007 
  2231 			keywordValue.resize(plus);		
  2008 			keywordValue.resize(plus);		
  2232 		}
  2009 		}
  2233 		if(stricmp (keyword.c_str(), "addr") == 0)
  2010 		if(stricmp (keyword.c_str(), "addr") == 0)
  2234 			aDataAddr = getNumber((TText*)keywordValue.c_str());
  2011 			Val(aDataAddr,keywordValue.c_str());
  2235 		
  2012 
  2236 		else 
  2013 		else 
  2237 			 aOrdinal = getNumber((TText*)keywordValue.c_str());
  2014 			Val(aOrdinal,keywordValue.c_str());
  2238 		
  2015 
  2239 		dataEntry->iDataAddress = aDataAddr;
  2016 		dataEntry->iDataAddress = aDataAddr;
  2240 		dataEntry->iOrdinal = aOrdinal;
  2017 		dataEntry->iOrdinal = aOrdinal;
  2241 		dataEntry->iOffset = aOffset;
  2018 		dataEntry->iOffset = aOffset;
  2242 
  2019 
  2243 		existingFile->SetDllData();
  2020 		existingFile->SetDllData();
  2244 
  2021 
  2245 		DllDataEntry *aDllDataEntry= existingFile->iEntry->GetFirstDllDataEntry();
  2022 		DllDataEntry *aDllDataEntry= existingFile->iEntry->GetFirstDllDataEntry();
  2246 		if (aDllDataEntry==NULL)
  2023 		if (aDllDataEntry == NULL) {
  2247 		{
       
  2248 			// Set the first node of the patchdata linked list
  2024 			// Set the first node of the patchdata linked list
  2249 			aDllDataEntry=dataEntry;
  2025 			aDllDataEntry=dataEntry;
  2250 			existingFile->iEntry->SetFirstDllDataEntry(aDllDataEntry);
  2026 			existingFile->iEntry->SetFirstDllDataEntry(aDllDataEntry);
  2251 		}
  2027 		}
  2252 		else
  2028 		else {
  2253 		{
       
  2254 			// Goto the last node
  2029 			// Goto the last node
  2255 			while((aDllDataEntry->NextDllDataEntry()) != NULL)
  2030 			while((aDllDataEntry->NextDllDataEntry()) != NULL) {
  2256 			{
       
  2257 				aDllDataEntry = aDllDataEntry->NextDllDataEntry();
  2031 				aDllDataEntry = aDllDataEntry->NextDllDataEntry();
  2258 			}
  2032 			}
  2259 			
       
  2260 			// Add the new node at the end of linked list
  2033 			// Add the new node at the end of linked list
  2261 			aDllDataEntry->AddDllDataEntry(dataEntry);			
  2034 			aDllDataEntry->AddDllDataEntry(dataEntry);			
  2262 		}
  2035 		}
  2263 	}
  2036 	}
  2264 	return ETrue;
  2037 	return ETrue;
  2265 }
  2038 }
  2266 
       
  2267 
       
  2268 
       
  2269 
       
  2270 
       
  2271 
       
  2272 
       
  2273 
       
  2274