mirror of
https://github.com/jeremysrand/abCalc.git
synced 2024-12-21 12:30:44 +00:00
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
/*
|
|
abCError.c
|
|
By: Jeremy Rand
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "abCError.h"
|
|
|
|
|
|
static char *gErrorStrings[abCalcErrorTypeMax];
|
|
|
|
static abCalcErrorType gCurrErrorType = abCalcNoError;
|
|
static char *gCurrErrorOpName = NULL;
|
|
|
|
char gErrorBuffer[128];
|
|
|
|
|
|
void abCalcErrorInit(void)
|
|
{
|
|
gErrorStrings[abCalcNoError] = NULL;
|
|
gErrorStrings[abCalcSyntaxError] = "Syntax Error";
|
|
gErrorStrings[abCalcBadArgTypeError] = "Bad Argument Type";
|
|
gErrorStrings[abCalcBadArgValueError] = "Bad Argument Value";
|
|
gErrorStrings[abCalcTooFewArgsError] = "Too Few Arguments";
|
|
gErrorStrings[abCalcStackFullError] = "Stack Full";
|
|
gErrorStrings[abCalcInfiniteResultError] = "Infinite Result";
|
|
gErrorStrings[abCalcComplexResultError] = "Complex Result";
|
|
}
|
|
|
|
|
|
void abCalcRaiseError(abCalcErrorType type, char *opName)
|
|
{
|
|
if ((type < abCalcErrorTypeMin) ||
|
|
(type >= abCalcErrorTypeMax))
|
|
return;
|
|
|
|
if (gCurrErrorType == abCalcNoError) {
|
|
gCurrErrorType = type;
|
|
gCurrErrorOpName = opName;
|
|
}
|
|
}
|
|
|
|
|
|
char *abCalcGetError(void)
|
|
{
|
|
char *errorString;
|
|
|
|
if ((gCurrErrorType < abCalcErrorTypeMin) ||
|
|
(gCurrErrorType >= abCalcErrorTypeMax))
|
|
return NULL;
|
|
|
|
errorString = gErrorStrings[gCurrErrorType];
|
|
|
|
if (errorString == NULL)
|
|
return NULL;
|
|
|
|
if (gCurrErrorOpName != NULL) {
|
|
sprintf(gErrorBuffer, "%s Error: %s", gCurrErrorOpName, gErrorStrings[gCurrErrorType]);
|
|
} else {
|
|
sprintf(gErrorBuffer, "Error: %s", gErrorStrings[gCurrErrorType]);
|
|
}
|
|
|
|
return gErrorBuffer;
|
|
}
|
|
|
|
|
|
void abCalcClearError(void)
|
|
{
|
|
gCurrErrorType = abCalcNoError;
|
|
gCurrErrorOpName = NULL;
|
|
}
|
|
|