Mercurial > baum
changeset 13:bf660b45bba9
added commandline options (-v, -c, file); logging only if -v is set
author | meillo@marmaro.de |
---|---|
date | Wed, 13 Feb 2008 09:13:02 +0100 |
parents | 8e34daa80f64 |
children | 15e11eea1c66 |
files | baum.c |
diffstat | 1 files changed, 55 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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 <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; + } 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); }