# HG changeset patch # User meillo@marmaro.de # Date 1202557331 -3600 # Node ID 495a56e706dc2cbca6a495fc1d48d4e090bed49a # Parent 6a6152cf63f731588f10912d9421464e681e11be input is now read from stdin diff -r 6a6152cf63f7 -r 495a56e706dc baum.c --- a/baum.c Sat Feb 09 11:57:16 2008 +0100 +++ b/baum.c Sat Feb 09 12:42:11 2008 +0100 @@ -181,59 +181,57 @@ /* read input */ -void read_input(char* filename) { - FILE* file; +void read_input() { int c; - char* cp; - int indent = 0; + int indent; char name[256]; int value; - file = fopen(filename, "r"); + indent = 0; + strcpy(name, ""); + value = 0; - - while ((c = getc(file)) != EOF) { - if (c == '#') { - printf("c\n"); - while ((c = getc(file)) != '\n') { + while ((c = getchar()) != EOF) { + if (c == '#') { /* comment */ + while ((c = getchar()) != '\n') { } } - if (c == ' ' || c == '\t') { - indent++; + if (c == ' ' || c == '\t') { /* indent if at start of line */ + if (strlen(name) == 0) { + indent++; + } } - if (c == '\n') { + if (c == '\n') { /* end of line: create node */ if (strlen(name) > 0) { printf(" %d - %s - %d\n", indent, name, value); - /* - */ - } else { - printf("comment\n"); + /* create node */ } indent = 0; strcpy(name, ""); value = 0; } - if (c >= 'a' && c <= 'z') { + if (c >= 'a' && c <= 'z') { /* name */ int i = 1; name[0] = (char) c; - while ((c = getc(file)) != '(') { - /*putc(c, stdout);*/ + while ((c = getchar()) != '(') { name[i] = (char) c; i++; + if (i > 255) { + break; + } } name[i] = '\0'; } - if (c == '(') { - fscanf(file, "%d)", &value); + if (c == '(') { /* value */ + scanf("%d)", &value); } } - fclose(file); } /* main */ @@ -253,6 +251,6 @@ delete(root); */ - read_input("./input_addition"); + read_input(); exit(shell_return); }