fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / rsc / source / parser / erscerr.cxx
blob29da7b660a53fa035435f19d07a28d298475fc97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <stdlib.h>
21 #include <stdio.h>
23 #include <tools/rcid.h>
24 #include <rschash.hxx>
25 #include <rscerror.h>
26 #include <rscall.h>
27 #include <rscdb.hxx>
28 #include <rscpar.hxx>
30 #include "rsclex.hxx"
32 ERRTYPE& ERRTYPE::operator = ( const ERRTYPE & rError )
34 if( !IsError() ){
35 if( rError.IsError() || !IsWarning() )
36 nError = rError.nError;
38 return *this;
41 void RscError::StdOut( const char * pStr, const RscVerbosity _verbosityLevel )
43 if ( m_verbosity >= _verbosityLevel )
45 if( pStr ){
46 printf( "%s", pStr );
47 fflush( stdout );
52 void RscError::StdErr( const char * pStr )
54 if( pStr )
55 fprintf( stderr, "%s", pStr );
58 void RscError::LstOut( const char * pStr ){
59 if( fListing && pStr )
60 fprintf( fListing, "%s", pStr );
63 void RscError::StdLstOut( const char * pStr ){
64 StdOut( pStr );
65 LstOut( pStr );
68 void RscError::StdLstErr( const char * pStr ){
69 StdErr( pStr );
70 LstOut( pStr );
73 void RscError::WriteError( const ERRTYPE& rError, const char * pMessage )
75 switch( rError )
77 case ERR_ERROR: {
78 StdLstErr( "!! " );
79 if( 1 == nErrors )
80 StdLstErr(OString::number(nErrors).getStr());
81 else
82 StdLstErr(OString::valueOf(static_cast<sal_Int32>(nErrors -1)).getStr());
83 StdLstErr( " Error" );
84 StdLstErr( " found!!" );
86 break;
88 case ERR_UNKNOWN_METHOD:
89 StdLstErr( "The used type is not allowed." );
90 break;
92 case ERR_OPENFILE:
93 StdLstErr( "This file <" );
94 StdLstErr( pMessage );
95 StdLstErr( "> cannot be opened." );
96 break;
98 case ERR_RENAMEFILE:
99 StdLstErr( "rename <" );
100 StdLstErr( pMessage );
101 StdLstErr( "> s not possible." );
102 break;
104 case ERR_FILESIZE:
105 StdLstErr( "Wrong file <" );
106 StdLstErr( pMessage );
107 StdLstErr( "> length." );
108 break;
110 case ERR_FILEFORMAT:
111 StdLstErr( "Wrong file type <" );
112 StdLstErr( pMessage );
113 StdLstErr( ">." );
114 break;
116 case ERR_NOCHAR:
117 StdLstErr( "Character: '\\xxx'; The value xxx is greater than 255.");
118 break;
120 case ERR_NORSCINST:
121 StdLstErr( "Internal error, instance invalid.");
122 break;
125 case ERR_NOINPUT:
126 StdLstErr( "Input file was not specified.\n");
127 case ERR_USAGE:
128 StdLstOut( "Copyright (C) 2000 - 2012 LibreOffice contributors.\n" );
130 char buf[40];
132 StdLstOut( "DataVersion: " );
133 sprintf( buf, "%d.%d\n\n",
134 RSCVERSION_ID / 100, RSCVERSION_ID % 100 );
135 StdLstOut( buf );
138 StdLstOut( "Command line: rsc [Switches] <Source File(s)>\n" );
139 StdLstOut( "Command line: rsc @<Command File>\n" );
140 StdLstOut( "-h shows this help.\n" );
141 StdLstOut( "-p No preprocessor.\n" );
142 StdLstOut( "-s Syntax analysis, creates .srs file\n");
143 StdLstOut( "-l Linker, links files created with rsc -s,\n" );
144 StdLstOut( " creates .rc file and .res file.\n" );
145 StdLstOut( "-r Prevents .res file.\n" );
146 StdLstOut( "-d Symbol definitions for the Preprocessor.\n" );
147 StdLstOut( "-i Include directives for the Preprocessor.\n" );
148 StdLstOut( "-presponse Use response file for Preprocessor.\n" );
149 StdLstOut( "-lg<language> Use a different language.\n" );
150 StdLstOut( "-fs=<filename> Name of the .res file.\n" );
151 StdLstOut( "-lip=<path> additional search path for system dependant files\n" );
152 StdLstOut( "-fp=<filename> Renaming of the .srs file.\n" );
153 StdLstOut( "-oil=<dir> Output directory for image list files\n" );
154 StdLstOut( "-sub<ENV>=<path> replace <path> by <ENV> in image list files\n" );
155 StdLstOut( "-BIGENDIAN Format of number values.\n" );
156 StdLstOut( "-LITTLEENDIAN Format of number values.\n" );
157 StdLstOut( "-SrsDefault Only write one language to srs file.\n" );
158 StdLstOut( "\nwhen creating multiple .res files in one pass, please give these\n" );
159 StdLstOut( "options in consecutive blocks:\n" );
160 StdLstOut( "-lg<language> -fs<filename> [-lip<path> [-lip<path>] ]\n" );
161 StdLstOut( "a new block begins when either -lg or -fs is used again.\n" );
162 break;
164 case ERR_UNKNOWNSW:
165 StdLstErr( "Unknown switch <" );
166 StdLstErr( pMessage );
167 StdLstErr( ">." );
168 break;
170 case ERR_REFTODEEP:
171 StdLstErr( "Too many reference levels have been used (see Switch -RefDeep)." );
172 break;
174 case ERR_CONT_INVALIDPOS:
175 StdLstErr( "Internal error, Container class: invalid position." );
176 break;
178 case ERR_CONT_INVALIDTYPE:
179 StdLstErr( "Invalid type <" );
180 StdLstErr( pMessage );
181 StdLstErr( ">." );
182 break;
184 case ERR_ARRAY_INVALIDINDEX:
185 StdLstErr( "Internal error, Array class: invalid index." );
186 break;
188 case ERR_RSCINST_NOVARNAME:
189 StdLstErr( "Internal error, invalid name of variable." );
190 break;
192 case ERR_YACC:
193 StdLstErr( pMessage );
194 break;
196 case ERR_DOUBLEID:
197 StdLstErr( "Two global resources have the same identifier." );
198 break;
200 case ERR_FALSETYPE:
201 StdLstErr( "Wrong type <" );
202 StdLstErr( pMessage );
203 StdLstErr( ">." );
204 break;
206 case ERR_NOVARIABLENAME:
207 StdLstErr( "The variable <" );
208 StdLstErr( pMessage );
209 StdLstErr( "> must not be used here." );
210 break;
212 case ERR_RSCRANGE_OUTDEFSET:
213 StdLstErr( "The used value is not in the expected domain." );
214 break;
216 case ERR_USHORTRANGE:
217 StdLstErr( "Value is <" );
218 StdLstErr( pMessage );
219 StdLstErr( "> the allowed domain is from 0 up to 65535." );
220 break;
222 case ERR_IDRANGE:
223 StdLstErr( "Value is <" );
224 StdLstErr( pMessage );
225 StdLstErr( "> the allowed domain is from 1 up to 32767." );
226 break;
228 case ERR_NOCOPYOBJ:
229 StdLstErr( "Default resource <" );
230 StdLstErr( pMessage );
231 StdLstErr( "> not found." );
232 break;
234 case ERR_REFNOTALLOWED:
235 StdLstErr( "The use of a reference is not allowed." );
236 break;
238 case ERR_COPYNOTALLOWED:
239 StdLstErr( "The use of a default resource is not allowed." );
240 break;
242 case ERR_IDEXPECTED:
243 StdLstErr( "An identifier needs to be specified." );
244 break;
246 case ERR_DOUBLEDEFINE:
247 StdLstErr( "The symbol <" );
248 StdLstErr( pMessage );
249 StdLstErr( "> is defined twice." );
250 break;
252 case ERR_RSCINST_RESERVEDNAME:
253 StdLstErr( "The symbol <" );
254 StdLstErr( pMessage );
255 StdLstErr( "> is a reserved name." );
256 break;
258 case ERR_ZERODIVISION:
259 StdLstErr( "Attempt to divide by zero." );
260 break;
262 case ERR_PRAGMA:
263 StdLstErr( "Error in a #pragma statement." );
264 break;
266 case ERR_DECLAREDEFINE:
267 StdLstErr( "Error in the declaration part of the macro." );
268 break;
270 case ERR_NOTYPE:
271 StdLstErr( "type expected." );
272 break;
274 case ERR_NOIMAGE:
275 StdLstErr( "The image(s) <" );
276 StdLstErr( pMessage );
277 StdLstErr( "> could not be found." );
278 break;
280 case WRN_LOCALID:
281 StdLstErr( "Sub resources should have an identifier < 256." );
282 break;
284 case WRN_GLOBALID:
285 StdLstErr( "Global resources should have an identifier >= 256." );
286 break;
288 case WRN_SUBINMEMBER:
289 StdLstErr( "Sub resources are ignored." );
290 break;
292 case WRN_CONT_NOID:
293 StdLstErr( "Resources without name are ignored." );
294 break;
296 case WRN_CONT_DOUBLEID:
297 StdLstErr( "Two local resources have the same identifier." );
298 break;
300 case WRN_STR_REFNOTFOUND:
301 StdLstErr( "String reference <" );
302 StdLstErr( pMessage );
303 StdLstErr( " > could not be resolved." );
304 break;
306 case WRN_MGR_REFNOTFOUND:
307 StdLstErr( "Reference <" );
308 StdLstErr( pMessage );
309 StdLstErr( " > could not be resolved." );
310 break;
312 default:
313 if( pMessage ){
314 StdLstErr( "\nMessage: " );
315 StdLstErr( pMessage );
317 break;
321 void RscError::ErrorFormat( const ERRTYPE& rError, RscTop * pClass,
322 const RscId & aId ){
323 char buf[ 10 ];
324 sal_uInt32 i;
326 if( pFI )
328 pFI->SetError( rError );
329 StdErr( "\n" );
330 StdErr( pFI->GetLine() );
331 StdErr( "\n" );
332 // Fehlerposition anzeigen
333 for( i = 0; (i +1) < pFI->GetScanPos(); i++ )
334 StdLstErr( " " );
335 LstOut( " ^" ); //Zeilennummern beachten
336 StdErr( "^" );
337 StdLstErr( "\n" );
339 StdLstErr( "f" );
340 sprintf( buf, "%u", (unsigned int)rError );
341 StdLstErr( buf );
343 if( pFI && pTC ){
344 StdLstErr( ": \"" );
345 StdLstErr( pTC->aFileTab.Get( pFI->GetFileIndex() )->aFileName.getStr() );
346 StdLstErr( "\", line " );
347 sprintf( buf, "%u", (unsigned int)pFI->GetLineNo() );
348 StdLstErr( buf );
351 if( rError.IsError() )
352 StdLstErr( ": Error" );
353 else
354 StdLstErr( ": Warning" );
356 if( pClass || aId.IsId() )
358 StdLstErr( " in the object (" );
359 if( pClass )
361 StdLstErr( "Type: " );
362 StdLstErr( pHS->getString( pClass->GetId() ).getStr() );
363 if( aId.IsId() )
364 StdLstErr( ", " );
366 if( aId.IsId() )
367 StdLstErr( aId.GetName().getStr() );
368 StdLstErr( "):\n" );
370 else
371 StdLstErr( ": " );
374 void RscError::Error( const ERRTYPE& rError, RscTop * pClass,
375 const RscId & aId, const char * pMessage )
377 if( WRN_LOCALID == rError ) // Keine Warning erzeugen
378 return;
379 if( rError.IsError() )
380 nErrors++;
381 if( rError.IsError() || rError.IsWarning() ){
382 ErrorFormat( rError, pClass, aId );
383 WriteError( rError, pMessage );
384 StdLstErr( "\n" );
388 void RscError::FatalError( const ERRTYPE& rError, const RscId &aId,
389 const char * pMessage )
391 if( ERR_USAGE != rError ){
392 nErrors++;
393 ErrorFormat( rError, NULL, aId );
394 WriteError( rError, pMessage );
395 StdLstErr( "\nTerminating compiler\n" );
397 else
398 WriteError( rError, pMessage );
400 exit( 1 );
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */