From d5bf86c1f580d5fcb313458ee116c7411f860f75 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Tue, 8 Oct 2024 13:40:06 +0200 Subject: [PATCH] [libChf] further simplification --- src/libChf/src/ChfPriv.h | 10 ---------- src/libChf/src/chf_abrt.c | 6 +++--- src/libChf/src/chf_gen.c | 2 +- src/libChf/src/chf_init.c | 14 ++++++-------- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libChf/src/ChfPriv.h b/src/libChf/src/ChfPriv.h index b70f309..694f085 100644 --- a/src/libChf/src/ChfPriv.h +++ b/src/libChf/src/ChfPriv.h @@ -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() diff --git a/src/libChf/src/chf_abrt.c b/src/libChf/src/chf_abrt.c index 2acb57f..8c85a0c 100644 --- a/src/libChf/src/chf_abrt.c +++ b/src/libChf/src/chf_abrt.c @@ -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 ) diff --git a/src/libChf/src/chf_gen.c b/src/libChf/src/chf_gen.c index 1ac4d3b..df8fd0d 100644 --- a/src/libChf/src/chf_gen.c +++ b/src/libChf/src/chf_gen.c @@ -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 diff --git a/src/libChf/src/chf_init.c b/src/libChf/src/chf_init.c index 429bba9..ca1a432 100644 --- a/src/libChf/src/chf_init.c +++ b/src/libChf/src/chf_init.c @@ -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; }