More integer operations

This commit is contained in:
Jeremy Rand 2013-07-24 20:02:07 -05:00
parent 062a5b6639
commit dcbbd4b1c1
12 changed files with 214 additions and 16 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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:

View File

@ -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();
}

30
abCalcOpBin.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCalcOpBin.c
By: Jeremy Rand
*/
#include <stdio.h>
#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);
}

14
abCalcOpBin.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCalcOpBin.h
By: Jeremy Rand
*/
#ifndef ABCALCOPBIN_H
#define ABCALCOPBIN_H
void abCalcOpBinInit(void);
#endif

30
abCalcOpDec.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCalcOpDec.c
By: Jeremy Rand
*/
#include <stdio.h>
#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);
}

14
abCalcOpDec.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCalcOpDec.h
By: Jeremy Rand
*/
#ifndef ABCALCOPDEC_H
#define ABCALCOPDEC_H
void abCalcOpDecInit(void);
#endif

30
abCalcOpHex.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCalcOpHex.c
By: Jeremy Rand
*/
#include <stdio.h>
#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);
}

14
abCalcOpHex.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCalcOpHex.h
By: Jeremy Rand
*/
#ifndef ABCALCOPHEX_H
#define ABCALCOPHEX_H
void abCalcOpHexInit(void);
#endif

30
abCalcOpOct.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCalcOpOct.c
By: Jeremy Rand
*/
#include <stdio.h>
#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);
}

14
abCalcOpOct.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCalcOpOct.h
By: Jeremy Rand
*/
#ifndef ABCALCOPOCT_H
#define ABCALCOPOCT_H
void abCalcOpOctInit(void);
#endif