xref: /AOO42X/main/rsc/source/parser/erscerr.cxx (revision fe133148701fcec9e65a6ab1046e6d5332903c6a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_rsc.hxx"
24 #include <stdlib.h>
25 #include <stdio.h>
26 
27 #include <tools/rcid.h>
28 #include <rschash.hxx>
29 #include <rscerror.h>
30 #include <rscall.h>
31 #include <rscdb.hxx>
32 #include <rscpar.hxx>
33 
34 #include "rsclex.hxx"
35 
36 /*************************************************************************
37 |*
38 |*    ERRTYPE::operator = ;
39 |*
40 |*    Beschreibung
41 |*    Ersterstellung    MM 25.09.91
42 |*    Letzte Aenderung  MM 25.09.91
43 |*
44 *************************************************************************/
operator =(const ERRTYPE & rError)45 ERRTYPE& ERRTYPE::operator = ( const ERRTYPE & rError )
46 {
47     if( !IsError() ){
48         if( rError.IsError() || !IsWarning() )
49             nError = rError.nError;
50     }
51     return *this;
52 }
53 
54 /*************************************************************************
55 |*
56 |*    RscError::StdOut();
57 |*
58 |*    Beschreibung
59 |*    Ersterstellung    MM 06.05.91
60 |*    Letzte Aenderung  MM 06.05.91
61 |*
62 *************************************************************************/
StdOut(const char * pStr,const RscVerbosity _verbosityLevel)63 void RscError::StdOut( const char * pStr, const RscVerbosity _verbosityLevel )
64 {
65     if ( m_verbosity >= _verbosityLevel )
66     {
67         if( pStr ){
68             printf( "%s", pStr );
69             fflush( stdout );
70         }
71     }
72 }
73 
74 /*************************************************************************
75 |*
76 |*    RscError::StdErr();
77 |*
78 |*    Beschreibung
79 |*    Ersterstellung    PL 11/07/2001
80 |*    Letzte Aenderung  PL 11/07/2001
81 |*
82 *************************************************************************/
StdErr(const char * pStr)83 void RscError::StdErr( const char * pStr )
84 {
85     if( pStr )
86         fprintf( stderr, "%s", pStr );
87 }
88 
89 /*************************************************************************
90 |*
91 |*    RscError::LstOut();
92 |*
93 |*    Beschreibung
94 |*    Ersterstellung    MM 06.05.91
95 |*    Letzte Aenderung  MM 06.05.91
96 |*
97 *************************************************************************/
LstOut(const char * pStr)98 void RscError::LstOut( const char * pStr ){
99     if( fListing && pStr )
100         fprintf( fListing, "%s", pStr );
101 }
102 
103 /*************************************************************************
104 |*
105 |*    RscError::StdLstOut();
106 |*
107 |*    Beschreibung
108 |*    Ersterstellung    MM 06.05.91
109 |*    Letzte Aenderung  MM 06.05.91
110 |*
111 *************************************************************************/
StdLstOut(const char * pStr)112 void RscError::StdLstOut( const char * pStr ){
113     StdOut( pStr );
114     LstOut( pStr );
115 }
116 
117 /*************************************************************************
118 |*
119 |*    RscError::StdLstErr();
120 |*
121 |*    Beschreibung
122 |*    Ersterstellung    PL 11/07/2001
123 |*    Letzte Aenderung  PL 11/07/2001
124 |*
125 *************************************************************************/
StdLstErr(const char * pStr)126 void RscError::StdLstErr( const char * pStr ){
127     StdErr( pStr );
128     LstOut( pStr );
129 }
130 
131 /*************************************************************************
132 |*
133 |*    RscError::WriteError();
134 |*
135 |*    Beschreibung
136 |*    Ersterstellung    MM 06.05.91
137 |*    Letzte Aenderung  MM 06.05.91
138 |*
139 *************************************************************************/
WriteError(const ERRTYPE & rError,const char * pMessage)140 void RscError::WriteError( const ERRTYPE& rError, const char * pMessage )
141 {
142     switch( rError )
143     {
144         case ERR_ERROR: {
145             StdLstErr( "!! " );
146             if( 1 == nErrors )
147                 StdLstErr( ByteString::CreateFromInt32( nErrors ).GetBuffer() );
148             else
149                 StdLstErr( ByteString::CreateFromInt32( (nErrors -1) ).GetBuffer() );
150             StdLstErr( " Error" );
151             StdLstErr( " found!!" );
152         }
153         break;
154 
155         case ERR_UNKNOWN_METHOD:
156             StdLstErr( "The used type is not allowed." );
157         break;
158 
159         case ERR_OPENFILE:
160             StdLstErr( "This file <" );
161             StdLstErr( pMessage );
162             StdLstErr( "> cannot be opened." );
163         break;
164 
165         case ERR_RENAMEFILE:
166             StdLstErr( "rename <" );
167             StdLstErr( pMessage );
168             StdLstErr( "> s not possible." );
169         break;
170 
171         case ERR_FILESIZE:
172             StdLstErr( "Wrong file <" );
173             StdLstErr( pMessage );
174             StdLstErr( "> length." );
175         break;
176 
177         case ERR_FILEFORMAT:
178             StdLstErr( "Wrong file type <" );
179             StdLstErr( pMessage );
180             StdLstErr( ">." );
181         break;
182 
183         case ERR_NOCHAR:
184             StdLstErr( "Character: '\\xxx'; The value xxx is greater than 255.");
185             break;
186 
187         case ERR_NORSCINST:
188             StdLstErr( "Internal error, instance invalid.");
189             break;
190 
191 
192         case ERR_NOINPUT:
193             StdLstErr( "Input file was not specified.\n");
194         case ERR_USAGE:
195             StdLstOut( "Copyright (C) 2000, 2010 Oracle and/or its affiliates.\n" );
196             {
197                 char    buf[40];
198 
199                 StdLstOut( "DataVersion: " );
200                 sprintf( buf, "%d.%d\n\n",
201                          RSCVERSION_ID / 100, RSCVERSION_ID % 100 );
202                 StdLstOut( buf );
203             };
204 
205             StdLstOut( "Command line: rsc [Switches] <Source File(s)>\n" );
206             StdLstOut( "Command line: rsc @<Command File>\n" );
207             StdLstOut( "-h  shows this help.\n" );
208             StdLstOut( "-p  No Preprocessor.\n" );
209             StdLstOut( "-s  Syntax analysis, creates .srs file\n");
210             StdLstOut( "-l  Linker, links files created with rsc -s,\n" );
211             StdLstOut( "    creates .rc file and .res file.\n" );
212             StdLstOut( "-r  Prevents .res file.\n" );
213             StdLstOut( "-d  Symbol definitions for the Preprocessor.\n" );
214             StdLstOut( "-i  Include directives for the Preprocessor.\n" );
215             StdLstOut( "-presponse     Use response file for Preprocessor.\n" );
216             StdLstOut( "-lg<language>  Use a different language.\n" );
217             StdLstOut( "-pp=<filename> Use a different Preprocessor.\n" );
218             StdLstOut( "-rsc2=<filename> Specify the location for rsc2.\n" );
219             StdLstOut( "No longer existent: -rc<filename>  Use a different system resource compiler.\n" );
220             StdLstOut( "-fs=<filename> Name of the .res file.\n" );
221             StdLstOut( "-lip=<path>    additional search path for system dependent files\n" );
222             StdLstOut( "-fp=<filename> Renaming of the .srs file.\n" );
223             StdLstOut( "-fl=<filename> Listing file.\n" );
224             StdLstOut( "-fh=<filename> Header file.\n" );
225             StdLstOut( "-fc=<filename> Code file.\n" );
226             StdLstOut( "-ft=<filename> Touch a file when done in rsc2 (for dependencies)\n" );
227             StdLstOut( "-fr=<filename> Resource constructor .cxx-file.\n" );
228             StdLstOut( "-fx=<filename> Name of .src-file.\n" );
229             StdLstOut( "-oil=<dir>     Output directory for image list files\n" );
230             StdLstOut( "-r<ENV>=<path> replace <path> by <ENV> in image list files\n" );
231             StdLstOut( "-CHARSET_...  Convert to this character set.\n" );
232             StdLstOut( "-BIGENDIAN    Format of number values.\n" );
233             StdLstOut( "-LITTLEENDIAN Format of number values.\n" );
234             StdLstOut( "-SMART        Generate smart names (cxx, hxx).\n" );
235             StdLstOut( "-SrsDefault   Only write one language to srs file.\n" );
236             StdLstOut( "\nwhen creating multiple .res files in one pass, please give these\n" );
237             StdLstOut( "options in consecutive blocks:\n" );
238             StdLstOut( "-lg<language> -fs<filename> [-lip<path> [-lip<path>] ]\n" );
239             StdLstOut( "a new block begins when either -lg or -fs is used again.\n" );
240             break;
241 
242         case ERR_UNKNOWNSW:
243             StdLstErr( "Unknown switch <" );
244             StdLstErr( pMessage );
245             StdLstErr( ">." );
246             break;
247 
248         case ERR_REFTODEEP:
249             StdLstErr( "Too many reference levels have been used (see Switch -RefDeep)." );
250             break;
251 
252         case ERR_CONT_INVALIDPOS:
253             StdLstErr( "Internal error, Container class: invalid position." );
254             break;
255 
256         case ERR_CONT_INVALIDTYPE:
257             StdLstErr( "Invalid type <" );
258             StdLstErr( pMessage );
259             StdLstErr( ">." );
260             break;
261 
262         case ERR_ARRAY_INVALIDINDEX:
263             StdLstErr( "Internal error, Array class: invalid index." );
264             break;
265 
266         case ERR_RSCINST_NOVARNAME:
267             StdLstErr( "Internal error, invalid name of variable." );
268             break;
269 
270         case ERR_YACC:
271             StdLstErr( pMessage );
272             break;
273 
274         case ERR_DOUBLEID:
275             StdLstErr( "Two global resources have the same identifier." );
276             break;
277 
278         case ERR_FALSETYPE:
279             StdLstErr( "Wrong type <" );
280             StdLstErr( pMessage );
281             StdLstErr( ">." );
282             break;
283 
284         case ERR_NOVARIABLENAME:
285             StdLstErr( "The variable <" );
286             StdLstErr( pMessage );
287             StdLstErr( "> must not be used here." );
288             break;
289 
290         case ERR_RSCRANGE_OUTDEFSET:
291             StdLstErr( "The used value is not in the expected domain." );
292             break;
293 
294         case ERR_USHORTRANGE:
295             StdLstErr( "Value is <" );
296             StdLstErr( pMessage );
297             StdLstErr( "> the allowed domain is from 0 up to 65535." );
298             break;
299 
300         case ERR_IDRANGE:
301             StdLstErr( "Value is <" );
302             StdLstErr( pMessage );
303             StdLstErr( "> the allowed domain is from 1 up to 32767." );
304             break;
305 
306         case ERR_NOCOPYOBJ:
307             StdLstErr( "Default resource <" );
308             StdLstErr( pMessage );
309             StdLstErr( "> not found." );
310             break;
311 
312         case ERR_REFNOTALLOWED:
313             StdLstErr( "The use of a reference is not allowed." );
314             break;
315 
316         case ERR_COPYNOTALLOWED:
317             StdLstErr( "The use of a default resource is not allowed." );
318             break;
319 
320         case ERR_IDEXPECTED:
321             StdLstErr( "An identifier needs to be specified." );
322             break;
323 
324         case ERR_DOUBLEDEFINE:
325             StdLstErr( "The symbol <" );
326             StdLstErr( pMessage );
327             StdLstErr( "> is defined twice." );
328             break;
329 
330         case ERR_RSCINST_RESERVEDNAME:
331             StdLstErr( "The symbol <" );
332             StdLstErr( pMessage );
333             StdLstErr( "> is a reserved name." );
334             break;
335 
336         case ERR_ZERODIVISION:
337             StdLstErr( "Attempt to divide by zero." );
338             break;
339 
340         case ERR_PRAGMA:
341             StdLstErr( "Error in a #pragma statement." );
342             break;
343 
344         case ERR_DECLAREDEFINE:
345             StdLstErr( "Error in the declaration part of the macro." );
346             break;
347 
348         case ERR_NOTYPE:
349             StdLstErr( "type expected." );
350             break;
351 
352         case ERR_NOIMAGE:
353             StdLstErr( "The image(s) <" );
354             StdLstErr( pMessage );
355             StdLstErr( "> could not be found." );
356             break;
357 
358 /****************** W A R N I N G S **************************************/
359         case WRN_LOCALID:
360             StdLstErr( "Sub resources should have an identifier < 256." );
361             break;
362 
363         case WRN_GLOBALID:
364             StdLstErr( "Global resources should have an identifier >= 256." );
365             break;
366 
367         case WRN_SUBINMEMBER:
368             StdLstErr( "Sub resources are ignored." );
369             break;
370 
371         case WRN_CONT_NOID:
372             StdLstErr( "Resources without name are ignored." );
373             break;
374 
375         case WRN_CONT_DOUBLEID:
376             StdLstErr( "Two local resources have the same identifier." );
377             break;
378 
379         case WRN_STR_REFNOTFOUND:
380             StdLstErr( "String reference <" );
381             StdLstErr( pMessage );
382             StdLstErr( " > could not be resolved." );
383             break;
384 
385         case WRN_MGR_REFNOTFOUND:
386             StdLstErr( "Reference <" );
387             StdLstErr( pMessage );
388             StdLstErr( " > could not be resolved." );
389             break;
390 
391         default:
392             if( pMessage ){
393                 StdLstErr( "\nMessage: " );
394                 StdLstErr( pMessage );
395             };
396             break;
397     }
398 }
399 
400 /*************************************************************************
401 |*
402 |*    RscErrorFormat()
403 |*
404 |*    Beschreibung
405 |*    Ersterstellung    MM 06.05.91
406 |*    Letzte Aenderung  MM 06.05.91
407 |*
408 *************************************************************************/
ErrorFormat(const ERRTYPE & rError,RscTop * pClass,const RscId & aId)409 void RscError::ErrorFormat( const ERRTYPE& rError, RscTop * pClass,
410                             const RscId & aId ){
411     char buf[ 10 ];
412     sal_uInt32 i;
413 
414     if( pFI )
415     {
416         pFI->SetError( rError );
417         StdErr( "\n" );
418         StdErr( pFI->GetLine() );
419         StdErr( "\n" );
420         // Fehlerposition anzeigen
421         for( i = 0; (i +1) < pFI->GetScanPos(); i++ )
422             StdLstErr( " " );
423         LstOut( "     ^" ); // Zeilennummern beachten
424         StdErr( "^" );
425         StdLstErr( "\n" );
426     }
427     StdLstErr( "f" );
428     sprintf( buf, "%u", (unsigned int)rError );
429     StdLstErr( buf );
430 
431     if( pFI && pTC ){
432         StdLstErr( ": \"" );
433         StdLstErr( pTC->aFileTab.Get( pFI->GetFileIndex() )->aFileName.GetBuffer() );
434         StdLstErr( "\", line " );
435         sprintf( buf, "%u", (unsigned int)pFI->GetLineNo() );
436         StdLstErr( buf );
437     }
438 
439     if( rError.IsError() )
440         StdLstErr( ": Error" );
441     else
442         StdLstErr( ": Warning" );
443 
444     if( pClass || aId.IsId() )
445     {
446         StdLstErr( " in the object (" );
447         if( pClass )
448         {
449             StdLstErr( "Type: " );
450             StdLstErr( pHS->getString( pClass->GetId() ).getStr() );
451             if( aId.IsId() )
452                 StdLstErr( ", " );
453         }
454         if( aId.IsId() )
455             StdLstErr( aId.GetName().GetBuffer() );
456         StdLstErr( "):\n" );
457     }
458     else
459         StdLstErr( ": " );
460 }
461 
462 /*************************************************************************
463 |*
464 |*    RscError::Error()
465 |*
466 |*    Beschreibung
467 |*    Ersterstellung    MM 06.05.91
468 |*    Letzte Aenderung  MM 06.05.91
469 |*
470 *************************************************************************/
Error(const ERRTYPE & rError,RscTop * pClass,const RscId & aId,const char * pMessage)471 void RscError::Error( const ERRTYPE& rError, RscTop * pClass,
472                       const RscId & aId, const char * pMessage )
473 {
474     if( WRN_LOCALID == rError ) // Keine Warning erzeugen
475         return;
476     if( rError.IsError() )
477         nErrors++;
478     if( rError.IsError() || rError.IsWarning() ){
479         ErrorFormat( rError, pClass, aId );
480         WriteError( rError, pMessage );
481         StdLstErr( "\n" );
482     };
483 }
484 
485 /*************************************************************************
486 |*
487 |*    RscError::FatalError();
488 |*
489 |*    Beschreibung
490 |*    Ersterstellung    MM 06.05.91
491 |*    Letzte Aenderung  MM 06.05.91
492 |*
493 *************************************************************************/
FatalError(const ERRTYPE & rError,const RscId & aId,const char * pMessage)494 void RscError::FatalError( const ERRTYPE& rError, const RscId &aId,
495                            const char * pMessage )
496 {
497     if( ERR_USAGE != rError ){
498         nErrors++;
499         ErrorFormat( rError, NULL, aId );
500         WriteError( rError, pMessage );
501         StdLstErr( "\nTerminating compiler\n" );
502     }
503     else
504         WriteError( rError, pMessage );
505 
506     exit( 1 );
507 }
508 
509 /* vim: set noet sw=4 ts=4: */
510