comparison baum.c @ 30:cd979b979610

fixed multiple (un)indentions in read_input; some better comments
author meillo@marmaro.de
date Fri, 22 Feb 2008 14:47:47 +0100
parents 88a51653db83
children 4e60d96265f0
comparison
equal deleted inserted replaced
29:88a51653db83 30:cd979b979610
13 13
14 #include "baum.h" 14 #include "baum.h"
15 #include "actions.h" 15 #include "actions.h"
16 16
17 #define VERSION "0.2" 17 #define VERSION "0.2"
18
18 19
19 int option_check = 0; 20 int option_check = 0;
20 int option_verbose = 0; 21 int option_verbose = 0;
21 22
22 struct Node* root = 0; 23 struct Node* root = 0;
108 109
109 110
110 111
111 112
112 113
113 /* read tree stack */ 114 /* stack for read_input */
114 void push(struct Node* node) { 115 void push(struct Node* node) {
115 struct Stackitem* tmp; 116 struct Stackitem* tmp;
116 struct Stackitem* new; 117 struct Stackitem* new;
117 new = (struct Stackitem*) malloc(sizeof(struct Stackitem)); 118 new = (struct Stackitem*) malloc(sizeof(struct Stackitem));
118 new->node = node; 119 new->node = node;
172 fprintf(stderr, " %d - %s - %d\n", indent, name, value); 173 fprintf(stderr, " %d - %s - %d\n", indent, name, value);
173 } 174 }
174 /* create node */ 175 /* create node */
175 node = newNode((char*) name, value); 176 node = newNode((char*) name, value);
176 if (indent > last_indent) { /* down */ 177 if (indent > last_indent) { /* down */
177 /* FIXME if it goes more than one level down -> error */ 178 /* if it goes more than one level down -> error */
179 if (indent - last_indent > 1) {
180 fprintf(stderr, "error: Indention over more than one level. Only indent by one!\n");
181 exit(50);
182 }
178 last_node->down = node; 183 last_node->down = node;
179 push(last_node); 184 push(last_node);
180 } else if (indent == last_indent) { /* right */ 185 } else if (indent == last_indent) { /* right */
181 last_node->right = node; 186 last_node->right = node;
182 } else if (indent < last_indent) { /* up */ 187 } else if (indent < last_indent) { /* up */
183 /* FIXME handle if it goes more than one level up */ 188 /* handle if it goes more than one level up */
184 last_node = pull(); 189 while (indent < last_indent) {
190 last_node = pull();
191 last_indent--;
192 }
185 last_node->right = node; 193 last_node->right = node;
186 } 194 }
187 last_indent = indent; 195 last_indent = indent;
188 last_node = node; 196 last_node = node;
189 } 197 }
209 fscanf(file, "%d)", &value); 217 fscanf(file, "%d)", &value);
210 } 218 }
211 219
212 } 220 }
213 221
214 /* empty stack */ 222 /* clear stack */
215 while (stack != NULL) { 223 while (stack != NULL) {
216 pull(); 224 pull();
217 } 225 }
218 226
219 fclose(file); 227 fclose(file);