Rolling back errormanager
This commit is contained in:
@@ -69,8 +69,8 @@ ENDIF (MSVC)
|
||||
|
||||
|
||||
# configure file groups
|
||||
file(GLOB EPANET_SOURCES src/*.c src/util/*.c)
|
||||
file(GLOB EPANET_LIB_ALL src/* src/util/*)
|
||||
file(GLOB EPANET_SOURCES src/*.c)
|
||||
file(GLOB EPANET_LIB_ALL src/*)
|
||||
source_group("Library" FILES ${EPANET_LIB_ALL})
|
||||
|
||||
|
||||
|
||||
844
src/epanet.c
844
src/epanet.c
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// errormanager.c
|
||||
//
|
||||
// Purpose: Provides a simple interface for managing runtime error messages.
|
||||
//
|
||||
// Date: 08/25/2017
|
||||
//
|
||||
// Author: Michael E. Tryby
|
||||
// US EPA - ORD/NRMRL
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "errormanager.h"
|
||||
|
||||
error_handle_t* new_errormanager(void (*p_error_message)(int, char*, int))
|
||||
//
|
||||
// Purpose: Constructs a new error handle.
|
||||
//
|
||||
{
|
||||
error_handle_t* error_handle;
|
||||
error_handle = (error_handle_t*)calloc(1, sizeof(error_handle_t));
|
||||
|
||||
if (error_handle != NULL)
|
||||
error_handle->p_msg_lookup = p_error_message;
|
||||
|
||||
return error_handle;
|
||||
}
|
||||
|
||||
void dst_errormanager(error_handle_t* error_handle)
|
||||
//
|
||||
// Purpose: Destroys the error handle.
|
||||
//
|
||||
{
|
||||
free(error_handle);
|
||||
}
|
||||
|
||||
int set_error(error_handle_t* error_handle, int errorcode)
|
||||
//
|
||||
// Purpose: Sets an error code in the handle.
|
||||
//
|
||||
{
|
||||
// If the error code is 0 no action is taken and 0 is returned.
|
||||
// This is a feature not a bug.
|
||||
if (errorcode)
|
||||
error_handle->error_status = errorcode;
|
||||
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
char* check_error(error_handle_t* error_handle)
|
||||
//
|
||||
// Purpose: Returns the error message or NULL.
|
||||
//
|
||||
// Note: Caller must free memory allocated by check_error
|
||||
//
|
||||
{
|
||||
char* temp = NULL;
|
||||
|
||||
if (error_handle->error_status != 0) {
|
||||
temp = (char*) calloc(ERR_MAXMSG, sizeof(char));
|
||||
|
||||
if (temp)
|
||||
error_handle->p_msg_lookup(error_handle->error_status, temp, ERR_MAXMSG);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
void clear_error(error_handle_t* error_handle)
|
||||
//
|
||||
// Purpose: Clears the error from the handle.
|
||||
//
|
||||
{
|
||||
error_handle->error_status = 0;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* errormanager.h
|
||||
*
|
||||
* Created on: Aug 25, 2017
|
||||
*
|
||||
* Author: Michael E. Tryby
|
||||
* US EPA - ORD/NRMRL
|
||||
*/
|
||||
|
||||
#ifndef ERRORMANAGER_H_
|
||||
#define ERRORMANAGER_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ERR_MAXMSG 256
|
||||
|
||||
typedef struct error_s {
|
||||
int error_status;
|
||||
void (*p_msg_lookup)(int, char*, int);
|
||||
} error_handle_t;
|
||||
|
||||
error_handle_t* new_errormanager(void (*p_error_message)(int, char*, int));
|
||||
void dst_errormanager(error_handle_t* error_handle);
|
||||
|
||||
int set_error(error_handle_t* error_handle, int errorcode);
|
||||
char* check_error(error_handle_t* error_handle);
|
||||
void clear_error(error_handle_t* error_handle);
|
||||
|
||||
#endif /* ERRORMANAGER_H_ */
|
||||
Reference in New Issue
Block a user