e32tools/elf2e32/source/deffile.h
author Zheng Shen <zheng.shen@nokia.com>
Wed, 13 Oct 2010 16:31:27 +0800
changeset 648 d5a8d436d33b
parent 0 044383f39525
permissions -rw-r--r--
Merge

// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// Implementation of the Class DefFile for the elf2e32 tool
// @internalComponent
// @released
// 
//

#ifndef _DEF_FILE_
#define _DEF_FILE_

#include <list>

class Symbol;
typedef std::list <Symbol*>	SymbolList;

/**
Class for DEF File Handler.
@internalComponent
@released
*/
class DefFile
{
	public:
		DefFile():iSymbolList(NULL){};
		virtual ~DefFile();
		SymbolList* ReadDefFile(char *defFile);
		void WriteDefFile(char *fileName, SymbolList *newSymbolList);
		SymbolList* GetSymbolEntryList(char *defFile);
		SymbolList* GetSymbolEntryList() { return iSymbolList;}
	private:
		char *iFileName;
		SymbolList *iSymbolList;
		int GetFileSize(FILE * fptrDef);
		char* OpenDefFile(char *defFile);
		void ParseDefFile(char *defData);
		bool Tokenize(char* tokens, int aLineNum, Symbol& aSymbol);
};

//Different states while parsing a line in the def file.
enum DefStates
{
	EInitState = 0,
	ESymbolName = 1,
	EAtSymbol,
	EOrdinal,
	EOptionals,
	EComment,
	EFinalState,
	EInvalidState
};

#define CODESYM "CODE"
#define DATASYM "DATA"

/**
Class for parsing a line from the DEF File.
@internalComponent
@released
*/
class LineToken
{
public:
	LineToken(char* , int , char *, Symbol *aSym);
	char *iLine;
	Symbol *iSymbol;
	int iOffset;
	DefStates iState;
	
	char *iFileName;
	int iLineNum;

	bool Tokenize();
	void NextToken();
	void IncrOffset(int aOff);
	void SetState(DefStates aState);

	bool IsWhiteSpace(char *aStr, int&);
	bool IsPattern(char*, int&, int&);
	bool IsDigit(char*, int&);
	bool IsWord(char*, int&);
};
#endif