41 #include "statusMessageReporting.h"
43 #if defined __cplusplus
48 static const char smr_mallocFailed[] =
"statusMessageReporting could not allocate memory for message";
51 static int smr_setMessage( statusMessageReporting *smr,
void *userInterface,
const char *file,
int line,
int code,
52 enum smr_status status,
const char *fmt, va_list *args );
59 smr->status = smr_status_Ok;
60 smr->packageName[0] = 0;
71 if( smr->message != NULL ) {
72 if( smr->message != smr_mallocFailed )
free( smr->message );
79 int smr_setMessageInfo( statusMessageReporting *smr,
void *userInterface,
const char *file,
int line,
int code,
const char *fmt, ... ) {
84 va_start( args, fmt );
85 status =
smr_setMessage( smr, userInterface, file, line, code, smr_status_Info, fmt, &args );
92 int smr_vsetMessageInfo( statusMessageReporting *smr,
void *userInterface,
const char *file,
int line,
int code,
const char *fmt, va_list *args ) {
94 int status =
smr_setMessage( smr, userInterface, file, line, code, smr_status_Info, fmt, args );
100 int smr_setMessageError( statusMessageReporting *smr,
void *userInterface,
const char *file,
int line,
int code,
const char *fmt, ... ) {
105 va_start( args, fmt );
106 status =
smr_setMessage( smr, userInterface, file, line, code, smr_status_Error, fmt, &args );
113 int smr_vsetMessageError( statusMessageReporting *smr,
void *userInterface,
const char *file,
int line,
int code,
const char *fmt, va_list *args ) {
115 int status =
smr_setMessage( smr, userInterface, file, line, code, smr_status_Error, fmt, args );
126 va_start( args, fmt );
137 char *message = NULL;
141 if( ( message = (
char *)
realloc( message, size ) ) == NULL )
return( NULL );
145 #elif defined __IBMCPP__
146 va_copy( args_, *args );
148 __va_copy( args_, *args );
150 n = vsnprintf( message, size, fmt, args_ );
152 if( ( n > -1 ) && ( n < size ) )
break;
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 ) {
167 char *userMsg = NULL;
170 if( smr == NULL )
return( 0 );
172 smr->status = status;
173 if( file != NULL ) strncpy( smr->packageName, file, smr_maximumPackageNameSize );
174 smr->packageName[smr_maximumPackageNameSize-1] = 0;
179 if( userInterface != NULL ) {
180 if( ( userSize = (*(smr_userInterface *) userInterface)( (
void *) userInterface, NULL ) ) > 0 ) {
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 );
187 strcat( smr->message, userMsg );
199 vfprintf( stderr, fmt, *args );
200 fprintf( stderr,
"\nAt line %d of %s\n", smr->line, smr->packageName );
201 smr->status = smr_status_Fatal;
202 smr->message = (
char *) smr_mallocFailed;
210 if( smr == NULL )
return( 1 );
211 return( smr->status == smr_status_Ok );
218 if( smr == NULL )
return( 1 );
219 return( smr->status == smr_status_Info );
226 if( smr == NULL )
return( 1 );
227 return( ( smr->status == smr_status_Error ) || ( smr->status == smr_status_Fatal ) );
234 if( smr == NULL )
return( 1 );
235 return( smr->status == smr_status_Fatal );
242 return( smr->message );
249 return(
smr_getFullMessage2(
"%s\nAt line %d of %s", smr->message, smr->line, smr->packageName ) );
259 va_start( args, fmt );
267 void smr_print( statusMessageReporting *smr, FILE *f,
int clear ) {
269 if( smr->message != NULL ) fprintf( f,
"%s\nAt line %d of %s\n", smr->message, smr->line, smr->packageName );
273 #if defined __cplusplus
char * smr_allocateFormatMessage(const char *fmt,...)
static int smr_setMessage(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, enum smr_status status, const char *fmt, va_list *args)
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_isError(statusMessageReporting *smr)
int smr_vsetMessageInfo(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args)
int smr_isFatal(statusMessageReporting *smr)
int smr_isOk(statusMessageReporting *smr)
static int smr_setAllocationFailure(statusMessageReporting *smr, const char *fmt, va_list *args)
void smr_print(statusMessageReporting *smr, FILE *f, int clear)
int smr_isInfo(statusMessageReporting *smr)
char * smr_getFullMessage(statusMessageReporting *smr)
static const char smr_mallocFailed[]
const char * smr_getMessage(statusMessageReporting *smr)
int smr_initialize(statusMessageReporting *smr)
void * realloc(void *__ptr, size_t __size)
int smr_setMessageInfo(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_release(statusMessageReporting *smr)
static char * smr_getFullMessage2(char const *fmt,...)
int smr_vsetMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args)
char * smr_vallocateFormatMessage(const char *fmt, va_list *args)