Esempio n. 1
0
Token* Scanner::GetSymbol(char currentChar) {
	string s = "";
	int pos = currentPos, line = currentLine;
	bool escapeDetector = false;
	currentChar = GetChar();
	s += currentChar;

	if(IsCharSeparator(currentChar))	throw ScannerException(currentLine, currentPos, "Empty character constant");
	if(IsEndOfLine(currentChar))		throw ScannerException(currentLine, currentPos, "Newline in character constant");
	if(IsTabulationSymbol(currentChar))	throw ScannerException(currentLine, currentPos, "Tabulation symbol in character constant");

	if(currentChar == '\\') {
		escapeDetector = true;
		s += (currentChar = GetChar());
		if(!IsEscapeSequence(currentChar)) 
			throw ScannerException(currentLine, currentPos, "Invalid ESCAPE-sequence: \"" + s + "\"");
	}

	if( IsCharSeparator(currentChar = GetChar()) )
		return new Token(line, pos, escapeDetector ? ESCAPE_SEQUENCE : CONST_CHAR, DEFAULT, s);
	else {
		s += currentChar;
		throw ScannerException(currentLine, currentPos, "Too many long character constant: \"" + s + "\"");
	}
}
Esempio n. 2
0
bool Scanner::Next() {
	char currentChar;
	do {
		if(lastString) {
			currentToken = new Token(currentLine, currentPos, END_OF_FILE, DEFAULT, "");
			return false;
		}
		currentChar = GetChar();
	}
	while(IsSpace(currentChar) || IsTabulationSymbol(currentChar) || IsEndOfLine(currentChar));

	if(IsCommentBegin(currentChar)) {
		char secondChar;
		if( IsCommentBegin(secondChar = GetChar()) ) {
			NextLine();
			return Next();
		}
		if(secondChar == '*') {
			while( GetChar() != '*' || !IsCommentBegin(GetChar()) ) {} 
			return Next();
		}
		else
			BackToPreviousChar();
	}
	if(IsLetter(currentChar))				currentToken = GetIdentificator(currentChar); else 
	if(IsNumber(currentChar))				currentToken = GetNumber(currentChar); else 
	if(IsCharSeparator(currentChar))		currentToken = GetSymbol(currentChar); else 
	if(IsStringSeparator(currentChar))		currentToken = GetString(currentChar); else 
	if(IsSeparator(currentChar))			currentToken = GetSeparator(currentChar); else 
	if(IsSpecialSymbol(currentChar))		currentToken = GetOperation(currentChar); else 
	throw ScannerException(currentLine, currentPos, "Indefinite character: \"" + string(1, currentChar) + "\"");

	return true;
}
Esempio n. 3
0
Token* Scanner::GetIdentificator(char currentChar) {
	string s = "";
	int pos = currentPos, line = currentLine;
	s += currentChar;

	while( !IsEndOfLine( currentChar = GetChar() ) && !IsSpace(currentChar) ) {
		if( IsLetter(currentChar) || IsNumber(currentChar) )
			s += currentChar;
		else {
			BackToPreviousChar();
			break;
		}
	}
	return new Token(line, pos, IsKeyWord(s) ? KEYWORD : IDENTIFIER, IsKeyWord(s) ? keyWord[s] : DEFAULT, s);
}
Esempio n. 4
0
Token* Scanner::GetOperation(char currentChar) {
	string s = "";
	char lastChar = currentChar;
	int pos = currentPos, line = currentLine;
	s += currentChar;
	currentChar = GetChar();

	if(!IsSpace(currentChar) && !IsTabulationSymbol(currentChar) && !IsEndOfLine(currentChar)) {
		if(IsOperation( string(1, lastChar) + string(1, currentChar) )) {
			s += currentChar;
		}
		else
			BackToPreviousChar();
	}
	return new Token(line, pos, OPERATOR, operation[s], s);
}
// -----------------------------------------------------------------------------
// CAknKeyRotatorImpl::SkipSpaces
// Goes over digits and returns that sequence.
// -----------------------------------------------------------------------------
//
TPtrC CAknKeyRotatorImpl::GetDigits( TLex& aLex )
    {
    // Mark current place and go over digits.
    aLex.Mark();
    while ( !aLex.Eos() && !IsEndOfLine( aLex.Peek() ) )
        {
        if ( aLex.Peek().IsDigit() )
            {
            aLex.Inc();
            }
        else
            {
            break;
            }
        }
    return aLex.MarkedToken();
    }
// -----------------------------------------------------------------------------
// CAknKeyRotatorImpl::SkipSpaces
// Skips over spaces.
// -----------------------------------------------------------------------------
//
TInt CAknKeyRotatorImpl::SkipSpaces( TLex& aLex )
    {
    TInt flags = 0;
    // Skip spaces, but stop at end of line.
    while ( !aLex.Eos() && !IsEndOfLine( aLex.Peek() ) )
        {
        if ( aLex.Peek().IsSpace() )
            {
            // There was a space, so ok for now.
            flags |= EAknWasSpace;
            aLex.Inc();
            }
        else
            {
            flags |= EAknWasCharacter;
            break;
            }
        }
    return flags;
    }
