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