2013-07-24 21:15:11 +00:00
|
|
|
/*
|
2013-07-25 14:42:02 +00:00
|
|
|
abCOp.c
|
2013-07-24 21:15:11 +00:00
|
|
|
By: Jeremy Rand
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-07-25 14:42:02 +00:00
|
|
|
#include "abCError.h"
|
|
|
|
#include "abCStack.h"
|
|
|
|
|
2013-07-25 15:21:21 +00:00
|
|
|
#include "expr/abCExpr.h"
|
|
|
|
|
|
|
|
#include "ops/abCOp.h"
|
|
|
|
|
|
|
|
#include "ops/abCOpAdd.h"
|
|
|
|
#include "ops/abCOpSubtr.h"
|
|
|
|
#include "ops/abCOpMult.h"
|
|
|
|
#include "ops/abCOpDiv.h"
|
|
|
|
#include "ops/abCOpPower.h"
|
|
|
|
|
|
|
|
#include "ops/abCOpAnd.h"
|
|
|
|
#include "ops/abCOpOr.h"
|
|
|
|
#include "ops/abCOpXor.h"
|
|
|
|
#include "ops/abCOpNot.h"
|
|
|
|
#include "ops/abCOpSl.h"
|
|
|
|
#include "ops/abCOpRl.h"
|
|
|
|
#include "ops/abCOpSr.h"
|
|
|
|
#include "ops/abCOpRr.h"
|
|
|
|
#include "ops/abCOpAsr.h"
|
|
|
|
|
|
|
|
#include "ops/abCOpBin.h"
|
|
|
|
#include "ops/abCOpOct.h"
|
|
|
|
#include "ops/abCOpDec.h"
|
|
|
|
#include "ops/abCOpHex.h"
|
|
|
|
#include "ops/abCOpStws.h"
|
|
|
|
#include "ops/abCOpRcws.h"
|
2013-07-25 01:02:07 +00:00
|
|
|
|
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();
|
2013-07-25 01:02:07 +00:00
|
|
|
|
2013-07-24 23:59:18 +00:00
|
|
|
abCalcOpAndInit();
|
|
|
|
abCalcOpOrInit();
|
|
|
|
abCalcOpXorInit();
|
|
|
|
abCalcOpNotInit();
|
2013-07-25 02:28:20 +00:00
|
|
|
abCalcOpSlInit();
|
|
|
|
abCalcOpRlInit();
|
|
|
|
abCalcOpSrInit();
|
|
|
|
abCalcOpRrInit();
|
|
|
|
abCalcOpAsrInit();
|
2013-07-25 01:02:07 +00:00
|
|
|
|
|
|
|
abCalcOpBinInit();
|
|
|
|
abCalcOpOctInit();
|
|
|
|
abCalcOpDecInit();
|
|
|
|
abCalcOpHexInit();
|
2013-07-25 01:20:54 +00:00
|
|
|
abCalcOpStwsInit();
|
|
|
|
abCalcOpRcwsInit();
|
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++) {
|
2013-07-25 16:50:12 +00:00
|
|
|
#ifdef ABCALC_GSOS
|
|
|
|
if (stricmp(gOps[i].name, name) == 0) {
|
|
|
|
#else
|
|
|
|
if (strcasecmp(gOps[i].name, name) == 0) {
|
|
|
|
#endif
|
2013-07-24 21:15:11 +00:00
|
|
|
return &gOps[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-24 23:01:04 +00:00
|
|
|
|
|
|
|
|