baum
diff 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 |
line diff
1.1 --- a/baum.c Fri Feb 22 13:55:57 2008 +0100 1.2 +++ b/baum.c Fri Feb 22 14:47:47 2008 +0100 1.3 @@ -16,6 +16,7 @@ 1.4 1.5 #define VERSION "0.2" 1.6 1.7 + 1.8 int option_check = 0; 1.9 int option_verbose = 0; 1.10 1.11 @@ -110,7 +111,7 @@ 1.12 1.13 1.14 1.15 -/* read tree stack */ 1.16 +/* stack for read_input */ 1.17 void push(struct Node* node) { 1.18 struct Stackitem* tmp; 1.19 struct Stackitem* new; 1.20 @@ -174,14 +175,21 @@ 1.21 /* create node */ 1.22 node = newNode((char*) name, value); 1.23 if (indent > last_indent) { /* down */ 1.24 - /* FIXME if it goes more than one level down -> error */ 1.25 + /* if it goes more than one level down -> error */ 1.26 + if (indent - last_indent > 1) { 1.27 + fprintf(stderr, "error: Indention over more than one level. Only indent by one!\n"); 1.28 + exit(50); 1.29 + } 1.30 last_node->down = node; 1.31 push(last_node); 1.32 } else if (indent == last_indent) { /* right */ 1.33 last_node->right = node; 1.34 } else if (indent < last_indent) { /* up */ 1.35 - /* FIXME handle if it goes more than one level up */ 1.36 - last_node = pull(); 1.37 + /* handle if it goes more than one level up */ 1.38 + while (indent < last_indent) { 1.39 + last_node = pull(); 1.40 + last_indent--; 1.41 + } 1.42 last_node->right = node; 1.43 } 1.44 last_indent = indent; 1.45 @@ -211,7 +219,7 @@ 1.46 1.47 } 1.48 1.49 - /* empty stack */ 1.50 + /* clear stack */ 1.51 while (stack != NULL) { 1.52 pull(); 1.53 }