From dcbbd4b1c149cd289b1adb872eb973c3c9b9fcb1 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Wed, 24 Jul 2013 20:02:07 -0500 Subject: [PATCH] More integer operations --- Makefile | 28 +++++++++++++++++----------- abCalcExpr.h | 2 +- abCalcExprInt.c | 12 ++++++++---- abCalcOp.c | 12 ++++++++++++ abCalcOpBin.c | 30 ++++++++++++++++++++++++++++++ abCalcOpBin.h | 14 ++++++++++++++ abCalcOpDec.c | 30 ++++++++++++++++++++++++++++++ abCalcOpDec.h | 14 ++++++++++++++ abCalcOpHex.c | 30 ++++++++++++++++++++++++++++++ abCalcOpHex.h | 14 ++++++++++++++ abCalcOpOct.c | 30 ++++++++++++++++++++++++++++++ abCalcOpOct.h | 14 ++++++++++++++ 12 files changed, 214 insertions(+), 16 deletions(-) create mode 100644 abCalcOpBin.c create mode 100644 abCalcOpBin.h create mode 100644 abCalcOpDec.c create mode 100644 abCalcOpDec.h create mode 100644 abCalcOpHex.c create mode 100644 abCalcOpHex.h create mode 100644 abCalcOpOct.c create mode 100644 abCalcOpOct.h diff --git a/Makefile b/Makefile index 19b7646..e0c0246 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ OBJS=abCalc.o abCalcExpr.o abCalcExpReal.o abCalcExprInt.o abCalcStack.o \ abCalcMode.o abCalcMain.o abCalcOp.o abCalcError.o abCalcOpAdd.o \ abCalcOpSubtr.o abCalcOpMult.o abCalcOpDiv.o abCalcOpPower.o \ - abCalcOpAnd.o abCalcOpOr.o abCalcOpXor.o abCalcOpNot.o + abCalcOpAnd.o abCalcOpOr.o abCalcOpXor.o abCalcOpNot.o \ + abCalcOpBin.o abCalcOpOct.o abCalcOpDec.o abCalcOpHex.o NAME=abCalc @@ -18,16 +19,21 @@ abCalc.o: abCalc.h abCalcExpr.h abCalcMode.h abCalcExpReal.h abCalcExprInt.h \ abCalcMain.o: abCalc.h abCalcStack.h abCalcExpr.h abCalcOp.h abCalcError.h abCalcOp.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpAdd.h \ abCalcOpSubtr.h abCalcOpMult.h abCalcOpDiv.h abCalcOpPower.h \ - abCalcOpAnd.h abCalcOpOr.h abCalcOpXor.h abCalcOpNot.h -abCalcOpAdd.o: abCalcOp.h abCalcError.h abCalcOpAdd.h -abCalcOpSubtr.o: abCalcOp.h abCalcError.h abCalcOpSubtr.h -abCalcOpMult.o: abCalcOp.h abCalcError.h abCalcOpMult.h -abCalcOpDiv.o: abCalcOp.h abCalcError.h abCalcOpDiv.h -abCalcOpPower.o: abCalcOp.h abCalcError.h abCalcOpPower.h -abCalcOpAnd.o: abCalcOp.h abCalcError.h abCalcOpAnd.h -abCalcOpOr.o: abCalcOp.h abCalcError.h abCalcOpOr.h -abCalcOpXor.o: abCalcOp.h abCalcError.h abCalcOpXor.h -abCalcOpNot.o: abCalcOp.h abCalcError.h abCalcOpNot.h + abCalcOpAnd.h abCalcOpOr.h abCalcOpXor.h abCalcOpNot.h abCalcOpBin.h \ + abCalcOpOct.h abCalcOpDec.h abCalcOpHex.h +abCalcOpAdd.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpAdd.h +abCalcOpSubtr.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpSubtr.h +abCalcOpMult.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpMult.h +abCalcOpDiv.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpDiv.h +abCalcOpPower.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpPower.h +abCalcOpAnd.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpAnd.h +abCalcOpOr.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpOr.h +abCalcOpXor.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpXor.h +abCalcOpNot.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpNot.h +abCalcOpBin.o: abCalcOp.h abCalcMode.h abCalcOpBin.h +abCalcOpOct.o: abCalcOp.h abCalcMode.h abCalcOpOct.h +abCalcOpDec.o: abCalcOp.h abCalcMode.h abCalcOpDec.h +abCalcOpHex.o: abCalcOp.h abCalcMode.h abCalcOpHex.h $(NAME): $(OBJS) diff --git a/abCalcExpr.h b/abCalcExpr.h index 60a20a3..0e1feec 100644 --- a/abCalcExpr.h +++ b/abCalcExpr.h @@ -23,7 +23,7 @@ typedef unsigned long abCalcIntType; #define AB_CALC_EXPR_MAX_INT_WIDTH ((sizeof(abCalcIntType) * 8)) -#define AB_CALC_EXPR_STRING_MAX (AB_CALC_EXPR_MAX_INT_WIDTH + 4) +#define AB_CALC_EXPR_STRING_MAX (AB_CALC_EXPR_MAX_INT_WIDTH + 8) typedef struct abCalcExpr { diff --git a/abCalcExprInt.c b/abCalcExprInt.c index f79add9..b9cbd90 100644 --- a/abCalcExprInt.c +++ b/abCalcExprInt.c @@ -201,7 +201,7 @@ char *abCalcExprIntFormat(abCalcExpr *expr, char *buffer) case abCalcModeBinBase: gotFirstOne = 0; ptr = buffer; - *ptr = '*'; + *ptr = '#'; ptr++; for (i = width - 1; i >= 0; i--) { @@ -220,19 +220,23 @@ char *abCalcExprIntFormat(abCalcExpr *expr, char *buffer) *ptr = '0'; ptr++; } + *ptr = ' '; + ptr++; + *ptr = 'b'; + ptr++; *ptr = '\0'; break; case abCalcModeOctBase: - sprintf(buffer, "#%lo", value); + sprintf(buffer, "#%lo o", value); break; case abCalcModeDecBase: - sprintf(buffer, "#%lu", value); + sprintf(buffer, "#%lu d", value); break; case abCalcModeHexBase: - sprintf(buffer, "#%lX", value); + sprintf(buffer, "#%lX h", value); break; default: diff --git a/abCalcOp.c b/abCalcOp.c index a8e4e54..34cbc6f 100644 --- a/abCalcOp.c +++ b/abCalcOp.c @@ -17,11 +17,17 @@ #include "abCalcOpMult.h" #include "abCalcOpDiv.h" #include "abCalcOpPower.h" + #include "abCalcOpAnd.h" #include "abCalcOpOr.h" #include "abCalcOpXor.h" #include "abCalcOpNot.h" +#include "abCalcOpBin.h" +#include "abCalcOpOct.h" +#include "abCalcOpDec.h" +#include "abCalcOpHex.h" + #define AB_CALC_MAX_OPS 128 @@ -39,10 +45,16 @@ void abCalcOpInit(void) abCalcOpMultInit(); abCalcOpDivInit(); abCalcOpPowerInit(); + abCalcOpAndInit(); abCalcOpOrInit(); abCalcOpXorInit(); abCalcOpNotInit(); + + abCalcOpBinInit(); + abCalcOpOctInit(); + abCalcOpDecInit(); + abCalcOpHexInit(); } diff --git a/abCalcOpBin.c b/abCalcOpBin.c new file mode 100644 index 0000000..657025a --- /dev/null +++ b/abCalcOpBin.c @@ -0,0 +1,30 @@ +/* + abCalcOpBin.c + By: Jeremy Rand + */ + + +#include + +#include "abCalcOpBin.h" + +#include "abCalcOp.h" +#include "abCalcMode.h" + + +#define OP_NAME "BIN" + + +static void binExecute(void); + + +void abCalcOpBinInit(void) +{ + abCalcOpRegister(OP_NAME, binExecute); +} + + +void binExecute(void) +{ + abCalcModeSetBase(abCalcModeBinBase); +} diff --git a/abCalcOpBin.h b/abCalcOpBin.h new file mode 100644 index 0000000..f517b46 --- /dev/null +++ b/abCalcOpBin.h @@ -0,0 +1,14 @@ +/* + abCalcOpBin.h + By: Jeremy Rand + */ + + +#ifndef ABCALCOPBIN_H +#define ABCALCOPBIN_H + + +void abCalcOpBinInit(void); + + +#endif diff --git a/abCalcOpDec.c b/abCalcOpDec.c new file mode 100644 index 0000000..5870354 --- /dev/null +++ b/abCalcOpDec.c @@ -0,0 +1,30 @@ +/* + abCalcOpDec.c + By: Jeremy Rand + */ + + +#include + +#include "abCalcOpDec.h" + +#include "abCalcOp.h" +#include "abCalcMode.h" + + +#define OP_NAME "DEC" + + +static void decExecute(void); + + +void abCalcOpDecInit(void) +{ + abCalcOpRegister(OP_NAME, decExecute); +} + + +void decExecute(void) +{ + abCalcModeSetBase(abCalcModeDecBase); +} diff --git a/abCalcOpDec.h b/abCalcOpDec.h new file mode 100644 index 0000000..4a598a5 --- /dev/null +++ b/abCalcOpDec.h @@ -0,0 +1,14 @@ +/* + abCalcOpDec.h + By: Jeremy Rand + */ + + +#ifndef ABCALCOPDEC_H +#define ABCALCOPDEC_H + + +void abCalcOpDecInit(void); + + +#endif diff --git a/abCalcOpHex.c b/abCalcOpHex.c new file mode 100644 index 0000000..4c86a78 --- /dev/null +++ b/abCalcOpHex.c @@ -0,0 +1,30 @@ +/* + abCalcOpHex.c + By: Jeremy Rand + */ + + +#include + +#include "abCalcOpHex.h" + +#include "abCalcOp.h" +#include "abCalcMode.h" + + +#define OP_NAME "HEX" + + +static void hexExecute(void); + + +void abCalcOpHexInit(void) +{ + abCalcOpRegister(OP_NAME, hexExecute); +} + + +void hexExecute(void) +{ + abCalcModeSetBase(abCalcModeHexBase); +} diff --git a/abCalcOpHex.h b/abCalcOpHex.h new file mode 100644 index 0000000..f5d55c3 --- /dev/null +++ b/abCalcOpHex.h @@ -0,0 +1,14 @@ +/* + abCalcOpHex.h + By: Jeremy Rand + */ + + +#ifndef ABCALCOPHEX_H +#define ABCALCOPHEX_H + + +void abCalcOpHexInit(void); + + +#endif diff --git a/abCalcOpOct.c b/abCalcOpOct.c new file mode 100644 index 0000000..c9b3c67 --- /dev/null +++ b/abCalcOpOct.c @@ -0,0 +1,30 @@ +/* + abCalcOpOct.c + By: Jeremy Rand + */ + + +#include + +#include "abCalcOpOct.h" + +#include "abCalcOp.h" +#include "abCalcMode.h" + + +#define OP_NAME "OCT" + + +static void octExecute(void); + + +void abCalcOpOctInit(void) +{ + abCalcOpRegister(OP_NAME, octExecute); +} + + +void octExecute(void) +{ + abCalcModeSetBase(abCalcModeOctBase); +} diff --git a/abCalcOpOct.h b/abCalcOpOct.h new file mode 100644 index 0000000..b4838c1 --- /dev/null +++ b/abCalcOpOct.h @@ -0,0 +1,14 @@ +/* + abCalcOpOct.h + By: Jeremy Rand + */ + + +#ifndef ABCALCOPOCT_H +#define ABCALCOPOCT_H + + +void abCalcOpOctInit(void); + + +#endif