changeset 4:90cd3d9a6ca3

Moved function array declaration, modified the ftoa function so it does not return trailing 0s Also added a return value to sGet though that seems to break some things... The errors for this were very odd, see TODO notes in std.c and init.c
author Jonathan Pevarnek <pevarnj@gmail.com>
date Wed, 02 Mar 2011 00:37:32 -0500
parents 0aa0ad9e1cc3
children 348c59c36703
files include/operations.h include/std.h src/init.c src/operations.c src/std.c
diffstat 5 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/include/operations.h	Tue Mar 01 23:33:51 2011 -0500
+++ b/include/operations.h	Wed Mar 02 00:37:32 2011 -0500
@@ -6,6 +6,7 @@
 
 enum Operation {PRINT, ADD, SUB, MULT, DIV, DUP, MAXOP};
 extern const char operationNames[MAXOP][10];
+extern void (*operation[MAXOP])(struct Stack*);
 
 void op_print(struct Stack *stack);
 void op_add(struct Stack *stack);
--- a/include/std.h	Tue Mar 01 23:33:51 2011 -0500
+++ b/include/std.h	Wed Mar 02 00:37:32 2011 -0500
@@ -7,7 +7,7 @@
 double atof(char *a);
 
 void sPrint(char *a);
-void sGet(char *a, unsigned int n);
+char* sGet(char *a, unsigned int n);
 
 int strcmp(const char *a, const char *b);
 
--- a/src/init.c	Tue Mar 01 23:33:51 2011 -0500
+++ b/src/init.c	Wed Mar 02 00:37:32 2011 -0500
@@ -36,14 +36,6 @@
 	dumpBuffer(string, 10);
 	*/
 
-	void (*operation[MAXOP])(struct Stack*) = {NULL};
-	operation[0] = op_print;
-	operation[1] = op_add;
-	operation[2] = op_sub;
-	operation[3] = op_mult;
-	operation[4] = op_div;
-	operation[5] = op_dup;
-
 	struct Stack theStack;
 	struct Stack *stack = &theStack;
 	initStack(stack);
@@ -54,6 +46,7 @@
 		sPrint("Please enter an operation or value: ");
 		sGet(input, 30);
 		opVal = arrayLookup(input, operationNames, MAXOP);
+//		opVal = arrayLookup(sGet(input, 30), operationNames, MAXOP); //TODO figure out what is wrong with this...
 		if(opVal != MAXOP) {
 			(*operation[opVal]) (stack); //call the function array
 		} else {
--- a/src/operations.c	Tue Mar 01 23:33:51 2011 -0500
+++ b/src/operations.c	Wed Mar 02 00:37:32 2011 -0500
@@ -3,6 +3,8 @@
 #include <stack.h>
 
 const char operationNames[MAXOP][10] = {".", "+", "-", "*", "/", "dup"};
+void (*operation[MAXOP])(struct Stack*) = {op_print, op_add, op_sub, op_mult,
+	op_div, op_dup};
 
 void op_print(struct Stack *stack)
 {
--- a/src/std.c	Tue Mar 01 23:33:51 2011 -0500
+++ b/src/std.c	Wed Mar 02 00:37:32 2011 -0500
@@ -37,7 +37,10 @@
 			*a++ = ((int) d) + '0';
 			d -= (int) d;
 		}
-		*a = '\0';
+		a--; //move back to the last digit
+//		while(*a == '0') a--; //TODO figure out why this "works" even with the other version of init.c
+		while(*a == '0' || *a == '.') a--; //get to the first non-zero decimal digit
+		*(a + 1) = '\0';
 	}
 	return ret;
 }
@@ -88,10 +91,11 @@
 	return -1;
 }
 
-void sGet(char *a, unsigned int n) //TODO bug Jeff about getline
+char* sGet(char *a, unsigned int n) //TODO bug Jeff about getline
 {
 	int length = getline(a, n);
 	a[(length < n)?length:n - 1] = '\0';
+	return a;
 }
 
 int arrayLookup(char *text, const char array[][10], int last)