Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <stdlib.h>
21 : #include <stdio.h>
22 : #include <string.h>
23 : #include <ctype.h>
24 : #include <limits.h>
25 :
26 : #ifdef _RSCERROR_H
27 : #include <rscerror.h>
28 : #endif
29 : #include <rschash.hxx>
30 : #include <rscdb.hxx>
31 : #include <rsctop.hxx>
32 : #include <rsckey.hxx>
33 : #include <rscpar.hxx>
34 : #include <rscdef.hxx>
35 :
36 : #include <rsclex.hxx>
37 : #include <rscyacc.hxx>
38 :
39 : #include <rtl/textcvt.h>
40 : #include <rtl/textenc.h>
41 :
42 :
43 85173 : const char* StringContainer::putString( const char* pString )
44 : {
45 85173 : OString aString( static_cast<const sal_Char*>(pString) );
46 : std::pair<
47 : boost::unordered_set< OString, OStringHash >::iterator,
48 : bool > aInsert =
49 85173 : m_aStrings.insert( aString );
50 :
51 85173 : return aInsert.first->getStr();
52 : }
53 :
54 : int c;
55 : bool bLastInclude;// War letztes Symbol INCLUDE
56 : RscFileInst* pFI;
57 : RscTypCont* pTC;
58 : RscExpression * pExp;
59 : struct KeyVal
60 : {
61 : int nKeyWord;
62 : YYSTYPE aYYSType;
63 : } aKeyVal[ 1 ];
64 : bool bTargetDefined;
65 :
66 : StringContainer* pStringContainer = NULL;
67 :
68 :
69 162526 : sal_uInt32 GetNumber()
70 : {
71 162526 : sal_uInt32 l = 0;
72 162526 : sal_uInt32 nLog = 10;
73 :
74 162526 : if( '0' == c )
75 : {
76 5947 : c = pFI->GetFastChar();
77 5947 : if( 'x' == c )
78 : {
79 1958 : nLog = 16;
80 1958 : c = pFI->GetFastChar();
81 : }
82 : };
83 :
84 162526 : if( nLog == 16 )
85 : {
86 11960 : while( isxdigit( c ) )
87 : {
88 8044 : if( isdigit( c ) )
89 4127 : l = l * nLog + (c - '0');
90 : else
91 3917 : l = l * nLog + (toupper( c ) - 'A' + 10 );
92 :
93 8044 : c = pFI->GetFastChar();
94 : }
95 : }
96 : else
97 : {
98 710554 : while( isdigit( c ) || 'x' == c )
99 : {
100 389418 : l = l * nLog + (c - '0');
101 389418 : c = pFI->GetFastChar();
102 : }
103 : }
104 :
105 327424 : while( c=='U' || c=='u' || c=='l' || c=='L' ) //Wg. Unsigned Longs
106 2372 : c = pFI->GetFastChar();
107 :
108 162526 : if( l > 0x7fffffff ) //Oberstes bit gegebenenfalls abschneiden;
109 62 : l &= 0x7fffffff;
110 :
111 162526 : return l;
112 : }
113 :
114 1295609 : int MakeToken( YYSTYPE * pTokenVal )
115 : {
116 : int c1;
117 :
118 : while( true ) // Kommentare und Leerzeichen ueberlesen
119 : {
120 3834574 : while( isspace( c ) )
121 1243356 : c = pFI->GetFastChar();
122 :
123 1295609 : if( '/' == c )
124 : {
125 195 : c1 = c;
126 195 : c = pFI->GetFastChar();
127 195 : if( '/' == c )
128 : {
129 0 : while( '\n' != c && !pFI->IsEof() )
130 0 : c = pFI->GetFastChar();
131 :
132 0 : c = pFI->GetFastChar();
133 : }
134 195 : else if( '*' == c )
135 : {
136 0 : c = pFI->GetFastChar();
137 0 : do
138 : {
139 0 : while( '*' != c && !pFI->IsEof() )
140 0 : c = pFI->GetFastChar();
141 :
142 0 : c = pFI->GetFastChar();
143 : }
144 0 : while( '/' != c && !pFI->IsEof() );
145 0 : c = pFI->GetFastChar();
146 : }
147 : else
148 195 : return( c1 );
149 : }
150 : else
151 1295414 : break;
152 : };
153 :
154 : // FIXME: wtf is this supposed to do?
155 1295414 : if( (c != 0) == pFI->IsEof() )
156 : {
157 0 : return( 0 );
158 : }
159 :
160 1295414 : if( bLastInclude )
161 : {
162 0 : bLastInclude = false; //Zuruecksetzten
163 0 : if( '<' == c )
164 : {
165 0 : OStringBuffer aBuf( 256 );
166 0 : c = pFI->GetFastChar();
167 0 : while( '>' != c && !pFI->IsEof() )
168 : {
169 0 : aBuf.append( sal_Char(c) );
170 0 : c = pFI->GetFastChar();
171 : };
172 0 : c = pFI->GetFastChar();
173 0 : pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
174 0 : return( INCLUDE_STRING );
175 : };
176 : }
177 :
178 1295414 : if( c == '"' )
179 : {
180 83932 : OStringBuffer aBuf( 256 );
181 83932 : bool bDone = false;
182 1646747 : while( !bDone && !pFI->IsEof() && c )
183 : {
184 1478883 : c = pFI->GetFastChar();
185 1478883 : if( c == '"' )
186 : {
187 102118 : do
188 : {
189 102118 : c = pFI->GetFastChar();
190 : }
191 186052 : while( c == ' ' || c == '\t' );
192 :
193 83934 : if( c == '"' )
194 : {
195 : // this is a continued string
196 : // note: multiline string continuations are handled by the parser
197 : // see rscyacc.y
198 : }
199 : else
200 83932 : bDone = true;
201 : }
202 1394949 : else if( c == '\\' )
203 : {
204 1762 : aBuf.append( '\\' );
205 1762 : c = pFI->GetFastChar();
206 1762 : if( c )
207 1762 : aBuf.append( sal_Char(c) );
208 : }
209 : else
210 1393187 : aBuf.append( sal_Char(c) );
211 : }
212 83932 : pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
213 83932 : return STRING;
214 : }
215 1211482 : if (isdigit (c))
216 : {
217 162526 : pTokenVal->value = GetNumber();
218 162526 : return( NUMBER );
219 : }
220 :
221 1048956 : if( isalpha (c) || (c == '_') )
222 : {
223 : Atom nHashId;
224 278481 : OStringBuffer aBuf( 256 );
225 :
226 2232406 : while( isalnum (c) || (c == '_') || (c == '-') )
227 : {
228 1675444 : aBuf.append( sal_Char(c) );
229 1675444 : c = pFI->GetFastChar();
230 : }
231 :
232 278481 : nHashId = pHS->getID( aBuf.getStr(), true );
233 278481 : if( InvalidAtom != nHashId )
234 : {
235 : KEY_STRUCT aKey;
236 :
237 : // Suche nach dem Schluesselwort
238 278481 : if( pTC->aNmTb.Get( nHashId, &aKey ) )
239 : {
240 :
241 : // Schluesselwort gefunden
242 278481 : switch( aKey.nTyp )
243 : {
244 : case CLASSNAME:
245 55463 : pTokenVal->pClass = (RscTop *)aKey.yylval;
246 55463 : break;
247 : case VARNAME:
248 114025 : pTokenVal->varid = aKey.nName;
249 114025 : break;
250 : case CONSTNAME:
251 64224 : pTokenVal->constname.hashid = aKey.nName;
252 64224 : pTokenVal->constname.nValue = aKey.yylval;
253 64224 : break;
254 : case BOOLEAN:
255 18820 : pTokenVal->svbool = (bool)aKey.yylval;
256 18820 : break;
257 : case INCLUDE:
258 0 : bLastInclude = true;
259 : default:
260 25949 : pTokenVal->value = aKey.yylval;
261 : };
262 :
263 278481 : return aKey.nTyp;
264 : }
265 : else
266 : {
267 0 : pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
268 0 : return SYMBOL;
269 : }
270 : }
271 : else
272 : {
273 : // Symbol
274 : RscDefine * pDef;
275 :
276 0 : pDef = pTC->aFileTab.FindDef( aBuf.getStr() );
277 0 : if( pDef )
278 : {
279 0 : pTokenVal->defineele = pDef;
280 :
281 0 : return RSCDEFINE;
282 : }
283 :
284 0 : pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
285 0 : return SYMBOL;
286 278481 : }
287 : }
288 :
289 770475 : if( c=='<' )
290 : {
291 5621 : c = pFI->GetFastChar();
292 5621 : if( c=='<' )
293 : {
294 831 : c = pFI->GetFastChar();
295 831 : return LEFTSHIFT;
296 : }
297 : else
298 4790 : return '<';
299 : }
300 :
301 764854 : if( c=='>' )
302 : {
303 4787 : c = pFI->GetFastChar();
304 4787 : if( c=='>' )
305 : {
306 0 : c = pFI->GetFastChar();
307 0 : return RIGHTSHIFT;
308 : }
309 : else
310 4787 : return '>';
311 : }
312 :
313 760067 : c1 = c;
314 760067 : c = pFI->GetFastChar();
315 760067 : return c1;
316 : }
317 :
318 : #if defined( RS6000 )
319 : extern "C" int yylex()
320 : #else
321 1295549 : int yylex()
322 : #endif
323 : {
324 1295549 : if( bTargetDefined )
325 0 : bTargetDefined = false;
326 : else
327 1295549 : aKeyVal[ 0 ].nKeyWord = MakeToken( &aKeyVal[ 0 ].aYYSType );
328 :
329 1295549 : yylval = aKeyVal[ 0 ].aYYSType;
330 1295549 : return aKeyVal[ 0 ].nKeyWord;
331 : }
332 :
333 : #ifdef RS6000
334 : extern "C" void yyerror( char* pMessage )
335 : #elif defined SOLARIS
336 : extern "C" void yyerror( const char* pMessage )
337 : #else
338 0 : void yyerror( char* pMessage )
339 : #endif
340 : {
341 0 : pTC->pEH->Error( ERR_YACC, NULL, RscId(), pMessage );
342 0 : }
343 :
344 687 : void InitParser( RscFileInst * pFileInst )
345 : {
346 687 : pTC = pFileInst->pTypCont; // Datenkontainer setzten
347 687 : pFI = pFileInst;
348 687 : pStringContainer = new StringContainer();
349 687 : pExp = NULL; //fuer MacroParser
350 687 : bTargetDefined = false;
351 :
352 : // Anfangszeichen initialisieren
353 687 : bLastInclude = false;
354 687 : c = pFI->GetFastChar();
355 687 : }
356 :
357 687 : void EndParser()
358 : {
359 : // Stack abraeumen
360 1374 : while( ! S.IsEmpty() )
361 0 : S.Pop();
362 :
363 : // free string container
364 687 : delete pStringContainer;
365 687 : pStringContainer = NULL;
366 :
367 687 : if( pExp )
368 0 : delete pExp;
369 687 : pTC = NULL;
370 687 : pFI = NULL;
371 687 : pExp = NULL;
372 :
373 687 : }
374 :
375 60 : void IncludeParser( RscFileInst * pFileInst )
376 : {
377 : int nToken; // Wert des Tokens
378 : YYSTYPE aYYSType; // Daten des Tokens
379 : RscFile * pFName; // Filestruktur
380 : sal_uLong lKey; // Fileschluessel
381 60 : RscTypCont * pTypCon = pFileInst->pTypCont;
382 :
383 60 : pFName = pTypCon->aFileTab.Get( pFileInst->GetFileIndex() );
384 60 : InitParser( pFileInst );
385 :
386 60 : nToken = MakeToken( &aYYSType );
387 120 : while( 0 != nToken && CLASSNAME != nToken )
388 : {
389 0 : if( '#' == nToken )
390 : {
391 0 : if( INCLUDE == (nToken = MakeToken( &aYYSType )) )
392 : {
393 0 : if( STRING == (nToken = MakeToken( &aYYSType )) )
394 : {
395 : lKey = pTypCon->aFileTab.NewIncFile( aYYSType.string,
396 0 : aYYSType.string );
397 0 : pFName->InsertDependFile( lKey, ULONG_MAX );
398 : }
399 0 : else if( INCLUDE_STRING == nToken )
400 : {
401 : lKey = pTypCon->aFileTab.NewIncFile( aYYSType.string,
402 0 : OString() );
403 0 : pFName->InsertDependFile( lKey, ULONG_MAX );
404 : };
405 : };
406 : };
407 0 : nToken = MakeToken( &aYYSType );
408 : };
409 :
410 60 : EndParser();
411 60 : }
412 :
413 627 : ERRTYPE parser( RscFileInst * pFileInst )
414 : {
415 627 : ERRTYPE aError;
416 :
417 627 : InitParser( pFileInst );
418 :
419 627 : aError = yyparse();
420 :
421 627 : EndParser();
422 :
423 : // yyparser gibt 0 zurueck, wenn erfolgreich
424 627 : if( 0 == aError )
425 627 : aError.Clear();
426 627 : if( pFileInst->pTypCont->pEH->nErrors )
427 0 : aError = ERR_ERROR;
428 627 : pFileInst->SetError( aError );
429 627 : return( aError );
430 : }
431 :
432 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|