# HG changeset patch # User meillo@marmaro.de # Date 1203456217 -3600 # Node ID f0856c177403e99ae313af440a640997e059b278 # Parent 6f2c1f9dc08fe72203a40e5b7a28d92c72531f33 removed obsolete stuff; only relevant stuff is extern now; refactoring diff -r 6f2c1f9dc08f -r f0856c177403 actions.c --- a/actions.c Wed Feb 13 22:04:50 2008 +0100 +++ b/actions.c Tue Feb 19 22:23:37 2008 +0100 @@ -4,6 +4,14 @@ #include "baum.h" #include "actions.h" +unsigned char action_print(struct Node* node); +unsigned char action_sum(struct Node* node); +unsigned char action_number(struct Node* node); +unsigned char action_input(struct Node* node); +unsigned char action_times(struct Node* node); +unsigned char action_blackhole(struct Node* node); + + unsigned char action(struct Node* node) { if (node == NULL) { @@ -11,28 +19,24 @@ return 0; } + logit(node->name); + if (strcmp(node->name, "print") == 0) { - logit("print-node"); return action_print(node); } else if (strcmp(node->name, "sum") == 0) { - logit("sum-node"); return action_sum(node); } else if (strcmp(node->name, "number") == 0) { - logit("number-node"); return action_number(node); } else if (strcmp(node->name, "input") == 0) { - logit("input-node"); return action_input(node); } else if (strcmp(node->name, "times") == 0) { - logit("times-node"); return action_times(node); } else if (strcmp(node->name, "blackhole") == 0) { - logit("blackhole-node"); return action_blackhole(node); } else { diff -r 6f2c1f9dc08f -r f0856c177403 actions.h --- a/actions.h Wed Feb 13 22:04:50 2008 +0100 +++ b/actions.h Tue Feb 19 22:23:37 2008 +0100 @@ -1,10 +1,1 @@ - unsigned char action(struct Node* node); - -unsigned char action_print(struct Node* node); -unsigned char action_sum(struct Node* node); -unsigned char action_number(struct Node* node); -unsigned char action_input(struct Node* node); -unsigned char action_times(struct Node* node); -unsigned char action_blackhole(struct Node* node); - diff -r 6f2c1f9dc08f -r f0856c177403 baum.c --- 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 (verbosly) check file and return 1 if invalid\n\ baum [-v] (verbosly) run file\n\ - "); +"); exit(0); } else if (strcmp(argv[0], "-c") == 0) { option_check = 1; diff -r 6f2c1f9dc08f -r f0856c177403 baum.h --- a/baum.h Wed Feb 13 22:04:50 2008 +0100 +++ b/baum.h Tue Feb 19 22:23:37 2008 +0100 @@ -2,17 +2,10 @@ void logit(char* text); struct Node* newNode(char* name, unsigned char value); -void setValue(struct Node* node, unsigned char value); -void delete(struct Node* node); -void printNode(struct Node* node); -void printTree(struct Node* root); -void traverse(struct Node* root); - -struct Node* nextNode(struct Node* node); -struct Node* lastNode(struct Node* node); struct Node* insertLast(struct Node* node, struct Node* insert); +/* structs */ struct Node { char name[256]; unsigned char value; @@ -20,7 +13,6 @@ struct Node* right; }; - struct Stackitem { struct Node* node; struct Stackitem* next;