Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/hadronic/models/lend/src/statusMessageReporting.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/hadronic/models/lend/src/statusMessageReporting.cc (Version 11.3.0) and /processes/hadronic/models/lend/src/statusMessageReporting.cc (Version 10.0)


                                                   >>   1 /*
                                                   >>   2 # <<BEGIN-copyright>>
                                                   >>   3 # Copyright (c) 2010, Lawrence Livermore National Security, LLC. 
                                                   >>   4 # Produced at the Lawrence Livermore National Laboratory 
                                                   >>   5 # Written by Bret R. Beck, beck6@llnl.gov. 
                                                   >>   6 # CODE-461393
                                                   >>   7 # All rights reserved. 
                                                   >>   8 #  
                                                   >>   9 # This file is part of GIDI. For details, see nuclear.llnl.gov. 
                                                   >>  10 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov. 
                                                   >>  11 # 
                                                   >>  12 # Redistribution and use in source and binary forms, with or without modification, 
                                                   >>  13 # are permitted provided that the following conditions are met: 
                                                   >>  14 #
                                                   >>  15 #      1) Redistributions of source code must retain the above copyright notice, 
                                                   >>  16 #         this list of conditions and the disclaimer below.
                                                   >>  17 #      2) Redistributions in binary form must reproduce the above copyright notice, 
                                                   >>  18 #         this list of conditions and the disclaimer (as noted below) in the 
                                                   >>  19 #          documentation and/or other materials provided with the distribution.
                                                   >>  20 #      3) Neither the name of the LLNS/LLNL nor the names of its contributors may be 
                                                   >>  21 #         used to endorse or promote products derived from this software without 
                                                   >>  22 #         specific prior written permission. 
                                                   >>  23 #
                                                   >>  24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
                                                   >>  25 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
                                                   >>  26 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT 
                                                   >>  27 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 
                                                   >>  28 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
                                                   >>  29 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
                                                   >>  30 # OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
                                                   >>  31 # AND ON  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
                                                   >>  32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
                                                   >>  33 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
                                                   >>  34 # <<END-copyright>>
                                                   >>  35 */
  1 #include <stdio.h>                                 36 #include <stdio.h>
  2 #include <stdlib.h>                                37 #include <stdlib.h>
  3 #include <string.h>                                38 #include <string.h>
  4 #include <stdarg.h>                                39 #include <stdarg.h>
  5                                                    40 
  6 #ifdef WIN32                                   << 
  7 /*#define va_copy(dst, src) ((dst) = (src))*/  << 
  8 #endif                                         << 
  9                                                << 
 10 #include "statusMessageReporting.h"                41 #include "statusMessageReporting.h"
 11                                                    42 
 12 #if defined __cplusplus                            43 #if defined __cplusplus
 13 namespace GIDI {                                   44 namespace GIDI {
 14 using namespace GIDI;                              45 using namespace GIDI;
 15 #endif                                             46 #endif
 16                                                    47 
 17 #define SMR_InitialMessageSize 1024            <<  48 static const char smr_mallocFailed[] = "statusMessageReporting could not allocate memory for message";
 18 #define SMR_IncrementMessageSize 1024          << 
 19                                                << 
 20 static int smrIsSetup = 0;                     << 
 21 static char smr_mallocFailed[] = "statusMessag << 
 22 static char statusStringOk[] = "Ok",  statusSt << 
 23     statusStringWarning[] = "Warning", statusS << 
 24                                                << 
 25 static int numberOfRegisteredLibraries = 0;    << 
 26 static char unknownLibrary[] = "unknownID";    << 
 27 static char tooManyLibrary[] = "tooManyIDs";   << 
 28 static char invalidLibrary[] = "invalidID";    << 
 29 static char errnoLibrary[] = "errnoID";        << 
 30 static char smrLibrary[] = "statusMessageRepor << 
 31 static char *registeredLibraries[smr_maximumNu << 
 32                                                << 
 33 static statusMessageReport *smr_reportNew( voi << 
 34 static int smr_reportInitialize( statusMessage << 
 35 static void smr_reportRelease( statusMessageRe << 
 36 static int smr_setReport( statusMessageReporti << 
 37     enum smr_status status, char const *fmt, v << 
 38 static int smr_setAllocationFailure( statusMes << 
 39 /*                                             << 
 40 ============================================== << 
 41 */                                             << 
 42 int smr_setup( void ) {                        << 
 43                                                << 
 44     int i;                                     << 
 45                                                << 
 46     if( smrIsSetup ) return( 0 );              << 
 47     smrIsSetup = 1;                            << 
 48     for( i = 0; i < smr_maximumNumberOfRegiste << 
 49     registeredLibraries[smr_unknownID] = unkno << 
 50     ++numberOfRegisteredLibraries;             << 
 51     registeredLibraries[smr_tooManyIDs] = tooM << 
 52     ++numberOfRegisteredLibraries;             << 
 53     registeredLibraries[smr_invalidID] = inval << 
 54     ++numberOfRegisteredLibraries;             << 
 55     registeredLibraries[smr_errnoID] = errnoLi << 
 56     ++numberOfRegisteredLibraries;             << 
 57     registeredLibraries[smr_smrID] = smrLibrar << 
 58     ++numberOfRegisteredLibraries;             << 
 59     return( 1 );                               << 
 60 }                                              << 
 61 /*                                             << 
 62 ============================================== << 
 63 */                                             << 
 64 int smr_cleanup( void ) {                      << 
 65                                                << 
 66     int i;                                     << 
 67                                                << 
 68     if( smrIsSetup == 0 ) return( 0 );         << 
 69     for( i = smr_smrID + 1; i < numberOfRegist << 
 70     numberOfRegisteredLibraries = 0;           << 
 71     smrIsSetup = 0;                            << 
 72                                                << 
 73     return( 0 );                               << 
 74 }                                              << 
 75 /*                                             << 
 76 ============================================== << 
 77 */                                             << 
 78 int smr_registerLibrary( char const *libraryNa << 
 79                                                << 
 80     int i;                                     << 
 81                                                << 
 82     if( smrIsSetup == 0 ) return( -1 );        << 
 83     if( numberOfRegisteredLibraries == smr_max << 
 84     for( i = 0; i < numberOfRegisteredLibrarie << 
 85         if( strcmp( libraryName, registeredLib << 
 86     }                                          << 
 87     if( ( registeredLibraries[numberOfRegister << 
 88     ++numberOfRegisteredLibraries;             << 
 89     return( numberOfRegisteredLibraries - 1 ); << 
 90 }                                              << 
 91 /*                                             << 
 92 ============================================== << 
 93 */                                             << 
 94 int smr_numberOfRegisteredLibraries( void ) {  << 
 95                                                << 
 96     return( numberOfRegisteredLibraries );     << 
 97 }                                              << 
 98 /*                                             << 
 99 ============================================== << 
100 */                                             << 
101 char const *smr_getRegisteredLibrariesName( in << 
102                                                << 
103     if( ( ID < 0 ) || ( ID >= smr_maximumNumbe << 
104     return( registeredLibraries[ID] );         << 
105 }                                              << 
106 /*                                             << 
107 ============================================== << 
108 */                                             << 
109 statusMessageReporting *smr_new( statusMessage << 
110                                                << 
111     statusMessageReporting *new_SMR;           << 
112                                                << 
113     if( ( new_SMR = (statusMessageReporting *) << 
114     smr_initialize( new_SMR, verbosity, append << 
115     return( new_SMR );                         << 
116 }                                              << 
117 /*                                             << 
118 ============================================== << 
119 */                                             << 
120 int smr_initialize( statusMessageReporting *sm << 
121                                                << 
122     if( smr == NULL ) return( 0 );             << 
123     smr->verbosity = verbosity;                << 
124     smr->append = append;                      << 
125     smr_reportInitialize( &(smr->report) );    << 
126     return( 0 );                               << 
127 }                                              << 
128 /*                                             << 
129 ============================================== << 
130 */                                             << 
131 statusMessageReporting *smr_clone( statusMessa << 
132                                                << 
133     if( smr == NULL ) return( NULL );          << 
134     return( smr_new( NULL, smr->verbosity, smr << 
135 }                                              << 
136 /*                                             << 
137 ============================================== << 
138 */                                             << 
139 void smr_release( statusMessageReporting *smr  << 
140                                                << 
141     statusMessageReport *current, *next, *firs << 
142                                                << 
143     if( smr == NULL ) return;                  << 
144     for( current = first; current != NULL; cur << 
145         next = smr_nextReport( current );      << 
146         smr_reportRelease( current );          << 
147         if( current != first ) smr_freeMemory( << 
148     }                                          << 
149     smr_initialize( smr, smr->verbosity, smr-> << 
150 }                                              << 
151 /*                                             << 
152 ============================================== << 
153 */                                             << 
154 void *smr_free( statusMessageReporting **smr ) << 
155                                                << 
156     if( smr == NULL ) return( NULL );          << 
157     if( *smr != NULL ) {                       << 
158         smr_release( *smr );                   << 
159         smr_freeMemory( (void **) smr );       << 
160     }                                          << 
161     return( *smr );                            << 
162 }                                              << 
163 /*                                             << 
164 ============================================== << 
165 */                                             << 
166 static statusMessageReport *smr_reportNew( voi << 
167                                                    49 
168     statusMessageReport *report;               <<  50 static int smr_setAllocationFailure( statusMessageReporting *smr, const char *fmt, va_list *args );
169                                                <<  51 static int smr_setMessage( statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, 
170     if( ( report = (statusMessageReport *) smr <<  52     enum smr_status status, const char *fmt, va_list *args );
171     smr_reportInitialize( report );            <<  53 static char *smr_getFullMessage2( char const *fmt, ... );
172     return( report );                          <<  54 /*
173 }                                              <<  55 ************************************************************
174 /*                                             <<  56 */
175 ============================================== <<  57 int smr_initialize( statusMessageReporting *smr ) {
176 */                                             <<  58 
177 static int smr_reportInitialize( statusMessage <<  59     smr->status = smr_status_Ok;
178                                                <<  60     smr->packageName[0] = 0;
179     report->next = NULL;                       <<  61     smr->line= -1;
180     report->status = smr_status_Ok;            <<  62     smr->code = 0;
181     report->libraryID = smr_unknownID;         <<  63     smr->message = NULL;
182     report->code = smr_codeNULL;               << 
183     report->line = -1;                         << 
184     report->fileName[0] = 0;                   << 
185     report->function[0] = 0;                   << 
186     report->message = NULL;                    << 
187     return( 0 );                                   64     return( 0 );
188 }                                                  65 }
189 /*                                                 66 /*
190 ============================================== <<  67 ************************************************************
191 */                                                 68 */
192 static void smr_reportRelease( statusMessageRe <<  69 int smr_release( statusMessageReporting *smr ) {
193                                                    70 
194     if( report->message != NULL ) {            <<  71     if( smr->message != NULL ) {
195         if( report->message != smr_mallocFaile <<  72         if( smr->message != smr_mallocFailed ) free( smr->message );
196     }                                              73     }
197     smr_reportInitialize( report );            <<  74     return( smr_initialize( smr ) );
198 }                                                  75 }
199 /*                                                 76 /*
200 ============================================== <<  77 ************************************************************
201 */                                                 78 */
202 static int smr_setReport( statusMessageReporti <<  79 int smr_setMessageInfo( statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, ... ) {
203     enum smr_status status, char const *fmt, v << 
204                                                << 
205     char *userMsg;                             << 
206     statusMessageReport *report, *next;        << 
207                                                << 
208     if( smr == NULL ) return( 0 );             << 
209     if( (int) status < (int) smr->verbosity )  << 
210     if( status == smr_status_Ok ) return( 0 ); << 
211     if( ( smr->report.status != smr_status_Ok  << 
212         if( ( report = smr_reportNew( ) ) == N << 
213         for( next = smr_firstReport( smr ); ne << 
214         next->next = report; }                 << 
215     else {                                     << 
216         if( status <= smr->report.status ) ret << 
217         smr_release( smr );                    << 
218         report = &(smr->report);               << 
219     }                                          << 
220     report->status = status;                   << 
221     if( ( libraryID < 0 ) || ( libraryID >= nu << 
222     report->libraryID = libraryID;             << 
223     report->code = code;                       << 
224     report->line = line;                       << 
225     if( file != NULL ) strncpy( report->fileNa << 
226     report->fileName[smr_maximumFileNameSize]  << 
227     if( function != NULL ) strncpy( report->fu << 
228     report->function[smr_maximumFileNameSize]  << 
229                                                << 
230     if( ( report->message = smr_vallocateForma << 
231     if( userInterface != NULL ) {              << 
232         if( ( userMsg = (*(smr_userInterface * << 
233             int userSize = (int) strlen( userM << 
234             if( ( report->message = (char *) s << 
235                 free( userMsg );               << 
236                 return( smr_setAllocationFailu << 
237             }                                  << 
238             strcat( report->message, userMsg ) << 
239             free( userMsg );                   << 
240         }                                      << 
241     }                                          << 
242     return( 0 );                               << 
243 }                                              << 
244 /*                                             << 
245 ============================================== << 
246 */                                             << 
247 static int smr_setAllocationFailure( statusMes << 
248                                                << 
249     vfprintf( stderr, fmt, *args );            << 
250     va_end( *args );                           << 
251     fprintf( stderr, "\nAt line %d of %s in fu << 
252     if( report != NULL ) {                     << 
253         report->status = smr_status_Error;     << 
254         report->message = (char *) smr_mallocF << 
255         return( 1 );                           << 
256     }                                          << 
257     return( -1 );                              << 
258 }                                              << 
259 /*                                             << 
260 ============================================== << 
261 */                                             << 
262 int smr_setReportInfo( statusMessageReporting  << 
263                                                    80 
264     int status;                                    81     int status;
265     va_list args;                                  82     va_list args;
266                                                    83 
267     va_start( args, fmt );                         84     va_start( args, fmt );
268     status = smr_setReport( smr, userInterface <<  85     status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Info, fmt, &args );
269     va_end( args );                                86     va_end( args );
270     return( status );                              87     return( status );
271 }                                                  88 }
272 /*                                                 89 /*
273 ============================================== <<  90 ************************************************************
274 */                                                 91 */
275 int smr_vsetReportInfo( statusMessageReporting <<  92 int smr_vsetMessageInfo( statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args ) {
276                                                    93 
277     return( smr_setReport( smr, userInterface, <<  94     int status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Info, fmt, args );
                                                   >>  95     return( status );
278 }                                                  96 }
279 /*                                                 97 /*
280 ============================================== <<  98 ************************************************************
281 */                                                 99 */
282 int smr_setReportWarning( statusMessageReporti << 100 int smr_setMessageError( statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, ... ) {
283                                                   101 
284     int status;                                   102     int status;
285     va_list args;                                 103     va_list args;
286                                                   104 
287     va_start( args, fmt );                        105     va_start( args, fmt );
288     status = smr_setReport( smr, userInterface << 106     status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Error, fmt, &args );
289     va_end( args );                               107     va_end( args );
290     return( status );                             108     return( status );
291 }                                                 109 }
292 /*                                                110 /*
293 ============================================== << 111 ************************************************************
294 */                                                112 */
295 int smr_vsetReportWarning( statusMessageReport << 113 int smr_vsetMessageError( statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args ) {
296                                                   114 
297     return( smr_setReport( smr, userInterface, << 115     int status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Error, fmt, args );
                                                   >> 116     return( status );
298 }                                                 117 }
299 /*                                                118 /*
300 ============================================== << 119 ************************************************************
301 */                                                120 */
302 int smr_setReportError( statusMessageReporting << 121 char *smr_allocateFormatMessage( const char *fmt, ... ) {
303                                                   122 
304     int status;                                << 123     char *s;
305     va_list args;                                 124     va_list args;
306                                                   125 
307     va_start( args, fmt );                        126     va_start( args, fmt );
308     status = smr_setReport( smr, userInterface << 127     s = smr_vallocateFormatMessage( fmt, &args );
309     va_end( args );                               128     va_end( args );
310     return( status );                          << 129     return( s );
311 }                                              << 
312 /*                                             << 
313 ============================================== << 
314 */                                             << 
315 int smr_vsetReportError( statusMessageReportin << 
316                                                << 
317     return( smr_setReport( smr, userInterface, << 
318 }                                              << 
319 /*                                             << 
320 ============================================== << 
321 */                                             << 
322 enum smr_status smr_highestStatus( statusMessa << 
323                                                << 
324     enum smr_status status = smr_status_Ok;    << 
325     statusMessageReport *report;               << 
326                                                << 
327     if( smr == NULL ) return( smr_status_Ok ); << 
328     for( report = smr_firstReport( smr ); repo << 
329     return( status );                          << 
330 }                                              << 
331 /*                                             << 
332 ============================================== << 
333 */                                             << 
334 int smr_isOk( statusMessageReporting *smr ) {  << 
335                                                << 
336     return( smr_highestStatus( smr ) == smr_st << 
337 }                                              << 
338 /*                                             << 
339 ============================================== << 
340 */                                             << 
341 int smr_isInfo( statusMessageReporting *smr )  << 
342                                                << 
343     return( smr_highestStatus( smr ) == smr_st << 
344 }                                              << 
345 /*                                             << 
346 ============================================== << 
347 */                                             << 
348 int smr_isWarning( statusMessageReporting *smr << 
349                                                << 
350     return( smr_highestStatus( smr ) == smr_st << 
351 }                                              << 
352 /*                                             << 
353 ============================================== << 
354 */                                             << 
355 int smr_isError( statusMessageReporting *smr ) << 
356                                                << 
357     return( smr_highestStatus( smr ) == smr_st << 
358 }                                              << 
359 /*                                             << 
360 ============================================== << 
361 */                                             << 
362 int smr_isWarningOrError( statusMessageReporti << 
363                                                << 
364     enum smr_status status = smr_highestStatus << 
365                                                << 
366     return( ( status == smr_status_Warning ) | << 
367 }                                              << 
368 /*                                             << 
369 ============================================== << 
370 */                                             << 
371 int smr_isReportOk( statusMessageReport *repor << 
372                                                << 
373     if( report == NULL ) return( 0 );          << 
374     return( report->status == smr_status_Ok ); << 
375 }                                              << 
376 /*                                             << 
377 ============================================== << 
378 */                                             << 
379 int smr_isReportInfo( statusMessageReport *rep << 
380                                                << 
381     if( report == NULL ) return( 0 );          << 
382     return( report->status == smr_status_Info  << 
383 }                                              << 
384 /*                                             << 
385 ============================================== << 
386 */                                             << 
387 int smr_isReportWarning( statusMessageReport * << 
388                                                << 
389     if( report == NULL ) return( 0 );          << 
390     return( report->status == smr_status_Warni << 
391 }                                              << 
392 /*                                             << 
393 ============================================== << 
394 */                                             << 
395 int smr_isReportError( statusMessageReport *re << 
396                                                << 
397     if( report == NULL ) return( 0 );          << 
398     return( report->status == smr_status_Error << 
399 }                                              << 
400 /*                                             << 
401 ============================================== << 
402 */                                             << 
403 int smr_isReportWarningOrError( statusMessageR << 
404                                                << 
405     if( report == NULL ) return( 0 );          << 
406     return( ( report->status == smr_status_War << 
407 }                                              << 
408 /*                                             << 
409 ============================================== << 
410 */                                             << 
411 int smr_numberOfReports( statusMessageReportin << 
412                                                << 
413     int n = 0;                                 << 
414     statusMessageReport *report;               << 
415                                                << 
416     if( smr == NULL ) return( 0 );             << 
417     if( smr->report.status == smr_status_Ok )  << 
418     for( report = smr_firstReport( smr ); repo << 
419     return( n );                               << 
420 }                                                 130 }
421 /*                                                131 /*
422 ============================================== << 132 ************************************************************
423 */                                                133 */
424 statusMessageReport *smr_firstReport( statusMe << 134 char *smr_vallocateFormatMessage( const char *fmt, va_list *args ) {
425                                                   135 
426     if( smr == NULL ) return( NULL );          << 136     int n, size = 128;
427     if( smr->report.status == smr_status_Ok )  << 137     char *message = NULL;
428     return( &(smr->report) );                  << 138     va_list args_;
429 }                                              << 
430 /*                                             << 
431 ============================================== << 
432 */                                             << 
433 statusMessageReport *smr_nextReport( statusMes << 
434                                                   139 
435     if( report == NULL ) return( NULL );       << 140     while( 1 ) {
436     return( report->next );                    << 141         if( ( message = (char *) realloc( message, size ) ) == NULL ) return( NULL );
                                                   >> 142         //TK110426
                                                   >> 143 #if defined WIN32
                                                   >> 144         args_ = *args;
                                                   >> 145 #elif defined __IBMCPP__
                                                   >> 146         va_copy( args_, *args );
                                                   >> 147 #else
                                                   >> 148         __va_copy( args_, *args );
                                                   >> 149 #endif
                                                   >> 150         n = vsnprintf( message, size, fmt, args_ );
                                                   >> 151         va_end( args_ );
                                                   >> 152         if( ( n > -1 ) && ( n < size ) ) break;
                                                   >> 153         if( n > -1 ) {      /* glibc 2.1 */
                                                   >> 154             size = n + 3; }
                                                   >> 155         else {              /* glibc 2.0 */
                                                   >> 156             size += 128;
                                                   >> 157         }
                                                   >> 158     }
                                                   >> 159     return( message );
437 }                                                 160 }
438 /*                                                161 /*
439 ============================================== << 162 ************************************************************
440 */                                                163 */
441 enum smr_status smr_getVerbosity( statusMessag << 164 static int smr_setMessage( statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, 
                                                   >> 165     enum smr_status status, const char *fmt, va_list *args ) {
442                                                   166 
443     if( smr == NULL ) return( smr_status_Ok ); << 167     char *userMsg = NULL;
444     return( smr->verbosity );                  << 168     int userSize;
445 }                                              << 
446 /*                                             << 
447 ============================================== << 
448 */                                             << 
449 int smr_getAppend( statusMessageReporting *smr << 
450                                                   169 
451     if( smr == NULL ) return( 0 );                170     if( smr == NULL ) return( 0 );
452     return( smr->append );                     << 171     smr_release( smr );
453 }                                              << 172     smr->status = status;
454 /*                                             << 173     if( file != NULL ) strncpy( smr->packageName, file, smr_maximumPackageNameSize );
455 ============================================== << 174     smr->packageName[smr_maximumPackageNameSize-1] = 0;
456 */                                             << 175     smr->line= line;
457 int smr_getLibraryID( statusMessageReport *rep << 176     smr->code = code;
458                                                << 
459     if( report == NULL ) return( 0 );          << 
460     return( report->libraryID );               << 
461 }                                              << 
462 /*                                             << 
463 ============================================== << 
464 */                                             << 
465 int smr_getCode( statusMessageReport *report ) << 
466                                                << 
467     if( report == NULL ) return( -1 );         << 
468     return( report->code );                    << 
469 }                                              << 
470 /*                                             << 
471 ============================================== << 
472 */                                             << 
473 int smr_getLine( statusMessageReport *report ) << 
474                                                << 
475     if( report == NULL ) return( -1 );         << 
476     return( report->line );                    << 
477 }                                              << 
478 /*                                             << 
479 ============================================== << 
480 */                                             << 
481 char const *smr_getFile( statusMessageReport * << 
482                                                << 
483     if( report == NULL ) return( NULL );       << 
484     return( report->fileName );                << 
485 }                                              << 
486 /*                                             << 
487 ============================================== << 
488 */                                             << 
489 char const *smr_getFunction( statusMessageRepo << 
490                                                << 
491     if( report == NULL ) return( NULL );       << 
492     return( report->function );                << 
493 }                                              << 
494 /*                                             << 
495 ============================================== << 
496 */                                             << 
497 char const *smr_getMessage( statusMessageRepor << 
498                                                   177 
499     if( report == NULL ) return( NULL );       << 178     if( ( smr->message = smr_vallocateFormatMessage( fmt, args ) ) == NULL ) return( smr_setAllocationFailure( smr, fmt, args ) );
500     return( report->message );                 << 179     if( userInterface != NULL ) {
                                                   >> 180         if( ( userSize = (*(smr_userInterface *) userInterface)( (void *) userInterface, NULL ) ) > 0 ) {
                                                   >> 181             //if( (smr->message = realloc(smr->message, strlen( smr->message ) + userSize + 2)) == NULL ) return( smr_setAllocationFailure( smr, fmt, args ) );
                                                   >> 182             if( (smr->message = (char*) realloc(smr->message, strlen( smr->message ) + userSize + 2)) == NULL ) return( smr_setAllocationFailure( smr, fmt, args ) );
                                                   >> 183             strcat( smr->message, "\n" );
                                                   >> 184             userSize = (*(smr_userInterface *) userInterface)( (void *) userInterface, &userMsg );
                                                   >> 185             if( userSize < 0 ) return( smr_setAllocationFailure( smr, fmt, args ) );
                                                   >> 186             if( userSize > 0 ) {
                                                   >> 187                 strcat( smr->message, userMsg );
                                                   >> 188                 free( userMsg );
                                                   >> 189             }
                                                   >> 190         }
                                                   >> 191     }
                                                   >> 192     return( 0 );
501 }                                                 193 }
502 /*                                                194 /*
503 ============================================== << 195 ************************************************************
504 */                                                196 */
505 char *smr_copyMessage( statusMessageReport *re << 197 static int smr_setAllocationFailure( statusMessageReporting *smr, const char *fmt, va_list *args ) {
506                                                   198 
507     if( report == NULL ) return( NULL );       << 199     vfprintf( stderr, fmt, *args );      /* Assume calling routine calls va_end( args ). */
508     if( report->status == smr_status_Ok ) retu << 200     fprintf( stderr, "\nAt line %d of %s\n", smr->line, smr->packageName );
509     return( smr_allocateFormatMessage( report- << 201     smr->status = smr_status_Fatal;
                                                   >> 202     smr->message = (char *) smr_mallocFailed;
                                                   >> 203     return( 1 );
510 }                                                 204 }
511 /*                                                205 /*
512 ============================================== << 206 ************************************************************
513 */                                                207 */
514 char *smr_copyFullMessage( statusMessageReport << 208 int smr_isOk( statusMessageReporting *smr ) { 
515                                                   209 
516     if( report == NULL ) return( NULL );       << 210     if( smr == NULL ) return( 1 );
517     if( report->status == smr_status_Ok ) retu << 211     return( smr->status == smr_status_Ok );
518     return( smr_allocateFormatMessage( "%s\nAt << 
519 }                                                 212 }
520 /*                                                213 /*
521 ============================================== << 214 ************************************************************
522 */                                                215 */
523 void smr_print( statusMessageReporting *smr, i << 216 int smr_isInfo( statusMessageReporting *smr ) { 
524                                                   217 
525     smr_write( smr, stdout, clear );           << 218     if( smr == NULL ) return( 1 );
                                                   >> 219     return( smr->status == smr_status_Info );
526 }                                                 220 }
527 /*                                                221 /*
528 ============================================== << 222 ************************************************************
529 */                                                223 */
530 void smr_write( statusMessageReporting *smr, F << 224 int smr_isError( statusMessageReporting *smr ) { 
531                                                << 
532     statusMessageReport *report;               << 
533                                                   225 
534     if( smr == NULL ) return;                  << 226     if( smr == NULL ) return( 1 );
535     for( report = smr_firstReport( smr ); repo << 227     return( ( smr->status == smr_status_Error ) || ( smr->status == smr_status_Fatal ) );
536     if( clear ) smr_release( smr );            << 
537 }                                                 228 }
538 /*                                                229 /*
539 ============================================== << 230 ************************************************************
540 */                                                231 */
541 void smr_reportPrint( statusMessageReport *rep << 232 int smr_isFatal( statusMessageReporting *smr ) { 
542                                                   233 
543     smr_reportWrite( report, stderr );         << 234     if( smr == NULL ) return( 1 );
                                                   >> 235     return( smr->status == smr_status_Fatal );
544 }                                                 236 }
545 /*                                                237 /*
546 ============================================== << 238 ************************************************************
547 */                                                239 */
548 void smr_reportWrite( statusMessageReport *rep << 240 const char *smr_getMessage( statusMessageReporting *smr ) {
549                                                   241 
550     if( report->message != NULL ) fprintf( f,  << 242     return( smr->message );
551 }                                                 243 }
552 /*                                                244 /*
553 ============================================== << 245 ************************************************************
554 */                                                246 */
555 char const *smr_statusToString( enum smr_statu << 247 char *smr_getFullMessage( statusMessageReporting *smr ) {
556                                                   248 
557     switch( status ) {                         << 249     return( smr_getFullMessage2( "%s\nAt line %d of %s", smr->message, smr->line, smr->packageName ) );
558     case smr_status_Ok : return( statusStringO << 
559     case smr_status_Info : return( statusStrin << 
560     case smr_status_Warning : return( statusSt << 
561     case smr_status_Error : return( statusStri << 
562     }                                          << 
563     return( statusStringInvalid );             << 
564 }                                                 250 }
565 /*                                                251 /*
566 ============================================== << 252 ************************************************************
567 */                                                253 */
568 char *smr_allocateFormatMessage( char const *f << 254 static char *smr_getFullMessage2( char const *fmt, ... ) {
569                                                   255 
570     char *s;                                   << 
571     va_list args;                                 256     va_list args;
                                                   >> 257     char *message;
572                                                   258 
573     va_start( args, fmt );                        259     va_start( args, fmt );
574     s = smr_vallocateFormatMessage( fmt, &args << 260     message = smr_vallocateFormatMessage( fmt, &args );
575     va_end( args );                               261     va_end( args );
576     return( s );                               << 
577 }                                              << 
578 /*                                             << 
579 ============================================== << 
580 */                                             << 
581 char *smr_vallocateFormatMessage( char const * << 
582                                                << 
583     int n, size = SMR_InitialMessageSize;      << 
584     char buffer[SMR_InitialMessageSize], *mess << 
585     va_list args_;                             << 
586                                                << 
587     while( 1 ) {                               << 
588         va_copy( args_, *args );               << 
589         n = vsnprintf( message, size, fmt, arg << 
590         va_end( args_ );                       << 
591         if( ( n > -1 ) && ( n < size ) ) break << 
592         if( n > -1 ) {      /* glibc 2.1 */    << 
593             size = n + 3; }                    << 
594         else {              /* glibc 2.0 */    << 
595             size += SMR_IncrementMessageSize;  << 
596         }                                      << 
597         if( message == buffer ) message = NULL << 
598         if( ( message = (char *) realloc( mess << 
599     }  // Loop checking, 11.06.2015, T. Koi    << 
600     if( message == buffer ) {                  << 
601         if( ( message = (char *) malloc( n + 1 << 
602         strcpy( message, buffer ); }           << 
603     else {                                     << 
604         if( ( message = (char *) realloc( mess << 
605     }                                          << 
606     return( message );                            262     return( message );
607 }                                                 263 }
608 /*                                                264 /*
609 ============================================== << 265 ************************************************************
610 */                                             << 
611 void *smr_malloc( statusMessageReporting *smr, << 
612                                                << 
613     void *p = smr_realloc( smr, NULL, size, fo << 
614     size_t i;                                  << 
615     char *c;                                   << 
616     long long *l;                              << 
617                                                << 
618     if( ( p != NULL ) && zero ) {              << 
619         for( i = 0, l = (long long *) p; i < s << 
620         for( i *= sizeof( long long ), c = (ch << 
621     }                                          << 
622                                                << 
623     return( p );                               << 
624 }                                              << 
625 /*                                             << 
626 ============================================== << 
627 */                                             << 
628 void *smr_realloc( statusMessageReporting *smr << 
629                                                << 
630     void *p = realloc( pOld, size );           << 
631                                                << 
632     if( ( p == NULL ) && ( smr != NULL ) ) {   << 
633         smr_setReportError( smr, NULL, file, l << 
634     }                                          << 
635     return( p );                               << 
636 }                                              << 
637 /*                                             << 
638 ============================================== << 
639 */                                                266 */
640 void *smr_freeMemory( void **p ) {             << 267 void smr_print( statusMessageReporting *smr, FILE *f, int clear ) {
641                                                   268 
642     if( p == NULL ) return( NULL );            << 269     if( smr->message != NULL ) fprintf( f, "%s\nAt line %d of %s\n", smr->message, smr->line, smr->packageName );
643     if( *p != NULL ) {                         << 270     if( clear ) smr_release( smr );
644         free( *p );                            << 
645         *p = NULL;                             << 
646     }                                          << 
647     return( *p );                              << 
648 }                                              << 
649 /*                                             << 
650 ============================================== << 
651 */                                             << 
652 char *smr_allocateCopyString( statusMessageRep << 
653 /*                                             << 
654 *   User must free returned string.            << 
655 */                                             << 
656     char *c = strdup( s );                     << 
657                                                << 
658     if( c == NULL ) smr_setReportError( smr, N << 
659                 strlen( s ), forItem );        << 
660     return( c );                               << 
661 }                                              << 
662 /*                                             << 
663 ============================================== << 
664 */                                             << 
665 char *smr_allocateCopyStringN( statusMessageRe << 
666 /*                                             << 
667 *   User must free returned string.            << 
668 */                                             << 
669     size_t l = strlen( s );                    << 
670     char *c;                                   << 
671                                                << 
672     if( l > n ) l = n;                         << 
673     if( ( c = (char *) smr_malloc( smr, l + 1, << 
674         strncpy( c, s, n );                    << 
675         c[l] = 0;                              << 
676     }                                          << 
677 /*                                             << 
678     c = strndup( s, l );        # Not standard << 
679     if( c != NULL ) {                          << 
680         c[l] = 0; }                            << 
681     else {                                     << 
682          smr_setReportError( smr, NULL, file,  << 
683             strlen( s ), forItem );            << 
684     }                                          << 
685 */                                             << 
686     return( c );                               << 
687 }                                                 271 }
688                                                   272 
689 #if defined __cplusplus                           273 #if defined __cplusplus
690 }                                                 274 }
691 #endif                                            275 #endif
692                                                   276