# HG changeset patch # User meillo@marmaro.de # Date 1202890382 -3600 # Node ID bf660b45bba99190c3ec34d69769ec0774a69a8c # Parent 8e34daa80f64d2b23c82c95be83a809333c8e46f added commandline options (-v, -c, file); logging only if -v is set diff -r 8e34daa80f64 -r bf660b45bba9 baum.c --- a/baum.c Tue Feb 12 15:53:08 2008 +0100 +++ b/baum.c Wed Feb 13 09:13:02 2008 +0100 @@ -14,13 +14,19 @@ #include "baum.h" #include "actions.h" +#define VERSION "0.1" + +int option_check = 0; +int option_verbose = 0; struct Node* root = 0; struct Stackitem* stack = NULL; void logit(char* text) { - fprintf(stderr, "[%s]\n", text); + if (option_verbose) { + fprintf(stderr, "[%s]\n", text); + } } @@ -164,7 +170,9 @@ if (c == '\n') { /* end of line: create node */ if (strlen(name) > 0) { - fprintf(stderr, " %d - %s - %d\n", indent, name, value); + if (option_verbose) { + fprintf(stderr, " %d - %s - %d\n", indent, name, value); + } /* create node */ node = newNode((char*) name, value); if (indent > last_indent) { /* down */ @@ -212,13 +220,54 @@ int main(int argc, char* argv[]) { unsigned char shell_return = 0; - read_input("./input_sum3input"); - printTree(root); + while (--argc > 0 && (*++argv)[0] == '-') { + if (strcmp(argv[0], "--version") == 0) { + printf("baum %s\n\ +an esoteric programming language\n\ +by markus schnalke and julian forster\n\ +http://prog.marmaro.de/baum\n", VERSION); + exit(0); + } else if (strcmp(argv[0], "--help") == 0) { + printf("\ +baum --version print version information and exit\n\ +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; + } else if (strcmp(argv[0], "-v") == 0) { + option_verbose = 1; + /* + } else if (strcmp(argv[0], "-W") == 0) { + / * TODO: catch if no value given * / + iDWarn = atoi((++argv)[0]); + argc--; + */ + } else { + fprintf(stderr, "unknown option: %s\n", argv[0]); + exit(127); + } + } + + if (argc != 1) { + fprintf(stderr, "%d source files given, please specify one.\n", argc); + exit(3); + } + + read_input(argv[0]); + + if (option_verbose) { + printTree(root); + } shell_return = action(root); - printTree(root); + if (option_verbose) { + printTree(root); + } + delete(root); - exit(shell_return); }