| 0 |      1 | // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
 | 
|  |      2 | // All rights reserved.
 | 
|  |      3 | // This component and the accompanying materials are made available
 | 
|  |      4 | // under the terms of the License "Eclipse Public License v1.0"
 | 
|  |      5 | // which accompanies this distribution, and is available
 | 
|  |      6 | // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 | 
|  |      7 | //
 | 
|  |      8 | // Initial Contributors:
 | 
|  |      9 | // Nokia Corporation - initial contribution.
 | 
|  |     10 | //
 | 
|  |     11 | // Contributors:
 | 
|  |     12 | //
 | 
|  |     13 | // Description:
 | 
|  |     14 | //
 | 
|  |     15 | 
 | 
|  |     16 | #include <string.h>
 | 
|  |     17 | #include <ctype.h>
 | 
|  |     18 | 
 | 
|  |     19 | #include "analyse.h"
 | 
|  |     20 | #include "obyfile.h"
 | 
|  |     21 | #include "nonxip.h"
 | 
|  |     22 | 
 | 
|  |     23 | #ifdef __MSVCDOTNET__
 | 
|  |     24 | #include <fstream>
 | 
|  |     25 | #else //!__MSVCDOTNET__
 | 
|  |     26 | #include <fstream.h>
 | 
|  |     27 | #endif //__MSVCDOTNET__
 | 
|  |     28 | 
 | 
|  |     29 | 
 | 
|  |     30 | // class ObyFile
 | 
|  |     31 | 
 | 
|  |     32 | ObyFile::ObyFile(const char* aObyFile)
 | 
|  |     33 | 	:iText(0)
 | 
|  |     34 | 	{
 | 
|  |     35 | 	ifstream file;
 | 
|  |     36 | #ifdef __MSVCDOTNET__
 | 
|  |     37 | 	file.open(aObyFile, ios::binary);
 | 
|  |     38 | #else //!__MSVCDOTNET__
 | 
|  |     39 | 	file.open(aObyFile, ios::nocreate | ios::binary);
 | 
|  |     40 | #endif //__MSVCDOTNET__
 | 
|  |     41 | 	if (!file)
 | 
|  |     42 | 		{
 | 
|  |     43 | 		cerr << "Unable to open OBY file '" << aObyFile << '\'' << endl;
 | 
|  |     44 | 		Analyse::Abort();
 | 
|  |     45 | 		}
 | 
|  |     46 | //
 | 
|  |     47 | 	file.seekg(0, ios::end);
 | 
|  |     48 | 	iLength = file.tellg();
 | 
|  |     49 | //
 | 
|  |     50 | 	iText = new char[iLength+1];
 | 
|  |     51 | 	file.seekg(0, ios::beg);
 | 
|  |     52 | 	file.read(iText, iLength);
 | 
|  |     53 | 	iText[iLength] = '\0';
 | 
|  |     54 | //
 | 
|  |     55 | 	file.close();
 | 
|  |     56 | 	for(char *p = iText;p < iText + iLength;p++) *p = tolower(*p);
 | 
|  |     57 | 	}
 | 
|  |     58 | 
 | 
|  |     59 | ObyFile::~ObyFile()
 | 
|  |     60 | 	{
 | 
|  |     61 | 	delete [] iText;
 | 
|  |     62 | 	}
 | 
|  |     63 | 
 | 
|  |     64 | void ObyFile::Parse(NonXIP* aNonXIP) const
 | 
|  |     65 | 	{
 | 
|  |     66 | //	char* text = strstr(iText, "files=");
 | 
|  |     67 | //	if (text == 0) return;
 | 
|  |     68 | 	char* text = iText;
 | 
|  |     69 | 	const char* end = iText + iLength;
 | 
|  |     70 | 	for(char* endl = strchr(text, '\r');text < end; text = endl + 2, endl = strchr(text, '\r'))
 | 
|  |     71 | 		{
 | 
|  |     72 | 		if (!endl) break;
 | 
|  |     73 | 		*endl = '\0';
 | 
|  |     74 | 
 | 
|  |     75 | 		for(;isspace(*text);text++);
 | 
|  |     76 | 		int offset = 0;
 | 
|  |     77 | 		if		(!strncmp(text, "primary", 7))			offset = 7;
 | 
|  |     78 | 		else if (!strncmp(text, "secondary", 9))		offset = 9;
 | 
|  |     79 | 		else if (!strncmp(text, "extension", 9))		offset = 9;
 | 
|  |     80 | 		else if (!strncmp(text, "variant", 7))			offset = 7;
 | 
|  |     81 | 		else if (!strncmp(text, "device", 6))			offset = 6;
 | 
|  |     82 | 		else if (!strncmp(text, "file", 4))				offset = 4;
 | 
|  |     83 | 		else if (!strncmp(text, "data", 4))				offset = 4;
 | 
|  |     84 | 		else if (!strncmp(text, "dll", 3))				offset = 3;
 | 
|  |     85 | 
 | 
|  |     86 | 		if (offset == 0) continue;
 | 
|  |     87 | 		text += offset;
 | 
|  |     88 | 
 | 
|  |     89 | 		if (*text == '[') 
 | 
|  |     90 | 			{
 | 
|  |     91 | 			text = strchr(text, ']');
 | 
|  |     92 | 			if (text == 0) continue;
 | 
|  |     93 | 			text++;
 | 
|  |     94 | 			}
 | 
|  |     95 | 		if (!(*text == '=' || *text == ' ' || *text == '\t')) continue;
 | 
|  |     96 | 		text++;
 | 
|  |     97 | 			
 | 
|  |     98 | 		for(;isspace(*text);text++);
 | 
|  |     99 | 		char* orig_name = text;
 | 
|  |    100 | 		if (*orig_name == '\"')
 | 
|  |    101 | 			for(text = ++orig_name;*text && *text != '\"';text++);
 | 
|  |    102 | 		else
 | 
|  |    103 | 			for(;*text && !isspace(*text);text++);
 | 
|  |    104 | 		if (*text == '\0') continue;
 | 
|  |    105 | 		*text = '\0';
 | 
|  |    106 | 
 | 
|  |    107 | 		while(isspace(*++text));
 | 
|  |    108 | 		char* seg_name = text;
 | 
|  |    109 | 		if (*seg_name == '\"')
 | 
|  |    110 | 			for(text = ++seg_name;*text && *text != '\"';text++);
 | 
|  |    111 | 		else
 | 
|  |    112 | 			for(;*text && !isspace(*text);text++);
 | 
|  |    113 | 		*text = '\0';
 | 
|  |    114 | 		if (*seg_name == '\0') continue;
 | 
|  |    115 | 		
 | 
|  |    116 | 		aNonXIP->AddObyNames(*seg_name == '\\' ? ++seg_name : seg_name, *orig_name == '\\' ? ++orig_name : orig_name);
 | 
|  |    117 | 		}
 | 
|  |    118 | 	}
 | 
|  |    119 | 
 |