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 .
27 #include <rschash.hxx>
35 #include <rscyacc.hxx>
37 #include <rtl/textcvt.h>
38 #include <rtl/textenc.h>
41 const char* StringContainer::putString( const char* pString
)
43 OString
aString( static_cast<const sal_Char
*>(pString
) );
45 std::unordered_set
< OString
, OStringHash
>::iterator
,
47 m_aStrings
.insert( aString
);
49 return aInsert
.first
->getStr();
53 bool bLastInclude
;// War letztes Symbol INCLUDE
64 StringContainer
* pStringContainer
= NULL
;
67 sal_uInt32
GetNumber()
74 c
= pFI
->GetFastChar();
78 c
= pFI
->GetFastChar();
84 while( isxdigit( c
) )
87 l
= l
* nLog
+ (c
- '0');
89 l
= l
* nLog
+ (toupper( c
) - 'A' + 10 );
91 c
= pFI
->GetFastChar();
96 while( isdigit( c
) || 'x' == c
)
98 l
= l
* nLog
+ (c
- '0');
99 c
= pFI
->GetFastChar();
103 while( c
=='U' || c
=='u' || c
=='l' || c
=='L' ) //Wg. Unsigned Longs
104 c
= pFI
->GetFastChar();
106 if( l
> 0x7fffffff ) //Oberstes bit gegebenenfalls abschneiden;
112 int MakeToken( YYSTYPE
* pTokenVal
)
116 while( true ) // Kommentare und Leerzeichen ueberlesen
118 while( isspace( c
) )
119 c
= pFI
->GetFastChar();
124 c
= pFI
->GetFastChar();
127 while( '\n' != c
&& !pFI
->IsEof() )
128 c
= pFI
->GetFastChar();
130 c
= pFI
->GetFastChar();
134 c
= pFI
->GetFastChar();
137 while( '*' != c
&& !pFI
->IsEof() )
138 c
= pFI
->GetFastChar();
140 c
= pFI
->GetFastChar();
142 while( '/' != c
&& !pFI
->IsEof() );
143 c
= pFI
->GetFastChar();
152 // FIXME: wtf is this supposed to do?
153 if( (c
!= 0) == pFI
->IsEof() )
160 bLastInclude
= false; //Zuruecksetzten
163 OStringBuffer
aBuf( 256 );
164 c
= pFI
->GetFastChar();
165 while( '>' != c
&& !pFI
->IsEof() )
167 aBuf
.append( sal_Char(c
) );
168 c
= pFI
->GetFastChar();
170 c
= pFI
->GetFastChar();
171 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
172 return INCLUDE_STRING
;
178 OStringBuffer
aBuf( 256 );
180 while( !bDone
&& !pFI
->IsEof() && c
)
182 c
= pFI
->GetFastChar();
187 c
= pFI
->GetFastChar();
189 while( c
== ' ' || c
== '\t' );
193 // this is a continued string
194 // note: multiline string continuations are handled by the parser
203 c
= pFI
->GetFastChar();
205 aBuf
.append( sal_Char(c
) );
208 aBuf
.append( sal_Char(c
) );
210 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
215 pTokenVal
->value
= GetNumber();
219 if( isalpha (c
) || (c
== '_') )
222 OStringBuffer
aBuf( 256 );
224 while( isalnum (c
) || (c
== '_') || (c
== '-') )
226 aBuf
.append( sal_Char(c
) );
227 c
= pFI
->GetFastChar();
230 nHashId
= pHS
->getID( aBuf
.getStr(), true );
231 if( InvalidAtom
!= nHashId
)
235 // Suche nach dem Schluesselwort
236 if( pTC
->aNmTb
.Get( nHashId
, &aKey
) )
239 // Schluesselwort gefunden
243 pTokenVal
->pClass
= reinterpret_cast<RscTop
*>(aKey
.yylval
);
246 pTokenVal
->varid
= aKey
.nName
;
249 pTokenVal
->constname
.hashid
= aKey
.nName
;
250 pTokenVal
->constname
.nValue
= aKey
.yylval
;
253 pTokenVal
->svbool
= (bool)aKey
.yylval
;
259 pTokenVal
->value
= aKey
.yylval
;
266 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
275 pDef
= pTC
->aFileTab
.FindDef( aBuf
.getStr() );
278 pTokenVal
->defineele
= pDef
;
283 pTokenVal
->string
= const_cast<char*>(pStringContainer
->putString( aBuf
.getStr() ));
290 c
= pFI
->GetFastChar();
293 c
= pFI
->GetFastChar();
302 c
= pFI
->GetFastChar();
305 c
= pFI
->GetFastChar();
313 c
= pFI
->GetFastChar();
320 bTargetDefined
= false;
322 aKeyVal
[ 0 ].nKeyWord
= MakeToken( &aKeyVal
[ 0 ].aYYSType
);
324 yylval
= aKeyVal
[ 0 ].aYYSType
;
325 return aKeyVal
[ 0 ].nKeyWord
;
329 extern "C" void yyerror( const char* pMessage
)
331 void yyerror( char* pMessage
)
334 pTC
->pEH
->Error( ERR_YACC
, NULL
, RscId(), pMessage
);
337 void InitParser( RscFileInst
* pFileInst
)
339 pTC
= pFileInst
->pTypCont
; // Datenkontainer setzten
341 pStringContainer
= new StringContainer();
342 pExp
= NULL
; //fuer MacroParser
343 bTargetDefined
= false;
345 // Anfangszeichen initialisieren
346 bLastInclude
= false;
347 c
= pFI
->GetFastChar();
353 while( ! S
.IsEmpty() )
356 // free string container
357 delete pStringContainer
;
358 pStringContainer
= NULL
;
368 void IncludeParser( RscFileInst
* pFileInst
)
370 int nToken
; // Wert des Tokens
371 YYSTYPE aYYSType
; // Daten des Tokens
372 RscFile
* pFName
; // Filestruktur
373 sal_uLong lKey
; // Fileschluessel
374 RscTypCont
* pTypCon
= pFileInst
->pTypCont
;
376 pFName
= pTypCon
->aFileTab
.Get( pFileInst
->GetFileIndex() );
377 InitParser( pFileInst
);
379 nToken
= MakeToken( &aYYSType
);
380 while( 0 != nToken
&& CLASSNAME
!= nToken
)
384 if( INCLUDE
== (nToken
= MakeToken( &aYYSType
)) )
386 if( STRING
== (nToken
= MakeToken( &aYYSType
)) )
388 lKey
= pTypCon
->aFileTab
.NewIncFile( aYYSType
.string
,
390 pFName
->InsertDependFile( lKey
, ULONG_MAX
);
392 else if( INCLUDE_STRING
== nToken
)
394 lKey
= pTypCon
->aFileTab
.NewIncFile( aYYSType
.string
,
396 pFName
->InsertDependFile( lKey
, ULONG_MAX
);
400 nToken
= MakeToken( &aYYSType
);
406 ERRTYPE
parser( RscFileInst
* pFileInst
)
410 InitParser( pFileInst
);
416 // yyparser gibt 0 zurueck, wenn erfolgreich
419 if( pFileInst
->pTypCont
->pEH
->nErrors
)
421 pFileInst
->SetError( aError
);
425 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */