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