sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "analyse.h" sl@0: #include "obyfile.h" sl@0: #include "nonxip.h" sl@0: sl@0: #ifdef __MSVCDOTNET__ sl@0: #include sl@0: #else //!__MSVCDOTNET__ sl@0: #include sl@0: #endif //__MSVCDOTNET__ sl@0: sl@0: sl@0: // class ObyFile sl@0: sl@0: ObyFile::ObyFile(const char* aObyFile) sl@0: :iText(0) sl@0: { sl@0: ifstream file; sl@0: #ifdef __MSVCDOTNET__ sl@0: file.open(aObyFile, ios::binary); sl@0: #else //!__MSVCDOTNET__ sl@0: file.open(aObyFile, ios::nocreate | ios::binary); sl@0: #endif //__MSVCDOTNET__ sl@0: if (!file) sl@0: { sl@0: cerr << "Unable to open OBY file '" << aObyFile << '\'' << endl; sl@0: Analyse::Abort(); sl@0: } sl@0: // sl@0: file.seekg(0, ios::end); sl@0: iLength = file.tellg(); sl@0: // sl@0: iText = new char[iLength+1]; sl@0: file.seekg(0, ios::beg); sl@0: file.read(iText, iLength); sl@0: iText[iLength] = '\0'; sl@0: // sl@0: file.close(); sl@0: for(char *p = iText;p < iText + iLength;p++) *p = tolower(*p); sl@0: } sl@0: sl@0: ObyFile::~ObyFile() sl@0: { sl@0: delete [] iText; sl@0: } sl@0: sl@0: void ObyFile::Parse(NonXIP* aNonXIP) const sl@0: { sl@0: // char* text = strstr(iText, "files="); sl@0: // if (text == 0) return; sl@0: char* text = iText; sl@0: const char* end = iText + iLength; sl@0: for(char* endl = strchr(text, '\r');text < end; text = endl + 2, endl = strchr(text, '\r')) sl@0: { sl@0: if (!endl) break; sl@0: *endl = '\0'; sl@0: sl@0: for(;isspace(*text);text++); sl@0: int offset = 0; sl@0: if (!strncmp(text, "primary", 7)) offset = 7; sl@0: else if (!strncmp(text, "secondary", 9)) offset = 9; sl@0: else if (!strncmp(text, "extension", 9)) offset = 9; sl@0: else if (!strncmp(text, "variant", 7)) offset = 7; sl@0: else if (!strncmp(text, "device", 6)) offset = 6; sl@0: else if (!strncmp(text, "file", 4)) offset = 4; sl@0: else if (!strncmp(text, "data", 4)) offset = 4; sl@0: else if (!strncmp(text, "dll", 3)) offset = 3; sl@0: sl@0: if (offset == 0) continue; sl@0: text += offset; sl@0: sl@0: if (*text == '[') sl@0: { sl@0: text = strchr(text, ']'); sl@0: if (text == 0) continue; sl@0: text++; sl@0: } sl@0: if (!(*text == '=' || *text == ' ' || *text == '\t')) continue; sl@0: text++; sl@0: sl@0: for(;isspace(*text);text++); sl@0: char* orig_name = text; sl@0: if (*orig_name == '\"') sl@0: for(text = ++orig_name;*text && *text != '\"';text++); sl@0: else sl@0: for(;*text && !isspace(*text);text++); sl@0: if (*text == '\0') continue; sl@0: *text = '\0'; sl@0: sl@0: while(isspace(*++text)); sl@0: char* seg_name = text; sl@0: if (*seg_name == '\"') sl@0: for(text = ++seg_name;*text && *text != '\"';text++); sl@0: else sl@0: for(;*text && !isspace(*text);text++); sl@0: *text = '\0'; sl@0: if (*seg_name == '\0') continue; sl@0: sl@0: aNonXIP->AddObyNames(*seg_name == '\\' ? ++seg_name : seg_name, *orig_name == '\\' ? ++orig_name : orig_name); sl@0: } sl@0: } sl@0: