[libChf] cleaning, code formatting

This commit is contained in:
Gwenhael Le Moine 2024-10-08 15:52:46 +02:00
parent c6a361466e
commit c20f4a7af4
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
10 changed files with 52 additions and 107 deletions

View file

@ -68,10 +68,6 @@
#define CHF_NULL_CONTEXT ( void* )NULL
#define CHF_NULL_POINTER ( void** )NULL
#define CHF_NULL_HANDLER ( ChfHandler ) NULL
#define CHF_LIBRARY_ID "$Id: Chf.h,v 2.2 2001/01/25 11:56:44 cibrario Exp $"
#define CHF_MAJOR_RELEASE_NUMBER 2
#define CHF_MINOR_RELEASE_NUMBER 2
#define CHF_MODULE_NAMES_SET 1
#define CHF_SET 2
@ -96,35 +92,28 @@
Type definitions
------------------------------------------------------------------------- */
typedef enum /* Condition severity codes */
{ CHF_SUCCESS,
CHF_INFO,
CHF_WARNING,
CHF_ERROR,
CHF_FATAL } ChfSeverity;
/* Condition severity codes */
typedef enum { CHF_SUCCESS, CHF_INFO, CHF_WARNING, CHF_ERROR, CHF_FATAL } ChfSeverity;
typedef enum /* Condition handler action codes */
{ CHF_CONTINUE, /* Continue application */
CHF_RESIGNAL, /* Resignal to next handler */
CHF_UNWIND, /* Stack unwind */
CHF_UNWIND_KEEP /* Unwind, keep last cond. group */
/* Condition handler action codes */
typedef enum {
CHF_CONTINUE, /* Continue application */
CHF_RESIGNAL, /* Resignal to next handler */
CHF_UNWIND, /* Stack unwind */
CHF_UNWIND_KEEP /* Unwind, keep last cond. group */
} ChfAction;
typedef int /* CHF options */
ChfOptions;
/* CHF options */
typedef int ChfOptions;
#define CHF_DEFAULT 0x0000 /* default flags */
#define CHF_ABORT 0x0001 /* use abort() instead of exit() */
typedef enum /* Current CHF state */
{ CHF_UNKNOWN,
CHF_IDLE,
CHF_SIGNALING,
CHF_UNWINDING,
CHF_SIGNAL_UNWINDING } ChfState;
/* Current CHF state */
typedef enum { CHF_UNKNOWN, CHF_IDLE, CHF_SIGNALING, CHF_UNWINDING, CHF_SIGNAL_UNWINDING } ChfState;
typedef struct ChfDescriptor_S /* Condition descriptor */
{
/* Condition descriptor */
typedef struct ChfDescriptor_S {
int module_id; /* Module identifier */
int condition_code; /* Condition code */
ChfSeverity severity; /* Severity */
@ -134,21 +123,21 @@ typedef struct ChfDescriptor_S /* Condition descriptor */
struct ChfDescriptor_S* next; /* Link to next descriptor */
} ChfDescriptor;
typedef struct ChfTable_S /* Standalone message table */
{
/* Standalone message table */
typedef struct ChfTable_S {
int module; /* Module identifier */
int code; /* Condition code */
char* msg_template; /* Message template */
} ChfTable;
typedef /* Condition handler */
ChfAction ( *ChfHandler )( const ChfDescriptor*, const ChfState, void* );
/* Condition handler */
typedef ChfAction ( *ChfHandler )( const ChfDescriptor*, const ChfState, void* );
typedef /* Message retrieval 'get_message' function */
const char* ( *ChfMrsGet )( void*, const int, const int, const char* default_message );
/* Message retrieval 'get_message' function */
typedef const char* ( *ChfMrsGet )( void*, const int, const int, const char* default_message );
typedef /* Message retrieval 'exit' function */
void ( *ChfMrsExit )( void* );
/* Message retrieval 'exit' function */
typedef void ( *ChfMrsExit )( void* );
/* -------------------------------------------------------------------------
Function prototypes

View file

@ -76,8 +76,8 @@ typedef struct ChfHandlerDescriptor_S {
void* handler_context;
} ChfHandlerDescriptor;
typedef struct ChfContext_S /* CHF Context */
{
/* CHF Context */
typedef struct ChfContext_S {
ChfState state; /* Current CHF state */
const char* app_name; /* Application's name */
ChfOptions options; /* Options */

View file

@ -32,8 +32,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include "Chf.h"
#include "ChfPriv.h"
@ -89,8 +87,8 @@
- added Win32 support
.- */
void ChfAbort( /* Abort application */
const int abort_code )
/* Abort application */
void ChfAbort( const int abort_code )
{
/* Abort codes message table; the relative position of the messages must
@ -113,14 +111,12 @@ void ChfAbort( /* Abort application */
if ( abort_code < 0 || abort_code >= ( int )( sizeof( message_table ) / sizeof( const char* ) ) )
fprintf( stderr, "Bad abort code <%d>d\n", abort_code );
else
fprintf( stderr, "%s\n", message_table[ abort_code ] );
}
if ( chf_context.state == CHF_UNKNOWN || chf_context.options & CHF_ABORT )
abort();
else
#ifndef _REENTRANT
exit( chf_context.exit_code );

View file

@ -25,9 +25,6 @@
.- */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include <stdarg.h>
#include <string.h>
@ -79,8 +76,8 @@
1.1, 3-May-1996, creation
.- */
void ChfGenerate( /* Generate a condition into the stack */
const int module_id, const char* file_name, const int line_number, const int condition_code, const ChfSeverity severity,
/* Generate a condition into the stack */
void ChfGenerate( const int module_id, const char* file_name, const int line_number, const int condition_code, const ChfSeverity severity,
... )
{
ChfDescriptor* new_descriptor;
@ -114,13 +111,9 @@ void ChfGenerate( /* Generate a condition into the stack */
chf_context.condition_sp++;
ChfSignal( module_id );
}
else
} else
ChfAbort( CHF_ABORT_COND_STACK_OVF );
}
else {
} else {
char def_message[ CHF_DEF_MESSAGE_LENGTH ];
char tmp_message[ CHF_TMP_MESSAGE_LENGTH ];

View file

@ -37,11 +37,6 @@
.- */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include "Chf.h"
#include "ChfPriv.h"
@ -144,32 +139,27 @@ static ChfAction StructuredHelper( const ChfDescriptor* desc, const ChfState sta
- added StructuredHelper handling
.- */
void ChfPushHandler( /* Push a new handler into the stack */
const int module_id, ChfHandler new_handler, void* unwind_context, void* handler_context )
/* Push a new handler into the stack */
void ChfPushHandler( const int module_id, ChfHandler new_handler, void* unwind_context, void* handler_context )
{
/* Make sure that CHF has been correctly initialized and is idle */
if ( chf_context.state == CHF_UNKNOWN )
ChfAbort( CHF_ABORT_INIT );
if ( chf_context.state != CHF_IDLE ) {
CHF_Condition( module_id ) CHF_F_BAD_STATE, CHF_FATAL ChfEnd;
ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_BAD_STATE, CHF_FATAL );
ChfSignal( module_id );
}
/* Check if the handler stack is full */
else if ( chf_context.handler_sp - chf_context.handler_stack >= chf_context.handler_stack_size ) {
CHF_Condition( module_id ) CHF_F_HDLR_STACK_FULL, CHF_FATAL ChfEnd;
ChfSignal( module_id );
}
else {
chf_context.handler_sp->unwind_context = unwind_context;
chf_context.handler_sp->handler_context = handler_context;
chf_context.handler_sp->handler = ( ( new_handler == CHF_NULL_HANDLER ) ? StructuredHelper : new_handler );
chf_context.handler_sp++;
}
} else
/* Check if the handler stack is full */
if ( chf_context.handler_sp - chf_context.handler_stack >= chf_context.handler_stack_size ) {
ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_HDLR_STACK_FULL, CHF_FATAL );
ChfSignal( module_id );
} else {
chf_context.handler_sp->unwind_context = unwind_context;
chf_context.handler_sp->handler_context = handler_context;
chf_context.handler_sp->handler = ( ( new_handler == CHF_NULL_HANDLER ) ? StructuredHelper : new_handler );
chf_context.handler_sp++;
}
}
/* .+
@ -214,14 +204,14 @@ void ChfPushHandler( /* Push a new handler into the stack */
/* ChfAbort( CHF_ABORT_INIT ); */
/* if ( chf_context.state != CHF_IDLE ) { */
/* CHF_Condition( module_id ) CHF_F_BAD_STATE, CHF_FATAL ChfEnd; */
/* ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_BAD_STATE, CHF_FATAL ); */
/* ChfSignal( module_id ); */
/* } */
/* /\* Check if the handler stack is empty *\/ */
/* else if ( chf_context.handler_sp == chf_context.handler_stack ) { */
/* CHF_Condition( module_id ) CHF_F_HDLR_STACK_EMPTY, CHF_FATAL ChfEnd; */
/* ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_HDLR_STACK_EMPTY, CHF_FATAL ); */
/* ChfSignal( module_id ); */
/* } */

View file

@ -49,8 +49,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include <string.h>
#include "Chf.h"
@ -60,11 +58,6 @@
Global and static variables
------------------------------------------------------------------------- */
/* Chf Library Id */
#ifndef lint
static char rcs_lib_id[] = CHF_LIBRARY_ID;
#endif
/* CHF context */
ChfContext _chf_context;

View file

@ -30,8 +30,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include <string.h>
#include <locale.h>
#include <nl_types.h>

View file

@ -37,9 +37,6 @@
.- */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include "Chf.h"
@ -310,7 +307,7 @@ void ChfSignal( const int module_id )
otherwise call ChfAbort()
*/
if ( chf_context.handler_sp > chf_context.handler_stack ) {
CHF_Condition( module_id ) CHF_F_INVALID_ACTION, CHF_FATAL, handler_result ChfEnd;
ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_INVALID_ACTION, CHF_FATAL, handler_result );
ChfSignal( module_id );
}

View file

@ -26,8 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include <string.h>
#include "Chf.h"
@ -54,13 +52,10 @@ static int Search( const void* l, const void* r )
{
if ( ( ( ChfTable* )l )->module > ( ( ChfTable* )r )->module )
return ( GT );
else if ( ( ( ChfTable* )l )->module < ( ( ChfTable* )r )->module )
return ( LT );
else if ( ( ( ChfTable* )l )->code > ( ( ChfTable* )r )->code )
return ( GT );
else if ( ( ( ChfTable* )l )->code < ( ( ChfTable* )r )->code )
return ( LT );
@ -125,8 +120,8 @@ static void ExitMessage( void* private_context ) {}
1.1, 27-May-1996, creation
.- */
int ChfStaticInit( /* Initialization with static message tables */
const char* app_name, /* Application's name */
/* Initialization with static message tables */
int ChfStaticInit( const char* app_name, /* Application's name */
const ChfOptions options, /* Options */
const ChfTable* table, /* Static message table */
const size_t table_size, /* Size of the message table */

View file

@ -28,12 +28,6 @@
.- */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include <string.h>
#include "Chf.h"
#include "ChfPriv.h"
@ -81,8 +75,8 @@
- condition stack referenced incorrectly
.- */
const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */
const int module_id )
/* Retrieve top condition */
const ChfDescriptor* ChfGetTopCondition( const int module_id )
{
ChfDescriptor* d;
@ -91,7 +85,7 @@ const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */
ChfAbort( CHF_ABORT_INIT );
if ( ( d = chf_context.condition_sp ) == chf_context.condition_base ) {
CHF_Condition( module_id ) CHF_F_BAD_STATE, CHF_FATAL ChfEnd;
ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_BAD_STATE, CHF_FATAL );
ChfSignal( module_id );
}