[libChf] further simplification

This commit is contained in:
Gwenhael Le Moine 2024-10-08 13:40:06 +02:00
parent 3dcf2b0b61
commit d5bf86c1f5
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 10 additions and 22 deletions

View file

@ -49,16 +49,6 @@
#define CHF_MODULE_ID CHF_SET
#define CHF_TMP_MESSAGE_LENGTH ( 2 * CHF_MAX_MESSAGE_LENGTH )
#define CHF_DEF_MESSAGE_LENGTH 40
#define CHF_DEF_PARTIAL_MSG_FMT "Code <%d>d"
#define CHF_DEF_MID_MSG_FMT "Mid <%d>d"
#define CHF_EXTENDED_INFO_FMT "(%s,%)"
#define CHF_SEVERITY_NAMES { "S", "I", "W", "E", "F" }
#define CHF_UNKNOWN_SEVERITY "?"
#define CHF_MESSAGE_SEPARATOR "-"
#define CHF_MESSAGE_TERMINATOR "\n"
#define CHF_ABORT_HEADER "ChfAbort-F-"
#define CHF_ABORT_BAD_CODE_FMT "Bad abort code <%d>d\n"
#define CHF_ABORT_GOOD_CODE_FMT "%s\n"
/* -------------------------------------------------------------------------
Abort codes used with ChfAbort()

View file

@ -109,13 +109,13 @@ void ChfAbort( /* Abort application */
"Pthread interaction failed" };
if ( abort_code != CHF_ABORT_SILENT ) {
fputs( CHF_ABORT_HEADER, stderr );
fputs( "ChfAbort-F-", stderr );
if ( abort_code < 0 || abort_code >= ( int )( sizeof( message_table ) / sizeof( const char* ) ) )
fprintf( stderr, CHF_ABORT_BAD_CODE_FMT, abort_code );
fprintf( stderr, "Bad abort code <%d>d\n", abort_code );
else
fprintf( stderr, CHF_ABORT_GOOD_CODE_FMT, message_table[ abort_code ] );
fprintf( stderr, "%s\n", message_table[ abort_code ] );
}
if ( chf_context.state == CHF_UNKNOWN || chf_context.options & CHF_ABORT )

View file

@ -131,7 +131,7 @@ void ChfGenerate( /* Generate a condition into the stack */
new_descriptor->file_name = file_name;
/* Generate the default message */
sprintf( def_message, CHF_DEF_PARTIAL_MSG_FMT, condition_code );
sprintf( def_message, "Code <%d>d", condition_code );
/* Generate the partial message associated with the condition using a
temporary area

View file

@ -69,8 +69,8 @@ static char rcs_lib_id[] = CHF_LIBRARY_ID;
ChfContext _chf_context;
/* Message separator and severity names for ChfBuildMessage() */
static const char separator[] = CHF_MESSAGE_SEPARATOR;
static const char* severity_name[] = CHF_SEVERITY_NAMES;
static const char separator[] = "-";
static const char* severity_name[] = { "S", "I", "W", "E", "F" };
/* -------------------------------------------------------------------------
Multithreading support
@ -374,7 +374,7 @@ char* ChfBuildMessage( /* Build a condition message */
tmp_p = scopy( tmp_p, "\t", tmp_end );
/* The message continues with the module name */
sprintf( def_message, CHF_DEF_MID_MSG_FMT, descriptor->module_id );
sprintf( def_message, "Mid <%d>d", descriptor->module_id );
tmp_p = scopy( tmp_p, ChfGetMessage( CHF_MODULE_NAMES_SET, descriptor->module_id, def_message ), tmp_end );
@ -382,7 +382,7 @@ char* ChfBuildMessage( /* Build a condition message */
if ( descriptor->line_number != CHF_UNKNOWN_LINE_NUMBER ) {
tmp_p = scopy( tmp_p, " ", tmp_end );
sprintf( def_message, CHF_EXTENDED_INFO_FMT, descriptor->file_name, descriptor->line_number );
sprintf( def_message, "(%s,%)", descriptor->file_name, descriptor->line_number );
tmp_p = scopy( tmp_p, def_message, tmp_end );
}
@ -390,16 +390,14 @@ char* ChfBuildMessage( /* Build a condition message */
tmp_p = scopy( tmp_p, separator, tmp_end );
/* Add the severity code of the message */
tmp_p = scopy( tmp_p,
( ( severity = descriptor->severity ) < CHF_SUCCESS || severity > CHF_FATAL ) ? CHF_UNKNOWN_SEVERITY
: severity_name[ severity ],
tmp_p = scopy( tmp_p, ( ( severity = descriptor->severity ) < CHF_SUCCESS || severity > CHF_FATAL ) ? "?" : severity_name[ severity ],
tmp_end );
tmp_p = scopy( tmp_p, separator, tmp_end );
/* The message ends with the partial message from the descriptor */
tmp_p = scopy( tmp_p, descriptor->message, tmp_end );
( void )scopy( tmp_p, CHF_MESSAGE_TERMINATOR, tmp_end );
( void )scopy( tmp_p, "\n", tmp_end );
return chf_context.message_buffer;
}