2013-07-24 21:15:11 +00:00
|
|
|
/*
|
|
|
|
abCalcOp.c
|
|
|
|
By: Jeremy Rand
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "abCalcOp.h"
|
2013-07-24 23:01:04 +00:00
|
|
|
#include "abCalcExpr.h"
|
|
|
|
#include "abCalcError.h"
|
|
|
|
#include "abCalcStack.h"
|
2013-07-24 21:15:11 +00:00
|
|
|
|
|
|
|
#include "abCalcOpAdd.h"
|
2013-07-24 23:59:18 +00:00
|
|
|
#include "abCalcOpSubtr.h"
|
|
|
|
#include "abCalcOpMult.h"
|
|
|
|
#include "abCalcOpDiv.h"
|
|
|
|
#include "abCalcOpPower.h"
|
|
|
|
#include "abCalcOpAnd.h"
|
|
|
|
#include "abCalcOpOr.h"
|
|
|
|
#include "abCalcOpXor.h"
|
|
|
|
#include "abCalcOpNot.h"
|
2013-07-24 21:15:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define AB_CALC_MAX_OPS 128
|
|
|
|
|
|
|
|
|
|
|
|
static abCalcOp gOps[AB_CALC_MAX_OPS];
|
|
|
|
static int gNumOps = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void abCalcOpInit(void)
|
|
|
|
{
|
|
|
|
memset(gOps, 0, sizeof(gOps));
|
|
|
|
|
|
|
|
abCalcOpAddInit();
|
2013-07-24 23:59:18 +00:00
|
|
|
abCalcOpSubtrInit();
|
|
|
|
abCalcOpMultInit();
|
|
|
|
abCalcOpDivInit();
|
|
|
|
abCalcOpPowerInit();
|
|
|
|
abCalcOpAndInit();
|
|
|
|
abCalcOpOrInit();
|
|
|
|
abCalcOpXorInit();
|
|
|
|
abCalcOpNotInit();
|
2013-07-24 21:15:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void abCalcOpRegister(char *name, void (*execute)(void))
|
|
|
|
{
|
|
|
|
if (gNumOps >= AB_CALC_MAX_OPS) {
|
|
|
|
fprintf(stderr, "Operation registration overflow");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gOps[gNumOps].name = name;
|
|
|
|
gOps[gNumOps].execute = execute;
|
|
|
|
gNumOps++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
abCalcOp *abCalcOpLookup(char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < gNumOps; i++) {
|
|
|
|
if (strcmp(gOps[i].name, name) == 0) {
|
|
|
|
return &gOps[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-24 23:01:04 +00:00
|
|
|
|
|
|
|
|