annotate baum.c @ 6:ab87b154a96b

first tries for the read input function
author meillo@marmaro.de
date Fri, 08 Feb 2008 21:44:07 +0100
parents c202ccccedb5
children 6a6152cf63f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
1 /*
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
2 * baum - an esoteric programming language
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
3 *
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
4 * (c) markus schnalke <meillo@marmaro.de>
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
5 * and julian forster
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
6 *
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
7 */
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
8
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
9
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
10 #include <stdio.h>
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
11 #include <stdlib.h>
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
12 #include <string.h>
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
13
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
14 #include "baum.h"
2
557fa4df2bcd added difference between char and number
meillo@marmaro.de
parents: 1
diff changeset
15 #include "actions.h"
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
16
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
17
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
18 struct Node* root = 0;
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
19
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
20
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
21 void logit(char* text) {
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
22 fprintf(stderr, "[%s]\n", text);
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
23 }
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
24
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
25
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
26 /* new */
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
27 struct Node* newNode(char* name, unsigned char value) {
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
28 struct Node* node;
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
29 node = (struct Node*) malloc(sizeof(struct Node));
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
30 node->name = name;
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
31 node->value = value;
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
32 node->right = 0;
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
33 node->down = 0;
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
34 return node;
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
35 }
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
36
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
37
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
38 void setValue(struct Node* node, unsigned char value) {
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
39 node->value = value;
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
40 }
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
41
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
42
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
43 struct Node* nextNode(struct Node* node) {
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
44 return node->right;
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
45 }
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
46
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
47 struct Node* lastNode(struct Node* node) {
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
48 while (node->right != NULL) {
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
49 node = node->right;
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
50 }
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
51 return node;
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
52 }
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
53
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
54 void insertLast(struct Node* node, struct Node* insert) {
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
55 node = lastNode(node);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
56 node->right = insert;
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
57 }
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
58
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
59 /* delete */
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
60 void delete(struct Node* node) {
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
61 if (node != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
62 if (node->down != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
63 delete(node->down);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
64 }
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
65 if (node->right != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
66 delete(node->right);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
67 }
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
68 free(node); node=0;
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
69 }
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
70 }
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
71
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
72
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
73 /* print */
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
74 void printNode(struct Node* node) {
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
75 if (node != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
76 fprintf(stderr, "Node: %20s (%d|%c)\n", node->name, node->value, node->value);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
77 }
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
78 }
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
79
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
80 void printTree(struct Node* root) {
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
81 if (root != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
82 printNode(root);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
83 fprintf(stderr, " down: ");
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
84 if (root->down != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
85 printTree(root->down);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
86 } else {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
87 fprintf(stderr, "NULL\n");
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
88 }
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
89 fprintf(stderr, " right: ");
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
90 if (root->right != NULL) {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
91 printTree(root->right);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
92 } else {
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
93 fprintf(stderr, "NULL\n");
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
94 }
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
95 }
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
96 }
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
97
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
98
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
99
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
100 /* traverse */
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
101 void traverse(struct Node* root) {
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
102 /* each node controlls the nodes below itself */
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
103 action(root);
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
104 }
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
105
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
106 /* init */
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
107 void init() {
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
108 /* add some numbers
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
109 root = newNode("print", 'n');
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
110 root->down = newNode("sum", 0);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
111
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
112 root->down->down = newNode("number", 60);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
113
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
114 root->down->down->right = newNode("number", 50);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
115
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
116 root->down->down->right->right = newNode("sum", 0);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
117 root->down->down->right->right->down = newNode("number", 1);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
118 root->down->down->right->right->down->right = newNode("number", 5);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
119 */
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
120
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
121 /* input numbers and add them
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
122 root = newNode("print", 'n');
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
123 root->down = newNode("sum", 0);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
124 root->down->down = newNode("input", 0);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
125 root->down->down->right = newNode("input", 0);
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
126 root->down->down->right->right = newNode("input", 0);
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
127 */
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
128
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
129 /* prints HelloWorld
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
130 */
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
131 struct Node* np = 0;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
132
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
133 root = newNode("blackhole", 0);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
134 root->down = newNode("sum", 0);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
135 root->down->down = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
136 np = root->down->down;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
137 np->down = newNode("number", 'H');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
138
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
139 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
140 np->right->down = newNode("number", 'e');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
141 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
142
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
143 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
144 np->right->down = newNode("number", 'l');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
145 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
146
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
147 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
148 np->right->down = newNode("number", 'l');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
149 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
150
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
151 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
152 np->right->down = newNode("number", 'o');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
153 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
154
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
155 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
156 np->right->down = newNode("number", ' ');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
157 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
158
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
159 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
160 np->right->down = newNode("number", 'L');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
161 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
162
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
163 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
164 np->right->down = newNode("number", 'y');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
165 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
166
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
167 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
168 np->right->down = newNode("number", 'd');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
169 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
170
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
171 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
172 np->right->down = newNode("number", 'i');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
173 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
174
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
175 np->right = newNode("print", 'c');
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
176 np->right->down = newNode("number", 10);
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
177 np = np->right;
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
178
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
179
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
180 }
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
181
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
182
6
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
183 /* read input */
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
184 void read_input(char* filename) {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
185 FILE* fp;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
186 char c;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
187 char* line;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
188 int indent;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
189 char* name;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
190 int value;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
191
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
192 fp = fopen(filename, "r");
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
193 indent = 0;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
194
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
195 while ((c = getc(fp)) != EOF) {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
196 if (c == ' ' || c == '\t') {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
197 indent++;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
198 } else if (c == '(') {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
199 fscanf(fp, "%d", &value);
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
200 } else if (c == '\n') {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
201
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
202 if (strcmp(name, "") != 0) {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
203 printf("\nindent: %d\nname: %s\nvalue: %d\n", indent, name, value);
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
204 }
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
205 indent = 0;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
206 strcpy(name, "");
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
207 value = 0;
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
208 } else {
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
209 fscanf(fp, "%[a-z]", name);
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
210 }
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
211 }
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
212 }
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
213
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
214 /* main */
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
215 int main(int argc, char* argv[]) {
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
216 unsigned char shell_return;
6
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
217 /*
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
218 init();
4
24a697f37e7c trivial output improvement
meillo@marmaro.de
parents: 3
diff changeset
219
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
220 printTree(root);
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
221 fprintf(stderr, "\n\n");
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
222
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
223 shell_return = action(root);
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
224
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
225 fprintf(stderr, "\n\n");
3
15d7d6b9766f added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents: 2
diff changeset
226 printTree(root);
4
24a697f37e7c trivial output improvement
meillo@marmaro.de
parents: 3
diff changeset
227
1
3da0ff17c8e7 added features (print, sum, number); split in header file
meillo@marmaro.de
parents: 0
diff changeset
228 delete(root);
6
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
229 */
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
230
6
ab87b154a96b first tries for the read input function
meillo@marmaro.de
parents: 5
diff changeset
231 read_input("./input_addition");
5
c202ccccedb5 added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents: 4
diff changeset
232 exit(shell_return);
0
2f71d692d4f9 initial commit
meillo@marmaro.de
parents:
diff changeset
233 }