Esempio n. 7
0
// ---------------------------------------------------------
// TCodParser::AttrLineL()
// ---------------------------------------------------------
//
TBool TCodParser::AttrLineL(CMediaObjectData *& aMediaObject)
    {
    SkipWhiteSpace();  // Skip lines which contain only WS and LF at the end.
    while ( IsEndOfLine() )
        {
        NextLine();
        SkipWhiteSpace();
        }
    TBool ok( ETrue );
    if ( iCurP < iEndP )
        {
        // Still has something to read.
        switch( AttrName() )
            {
            case ECodName:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetNameL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodVendor:
                {
                if ( Colon() )
                    {
                    ok = iData->SetVendorL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodDescription:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetDescriptionL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodSize:
                {
                if ( Colon() )
                    {
                    // Parse as TUint - negative not allowed.
                    TUint size;
                    TLex lex( AttrValue() );
                    if ( !lex.Val( size ) )
                        {
                        aMediaObject->SetSize( size );
                        }
                    else
                        {
                        ok = EFalse;
                        }
                    EndOfLine();
                    }
                break;
                }

            case ECodInstallNotify:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetInstallNotifyL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodNextUrl:
                {
                if ( Colon() )
                    {
                    ok = iData->SetNextUrlL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodNextUrlAtError:
                {
                if ( Colon() )
                    {
                    ok = iData->SetNextUrlAtErrorL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodInfoUrl:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetInfoUrlL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodPrice:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetPriceL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodIcon:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetIconL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }
            case ECodType:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetTypeL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }
            case ECodUrl:
                {
                if ( Colon() )
                    {
                    ok = aMediaObject->SetUrlL( AttrValue() );
                    EndOfLine();
                    }
                break;
                }

            case ECodUnknownAttr:
                {
                // Name unknown; check colon anyway (syntax check).
                ok = Colon();
                // Rest of the line goes unchecked.
                break;
                }

            default:
                {
                // Unexpected value.
                CodPanic( ECodInternal );
                }

            }
        if ( !ok )
            {
            Error( KErrCodInvalidDescriptor );
            }
        NextLine();     // Step past LF.
        return ETrue;   // More lines to go.
        }
    else
        {
        // EOF reached; done.
        // Note: not expecting EOF in any other place than here (well-formed
        // COD has complete attrlines. If EOF is found some other place, it
        // is a syntax error.
        return EFalse;
        }
    }
// -----------------------------------------------------------------------------
// CAknKeyRotatorImpl::GetKeyRotatorCompensationL
// Parses wsini.ini to read key rotator compensation value.
// -----------------------------------------------------------------------------
//
TInt CAknKeyRotatorImpl::GetKeyRotatorCompensationL()
    {
    TInt result = 0;
    HBufC* wsiniText = GetWsiniLC();
    
    // Now look for keyword
    const TInt pos = wsiniText->Find( KAknKeyRotatorKey );
    if ( pos != KErrNotFound )
        {        
        // Keyword was found. Check that it is the beginning of line.
        // Three cases:
        // 1. Keyword could be at the beginning of the file.
        // 2. Keyword could be at the beginning of the file 
        //    after byte ordering marker.
        // 3. Previous character can be end of line marker.
        const TInt previousPos = pos - 1;
        if ( previousPos < 0 || 
             ( !previousPos && 
               IsByteOrderingMarker( (*wsiniText)[ previousPos ] ) ) || 
             IsEndOfLine( (*wsiniText)[ previousPos ] ) )
            {
            TLex text( wsiniText->Mid( pos + KAknKeyRotatorKey().Length() ) );
            
            // First, there must be at least a space after keyword.
            TBool fail = !( SkipSpaces( text ) & EAknWasSpace );
           
            // Case 1: Disabled
            TBool wasDisabled = EFalse;
            if ( !fail )
                {
                wasDisabled = 
                    !text.Remainder().Left( KAknKeyRotatorDisabled().Length() ).
                    CompareF( KAknKeyRotatorDisabled );

                if ( wasDisabled )
                    {
                    // wasDisabled == True, KAknKeyRotatorDisabled was prefix
                    // of text. So skip over it
                    text.Inc( KAknKeyRotatorDisabled().Length() );
                    }
                }
            
            // Case 2: Then follows a sequence of digits, optionally preceded by '-'.
            if ( !wasDisabled && !fail )
                {
                // Check optional -
                TBool negate = EFalse;
                if ( !text.Eos() && text.Peek() == '-' )
                    {
                    negate = ETrue;
                    text.Inc();
                    }
                    
                // Get digit sequence and convert to integer value.
                TPtrC token = GetDigits( text );
                fail = !token.Length() || 
                       ( TLex( token ).Val( result ) != KErrNone );
                
                // Handle negation
                if ( !fail && negate )
                    {
                    result = -result;
                    }
                }

            // That sequence of digits is followed by sequence of spaces until
            // end of line or end of file.
            fail = fail || ( SkipSpaces( text ) & EAknWasCharacter );
            
            if ( !wasDisabled )
                {
                // Finally, that sequence of digits must represent
                // one valid decimal value of the following: 
                // -270, -180, -90, 0, 90, 180, 270.
                fail = fail || !CheckCompensationValue( result );
                }
                
            // If any of above checks failed, use default value 0.
            if ( fail )
                {
                result = 0;
                }
            else
                {
                if ( wasDisabled )
                    {
                    result = KMaxTInt;
                    }
                }
            }
        }
        
    CleanupStack::PopAndDestroy( wsiniText );   
    return result;
    }