baum
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 diff
1.1 --- a/actions.c Sun Mar 02 15:54:35 2008 +0100 1.2 +++ b/actions.c Sun Mar 02 16:17:18 2008 +0100 1.3 @@ -6,7 +6,7 @@ 1.4 unsigned char action_print(struct Node* node); 1.5 unsigned char action_sum(struct Node* node); 1.6 unsigned char action_number(struct Node* node); 1.7 -unsigned char action_input(struct Node* node); 1.8 +unsigned char action_create(struct Node* node); 1.9 unsigned char action_times(struct Node* node); 1.10 unsigned char action_if(struct Node* node); 1.11 unsigned char action_while(struct Node* node); 1.12 @@ -30,8 +30,8 @@ 1.13 } else if (strcmp(node->name, "number") == 0) { 1.14 return action_number(node); 1.15 1.16 - } else if (strcmp(node->name, "input") == 0) { 1.17 - return action_input(node); 1.18 + } else if (strcmp(node->name, "create") == 0) { 1.19 + return action_create(node); 1.20 1.21 } else if (strcmp(node->name, "times") == 0) { 1.22 return action_times(node); 1.23 @@ -81,11 +81,19 @@ 1.24 } 1.25 1.26 1.27 -unsigned char action_input(struct Node* node) { 1.28 +unsigned char action_create(struct Node* node) { 1.29 int input; 1.30 - printf("input: "); 1.31 - scanf("%d", &input); 1.32 - input = input % 256; 1.33 + 1.34 + if (node->down == NULL) { 1.35 + /* user input */ 1.36 + printf("input: "); 1.37 + scanf("%d", &input); 1.38 + input = input % 256; 1.39 + } else { 1.40 + /* return value */ 1.41 + input = action(node->down); 1.42 + } 1.43 + 1.44 insertLast(node, newNode("number", (char) input)); 1.45 return 0; 1.46 }