12 #if defined __cplusplus
17 #define SMR_InitialMessageSize 1024
18 #define SMR_IncrementMessageSize 1024
21 static char smr_mallocFailed[] =
"statusMessageReporting could not allocate memory for message";
37 enum smr_status status,
char const *fmt, va_list *args );
70 numberOfRegisteredLibraries = 0;
87 if( (
registeredLibraries[numberOfRegisteredLibraries] = strdup( libraryName ) ) == NULL )
return( -2 );
89 return( numberOfRegisteredLibraries - 1 );
122 if( smr == NULL )
return( 0 );
133 if( smr == NULL )
return( NULL );
143 if( smr == NULL )
return;
144 for( current = first; current != NULL; current = next ) {
156 if( smr == NULL )
return( NULL );
194 if( report->
message != NULL ) {
203 enum smr_status status,
char const *fmt, va_list *args ) {
208 if( smr == NULL )
return( 0 );
209 if( (
int) status < (
int) smr->
verbosity )
return( 0 );
214 next->
next = report; }
216 if( status <= smr->report.
status )
return( 0 );
231 if( userInterface != NULL ) {
232 if( ( userMsg = (*(
smr_userInterface *) userInterface)( (
void *) userInterface ) ) != NULL ) {
233 int userSize = (
int) strlen( userMsg );
238 strcat( report->
message, userMsg );
249 vfprintf( stderr, fmt, *args );
251 fprintf( stderr,
"\nAt line %d of %s in function %s\n", line, file,
function );
252 if( report != NULL ) {
267 va_start( args, fmt );
287 va_start( args, fmt );
307 va_start( args, fmt );
373 if( report == NULL )
return( 0 );
381 if( report == NULL )
return( 0 );
389 if( report == NULL )
return( 0 );
397 if( report == NULL )
return( 0 );
405 if( report == NULL )
return( 0 );
416 if( smr == NULL )
return( 0 );
426 if( smr == NULL )
return( NULL );
435 if( report == NULL )
return( NULL );
436 return( report->
next );
451 if( smr == NULL )
return( 0 );
459 if( report == NULL )
return( 0 );
467 if( report == NULL )
return( -1 );
468 return( report->
code );
475 if( report == NULL )
return( -1 );
476 return( report->
line );
483 if( report == NULL )
return( NULL );
491 if( report == NULL )
return( NULL );
499 if( report == NULL )
return( NULL );
507 if( report == NULL )
return( NULL );
516 if( report == NULL )
return( NULL );
534 if( smr == NULL )
return;
573 va_start( args, fmt );
588 va_copy( args_, *args );
589 n = vsnprintf( message, size, fmt, args_ );
591 if( ( n > -1 ) && ( n < size ) )
break;
597 if( message == buffer ) message = NULL;
598 if( ( message = (
char *) realloc( message, size ) ) == NULL )
return( NULL );
600 if( message == buffer ) {
601 if( ( message = (
char *) malloc( n + 1 ) ) == NULL )
return( NULL );
602 strcpy( message, buffer ); }
604 if( ( message = (
char *) realloc( message, n + 1 ) ) == NULL )
return( NULL );
613 void *
p =
smr_realloc( smr, NULL, size, forItem, file, line,
function );
618 if( ( p != NULL ) && zero ) {
619 for( i = 0, l = (
long long *) p; i < size /
sizeof(
long long ); i++, l++ ) *l = 0;
620 for( i *=
sizeof(
long long ), c = (
char *) l; i < size; i++, c++ ) *c = 0;
630 void *
p = realloc( pOld, size );
632 if( ( p == NULL ) && ( smr != NULL ) ) {
633 smr_setReportError( smr, NULL, file, line,
function,
smr_smrID, -1,
" smr_realloc: failed to realloc size = %z for variable %s\n", size, forItem );
642 if( p == NULL )
return( NULL );
656 char *c = strdup( s );
658 if( c == NULL )
smr_setReportError( smr, NULL, file, line,
function,
smr_smrID, -1,
" smr_allocateCopyString: strdup failed for strlen( s ) = %z for variable %s",
659 strlen( s ), forItem );
669 size_t l = strlen( s );
673 if( ( c = (
char *)
smr_malloc( smr, l + 1, 0, forItem, file, line,
function ) ) != NULL ) {
689 #if defined __cplusplus
int smr_isReportWarning(statusMessageReport *report)
static char statusStringInfo[]
int smr_numberOfRegisteredLibraries(void)
char function[smr_maximumFileNameSize+1]
char * smr_allocateCopyStringN(statusMessageReporting *smr, char const *s, size_t n, char const *forItem, char const *file, int line, char const *function)
static char smr_mallocFailed[]
#define smr_realloc2(smr, old, size, forItem)
enum smr_status smr_getVerbosity(statusMessageReporting *smr)
int smr_isInfo(statusMessageReporting *smr)
static void smr_reportRelease(statusMessageReport *report)
statusMessageReport * smr_nextReport(statusMessageReport *report)
int smr_isWarningOrError(statusMessageReporting *smr)
int smr_isReportWarningOrError(statusMessageReport *report)
void message(RunManager *runmanager)
int smr_isReportError(statusMessageReport *report)
void * smr_realloc(statusMessageReporting *smr, void *pOld, size_t size, char const *forItem, char const *file, int line, char const *function)
static int numberOfRegisteredLibraries
int smr_setReportInfo(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
char * smr_allocateCopyString(statusMessageReporting *smr, char const *s, char const *forItem, char const *file, int line, char const *function)
enum smr_status smr_highestStatus(statusMessageReporting *smr)
int smr_isReportOk(statusMessageReport *report)
static int smr_setReport(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, enum smr_status status, char const *fmt, va_list *args)
#define smr_maximumNumberOfRegisteredLibraries
static char tooManyLibrary[]
static int smr_reportInitialize(statusMessageReport *report)
void smr_reportPrint(statusMessageReport *report)
int smr_getCode(statusMessageReport *report)
#define smr_malloc2(smr, size, zero, forItem)
void smr_reportWrite(statusMessageReport *report, FILE *f)
statusMessageReporting * smr_clone(statusMessageReporting *smr)
char const * smr_getRegisteredLibrariesName(int ID)
static char * registeredLibraries[smr_maximumNumberOfRegisteredLibraries]
char const * smr_getFile(statusMessageReport *report)
int smr_isOk(statusMessageReporting *smr)
int smr_getLibraryID(statusMessageReport *report)
int smr_isError(statusMessageReporting *smr)
void * smr_malloc(statusMessageReporting *smr, size_t size, int zero, char const *forItem, char const *file, int line, char const *function)
int smr_initialize(statusMessageReporting *smr, enum smr_status verbosity, int append)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static int smr_setAllocationFailure(statusMessageReport *report, char const *file, int line, char const *function, char const *fmt, va_list *args)
static char statusStringError[]
int smr_vsetReportInfo(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt, va_list *args)
int smr_vsetReportWarning(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt, va_list *args)
static statusMessageReport * smr_reportNew(void)
int smr_isReportInfo(statusMessageReport *report)
statusMessageReporting * smr_new(statusMessageReporting *smr, enum smr_status verbosity, int append)
char const * smr_getMessage(statusMessageReport *report)
void smr_write(statusMessageReporting *smr, FILE *f, int clear)
#define smr_maximumFileNameSize
void * smr_freeMemory(void **p)
int smr_registerLibrary(char const *libraryName)
char * smr_vallocateFormatMessage(char const *fmt, va_list *args)
int smr_setReportWarning(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
static char unknownLibrary[]
int smr_getAppend(statusMessageReporting *smr)
enum smr_status verbosity
char const * smr_getFunction(statusMessageReport *report)
int smr_getLine(statusMessageReport *report)
char * smr_allocateFormatMessage(char const *fmt,...)
char const * smr_statusToString(enum smr_status status)
static char statusStringOk[]
static char invalidLibrary[]
void smr_release(statusMessageReporting *smr)
int smr_isWarning(statusMessageReporting *smr)
char fileName[smr_maximumFileNameSize+1]
int smr_vsetReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt, va_list *args)
static char statusStringInvalid[]
char *(* smr_userInterface)(void *userData)
#define SMR_IncrementMessageSize
static char statusStringWarning[]
char * smr_copyFullMessage(statusMessageReport *report)
void smr_print(statusMessageReporting *smr, int clear)
int smr_setReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
#define SMR_InitialMessageSize
char * smr_copyMessage(statusMessageReport *report)
static char errnoLibrary[]
void * smr_free(statusMessageReporting **smr)
int smr_numberOfReports(statusMessageReporting *smr)
statusMessageReport * smr_firstReport(statusMessageReporting *smr)
statusMessageReport report
struct statusMessageReport * next