1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rsclex.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
42 #include <rschash.hxx>
50 #include <yyrscyacc.hxx>
52 #include <rtl/textcvt.h>
53 #include <rtl/textenc.h>
57 const char* StringContainer::putString( const char* pString
)
59 OString
aString( static_cast<const sal_Char
*>(pString
) );
61 std::hash_set
< OString
, OStringHash
>::iterator
,
63 m_aStrings
.insert( aString
);
65 return aInsert
.first
->getStr();
68 /*************************************************************************/
70 BOOL bLastInclude
;// War letztes Symbol INCLUDE
80 StringContainer
* pStringContainer
= NULL
;
83 /****************** C O D E **********************************************/
89 c
= pFI
->GetFastChar();
92 c
= pFI
->GetFastChar();
97 while( isxdigit( c
) ){
99 l
= l
* nLog
+ (c
- '0');
101 l
= l
* nLog
+ (toupper( c
) - 'A' + 10 );
102 c
= pFI
->GetFastChar();
106 while( isdigit( c
) || 'x' == c
){
107 l
= l
* nLog
+ (c
- '0');
108 c
= pFI
->GetFastChar();
112 while( c
=='U' || c
=='u' || c
=='l' || c
=='L' ) //Wg. Unsigned Longs
113 c
= pFI
->GetFastChar();
115 if( l
> 0x7fffffff ) //Oberstes bit gegebenenfalls abschneiden;
121 int MakeToken( YYSTYPE
* pTokenVal
){
125 while( TRUE
){ // Kommentare und Leerzeichen ueberlesen
126 while( isspace( c
) )
127 c
= pFI
->GetFastChar();
130 c
= pFI
->GetFastChar();
132 while( '\n' != c
&& !pFI
->IsEof() )
133 c
= pFI
->GetFastChar();
134 c
= pFI
->GetFastChar();
137 c
= pFI
->GetFastChar();
139 while( '*' != c
&& !pFI
->IsEof() )
140 c
= pFI
->GetFastChar();
141 c
= pFI
->GetFastChar();
142 } while( '/' != c
&& !pFI
->IsEof() );
143 c
= pFI
->GetFastChar();
152 if( c
== pFI
->IsEof() ){
157 bLastInclude
= FALSE
; //Zuruecksetzten
159 OStringBuffer
aBuf( 256 );
160 c
= pFI
->GetFastChar();
161 while( '>' != c
&& !pFI
->IsEof() )
163 aBuf
.append( sal_Char(c
) );
164 c
= pFI
->GetFastChar();
166 c
= pFI
->GetFastChar();
167 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
168 return( INCLUDE_STRING
);
174 OStringBuffer
aBuf( 256 );
176 while( !bDone
&& !pFI
->IsEof() && c
)
178 c
= pFI
->GetFastChar();
181 c
= pFI
->GetFastChar();
193 c
= pFI
->GetFastChar();
195 aBuf
.append( sal_Char(c
) );
198 aBuf
.append( sal_Char(c
) );
200 pStr
= pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
204 pTokenVal
->value
= GetNumber();
208 if( isalpha (c
) || (c
== '_') ){
210 OStringBuffer
aBuf( 256 );
212 while( isalnum (c
) || (c
== '_') || (c
== '-') )
214 aBuf
.append( sal_Char(c
) );
215 c
= pFI
->GetFastChar();
218 nHashId
= pHS
->getID( aBuf
.getStr(), true );
219 if( InvalidAtom
!= nHashId
)
223 // Suche nach dem Schluesselwort
224 if( pTC
->aNmTb
.Get( nHashId
, &aKey
) )
227 // Schluesselwort gefunden
231 pTokenVal
->pClass
= (RscTop
*)aKey
.yylval
;
234 pTokenVal
->varid
= aKey
.nName
;
237 pTokenVal
->constname
.hashid
= aKey
.nName
;
238 pTokenVal
->constname
.nValue
= aKey
.yylval
;
241 pTokenVal
->svbool
= (BOOL
)aKey
.yylval
;
246 pTokenVal
->value
= aKey
.yylval
;
253 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
260 pDef
= pTC
->aFileTab
.FindDef( aBuf
.getStr() );
262 pTokenVal
->defineele
= pDef
;
267 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
274 c
= pFI
->GetFastChar();
277 c
= pFI
->GetFastChar();
286 c
= pFI
->GetFastChar();
289 c
= pFI
->GetFastChar();
297 c
= pFI
->GetFastChar();
301 #if defined( RS6000 ) || defined( HP9000 ) || defined( SCO )
302 extern "C" int yylex()
308 bTargetDefined
= FALSE
;
310 aKeyVal
[ 0 ].nKeyWord
=
311 MakeToken( &aKeyVal
[ 0 ].aYYSType
);
313 yylval
= aKeyVal
[ 0 ].aYYSType
;
314 return( aKeyVal
[ 0 ].nKeyWord
);
317 /****************** yyerror **********************************************/
319 extern "C" void yyerror( char* pMessage
)
320 #elif defined HP9000 || defined SCO || defined IRIX || defined SOLARIS
321 extern "C" void yyerror( const char* pMessage
)
323 void yyerror( char* pMessage
)
326 pTC
->pEH
->Error( ERR_YACC
, NULL
, RscId(), pMessage
);
329 /****************** parser start function ********************************/
330 void InitParser( RscFileInst
* pFileInst
)
332 pTC
= pFileInst
->pTypCont
; // Datenkontainer setzten
334 pStringContainer
= new StringContainer();
335 pExp
= NULL
; //fuer MacroParser
336 bTargetDefined
= FALSE
;
338 // Anfangszeichen initialisieren
339 bLastInclude
= FALSE
;
340 c
= pFI
->GetFastChar();
345 while( ! S
.IsEmpty() )
348 // free string container
349 delete pStringContainer
;
350 pStringContainer
= NULL
;
360 void IncludeParser( RscFileInst
* pFileInst
)
362 int nToken
; // Wert des Tokens
363 YYSTYPE aYYSType
; // Daten des Tokens
364 RscFile
* pFName
; // Filestruktur
365 ULONG lKey
; // Fileschluessel
366 RscTypCont
* pTypCon
= pFileInst
->pTypCont
;
368 pFName
= pTypCon
->aFileTab
.Get( pFileInst
->GetFileIndex() );
369 InitParser( pFileInst
);
371 nToken
= MakeToken( &aYYSType
);
372 while( 0 != nToken
&& CLASSNAME
!= nToken
){
374 if( INCLUDE
== (nToken
= MakeToken( &aYYSType
)) ){
375 if( STRING
== (nToken
= MakeToken( &aYYSType
)) ){
376 lKey
= pTypCon
->aFileTab
.NewIncFile( aYYSType
.string
,
378 pFName
->InsertDependFile( lKey
, LIST_APPEND
);
380 else if( INCLUDE_STRING
== nToken
){
381 lKey
= pTypCon
->aFileTab
.NewIncFile( aYYSType
.string
,
383 pFName
->InsertDependFile( lKey
, LIST_APPEND
);
387 nToken
= MakeToken( &aYYSType
);
393 ERRTYPE
parser( RscFileInst
* pFileInst
)
397 InitParser( pFileInst
);
403 // yyparser gibt 0 zurueck, wenn erfolgreich
406 if( pFileInst
->pTypCont
->pEH
->nErrors
)
408 pFileInst
->SetError( aError
);
412 RscExpression
* MacroParser( RscFileInst
& rFileInst
)
415 RscExpression
* pExpression
;
417 InitParser( &rFileInst
);
419 //Ziel auf macro_expression setzen
420 aKeyVal
[ 0 ].nKeyWord
= MACROTARGET
;
421 bTargetDefined
= TRUE
;
425 //EndParser() wuerde pExp loeschen
431 // yyparser gibt 0 zurueck, wenn erfolgreich
434 if( rFileInst
.pTypCont
->pEH
->nErrors
)
436 rFileInst
.SetError( aError
);
438 //im Fehlerfall pExpression loeschen
439 if( aError
.IsError() && pExpression
){
443 return( pExpression
);