1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
29 #include <rschash.hxx>
37 #include <rscyacc.hxx>
39 #include <rtl/textcvt.h>
40 #include <rtl/textenc.h>
43 const char* StringContainer::putString( const char* pString
)
45 OString
aString( static_cast<const sal_Char
*>(pString
) );
47 boost::unordered_set
< OString
, OStringHash
>::iterator
,
49 m_aStrings
.insert( aString
);
51 return aInsert
.first
->getStr();
55 sal_Bool bLastInclude
;// War letztes Symbol INCLUDE
63 sal_Bool bTargetDefined
;
65 StringContainer
* pStringContainer
= NULL
;
68 sal_uInt32
GetNumber(){
73 c
= pFI
->GetFastChar();
76 c
= pFI
->GetFastChar();
81 while( isxdigit( c
) ){
83 l
= l
* nLog
+ (c
- '0');
85 l
= l
* nLog
+ (toupper( c
) - 'A' + 10 );
86 c
= pFI
->GetFastChar();
90 while( isdigit( c
) || 'x' == c
){
91 l
= l
* nLog
+ (c
- '0');
92 c
= pFI
->GetFastChar();
96 while( c
=='U' || c
=='u' || c
=='l' || c
=='L' ) //Wg. Unsigned Longs
97 c
= pFI
->GetFastChar();
99 if( l
> 0x7fffffff ) //Oberstes bit gegebenenfalls abschneiden;
105 int MakeToken( YYSTYPE
* pTokenVal
){
108 while( true ){ // Kommentare und Leerzeichen ueberlesen
109 while( isspace( c
) )
110 c
= pFI
->GetFastChar();
113 c
= pFI
->GetFastChar();
115 while( '\n' != c
&& !pFI
->IsEof() )
116 c
= pFI
->GetFastChar();
117 c
= pFI
->GetFastChar();
120 c
= pFI
->GetFastChar();
122 while( '*' != c
&& !pFI
->IsEof() )
123 c
= pFI
->GetFastChar();
124 c
= pFI
->GetFastChar();
125 } while( '/' != c
&& !pFI
->IsEof() );
126 c
= pFI
->GetFastChar();
135 if( c
== pFI
->IsEof() ){
140 bLastInclude
= sal_False
; //Zuruecksetzten
142 OStringBuffer
aBuf( 256 );
143 c
= pFI
->GetFastChar();
144 while( '>' != c
&& !pFI
->IsEof() )
146 aBuf
.append( sal_Char(c
) );
147 c
= pFI
->GetFastChar();
149 c
= pFI
->GetFastChar();
150 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
151 return( INCLUDE_STRING
);
157 OStringBuffer
aBuf( 256 );
158 sal_Bool bDone
= sal_False
;
159 while( !bDone
&& !pFI
->IsEof() && c
)
161 c
= pFI
->GetFastChar();
166 c
= pFI
->GetFastChar();
168 while( c
== ' ' || c
== '\t' );
171 // this is a continued string
172 // note: multiline string continuations are handled by the parser
181 c
= pFI
->GetFastChar();
183 aBuf
.append( sal_Char(c
) );
186 aBuf
.append( sal_Char(c
) );
188 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
192 pTokenVal
->value
= GetNumber();
196 if( isalpha (c
) || (c
== '_') ){
198 OStringBuffer
aBuf( 256 );
200 while( isalnum (c
) || (c
== '_') || (c
== '-') )
202 aBuf
.append( sal_Char(c
) );
203 c
= pFI
->GetFastChar();
206 nHashId
= pHS
->getID( aBuf
.getStr(), true );
207 if( InvalidAtom
!= nHashId
)
211 // Suche nach dem Schluesselwort
212 if( pTC
->aNmTb
.Get( nHashId
, &aKey
) )
215 // Schluesselwort gefunden
219 pTokenVal
->pClass
= (RscTop
*)aKey
.yylval
;
222 pTokenVal
->varid
= aKey
.nName
;
225 pTokenVal
->constname
.hashid
= aKey
.nName
;
226 pTokenVal
->constname
.nValue
= aKey
.yylval
;
229 pTokenVal
->svbool
= (sal_Bool
)aKey
.yylval
;
232 bLastInclude
= sal_True
;
234 pTokenVal
->value
= aKey
.yylval
;
241 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
248 pDef
= pTC
->aFileTab
.FindDef( aBuf
.getStr() );
250 pTokenVal
->defineele
= pDef
;
255 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
262 c
= pFI
->GetFastChar();
265 c
= pFI
->GetFastChar();
274 c
= pFI
->GetFastChar();
277 c
= pFI
->GetFastChar();
285 c
= pFI
->GetFastChar();
289 #if defined( RS6000 )
290 extern "C" int yylex()
296 bTargetDefined
= sal_False
;
298 aKeyVal
[ 0 ].nKeyWord
=
299 MakeToken( &aKeyVal
[ 0 ].aYYSType
);
301 yylval
= aKeyVal
[ 0 ].aYYSType
;
302 return( aKeyVal
[ 0 ].nKeyWord
);
306 extern "C" void yyerror( char* pMessage
)
307 #elif defined SOLARIS
308 extern "C" void yyerror( const char* pMessage
)
310 void yyerror( char* pMessage
)
313 pTC
->pEH
->Error( ERR_YACC
, NULL
, RscId(), pMessage
);
316 void InitParser( RscFileInst
* pFileInst
)
318 pTC
= pFileInst
->pTypCont
; // Datenkontainer setzten
320 pStringContainer
= new StringContainer();
321 pExp
= NULL
; //fuer MacroParser
322 bTargetDefined
= sal_False
;
324 // Anfangszeichen initialisieren
325 bLastInclude
= sal_False
;
326 c
= pFI
->GetFastChar();
331 while( ! S
.IsEmpty() )
334 // free string container
335 delete pStringContainer
;
336 pStringContainer
= NULL
;
346 void IncludeParser( RscFileInst
* pFileInst
)
348 int nToken
; // Wert des Tokens
349 YYSTYPE aYYSType
; // Daten des Tokens
350 RscFile
* pFName
; // Filestruktur
351 sal_uLong lKey
; // Fileschluessel
352 RscTypCont
* pTypCon
= pFileInst
->pTypCont
;
354 pFName
= pTypCon
->aFileTab
.Get( pFileInst
->GetFileIndex() );
355 InitParser( pFileInst
);
357 nToken
= MakeToken( &aYYSType
);
358 while( 0 != nToken
&& CLASSNAME
!= nToken
){
360 if( INCLUDE
== (nToken
= MakeToken( &aYYSType
)) ){
361 if( STRING
== (nToken
= MakeToken( &aYYSType
)) ){
362 lKey
= pTypCon
->aFileTab
.NewIncFile( aYYSType
.string
,
364 pFName
->InsertDependFile( lKey
, ULONG_MAX
);
366 else if( INCLUDE_STRING
== nToken
){
367 lKey
= pTypCon
->aFileTab
.NewIncFile( aYYSType
.string
,
369 pFName
->InsertDependFile( lKey
, ULONG_MAX
);
373 nToken
= MakeToken( &aYYSType
);
379 ERRTYPE
parser( RscFileInst
* pFileInst
)
383 InitParser( pFileInst
);
389 // yyparser gibt 0 zurueck, wenn erfolgreich
392 if( pFileInst
->pTypCont
->pEH
->nErrors
)
394 pFileInst
->SetError( aError
);
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */