diff baum.c @ 26:f0856c177403

removed obsolete stuff; only relevant stuff is extern now; refactoring
author meillo@marmaro.de
date Tue, 19 Feb 2008 22:23:37 +0100
parents e2048e569891
children 1c3dd1e88bdf
line wrap: on
line diff
--- a/baum.c	Wed Feb 13 22:04:50 2008 +0100
+++ b/baum.c	Tue Feb 19 22:23:37 2008 +0100
@@ -23,6 +23,13 @@
 struct Stackitem* stack = NULL;
 
 
+void printNode(struct Node* node);
+void printTree(struct Node* root);
+struct Node* lastNode(struct Node* node);
+void delete(struct Node* node);
+
+
+
 void logit(char* text) {
 	if (option_verbose) {
 		fprintf(stderr, "[%s]\n", text);
@@ -42,14 +49,6 @@
 }
 
 
-void setValue(struct Node* node, unsigned char value) {
-	node->value = value;
-}
-
-
-struct Node* nextNode(struct Node* node) {
-	return node->right;
-}
 
 struct Node* lastNode(struct Node* node) {
 	while (node->right != NULL) {
@@ -64,17 +63,19 @@
 	return insert;
 }
 
+
 /* delete */
 void delete(struct Node* node) {
-	if (node != NULL) {
-		if (node->down != NULL) {
-			delete(node->down);
-		}
-		if (node->right != NULL) {
-			delete(node->right);
-		}
-		free(node); node=0;
+	if (node == NULL) {
+		return;
 	}
+	if (node->down != NULL) {
+		delete(node->down);
+	}
+	if (node->right != NULL) {
+		delete(node->right);
+	}
+	free(node); node=0;
 }
 
 
@@ -86,34 +87,30 @@
 }
 
 void printTree(struct Node* root) {
-	if (root != NULL) {
-		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");
-		}
+	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");
 	}
 }
 
 
 
-/* traverse */
-void traverse(struct Node* root) {
-	/* each node controlls the nodes below itself */
-	action(root);
-}
 
 
-
-
+/* read tree stack */
 void push(struct Node* node) {
 	struct Stackitem* tmp;
 	struct Stackitem* new;
@@ -177,12 +174,13 @@
 				/* create node */
 				node = newNode((char*) name, value);
 				if (indent > last_indent) { /* down */
+					/* FIXME if it goes more than one level down -> error */
 					last_node->down = node;
 					push(last_node);
 				} else if (indent == last_indent) { /* right */
 					last_node->right = node;
 				} else if (indent < last_indent) { /* up */
-					/* FIXME what if it goes more than one level up? */
+					/* FIXME handle if it goes more than one level up */
 					last_node = pull();
 					last_node->right = node;
 				}
@@ -214,8 +212,9 @@
 	}
 
 	fclose(file);
+}
 
-}
+
 
 /* main */
 int main(int argc, char* argv[]) {
@@ -223,10 +222,12 @@
 	
 	while (--argc > 0 && (*++argv)[0] == '-') {
 		if (strcmp(argv[0], "--version") == 0) {
-			printf("baum %s\n\
+			printf("\
+baum %s\n\
 an esoteric programming language\n\
 by markus schnalke and julian forster\n\
-http://prog.marmaro.de/baum\n", VERSION);
+http://prog.marmaro.de/baum\n\
+", VERSION);
 			exit(0);
 		} else if (strcmp(argv[0], "--help") == 0) {
 			printf("\
@@ -234,7 +235,7 @@
 baum --help           print this output\n\
 baum [-v] -c <file>   (verbosly) check file and return 1 if invalid\n\
 baum [-v] <file>      (verbosly) run file\n\
-					");
+");
 			exit(0);
 		} else if (strcmp(argv[0], "-c") == 0) {
 			option_check = 1;