diff actions.c @ 51:7d7abe88e71b

"input" node is now "create" node and can handle more than user input now
author meillo@marmaro.de
date Sun, 02 Mar 2008 16:17:18 +0100
parents 0870e261bf28
children 201b4603671a
line wrap: on
line diff
--- a/actions.c	Sun Mar 02 15:54:35 2008 +0100
+++ b/actions.c	Sun Mar 02 16:17:18 2008 +0100
@@ -6,7 +6,7 @@
 unsigned char action_print(struct Node* node);
 unsigned char action_sum(struct Node* node);
 unsigned char action_number(struct Node* node);
-unsigned char action_input(struct Node* node);
+unsigned char action_create(struct Node* node);
 unsigned char action_times(struct Node* node);
 unsigned char action_if(struct Node* node);
 unsigned char action_while(struct Node* node);
@@ -30,8 +30,8 @@
 	} else if (strcmp(node->name, "number") == 0) {
 		return action_number(node);
 
-	} else if (strcmp(node->name, "input") == 0) {
-		return action_input(node);
+	} else if (strcmp(node->name, "create") == 0) {
+		return action_create(node);
 
 	} else if (strcmp(node->name, "times") == 0) {
 		return action_times(node);
@@ -81,11 +81,19 @@
 }
 
 
-unsigned char action_input(struct Node* node) {
+unsigned char action_create(struct Node* node) {
 	int input;
-	printf("input: ");
-	scanf("%d", &input);
-	input = input % 256;
+
+	if (node->down == NULL) {
+		/* user input */
+		printf("input: ");
+		scanf("%d", &input);
+		input = input % 256;
+	} else {
+		/* return value */
+		input = action(node->down);
+	}
+
 	insertLast(node, newNode("number", (char) input));
 	return 0;
 }