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
char * smr_allocateCopyStringN(statusMessageReporting *smr, char const *s, size_t n, char const *forItem, char const *file, int line, char const *function)
int smr_isReportError(statusMessageReport *report)
static char statusStringWarning[]
void smr_release(statusMessageReporting *smr)
static char statusStringError[]
static char * registeredLibraries[smr_maximumNumberOfRegisteredLibraries]
enum smr_status verbosity
statusMessageReporting * smr_clone(statusMessageReporting *smr)
static char unknownLibrary[]
char const * smr_getRegisteredLibrariesName(int ID)
static char statusStringInvalid[]
char const * smr_getFunction(statusMessageReport *report)
int smr_isWarning(statusMessageReporting *smr)
char *(* smr_userInterface)(void *userData)
void * smr_free(statusMessageReporting **smr)
#define SMR_IncrementMessageSize
static char statusStringInfo[]
int smr_getLibraryID(statusMessageReport *report)
static char smr_mallocFailed[]
int smr_numberOfReports(statusMessageReporting *smr)
int smr_isReportOk(statusMessageReport *report)
int smr_isInfo(statusMessageReporting *smr)
void smr_print(statusMessageReporting *smr, int clear)
char * smr_allocateFormatMessage(char const *fmt,...)
int smr_isReportWarning(statusMessageReport *report)
int smr_setReportInfo(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
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)
char const * smr_statusToString(enum smr_status status)
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)
statusMessageReport * smr_firstReport(statusMessageReporting *smr)
enum smr_status smr_getVerbosity(statusMessageReporting *smr)
int smr_isReportWarningOrError(statusMessageReport *report)
statusMessageReport report
static char tooManyLibrary[]
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_InitialMessageSize
int smr_getLine(statusMessageReport *report)
void smr_reportPrint(statusMessageReport *report)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static char invalidLibrary[]
static char statusStringOk[]
#define smr_malloc2(smr, size, zero, forItem)
int smr_setReportWarning(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
void smr_write(statusMessageReporting *smr, FILE *f, int clear)
enum smr_status smr_highestStatus(statusMessageReporting *smr)
char * smr_allocateCopyString(statusMessageReporting *smr, char const *s, char const *forItem, char const *file, int line, char const *function)
int smr_isOk(statusMessageReporting *smr)
char fileName[smr_maximumFileNameSize+1]
static char errnoLibrary[]
static int smr_setAllocationFailure(statusMessageReport *report, char const *file, int line, char const *function, char const *fmt, va_list *args)
char * smr_copyFullMessage(statusMessageReport *report)
static int smr_reportInitialize(statusMessageReport *report)
void * smr_freeMemory(void **p)
char * smr_vallocateFormatMessage(char const *fmt, va_list *args)
void * smr_malloc(statusMessageReporting *smr, size_t size, int zero, char const *forItem, char const *file, int line, char const *function)
int smr_setReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
int smr_isWarningOrError(statusMessageReporting *smr)
char const * smr_getFile(statusMessageReport *report)
statusMessageReporting * smr_new(statusMessageReporting *smr, enum smr_status verbosity, int append)
struct statusMessageReport * next
static statusMessageReport * smr_reportNew(void)
static int numberOfRegisteredLibraries
char * smr_copyMessage(statusMessageReport *report)
char const * smr_getMessage(statusMessageReport *report)
char function[smr_maximumFileNameSize+1]
int smr_initialize(statusMessageReporting *smr, enum smr_status verbosity, int append)
#define smr_realloc2(smr, old, size, forItem)
int smr_isError(statusMessageReporting *smr)
int smr_registerLibrary(char const *libraryName)
int smr_getAppend(statusMessageReporting *smr)
int smr_isReportInfo(statusMessageReport *report)
#define smr_maximumNumberOfRegisteredLibraries
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)
int smr_getCode(statusMessageReport *report)
void * smr_realloc(statusMessageReporting *smr, void *pOld, size_t size, char const *forItem, char const *file, int line, char const *function)
int smr_numberOfRegisteredLibraries(void)
statusMessageReport * smr_nextReport(statusMessageReport *report)
static void smr_reportRelease(statusMessageReport *report)
void smr_reportWrite(statusMessageReport *report, FILE *f)
#define smr_maximumFileNameSize