comparison baum.c @ 34:e986c6abed2b

eliminated generic blackhole node at root
author meillo@marmaro.de
date Sat, 01 Mar 2008 17:45:55 +0100
parents 2e564bf8599c
children 29172b6e802a
comparison
equal deleted inserted replaced
33:2e564bf8599c 34:e986c6abed2b
136 136
137 indent = 0; 137 indent = 0;
138 strcpy(name, ""); 138 strcpy(name, "");
139 value = 0; 139 value = 0;
140 last_indent = -1; 140 last_indent = -1;
141 root = newNode("blackhole", 0); 141 last_node = NULL;
142 last_node = root;
143 file = fopen(filename, "r"); 142 file = fopen(filename, "r");
144 143
145 while ((c = getc(file)) != EOF) { 144 while ((c = getc(file)) != EOF) {
146 if (c == '#') { /* comment */ 145 if (c == '#') { /* comment */
147 while ((c = getc(file)) != '\n') { 146 while ((c = getc(file)) != '\n') {
165 /* if it goes more than one level down -> error */ 164 /* if it goes more than one level down -> error */
166 if (indent > last_indent + 1) { 165 if (indent > last_indent + 1) {
167 fprintf(stderr, "error: Indention over more than one level. Only indent by one!\n"); 166 fprintf(stderr, "error: Indention over more than one level. Only indent by one!\n");
168 exit(5); 167 exit(5);
169 } 168 }
170 last_node->down = node; 169 if (last_node == NULL) {
170 root = node;
171 last_node = root;
172 } else {
173 last_node->down = node;
174 }
171 push(last_node); 175 push(last_node);
172 } else if (indent == last_indent) { /* right */ 176 } else if (indent == last_indent) { /* right */
173 last_node->right = node; 177 last_node->right = node;
174 } else if (indent < last_indent) { /* up */ 178 } else if (indent < last_indent) { /* up */
175 /* handle if it goes more than one level up */ 179 /* handle if it goes more than one level up */
261 if (option_verbose) { 265 if (option_verbose) {
262 printTree(root, 0); 266 printTree(root, 0);
263 } 267 }
264 268
265 shell_return = action(root); 269 shell_return = action(root);
270 fflush(stdout);
266 271
267 if (option_verbose) { 272 if (option_verbose) {
268 printTree(root, 0); 273 printTree(root, 0);
269 } 274 }
270 275