# HG changeset patch # User meillo@marmaro.de # Date 1204389419 -3600 # Node ID 2e564bf8599c9b791596960d0feb5f3a8326cff4 # Parent 3903effae5efcba191a6b459da457a3cff897c22 new error code 6; more readable printTree; cleanups diff -r 3903effae5ef -r 2e564bf8599c baum.1 --- a/baum.1 Fri Feb 22 15:58:25 2008 +0100 +++ b/baum.1 Sat Mar 01 17:36:59 2008 +0100 @@ -90,6 +90,10 @@ indention over more than one level .TP +.BI 6 +node name too long, or no value given + +.TP .BI 127 invalid command line options diff -r 3903effae5ef -r 2e564bf8599c baum.c --- a/baum.c Fri Feb 22 15:58:25 2008 +0100 +++ b/baum.c Sat Mar 01 17:36:59 2008 +0100 @@ -23,8 +23,8 @@ struct Stackitem* stack = NULL; -void printNode(struct Node* node); -void printTree(struct Node* root); +void printNode(struct Node* node, int level); +void printTree(struct Node* root, int level); struct Node* lastNode(struct Node* node); void delete(struct Node* node); @@ -69,41 +69,29 @@ if (node == NULL) { return; } - if (node->down != NULL) { - delete(node->down); - } - if (node->right != NULL) { - delete(node->right); - } + delete(node->down); + delete(node->right); free(node); node=0; } /* print */ -void printNode(struct Node* node) { +void printNode(struct Node* node, int level) { if (node != NULL) { - fprintf(stderr, "Node: %10s (%d|%c)\n", node->name, node->value, node->value); + while (level-- > 0) { + fprintf(stderr, "\t"); + } + fprintf(stderr, "%s (%d|%c)\n", node->name, node->value, node->value); } } -void printTree(struct Node* root) { +void printTree(struct Node* root, int level) { if (root == NULL) { return; } - - printNode(root); - fprintf(stderr, " down: "); - if (root->down != NULL) { - printTree(root->down); - } else { - fprintf(stderr, "NULL\n"); - } - fprintf(stderr, " right: "); - if (root->right != NULL) { - printTree(root->right); - } else { - fprintf(stderr, "NULL\n"); - } + printNode(root, level); + printTree(root->down, level+1); + printTree(root->right, level); } @@ -175,7 +163,7 @@ node = newNode((char*) name, value); if (indent > last_indent) { /* down */ /* if it goes more than one level down -> error */ - if (indent - last_indent > 1) { + if (indent > last_indent + 1) { fprintf(stderr, "error: Indention over more than one level. Only indent by one!\n"); exit(5); } @@ -206,7 +194,8 @@ name[i] = (char) c; i++; if (i > 255) { - break; + fprintf(stderr, "error: node name too long, or no value given\n"); + exit(6); } } name[i] = '\0'; @@ -270,13 +259,13 @@ read_input(argv[0]); if (option_verbose) { - printTree(root); + printTree(root, 0); } shell_return = action(root); if (option_verbose) { - printTree(root); + printTree(root, 0); } delete(root);