imgtools/romtools/rofsbuild/src/logging/logparser.cpp
author lorewang
Mon, 22 Nov 2010 10:41:57 +0800
changeset 699 9ca650050cf0
parent 691 9eeecb73a5d4
permissions -rw-r--r--
ou1cimx1#656196 one line message of ROM tools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     1
/*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     8
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    11
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    12
* Contributors:
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    13
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    14
* Description:
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    15
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    16
*/
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    17
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    18
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    19
#include <new>
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    20
#include <iostream>
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    21
#include <fstream>
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    22
#include <string>
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    23
using namespace std;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    24
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    25
#include "logging/loggingexception.hpp"
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    26
#include "logging/logparser.hpp"
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    27
#include "symbolgenerator.h"
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    28
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    29
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    30
LogParser* LogParser::Only = (LogParser*)0;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    31
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    32
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    33
LogParser* LogParser::GetInstance(void) throw (LoggingException)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    34
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    35
	if(! LogParser::Only)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    36
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    37
		LogParser::Only = new (std::nothrow) LogParser();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    38
		if(! LogParser::Only)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    39
			throw LoggingException(LoggingException::RESOURCE_ALLOCATION_FAILURE);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    40
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    41
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    42
	return LogParser::Only;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    43
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    44
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    45
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    46
void LogParser::ParseSymbol(const char* LogFilename) throw (LoggingException)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    47
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    48
	string linebuf;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    49
	SymbolGenerator* symgen = SymbolGenerator::GetInstance();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    50
	symgen->SetSymbolFileName(string(LogFilename));
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    51
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    52
	ifstream logfd(LogFilename);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    53
	if(logfd.is_open())
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    54
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    55
		while(! logfd.eof())
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    56
		{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    57
			getline(logfd, linebuf);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    58
			if(linebuf.compare(0,4,"File") == 0)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    59
			{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    60
				if(linebuf.find("size:", 4) != string::npos)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    61
				{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    62
					size_t startpos = linebuf.find('\'') ;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    63
					size_t endpos   = linebuf.rfind('\'');
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    64
					if((startpos!=string::npos) && (endpos!=string::npos))
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    65
					{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    66
						symgen->AddFile(linebuf.substr(startpos+1,endpos-startpos-1), false);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    67
					}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    68
				}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    69
			}
691
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    70
			else if(linebuf.compare(0,15,"Executable File") == 0)
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    71
			{
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    72
				if(linebuf.find("size:", 26) != string::npos)
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    73
				{
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    74
					size_t startpos = linebuf.find('\'') ;
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    75
					size_t endpos   = linebuf.rfind('\'');
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    76
					if((startpos!=string::npos) && (endpos!=string::npos))
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    77
					{
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    78
						symgen->AddFile(linebuf.substr(startpos+1,endpos-startpos-1), true);
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    79
					}
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    80
				}
9eeecb73a5d4 fix ou1cimx1#651819
marvin shi <marvin.shi@nokia.com>
parents: 654
diff changeset
    81
			}
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    82
			else if(linebuf.compare(0,26,"Compressed executable File") == 0)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    83
			{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    84
				if(linebuf.find("size:", 26) != string::npos)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    85
				{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    86
					size_t startpos = linebuf.find('\'') ;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    87
					size_t endpos   = linebuf.rfind('\'');
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    88
					if((startpos!=string::npos) && (endpos!=string::npos))
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    89
					{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    90
						symgen->AddFile(linebuf.substr(startpos+1,endpos-startpos-1), true);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    91
					}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    92
				}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    93
			}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    94
		}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    95
		symgen->SetFinished();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    96
		symgen->Release();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    97
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    98
	else
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    99
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   100
		throw LoggingException(LoggingException::INVALID_LOG_FILENAME);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   101
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   102
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   103
	return;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   104
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   105
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   106
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   107
void LogParser::Cleanup(void)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   108
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   109
	return;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   110
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   111
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   112
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   113
LogParser::LogParser(void)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   114
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   115
	return;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   116
}