os/graphics/graphicstools/bitmapfonttools/src/READER.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstools/bitmapfonttools/src/READER.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,168 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Header READER.CPP
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#include "READER.H"
    1.24 +
    1.25 +Reader::Reader()
    1.26 +	{
    1.27 +	iLexAnal = NULL;
    1.28 +	}
    1.29 +
    1.30 +boolean Reader::Open(const String& aFilename)
    1.31 +	{
    1.32 +	boolean state;
    1.33 +	String string = aFilename;
    1.34 +	if (iLexAnal != NULL)
    1.35 +		delete iLexAnal;
    1.36 +	iLexAnal = new LexAnal(string.Text());
    1.37 +
    1.38 +	if (iLexAnal)
    1.39 +		{
    1.40 +		state = etrue;
    1.41 +		iLex =& (iLexAnal->iLex);
    1.42 +		iLexAnal->Read();	// reads first lexical
    1.43 +		}
    1.44 +	else
    1.45 +		state = efalse;
    1.46 +
    1.47 +	return state;
    1.48 +	}
    1.49 +
    1.50 +Reader::~Reader()
    1.51 +	{
    1.52 +	if (iLexAnal != NULL)
    1.53 +		delete iLexAnal;
    1.54 +	}
    1.55 +
    1.56 +boolean Reader::_EOF()
    1.57 +	{
    1.58 +	return ((iLex->iType) == ELexEOF);
    1.59 +	}
    1.60 +
    1.61 +boolean Reader::NewLine()
    1.62 +	{
    1.63 +	boolean state;
    1.64 +	if (iLex->iType == ELexNL)
    1.65 +		{
    1.66 +		iLexAnal->Read();
    1.67 +		state = etrue;
    1.68 +		}
    1.69 +	else
    1.70 +		{
    1.71 +		Error(String("Newline expected"));
    1.72 +		state = efalse;
    1.73 +		}
    1.74 +	return state;
    1.75 +	}
    1.76 +
    1.77 +boolean Reader::Number(int& aNumber)
    1.78 +	{
    1.79 +	boolean state;
    1.80 +	if (iLex->iType == ELexNumber)
    1.81 +		{
    1.82 +		aNumber = iLex->iNumber;
    1.83 +		iLexAnal->Read();
    1.84 +		state = etrue;
    1.85 +		}
    1.86 +	else
    1.87 +		{
    1.88 +		Error(String("Number expected"));
    1.89 +		state = efalse;
    1.90 +		}
    1.91 +	return state;
    1.92 +	}
    1.93 +
    1.94 +boolean Reader::IdentComp(const String& aIdent)
    1.95 +	{
    1.96 +	boolean state;
    1.97 +	if (iLex->iType == ELexIdent)
    1.98 +		{
    1.99 +		if (aIdent == iLex->iText)
   1.100 +			{
   1.101 +			iLexAnal->Read();
   1.102 +			state = etrue;
   1.103 +			}
   1.104 +		else
   1.105 +			state = efalse;
   1.106 +		}
   1.107 +	else
   1.108 +		{
   1.109 +		state = efalse;
   1.110 +		}
   1.111 +	return state;
   1.112 +	}
   1.113 +
   1.114 +boolean Reader::IdentCopy(String& aIdent)
   1.115 +	{
   1.116 +	boolean state;
   1.117 +	if (iLex->iType == ELexIdent)
   1.118 +		{
   1.119 +		aIdent = iLex->iText;
   1.120 +		iLexAnal->Read();
   1.121 +		state = etrue;
   1.122 +		}
   1.123 +	else
   1.124 +		{
   1.125 +		Error(String("Identifier expected"));
   1.126 +		state = efalse;
   1.127 +		}
   1.128 +	return state;
   1.129 +	}
   1.130 +
   1.131 +boolean Reader::StringCopy(String& aString)
   1.132 +	{
   1.133 +	boolean state;
   1.134 +	if (iLex->iType == ELexString)
   1.135 +		{
   1.136 +		aString = iLex->iText;
   1.137 +		iLexAnal->Read();
   1.138 +		state = etrue;
   1.139 +		}
   1.140 +	else
   1.141 +		{
   1.142 +		Error(String("String expected"));
   1.143 +		state = efalse;
   1.144 +		}
   1.145 +	return state;
   1.146 +	}
   1.147 +
   1.148 +boolean Reader::Operator(char& aCh)
   1.149 +	{
   1.150 +	boolean state;
   1.151 +	if (iLex->iType == ELexOperator)
   1.152 +		{
   1.153 +		aCh = iLex->iText[0];
   1.154 +		iLexAnal->Read();
   1.155 +		state = etrue;
   1.156 +		}
   1.157 +	else
   1.158 +		{
   1.159 +		Error(String("Operator expected"));
   1.160 +		state = efalse;
   1.161 +		}
   1.162 +	return state;
   1.163 +	}
   1.164 +
   1.165 +EXPORT_C void Reader::Error(const String& aString)
   1.166 +	{
   1.167 +	cerr << "Error: " << aString;
   1.168 +	iLexAnal->Report();
   1.169 +	while ((iLex->iType != ELexNL) && (iLex->iType != ELexEOF))
   1.170 +		iLexAnal->Read();
   1.171 +	}