You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.8 KiB
60 lines
2.8 KiB
#include <limits.h> |
|
|
|
#include "../include/easycsv.h" |
|
#include "easycsv_error.h" |
|
|
|
/* void */ |
|
/* _easycsv_printerror(const _easycsv *_priv, */ |
|
/* const EASYCSV_ERROR error) */ |
|
/* { */ |
|
/* switch (_priv->error) { */ |
|
/* case EASYCSV_ERROROFF: return; */ |
|
/* case EASYCSV_ERRORSTDOUT: _easycsv_geterror(_priv, error, stdout); break; */ |
|
/* case EASYCSV_ERRORSTDERR: */ |
|
/* default: _easycsv_geterror(_priv, error, stderr); return; */ |
|
/* } */ |
|
/* } */ |
|
|
|
static char s_error_msg[SCHAR_MAX]; |
|
|
|
void |
|
easycsv_error(EASYCSV_ERROR error, |
|
const char *error_msg) |
|
{ |
|
switch (error) { |
|
case EASYCSV_NOERROR: sprintf(s_error_msg, "no error"); return; |
|
case EASYCSV_NULLCSV: sprintf(s_error_msg, "easycsv pointer is NULL"); return; |
|
case EASYCSV_NULLPTR: sprintf(s_error_msg, "pointer is NULL"); return; |
|
case EASYCSV_EMPTYSTRING: sprintf(s_error_msg, "string is empty"); return; |
|
case EASYCSV_EMPTYVALUE: sprintf(s_error_msg, "value in CSV file is empty"); return; |
|
case EASYCSV_OVERMAXROW: sprintf(s_error_msg, "int exceeds row limit of %s", error_msg); return; |
|
case EASYCSV_OVERMAXCOL: sprintf(s_error_msg, "int exceeds column limit of %s", error_msg); return; |
|
case EASYCSV_ZEROROW: sprintf(s_error_msg, "parameterised row number is zero"); return; |
|
case EASYCSV_ZEROCOL: sprintf(s_error_msg, "parameterised column number is zero"); return; |
|
case EASYCSV_MEMALLOC: sprintf(s_error_msg, "memory allocation failure"); return; |
|
|
|
case EASYCSV_UNKNOWNIOMODE: sprintf(s_error_msg, "unknown file IO mode"); return; |
|
case EASYCSV_OPENFAIL: sprintf(s_error_msg, "failed to open file"); return; |
|
case EASYCSV_REOPENFAIL: sprintf(s_error_msg, "failed to reopen file"); return; |
|
case EASYCSV_EMPTYCSV: sprintf(s_error_msg, "CSV file is empty"); return; |
|
case EASYCSV_UNWRITABLE: sprintf(s_error_msg, "CSV file is not in a writable mode"); return; |
|
case EASYCSV_UNREADABLE: sprintf(s_error_msg, "CSV file is not in a readable mode"); return; |
|
case EASYCSV_UPDATEFAIL: sprintf(s_error_msg, "CSV file has failed to update"); return; |
|
case EASYCSV_UPDATETEMPFAIL: sprintf(s_error_msg, "failed to update temp CSV file"); return; |
|
case EASYCSV_FILEPTRFAIL: sprintf(s_error_msg, "failed to move FILE pointer"); return; |
|
|
|
case EASYCSV_ROWNOTEXIST: sprintf(s_error_msg, "given row does not exist"); return; |
|
case EASYCSV_COLNOTEXIST: sprintf(s_error_msg, "given column does not exist"); return; |
|
|
|
case EASYCSV_PUSHCOLFAIL: sprintf(s_error_msg, "failed to push value under column"); return; |
|
case EASYCSV_COLNUMFAIL: sprintf(s_error_msg, "failed to determine the column number of a value in the first row"); return; |
|
case EASYCSV_FINDVALUEFAIL: sprintf(s_error_msg, "cannot find the value %s", error_msg); return; |
|
default: sprintf(s_error_msg, "unknown error"); return; |
|
} |
|
} |
|
|
|
char* |
|
easycsv_get_error() |
|
{ |
|
return s_error_msg; |
|
}
|
|
|